Class ClassSearcher
Warning: Using the search feature of this class will trigger other classes to be loaded. Thus, clients should not make calls to this class inside of static initializer blocks
Note: if your application is not using a module structure for its release build, then your application must create the following file, with the required entries, in order to find extension points:
<install dir>/data/ExtensionPoint.manifest
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
This provides a means for custom apps that do not use a module structure to search all jars -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Add a change listener that will be notified when the classpath is searched for new classes.getClasses
(Class<T> ancestorClass) Getpriority-sorted
classes that implement or derive from the given ancestor classgetClasses
(Class<T> ancestorClass, Predicate<Class<? extends T>> classFilter) Getpriority-sorted
classes that implement or derive from the given ancestor classstatic Set
<ClassFileInfo> Gets class information about each discovered potential extension point.static String
getExtensionPointSuffix
(String className) Gets the given class's extension point suffix.static Set
<ClassFileInfo> Gets class information about discovered potential extension points that end up not getting loaded.static <T> List
<T> getInstances
(Class<T> c) Gets allpriority-sorted
class instances that implement or derive from the given filter classstatic <T> List
<T> getInstances
(Class<T> c, ClassFilter filter) Getpriority-sorted
classes instances that implement or derive from the given filter class and pass the given filter predicatestatic Set
<ClassFileInfo> Gets class information about each loaded extension point.static boolean
isClassOfInterest
(Class<?> c) Checks to see if the given class is an extension point of interest.static void
Writes the current class searcher statistics to the info logstatic void
Remove the change listenerstatic void
search
(TaskMonitor monitor) Searches the classpath and updates the list of available classes which satisfies the internal class filter.
-
Field Details
-
SEARCH_ALL_JARS_PROPERTY
This provides a means for custom apps that do not use a module structure to search all jars- See Also:
-
-
Method Details
-
search
Searches the classpath and updates the list of available classes which satisfies the internal class filter. When the search completes (and was not cancelled), any registered change listeners are notified.- Parameters:
monitor
- the progress monitor for the search- Throws:
CancelledException
- if the operation was cancelled
-
getClasses
Getpriority-sorted
classes that implement or derive from the given ancestor class- Parameters:
ancestorClass
- the ancestor class- Returns:
- set of classes that implement or extend T
-
getClasses
public static <T> List<Class<? extends T>> getClasses(Class<T> ancestorClass, Predicate<Class<? extends T>> classFilter) Getpriority-sorted
classes that implement or derive from the given ancestor class- Parameters:
ancestorClass
- the ancestor classclassFilter
- A Predicate that tests class objects (that are already of type T) for further filtering,null
is equivalent to "return true"- Returns:
priority-sorted
list of classes that implement or extend T and pass the filtering test performed by the predicate
-
getInstances
Gets allpriority-sorted
class instances that implement or derive from the given filter class- Parameters:
c
- the filter class- Returns:
priority-sorted
List
of class instances that implement or extend T
-
getInstances
Getpriority-sorted
classes instances that implement or derive from the given filter class and pass the given filter predicate- Parameters:
c
- the filter classfilter
- A filter predicate that tests class objects (that are already of type T).null
is equivalent to "return true".- Returns:
priority-sorted
List
of class instances that implement or extend T and pass the filtering test performed by the predicate
-
addChangeListener
Add a change listener that will be notified when the classpath is searched for new classes.Note: The listener list is implemented using WeakReferences. Therefore, the caller must maintain a handle to the listener being added, or else it will be garbage collected and never called.
- Parameters:
l
- the listener to add
-
removeChangeListener
Remove the change listener- Parameters:
l
- the listener to remove
-
getExtensionPointInfo
Gets class information about each discovered potential extension point.NOTE: A discovered potential extension point may end up not getting loaded if it is not "of interest" (see
isClassOfInterest(Class)
. These are referred to as false positives.- Returns:
- A
Set
of class information about each discovered potential extension point
-
getLoaded
Gets class information about each loaded extension point.NOTE: Ghidra may load more classes as it runs. Therefore, repeated calls to this method may return more results, as more extension points are loaded.
- Returns:
- A
Set
of class information about each loaded extension point
-
getFalsePositives
Gets class information about discovered potential extension points that end up not getting loaded.NOTE: Ghidra may load more classes as it runs. Therefore, repeated calls to this method may return more results, as more potential extension points are identified as false positives.
- Returns:
- A
Set
of class information about each loaded extension point
-
getExtensionPointSuffix
Gets the given class's extension point suffix.Note that if multiple suffixes match, the smallest will be chosen. For a detailed explanation, see the comment inside
loadExtensionPointSuffixes()
.- Parameters:
className
- The name of the potential extension point class- Returns:
- The given class's extension point suffix, or null if it is not an extension point or
search(TaskMonitor)
has not been called yet
-
isClassOfInterest
Checks to see if the given class is an extension point of interest.- Parameters:
c
- The class to check.- Returns:
- True if the given class is an extension point of interest; otherwise, false.
-
logStatistics
public static void logStatistics()Writes the current class searcher statistics to the info log
-