Class ClassInfoList

    • Method Detail

      • loadClasses

        public <T> List<Class<T>> loadClasses​(Class<T> superclassOrInterfaceType,
                                              boolean ignoreExceptions)
        Convert this list of ClassInfo objects to a list of Class<?> objects, casting each item in the list to the requested superclass or interface type. Causes the classloader to load the class named by each ClassInfo object, if it is not already loaded.

        Important note: since superclassOrInterfaceType is a class reference for an already-loaded class, it is critical that superclassOrInterfaceType is loaded by the same classloader as the class referred to by this ClassInfo object, otherwise the class cast will fail.

        Parameters:
        superclassOrInterfaceType - The type to cast each loaded class to.
        ignoreExceptions - If true, ignore any exceptions or errors thrown during classloading, or when attempting to cast the resulting Class<?> reference to the requested type. If an exception or error is thrown, no Class<?> reference is added to the output class for the corresponding ClassInfo object, so the returned list may contain fewer items than this input list. If false, IllegalArgumentException is thrown if the class could not be loaded or cast to the requested type.
        Returns:
        The loaded Class<?> objects corresponding to each ClassInfo object in this list.
        Throws:
        IllegalArgumentException - if ignoreExceptions is false and an exception or error was thrown while trying to load or cast any of the classes.
      • loadClasses

        public <T> List<Class<T>> loadClasses​(Class<T> superclassOrInterfaceType)
        Convert this list of ClassInfo objects to a list of Class<?> objects, casting each item in the list to the requested superclass or interface type. Causes the classloader to load the class named by each ClassInfo object, if it is not already loaded.

        Important note: since superclassOrInterfaceType is a class reference for an already-loaded class, it is critical that superclassOrInterfaceType is loaded by the same classloader as the class referred to by this ClassInfo object, otherwise the class cast will fail.

        Parameters:
        superclassOrInterfaceType - The type to cast each loaded class to.
        Returns:
        The loaded Class<?> objects corresponding to each ClassInfo object in this list.
        Throws:
        IllegalArgumentException - if an exception or error was thrown while trying to load or cast any of the classes.
      • loadClasses

        public List<Class<?>> loadClasses​(boolean ignoreExceptions)
        Convert this list of ClassInfo objects to a list of Class<?> objects. Causes the classloader to load the class named by each ClassInfo object, if it is not already loaded.
        Parameters:
        ignoreExceptions - If true, ignore any exceptions or errors thrown during classloading. If an exception or error is thrown during classloading, no Class<?> reference is added to the output class for the corresponding ClassInfo object, so the returned list may contain fewer items than this input list. If false, IllegalArgumentException is thrown if the class could not be loaded.
        Returns:
        The loaded Class<?> objects corresponding to each ClassInfo object in this list.
        Throws:
        IllegalArgumentException - if ignoreExceptions is false and an exception or error was thrown while trying to load any of the classes.
      • loadClasses

        public List<Class<?>> loadClasses()
        Convert this list of ClassInfo objects to a list of Class<?> objects. Causes the classloader to load the class named by each ClassInfo object, if it is not already loaded.
        Returns:
        The loaded Class<?> objects corresponding to each ClassInfo object in this list.
        Throws:
        IllegalArgumentException - if an exception or error was thrown while trying to load any of the classes.
      • getNames

        public List<String> getNames()
        Get the names of all classes in this list.
      • getAsStrings

        public List<String> getAsStrings()
        Get the string representations of all classes in this list (with annotations, modifiers, etc.), by calling ClassInfo.toString() on each item in the list.
      • containsName

        public boolean containsName​(String className)
        Return true if this ClassInfo list contains a class with the given name.
      • get

        public ClassInfo get​(String name)
        Return the ClassInfo object in the list with the given name, or null if not found.
      • directOnly

        public ClassInfoList directOnly()
        Get the list of classes that were directly related, as opposed to reachable through multiple steps. For example, if this ClassInfoList was produced by querying for all superclasses of a given class, then directOnly() will return only the direct superclass of this class.
        Returns:
        The list of directly-related classes.
      • getStandardClasses

        public ClassInfoList getStandardClasses()
        Filter this ClassInfoList to include only standard classes (classes that are not interfaces or annotations).
        Returns:
        The filtered list, containing only standard classes.
      • getInterfacesAndAnnotations

        public ClassInfoList getInterfacesAndAnnotations()
        Filter this ClassInfoList to include only interfaces and annotations (annotations are interfaces, and can be implemented). See also getInterfaces().
        Returns:
        The filtered list, containing only interfaces.
      • getImplementedInterfaces

        public ClassInfoList getImplementedInterfaces()
        Filter this ClassInfoList to include only implemented interfaces, i.e. non-annotation interfaces, or annotations that have been implemented by a class.
        Returns:
        The filtered list, containing only implemented interfaces.
      • getAnnotations

        public ClassInfoList getAnnotations()
        Filter this ClassInfoList to include only annotations.
        Returns:
        The filtered list, containing only annotations.
      • getEnums

        public ClassInfoList getEnums()
        Filter this ClassInfoList to include only Enum classes.
        Returns:
        The filtered list, containing only enums.
      • generateGraphVizDotFile

        public String generateGraphVizDotFile​(float sizeX,
                                              float sizeY,
                                              boolean showFields,
                                              boolean showMethods,
                                              boolean showAnnotations)
        Generate a .dot file which can be fed into GraphViz for layout and visualization of the class graph. The sizeX and sizeY parameters are the image output size to use (in inches) when GraphViz is asked to render the .dot file.

        Note that if you call this with showFields or showMethods set to false, but with method and/or field info enabled during scanning, then arrows will still be added between classes even if the field or method that created that dependency is not shown.

        Parameters:
        sizeX - The GraphViz layout width in inches.
        sizeY - The GraphViz layout width in inches.
        showFields - If true, show fields within class nodes in the graph. To show fields, FastClasspathScanner.enableFieldInfo() must be called before scanning. You may also want to call FastClasspathScanner.ignoreFieldVisibility() before scanning, to show non-public fields.
        showMethods - If true, show methods within class nodes in the graph. To show methods, FastClasspathScanner.enableMethodInfo() must be called before scanning. You may also want to call FastClasspathScanner.ignoreMethodVisibility() before scanning, to show non-public methods.
        showAnnotations - If true, show annotations in the graph. To show annotations, FastClasspathScanner.enableAnnotationInfo() must be called before scanning. You may also want to call FastClasspathScanner.ignoreClassVisibility() before scanning, to show non-public classes (including non-public annotation classes).
        Returns:
        the GraphViz file contents.