Class ClassSearcher


  • public class ClassSearcher
    extends java.lang.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
     
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static void addChangeListener​(javax.swing.event.ChangeListener l)
      Add a change listener that will be notified when the classpath is searched for new classes.
      static <T> java.util.List<java.lang.Class<? extends T>> getClasses​(java.lang.Class<T> c)
      Get priority-sorted classes that implement or derive from the given class
      static <T> java.util.List<java.lang.Class<? extends T>> getClasses​(java.lang.Class<T> c, java.util.function.Predicate<java.lang.Class<? extends T>> classFilter)
      Get priority-sorted classes that implement or derive from the given class
      static <T> java.util.List<T> getInstances​(java.lang.Class<T> c)  
      static <T> java.util.List<T> getInstances​(java.lang.Class<T> c, ClassFilter filter)
      Get priority-sorted classes instances that implement or derive from the given class
      static void removeChangeListener​(javax.swing.event.ChangeListener l)
      Remove the change listener
      static void search​(boolean forceRefresh, TaskMonitor monitor)
      Deprecated, for removal: This API element is subject to removal in a future version.
      static void search​(TaskMonitor monitor)
      Searches the classpath and updates the list of available classes which satisfy the class filter.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • SEARCH_ALL_JARS_PROPERTY

        public static final java.lang.String SEARCH_ALL_JARS_PROPERTY
        See Also:
        Constant Field Values
    • Method Detail

      • getClasses

        public static <T> java.util.List<java.lang.Class<? extends T>> getClasses​(java.lang.Class<T> c)
        Get priority-sorted classes that implement or derive from the given class
        Parameters:
        c - the filter class
        Returns:
        set of classes that implement or extend T
      • getClasses

        public static <T> java.util.List<java.lang.Class<? extends T>> getClasses​(java.lang.Class<T> c,
                                                                                  java.util.function.Predicate<java.lang.Class<? extends T>> classFilter)
        Get priority-sorted classes that implement or derive from the given class
        Parameters:
        c - the filter 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> java.util.List<T> getInstances​(java.lang.Class<T> c)
      • getInstances

        public static <T> java.util.List<T> getInstances​(java.lang.Class<T> c,
                                                         ClassFilter filter)
        Get priority-sorted classes instances that implement or derive from the given class
        Parameters:
        c - the filter class
        filter - 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 instances that implement or extend T and pass the filtering test performed by the predicate
      • addChangeListener

        public static void addChangeListener​(javax.swing.event.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​(javax.swing.event.ChangeListener l)
        Remove the change listener
        Parameters:
        l - the listener to remove
      • search

        @Deprecated(forRemoval=true,
                    since="10.1")
        public static void search​(boolean forceRefresh,
                                  TaskMonitor monitor)
                           throws CancelledException
        Deprecated, for removal: This API element is subject to removal in a future version.
        This deprecated method is now simply a pass-through for search(TaskMonitor).
        Parameters:
        forceRefresh - ignored
        monitor - the task monitor
        Throws:
        CancelledException - if cancelled
      • search

        public static void search​(TaskMonitor monitor)
                           throws CancelledException
        Searches the classpath and updates the list of available classes which satisfy the class filter. Classes which data types, and language providers. When the search completes and was not cancelled, the change listeners are notified.
        Parameters:
        monitor - the progress monitor for the search.
        Throws:
        CancelledException - if the operation is cancelled