Class ClassInfo

    • Field Detail

      • scanResult

        protected transient ScanResult scanResult
    • Method Detail

      • getName

        public String getName()
        Returns:
        The name of the class.
      • isExternalClass

        public boolean isExternalClass()
        Returns:
        true if this class is an external class, i.e. was referenced by a whitelisted class as a superclass, interface, or annotation, but is not itself a whitelisted class.
      • getModifiers

        public int getModifiers()
        Returns:
        The class modifier bits, e.g. Modifier.PUBLIC.
      • getModifiersStr

        public String getModifiersStr()
        Returns:
        The field modifiers as a string, e.g. "public static final". For the modifier bits, call getModifiers().
      • isPublic

        public boolean isPublic()
        Returns:
        true if this class is a public class.
      • isAbstract

        public boolean isAbstract()
        Returns:
        true if this class is an abstract class.
      • isSynthetic

        public boolean isSynthetic()
        Returns:
        true if this class is a synthetic class.
      • isFinal

        public boolean isFinal()
        Returns:
        true if this class is a final class.
      • isStatic

        public boolean isStatic()
        Returns:
        true if this class is static.
      • isAnnotation

        public boolean isAnnotation()
        Returns:
        true if this class is an annotation class.
      • isInterface

        public boolean isInterface()
        Returns:
        true if this class is an interface and is not an annotation (annotations are interfaces, and can be implemented).
      • isInterfaceOrAnnotation

        public boolean isInterfaceOrAnnotation()
        Returns:
        true if this class is an interface or an annotation (annotations are interfaces, and can be implemented).
      • isEnum

        public boolean isEnum()
        Returns:
        true if this class is an Enum.
      • isStandardClass

        public boolean isStandardClass()
        Returns:
        true if this class is a standard class (i.e. is not an annotation or interface).
      • extendsSuperclass

        public boolean extendsSuperclass​(String superclassName)
        Parameters:
        superclassName - The name of a superclass.
        Returns:
        true if this class extends the named superclass.
      • isInnerClass

        public boolean isInnerClass()
        Returns:
        true if this is an inner class (call isAnonymousInnerClass() to test if this is an anonymous inner class). If true, the containing class can be determined by calling getOuterClasses().
      • isOuterClass

        public boolean isOuterClass()
        Returns:
        true if this class contains inner classes. If true, the inner classes can be determined by calling getInnerClasses().
      • isAnonymousInnerClass

        public boolean isAnonymousInnerClass()
        Returns:
        true if this is an anonymous inner class. If true, the name of the containing method can be obtained by calling getFullyQualifiedDefiningMethodName().
      • isImplementedInterface

        public boolean isImplementedInterface()
        Return whether this class is an implemented interface (meaning a standard, non-annotation interface, or an annotation that has also been implemented as an interface by some class).

        Annotations are interfaces, but you can also implement an annotation, so to we return whether an interface (even an annotation) is implemented by a class or extended by a subinterface, or (failing that) if it is not an interface but not an annotation.

        Returns:
        true if this class is an implemented interface.
      • implementsInterface

        public boolean implementsInterface​(String interfaceName)
        Parameters:
        interfaceName - The name of an interface.
        Returns:
        true if this class implements the named interface.
      • hasAnnotation

        public boolean hasAnnotation​(String annotationName)
        Parameters:
        annotationName - The name of an annotation.
        Returns:
        true if this class has the named annotation.
      • hasField

        public boolean hasField​(String fieldName)
        Parameters:
        fieldName - The name of a field.
        Returns:
        true if this class has the named field.
      • hasFieldAnnotation

        public boolean hasFieldAnnotation​(String fieldAnnotationName)
        Parameters:
        fieldAnnotationName - The name of a field annotation.
        Returns:
        true if this class has a field with the named annotation.
      • hasMethod

        public boolean hasMethod​(String methodName)
        Parameters:
        methodName - The name of a method.
        Returns:
        true if this class has a method of the requested name.
      • hasMethodAnnotation

        public boolean hasMethodAnnotation​(String methodAnnotationName)
        Parameters:
        methodAnnotationName - The name of a mehtod annotation.
        Returns:
        true if this class has a method with the named annotation.
      • getSubclasses

        public ClassInfoList getSubclasses()
        Get the subclasses of this class, sorted in order of name. Call ClassInfoList.directOnly() to get direct subclasses.
        Returns:
        the list of subclasses of this class, or the empty list if none.
      • getSuperclasses

        public ClassInfoList getSuperclasses()
        Get all superclasses of this class, in ascending order in the class hierarchy. Does not include superinterfaces, if this is an interface (use getInterfaces() to get superinterfaces of an interface.}
        Returns:
        the list of all superclasses of this class, or the empty list if none.
      • getSuperclass

        public ClassInfo getSuperclass()
        Get the single direct superclass of this class, or null if none. Does not return the superinterfaces, if this is an interface (use getInterfaces() to get superinterfaces of an interface.}
        Returns:
        the superclass of this class, or null if none.
      • getOuterClasses

        public ClassInfoList getOuterClasses()
        Returns:
        A list of the containing outer classes, if this is an inner class, otherwise the empty list. Note that all containing outer classes are returned, not just the innermost of the containing outer classes.
      • getInnerClasses

        public ClassInfoList getInnerClasses()
        Returns:
        A list of the inner classes contained within this class, or the empty list if none.
      • getFullyQualifiedDefiningMethodName

        public String getFullyQualifiedDefiningMethodName()
        Returns:
        The fully-qualified method name (i.e. fully qualified classname, followed by dot, followed by method name) for the defining method, if this is an anonymous inner class, or null if not.
      • getInterfaces

        public ClassInfoList getInterfaces()
        Returns:
        The list of interfaces implemented by this class or by one of its superclasses, if this is a standard class, or the superinterfaces extended by this interface, if this is an interface. Returns the empty list if none.
      • getClassesImplementing

        public ClassInfoList getClassesImplementing()
        Returns:
        the list of the classes (and their subclasses) that implement this interface, if this is an interface, otherwise returns the empty list.
      • getAnnotations

        public ClassInfoList getAnnotations()
        Get the annotations and meta-annotations on this class. (Call getAnnotationInfo() instead, if you need the parameter values of annotations, rather than just the annotation classes.)

        Also handles the Inherited meta-annotation, which causes an annotation to annotate a class and all of its subclasses.

        Returns:
        the list of annotations and meta-annotations on this class.
      • getAnnotationInfo

        public AnnotationInfoList getAnnotationInfo()
        Get a list of direct annotations on this method, along with any annotation parameter values, as a list of AnnotationInfo objects, or the empty list if none.

        Also handles the Inherited meta-annotation, which causes an annotation to annotate a class and all of its subclasses.

        Returns:
        A list of AnnotationInfo objects for the annotations on this method, or the empty list if none.
      • getAnnotationDefaultParameterValues

        public List<AnnotationParameterValue> getAnnotationDefaultParameterValues()
        Returns:
        A list of AnnotationParameterValue objects for each of the default parameter values for this annotation, if this is an annotation class with default parameter values, otherwise the empty list.
      • getClassesWithAnnotation

        public ClassInfoList getClassesWithAnnotation()
        Returns:
        A list of standard classes and non-annotation interfaces that are annotated by this class, if this is an annotation class, or the empty list if none. Also handles the Inherited meta-annotation, which causes an annotation on a class to be inherited by all of its subclasses.
      • getMethodAndConstructorInfo

        public MethodInfoList getMethodAndConstructorInfo()
        Returns information on visible methods and constructors of the class. There may be more than one method or constructor or method of a given name with different type signatures, due to overloading. Constructors have the method name of "<init>" and static initializer blocks have the name of "<clinit>".

        Requires that ClassGraph.enableMethodInfo() be called before scanning, otherwise throws IllegalArgumentException.

        By default only returns information for public methods and constructors, unless ClassGraph.ignoreMethodVisibility() was called before the scan. If method visibility is ignored, the result may include a reference to a private static class initializer block, with a method name of "<clinit>".

        Returns:
        the list of MethodInfo objects for visible methods and constructors of this class, or the empty list if no methods or constructors were found or visible.
        Throws:
        IllegalArgumentException - if ClassGraph.enableMethodInfo() was not called prior to initiating the scan.
      • getMethodInfo

        public MethodInfoList getMethodInfo​(String methodName)
        Returns information on the method(s) or constructor(s) of the class with the given method name. Constructors have the method name of "<init>".

        Requires that ClassGraph.enableMethodInfo() be called before scanning, otherwise throws IllegalArgumentException.

        By default only returns information for public methods, unless ClassGraph.ignoreMethodVisibility() was called before the scan.

        May return info for multiple methods with the same name (with different type signatures).

        Parameters:
        methodName - The method name to query.
        Returns:
        a list of MethodInfo objects for the method(s) with the given name, or the empty list if the method was not found in this class (or is not visible).
        Throws:
        IllegalArgumentException - if ClassGraph.enableMethodInfo() was not called prior to initiating the scan.
      • getMethodAnnotations

        public ClassInfoList getMethodAnnotations()
        Returns:
        A list of method annotations or meta-annotations on this class, as a list of ClassInfo objects, or the empty list if none. N.B. these annotations do not contain specific annotation parameters -- call MethodInfo.getAnnotationInfo() to get details on specific method annotation instances.
      • getClassesWithMethodAnnotation

        public ClassInfoList getClassesWithMethodAnnotation()
        Returns:
        A list of classes that have a method with this annotation or meta-annotation, or the empty list if none.
      • getFieldAnnotations

        public ClassInfoList getFieldAnnotations()
        Returns:
        A list of field annotations on this class, or the empty list if none. N.B. these annotations do not contain specific annotation parameters -- call FieldInfo.getAnnotationInfo() to get details on specific field annotation instances.
      • getClassesWithFieldAnnotation

        public ClassInfoList getClassesWithFieldAnnotation()
        Returns:
        A list of classes that have a field with this annotation or meta-annotation, or the empty list if none.
      • getTypeSignature

        public ClassTypeSignature getTypeSignature()
        Returns:
        The class type signature, if available, otherwise returns null.
      • getClasspathElementURL

        public URL getClasspathElementURL()
        Returns:
        The URL of the classpath element that this class was found within.
      • getClasspathElementFile

        public File getClasspathElementFile()
        Returns:
        The File for the classpath element package root dir or jar that this class was found within, or null if this class was found in a module. (See also getModuleRef().)
      • getModuleRef

        public ModuleRef getModuleRef()
        Returns:
        The module in the module path that this class was found within, as a ModuleRef, or null if this class was found in a directory or jar in the classpath. (See also getClasspathElementFile().)
      • loadClass

        public <T> Class<T> loadClass​(Class<T> superclassOrInterfaceType,
                                      boolean ignoreExceptions)
        Obtain a Class<?> reference for the class named by this ClassInfo object, casting it to the requested interface or superclass type. Causes the ClassLoader to load the class, 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 the loaded class to.
        ignoreExceptions - If true, return null if any exceptions or errors thrown during classloading, or if attempting to cast the resulting Class<?> reference to the requested superclass or interface type fails. If false, IllegalArgumentException is thrown if the class could not be loaded or could not be cast to the requested type.
        Returns:
        The class reference, or null, if ignoreExceptions is true and there was an exception or error loading the class.
        Throws:
        IllegalArgumentException - if ignoreExceptions is false and there were problems loading the class, or casting it to the requested type.
      • loadClass

        public <T> Class<T> loadClass​(Class<T> superclassOrInterfaceType)
        Obtain a Class<?> reference for the class named by this ClassInfo object, casting it to the requested interface or superclass type. Causes the ClassLoader to load the class, 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 the loaded class to.
        Returns:
        The class reference.
        Throws:
        IllegalArgumentException - if there were problems loading the class or casting it to the requested type.
      • loadClass

        public Class<?> loadClass​(boolean ignoreExceptions)
        Obtain a Class<?> reference for the class named by this ClassInfo object. Causes the ClassLoader to load the class, if it is not already loaded.
        Returns:
        The class reference, or null, if ignoreExceptions is true and there was an exception or error loading the class.
        Throws:
        IllegalArgumentException - if ignoreExceptions is false and there were problems loading the class.
      • loadClass

        public Class<?> loadClass()
        Obtain a Class<?> reference for the class named by this ClassInfo object. Causes the ClassLoader to load the class, if it is not already loaded.
        Returns:
        The class reference.
        Throws:
        IllegalArgumentException - if there were problems loading the class.
      • getClassName

        protected String getClassName()
        The name of the class (used by getClassInfo() to fetch the ClassInfo object for the class).
        Returns:
        The class name.
      • getClassInfo

        protected ClassInfo getClassInfo()
      • getClassNamesFromTypeDescriptors

        protected void getClassNamesFromTypeDescriptors​(Set<String> classNames)
        Get the names of any classes referenced in this class' type descriptor, or the type descriptors of fields, methods or annotations.
      • equals

        public boolean equals​(Object obj)
        Use class name for equals().
        Overrides:
        equals in class Object
      • hashCode

        public int hashCode()
        Use hash code of class name.
        Overrides:
        hashCode in class Object