Class ClassInfo

    • Field Detail

      • scanResult

        protected transient ScanResult scanResult
    • Method Detail

      • 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, 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 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.
      • getName

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

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

        public int getModifiers()
        Get the class modifier flags, e.g. Modifier.PUBLIC
        Returns:
        The class modifiers.
      • getModifiersStr

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

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

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

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

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

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

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

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

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

        public boolean isEnum()
        Return whether this class is an enum.
        Returns:
        true if this class is an enum.
      • getTypeSignature

        public ClassTypeSignature getTypeSignature()
        Get the type signature for the class, if available (else returns null).
        Returns:
        The class type signature.
      • getClasspathElementURL

        public URL getClasspathElementURL()
        The classpath element URL (for a classpath root dir, jar or module) that this class was found within. N.B. Classpath elements are handled as File objects internally. It is much faster to call getClasspathElementFile() and/or getClasspathElementModule() -- the conversion of a File into a URL (via File#toURI()#toURL()) is time consuming.
        Returns:
        The classpath element, as a URL.
      • getClasspathElementFile

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

        public ModuleRef getModuleRef()
        The module in the module path that this class was found within, or null if this class was found in a directory or jar in the classpath.
        Returns:
        The module, as a ModuleRef.
      • 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
      • 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.
      • getClassName

        protected String getClassName()
      • isStandardClass

        public boolean isStandardClass()
        Return whether this class is a standard class (not an annotation or interface).
        Returns:
        true if this class is a standard class (not an annotation or interface).
      • getSubclasses

        public ClassInfoList getSubclasses()
        Get the subclasses of this class.
        Returns:
        the list of subclasses of this class, or the empty list if none.
      • getSuperclasses

        public ClassInfoList getSuperclasses()
        Get all superclasses of this class. 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.
      • extendsSuperclass

        public boolean extendsSuperclass​(String superclassName)
        Returns true if this class implements the named interface.
      • 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() or getOuterClassNames().
        Returns:
        True if this class is an inner class.
      • getOuterClasses

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

        public boolean isOuterClass()
        Returns true if this class contains inner classes. If true, the inner classes can be determined by calling getInnerClasses() or getInnerClassNames().
        Returns:
        True if this is an outer class.
      • getInnerClasses

        public ClassInfoList getInnerClasses()
        Returns the inner classes contained within this class. Returns the empty list if none.
        Returns:
        The list of inner classes within this class.
      • 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 getFullyQualifiedContainingMethodName().
        Returns:
        True if this is an anonymous inner class.
      • getFullyQualifiedDefiningMethodName

        public String getFullyQualifiedDefiningMethodName()
        For anonymous inner classes, returns the fully-qualified method name (i.e. fully qualified classname, followed by dot, followed by method name), for the defining method.
        Returns:
        The fully-qualified name of the method that this anonymous inner class was defined within.
      • 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.

        (This is named "implemented interface" rather than just "interface" to distinguish it from an annotation.)

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

        public ClassInfoList getInterfaces()
        Get the 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 list of interfaces implemented by this standard class, or by one of its superclasses. Returns the empty list if none.
      • implementsInterface

        public boolean implementsInterface​(String interfaceName)
        Returns true if this class implements the named interface.
      • getClassesImplementing

        public ClassInfoList getClassesImplementing()
        Get the classes that implement this interface, and their subclasses, if this is an interface, otherwise returns the empty list.
        Returns:
        the list of classes implementing this interface, or the empty list if none.
      • 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.
      • hasAnnotation

        public boolean hasAnnotation​(String annotationName)
        Returns true if this class has the named annotation.
      • 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()
        If this is an annotation, and it has default parameter values, returns a list of the default parameter values, otherwise returns the empty list.
        Returns:
        If this is an annotation class, the list of AnnotationParameterValue objects for each of the default parameter values for this annotation, otherwise the empty list.
      • getClassesWithAnnotation

        public ClassInfoList getClassesWithAnnotation()
        Get the standard classes and non-annotation interfaces that are annotated by this annotation.

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

        Returns:
        the list of standard classes and non-annotation interfaces that are annotated by the annotation corresponding to this ClassInfo class, or the empty list if none.
      • getMethodInfo

        public MethodInfoList getMethodInfo()
        Returns information on visible methods of the class that are not constructors. (Call getMethodAndConstructorInfo() if you need methods and constructors.) There may be more than one method of a given name with different type signatures, due to overloading.

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

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

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

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

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

        By default only returns information for public constructors, unless FastClasspathScanner#ignoreMethodVisibility() was called before the scan.

        Returns:
        the list of MethodInfo objects for visible constructors of this class, or the empty list if no constructors were found or visible.
        Throws:
        IllegalArgumentException - if FastClasspathScanner#enableMethodInfo() was not called prior to initiating the scan.
      • 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 FastClasspathScanner#enableMethodInfo() be called before scanning, otherwise throws IllegalArgumentException.

        By default only returns information for public methods and constructors, unless FastClasspathScanner#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 FastClasspathScanner#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 FastClasspathScanner#enableMethodInfo() be called before scanning, otherwise throws IllegalArgumentException.

        By default only returns information for public methods, unless FastClasspathScanner#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 FastClasspathScanner#enableMethodInfo() was not called prior to initiating the scan.
      • hasMethod

        public boolean hasMethod​(String methodName)
        Returns true if this class has the named method.
      • getMethodAnnotations

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

        public boolean hasMethodAnnotation​(String methodAnnotationName)
        Returns true if this class has the named method annotation.
      • getClassesWithMethodAnnotation

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

        public FieldInfoList getFieldInfo()
        Returns information on all visible fields of the class.

        Requires that FastClasspathScanner#enableFieldInfo() be called before scanning, otherwise throws IllegalArgumentException.

        By default only returns information for public methods, unless FastClasspathScanner#ignoreFieldVisibility() was called before the scan.

        Returns:
        the list of FieldInfo objects for visible fields of this class, or the empty list if no fields were found or visible.
        Throws:
        IllegalArgumentException - if FastClasspathScanner#enableFieldInfo() was not called prior to initiating the scan.
      • getFieldInfo

        public FieldInfo getFieldInfo​(String fieldName)
        Returns information on a given visible field of the class.

        Requires that FastClasspathScanner#enableFieldInfo() be called before scanning, otherwise throws IllegalArgumentException.

        By default only returns information for public fields, unless FastClasspathScanner#ignoreFieldVisibility() was called before the scan.

        Parameters:
        fieldName - The field name to query.
        Returns:
        the FieldInfo object for the named field, or null if the field was not found in this class (or is not visible).
        Throws:
        IllegalArgumentException - if FastClasspathScanner#enableFieldInfo() was not called prior to initiating the scan.
      • hasField

        public boolean hasField​(String fieldName)
        Returns true if this class has the named field.
      • getFieldAnnotations

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

        public boolean hasFieldAnnotation​(String fieldAnnotationName)
        Returns true if this class has the named field annotation.
      • getClassesWithFieldAnnotation

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