Package ghidra.util.classfinder

# Class ClassSearcher

java.lang.Object
ghidra.util.classfinder.ClassSearcher

public class ClassSearcher extends Object
This class is a collection of static methods used to discover classes that implement a particular interface or extend a particular base class.

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

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `SEARCH_ALL_JARS_PROPERTY`
  This provides a means for custom apps that do not use a module structure to search all jars

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `addChangeListener(ChangeListener l)`
  Add a change listener that will be notified when the classpath is searched for new classes.
  `static <T> List<Class<? extends T>>`
  `getClasses(Class<T> ancestorClass)`
  Get `priority-sorted` classes that implement or derive from the given ancestor class
  `static <T> List<Class<? extends T>>`
  `getClasses(Class<T> ancestorClass, Predicate<Class<? extends T>> classFilter)`
  Get `priority-sorted` classes that implement or derive from the given ancestor class
  `static Set<ClassFileInfo>`
  `getExtensionPointInfo()`
  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>`
  `getFalsePositives()`
  Gets class information about discovered potential extension points that end up not getting loaded.
  `static <T> List<T>`
  `getInstances(Class<T> c)`
  Gets all `priority-sorted` class instances that implement or derive from the given filter class
  `static <T> List<T>`
  `getInstances(Class<T> c, ClassFilter filter)`
  Get `priority-sorted` classes instances that implement or derive from the given filter class and pass the given filter predicate
  `static Set<ClassFileInfo>`
  `getLoaded()`
  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`
  `logStatistics()`
  Writes the current class searcher statistics to the info log
  `static void`
  `removeChangeListener(ChangeListener l)`
  Remove the change listener
  `static void`
  `search(TaskMonitor monitor)`
  Searches the classpath and updates the list of available classes which satisfies the internal class filter.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### SEARCH_ALL_JARS_PROPERTY

    public static final String SEARCH_ALL_JARS_PROPERTY
    This provides a means for custom apps that do not use a module structure to search all jars
    See Also:
      - Constant Field Values

- ## Method Details

  - ### search

    public static void search(TaskMonitor monitor) throws CancelledException
    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

    public static <T> List<Class<? extends T>> getClasses(Class<T> ancestorClass)
    Get `priority-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)
    Get `priority-sorted` classes that implement or derive from the given ancestor class
    Parameters:
      `ancestorClass` - the ancestor class
      `classFilter` - 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

    public static <T> List<T> getInstances(Class<T> c)
    Gets all `priority-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

    public static <T> List<T> getInstances(Class<T> c, ClassFilter filter)
    Get `priority-sorted` classes instances that implement or derive from the given filter class and pass the given filter predicate
    Parameters:
      `c` - the filter class
      `filter` - 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

    public static void addChangeListener(ChangeListener l)
    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

    public static void removeChangeListener(ChangeListener l)
    Remove the change listener
    Parameters:
      `l` - the listener to remove

  - ### getExtensionPointInfo

    public static Set<ClassFileInfo> 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

    public static Set<ClassFileInfo> 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

    public static Set<ClassFileInfo> 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

    public static String getExtensionPointSuffix(String className)
    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

    public static boolean isClassOfInterest(Class<?> c)
    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