Class ClassInfo
- java.lang.Object
-
- io.github.classgraph.ClassInfo
-
-
Field Summary
Fields Modifier and Type Field Description protected ScanResultscanResultThe scan result.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(ClassInfo o)Compare based on class name.booleanequals(java.lang.Object obj)Use class name for equals().booleanextendsSuperclass(java.lang.String superclassName)Checks if this class extends the named superclass.protected voidfindReferencedClassNames(java.util.Set<java.lang.String> referencedClassNames)Get the names of any classes referenced in this class' type descriptor, or the type descriptors of fields, methods or annotations.AnnotationParameterValueListgetAnnotationDefaultParameterValues()Get the default parameter values for this annotation, if this is an annotation class.AnnotationInfoListgetAnnotationInfo()Get a list of the annotations on this class, or the empty list if none.AnnotationInfogetAnnotationInfo(java.lang.String annotationName)Get a the named non-Repeatableannotation on this class, or null if the class does not have the named annotation.AnnotationInfoListgetAnnotationInfoRepeatable(java.lang.String annotationName)Get a the namedRepeatableannotation on this class, or the empty list if the class does not have the named annotation.ClassInfoListgetAnnotations()Get the annotations and meta-annotations on this class.ClassInfoListgetClassDependencies()Get the class dependencies.ClassInfoListgetClassesImplementing()Get the classes (and their subclasses) that implement this interface, if this is an interface.ClassInfoListgetClassesWithAnnotation()Get the classes that have this class as an annotation.ClassInfoListgetClassesWithFieldAnnotation()Get the classes that have this class as a field annotation or meta-annotation.ClassInfoListgetClassesWithMethodAnnotation()Get the classes that have this class as a method annotation.protected ClassInfogetClassInfo()protected java.lang.StringgetClassName()The name of the class (used bygetClassInfo()to fetch theClassInfoobject for the class).java.io.FilegetClasspathElementFile()Get theFilefor the classpath element package root dir or jar that this class was found within, or null if this class was found in a module.java.net.URLgetClasspathElementURL()Get theURLof the classpath element that this class was found within.MethodInfoListgetConstructorInfo()Returns information on visible constructors declared by this class, or by its interfaces or superclasses.MethodInfoListgetDeclaredConstructorInfo()Returns information on visible constructors declared by this class, but not by its interfaces or superclasses.FieldInfoListgetDeclaredFieldInfo()Returns information on all visible fields declared by this class, but not by its superclasses.FieldInfogetDeclaredFieldInfo(java.lang.String fieldName)Returns information on the named field declared by the class, but not by its superclasses.MethodInfoListgetDeclaredMethodAndConstructorInfo()Returns information on visible methods and constructors declared by this class, but not by its interfaces or superclasses.MethodInfoListgetDeclaredMethodInfo()Returns information on visible methods declared by this class, but not by its interfaces or superclasses, that are not constructors.MethodInfoListgetDeclaredMethodInfo(java.lang.String methodName)Returns information on the method(s) or constructor(s) of the given name declared by this class, but not by its interfaces or superclasses.ClassInfoListgetFieldAnnotations()Get the classes that annotate fields of this class.FieldInfoListgetFieldInfo()Returns information on all visible fields declared by this class, or by its superclasses.FieldInfogetFieldInfo(java.lang.String fieldName)Returns information on the named filed declared by this class, or by its superclasses.java.lang.StringgetFullyQualifiedDefiningMethodName()Gets fully-qualified method name (i.e.ClassInfoListgetInnerClasses()Get the inner classes contained within this class, if this is an outer class.ClassInfoListgetInterfaces()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.MethodInfoListgetMethodAndConstructorInfo()Returns information on visible constructors declared by this class, or by its interfaces or superclasses.ClassInfoListgetMethodAnnotations()Get the method annotations.MethodInfoListgetMethodInfo()Returns information on visible methods declared by this class, or by its interfaces or superclasses, that are not constructors.MethodInfoListgetMethodInfo(java.lang.String methodName)Returns information on the method(s) or constructor(s) of the given name declared by this class, but not by its interfaces or superclasses.intgetModifiers()Get the class modifier bits.java.lang.StringgetModifiersStr()Get the class modifiers as a String.ModuleInfogetModuleInfo()Get theModuleInfoobject for the class.ModuleRefgetModuleRef()Get the module that this class was found within, as aModuleRef, or null if this class was found in a directory or jar in the classpath.java.lang.StringgetName()Get the name of the class.ClassInfoListgetOuterClasses()Get the containing outer classes, if this is an inner class.PackageInfogetPackageInfo()Get thePackageInfoobject for the class.java.lang.StringgetPackageName()Get the name of the class' package.ResourcegetResource()TheResourcefor the classfile of this class.java.lang.StringgetSimpleName()Get the simple name of the class.ClassInfoListgetSubclasses()Get the subclasses of this class, sorted in order of name.ClassInfogetSuperclass()Get the single direct superclass of this class, or null if none.ClassInfoListgetSuperclasses()Get all superclasses of this class, in ascending order in the class hierarchy.ClassTypeSignaturegetTypeSignature()Get the type signature of the class.booleanhasAnnotation(java.lang.String annotationName)Checks whether this class has the named annotation.booleanhasDeclaredField(java.lang.String fieldName)Checks whether this class has the named declared field.booleanhasDeclaredFieldAnnotation(java.lang.String fieldAnnotationName)Checks whether this class declares a field with the named annotation.booleanhasDeclaredMethod(java.lang.String methodName)Checks whether this class declares a field of the given name.booleanhasDeclaredMethodAnnotation(java.lang.String methodAnnotationName)Checks whether this class declares a method with the named annotation.booleanhasDeclaredMethodParameterAnnotation(java.lang.String methodParameterAnnotationName)Checks whether this class declares a method with the named annotation.booleanhasField(java.lang.String fieldName)Checks whether this class or one of its superclasses has the named field.booleanhasFieldAnnotation(java.lang.String fieldAnnotationName)Checks whether this class or one of its superclasses declares a field with the named annotation.inthashCode()Use hash code of class name.booleanhasMethod(java.lang.String methodName)Checks whether this class or one of its superclasses or interfaces declares a method of the given name.booleanhasMethodAnnotation(java.lang.String methodAnnotationName)Checks whether this class or one of its superclasses or interfaces declares a method with the named annotation.booleanhasMethodParameterAnnotation(java.lang.String methodParameterAnnotationName)Checks whether this class or one of its superclasses or interfaces has a method with the named annotation.booleanimplementsInterface(java.lang.String interfaceName)Checks whether this class implements the named interface.booleanisAbstract()Checks if the class is abstract.booleanisAnnotation()Checks if the class is an annotation.booleanisAnonymousInnerClass()Checks if this class is an anonymous inner class.booleanisEnum()Checks if is the class is anEnum.booleanisExternalClass()Checks if this is an external class.booleanisFinal()Checks if the class is final.booleanisImplementedInterface()Checks 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).booleanisInnerClass()Checks if this class is an inner class.booleanisInterface()Checks if is the class an interface and is not an annotation.booleanisInterfaceOrAnnotation()Checks if is an interface or an annotation.booleanisOuterClass()Checks if this class is an outer class.booleanisPublic()Checks if the class is public.booleanisStandardClass()Checks if this class is a standard class.booleanisStatic()Checks if the class is static.booleanisSynthetic()Checks if the class is synthetic.java.lang.Class<?>loadClass()Obtain aClass<?>reference for the class named by thisClassInfoobject.java.lang.Class<?>loadClass(boolean ignoreExceptions)Obtain aClass<?>reference for the class named by thisClassInfoobject.<T> java.lang.Class<T>loadClass(java.lang.Class<T> superclassOrInterfaceType)Obtain aClass<?>reference for the class named by thisClassInfoobject, casting it to the requested interface or superclass type.<T> java.lang.Class<T>loadClass(java.lang.Class<T> superclassOrInterfaceType, boolean ignoreExceptions)Obtain aClass<?>reference for the class named by thisClassInfoobject, casting it to the requested interface or superclass type.java.lang.StringtoString()
-
-
-
Field Detail
-
scanResult
protected transient ScanResult scanResult
The scan result.
-
-
Method Detail
-
getName
public java.lang.String getName()
Get the name of the class.- Returns:
- The name of the class.
-
getSimpleName
public java.lang.String getSimpleName()
Get the simple name of the class.- Returns:
- The simple name of the class.
-
getModuleInfo
public ModuleInfo getModuleInfo()
Get theModuleInfoobject for the class.- Returns:
- the
ModuleInfoobject for the class, or null if the class is not part of a named module.
-
getPackageInfo
public PackageInfo getPackageInfo()
Get thePackageInfoobject for the class.- Returns:
- the
PackageInfoobject for the package that contains the class.
-
getPackageName
public java.lang.String getPackageName()
Get the name of the class' package.- Returns:
- The name of the class' package.
-
isExternalClass
public boolean isExternalClass()
Checks if this is an external class.- 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()
Get the class modifier bits.- Returns:
- The class modifier bits, e.g.
Modifier.PUBLIC.
-
getModifiersStr
public java.lang.String getModifiersStr()
Get the class modifiers as a String.- Returns:
- The field modifiers as a string, e.g. "public static final". For the modifier bits, call
getModifiers().
-
isPublic
public boolean isPublic()
Checks if the class is public.- Returns:
- true if this class is a public class.
-
isAbstract
public boolean isAbstract()
Checks if the class is abstract.- Returns:
- true if this class is an abstract class.
-
isSynthetic
public boolean isSynthetic()
Checks if the class is synthetic.- Returns:
- true if this class is a synthetic class.
-
isFinal
public boolean isFinal()
Checks if the class is final.- Returns:
- true if this class is a final class.
-
isStatic
public boolean isStatic()
Checks if the class is static.- Returns:
- true if this class is static.
-
isAnnotation
public boolean isAnnotation()
Checks if the class is an annotation.- Returns:
- true if this class is an annotation class.
-
isInterface
public boolean isInterface()
Checks if is the class an interface and is not an annotation.- Returns:
- true if this class is an interface and is not an annotation (annotations are interfaces, and can be implemented).
-
isInterfaceOrAnnotation
public boolean isInterfaceOrAnnotation()
Checks if is an interface or an annotation.- Returns:
- true if this class is an interface or an annotation (annotations are interfaces, and can be implemented).
-
isEnum
public boolean isEnum()
Checks if is the class is anEnum.- Returns:
- true if this class is an
Enum.
-
isStandardClass
public boolean isStandardClass()
Checks if this class is a standard class.- Returns:
- true if this class is a standard class (i.e. is not an annotation or interface).
-
extendsSuperclass
public boolean extendsSuperclass(java.lang.String superclassName)
Checks if this class extends the named superclass.- Parameters:
superclassName- The name of a superclass.- Returns:
- true if this class extends the named superclass.
-
isInnerClass
public boolean isInnerClass()
Checks if this class is an inner class.- 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 callinggetOuterClasses().
-
isOuterClass
public boolean isOuterClass()
Checks if this class is an outer class.- Returns:
- true if this class contains inner classes. If true, the inner classes can be determined by calling
getInnerClasses().
-
isAnonymousInnerClass
public boolean isAnonymousInnerClass()
Checks if this class is an anonymous inner class.- 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()
Checks 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(java.lang.String interfaceName)
Checks whether this class implements the named interface.- Parameters:
interfaceName- The name of an interface.- Returns:
- true if this class implements the named interface.
-
hasAnnotation
public boolean hasAnnotation(java.lang.String annotationName)
Checks whether this class has the named annotation.- Parameters:
annotationName- The name of an annotation.- Returns:
- true if this class has the named annotation.
-
hasDeclaredField
public boolean hasDeclaredField(java.lang.String fieldName)
Checks whether this class has the named declared field.- Parameters:
fieldName- The name of a field.- Returns:
- true if this class declares a field of the given name.
-
hasField
public boolean hasField(java.lang.String fieldName)
Checks whether this class or one of its superclasses has the named field.- Parameters:
fieldName- The name of a field.- Returns:
- true if this class or one of its superclasses declares a field of the given name.
-
hasDeclaredFieldAnnotation
public boolean hasDeclaredFieldAnnotation(java.lang.String fieldAnnotationName)
Checks whether this class declares a field with the named annotation.- Parameters:
fieldAnnotationName- The name of a field annotation.- Returns:
- true if this class declares a field with the named annotation.
-
hasFieldAnnotation
public boolean hasFieldAnnotation(java.lang.String fieldAnnotationName)
Checks whether this class or one of its superclasses declares a field with the named annotation.- Parameters:
fieldAnnotationName- The name of a field annotation.- Returns:
- true if this class or one of its superclasses declares a field with the named annotation.
-
hasDeclaredMethod
public boolean hasDeclaredMethod(java.lang.String methodName)
Checks whether this class declares a field of the given name.- Parameters:
methodName- The name of a method.- Returns:
- true if this class declares a field of the given name.
-
hasMethod
public boolean hasMethod(java.lang.String methodName)
Checks whether this class or one of its superclasses or interfaces declares a method of the given name.- Parameters:
methodName- The name of a method.- Returns:
- true if this class or one of its superclasses or interfaces declares a method of the given name.
-
hasDeclaredMethodAnnotation
public boolean hasDeclaredMethodAnnotation(java.lang.String methodAnnotationName)
Checks whether this class declares a method with the named annotation.- Parameters:
methodAnnotationName- The name of a method annotation.- Returns:
- true if this class declares a method with the named annotation.
-
hasMethodAnnotation
public boolean hasMethodAnnotation(java.lang.String methodAnnotationName)
Checks whether this class or one of its superclasses or interfaces declares a method with the named annotation.- Parameters:
methodAnnotationName- The name of a method annotation.- Returns:
- true if this class or one of its superclasses or interfaces declares a method with the named annotation.
-
hasDeclaredMethodParameterAnnotation
public boolean hasDeclaredMethodParameterAnnotation(java.lang.String methodParameterAnnotationName)
Checks whether this class declares a method with the named annotation.- Parameters:
methodParameterAnnotationName- The name of a method annotation.- Returns:
- true if this class declares a method with the named annotation.
-
hasMethodParameterAnnotation
public boolean hasMethodParameterAnnotation(java.lang.String methodParameterAnnotationName)
Checks whether this class or one of its superclasses or interfaces has a method with the named annotation.- Parameters:
methodParameterAnnotationName- The name of a method annotation.- Returns:
- true if this class or one of its superclasses or interfaces has a method with the named annotation.
-
getSubclasses
public ClassInfoList getSubclasses()
Get the subclasses of this class, sorted in order of name. CallClassInfoList.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 (usegetInterfaces()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 (usegetInterfaces()to get superinterfaces of an interface.}- Returns:
- the superclass of this class, or null if none.
-
getOuterClasses
public ClassInfoList getOuterClasses()
Get the containing outer classes, if this is an inner class.- 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()
Get the inner classes contained within this class, if this is an outer class.- Returns:
- A list of the inner classes contained within this class, or the empty list if none.
-
getFullyQualifiedDefiningMethodName
public java.lang.String getFullyQualifiedDefiningMethodName()
Gets 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.- 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()
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 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()
Get the classes (and their subclasses) that implement this interface, if this is an interface.- 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. (CallgetAnnotationInfo()instead, if you need the parameter values of annotations, rather than just the annotation classes.)Also handles the
Inheritedmeta-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 the annotations on this class, or the empty list if none.Also handles the
Inheritedmeta-annotation, which causes an annotation to annotate a class and all of its subclasses.- Returns:
- A list of
AnnotationInfoobjects for the annotations on this class, or the empty list if none.
-
getAnnotationInfo
public AnnotationInfo getAnnotationInfo(java.lang.String annotationName)
Get a the named non-Repeatableannotation on this class, or null if the class does not have the named annotation. (UsegetAnnotationInfoRepeatable(String)forRepeatableannotations.)Also handles the
Inheritedmeta-annotation, which causes an annotation to annotate a class and all of its subclasses.Note that if you need to get multiple named annotations, it is faster to call
getAnnotationInfo(), and then get the named annotations from the returnedAnnotationInfoList, so that the returned list doesn't have to be built multiple times.- Parameters:
annotationName- The annotation name.- Returns:
- An
AnnotationInfoobject representing the named annotation on this class, or null if the class does not have the named annotation.
-
getAnnotationInfoRepeatable
public AnnotationInfoList getAnnotationInfoRepeatable(java.lang.String annotationName)
Get a the namedRepeatableannotation on this class, or the empty list if the class does not have the named annotation.Also handles the
Inheritedmeta-annotation, which causes an annotation to annotate a class and all of its subclasses.Note that if you need to get multiple named annotations, it is faster to call
getAnnotationInfo(), and then get the named annotations from the returnedAnnotationInfoList, so that the returned list doesn't have to be built multiple times.- Parameters:
annotationName- The annotation name.- Returns:
- An
AnnotationInfoListof all instances of the named annotation on this class, or the empty list if the class does not have the named annotation.
-
getAnnotationDefaultParameterValues
public AnnotationParameterValueList getAnnotationDefaultParameterValues()
Get the default parameter values for this annotation, if this is an annotation class.- Returns:
- A list of
AnnotationParameterValueobjects 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()
Get the classes that have this class as an annotation.- 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
Inheritedmeta-annotation, which causes an annotation on a class to be inherited by all of its subclasses.
-
getDeclaredMethodInfo
public MethodInfoList getDeclaredMethodInfo()
Returns information on visible methods declared by this class, but not by its interfaces or superclasses, that are not constructors. See also:getMethodInfo(String)getDeclaredMethodInfo(String)getMethodInfo()getConstructorInfo()getDeclaredConstructorInfo()getMethodAndConstructorInfo()getDeclaredMethodAndConstructorInfo()
There may be more than one method of a given name with different type signatures, due to overloading.
Requires that
ClassGraph.enableMethodInfo()be called before scanning, otherwise throwsIllegalArgumentException.By default only returns information for public methods, unless
ClassGraph.ignoreMethodVisibility()was called before the scan.- Returns:
- the list of
MethodInfoobjects for visible methods declared by this class, or the empty list if no methods were found. - Throws:
java.lang.IllegalArgumentException- ifClassGraph.enableMethodInfo()was not called prior to initiating the scan.
-
getMethodInfo
public MethodInfoList getMethodInfo()
Returns information on visible methods declared by this class, or by its interfaces or superclasses, that are not constructors. See also:getMethodInfo(String)getDeclaredMethodInfo(String)getDeclaredMethodInfo()getConstructorInfo()getDeclaredConstructorInfo()getMethodAndConstructorInfo()getDeclaredMethodAndConstructorInfo()
There may be more than one method of a given name with different type signatures, due to overloading.
Requires that
ClassGraph.enableMethodInfo()be called before scanning, otherwise throwsIllegalArgumentException.By default only returns information for public methods, unless
ClassGraph.ignoreMethodVisibility()was called before the scan.- Returns:
- the list of
MethodInfoobjects for visible methods of this class, its interfaces and superclasses, or the empty list if no methods were found. - Throws:
java.lang.IllegalArgumentException- ifClassGraph.enableMethodInfo()was not called prior to initiating the scan.
-
getDeclaredConstructorInfo
public MethodInfoList getDeclaredConstructorInfo()
Returns information on visible constructors declared by this class, but not by its interfaces or superclasses. Constructors have the method name of"<init>". See also:getMethodInfo(String)getDeclaredMethodInfo(String)getMethodInfo()getDeclaredMethodInfo()getConstructorInfo()getMethodAndConstructorInfo()getDeclaredMethodAndConstructorInfo()
There may be more than one constructor of a given name with different type signatures, due to overloading.
Requires that
ClassGraph.enableMethodInfo()be called before scanning, otherwise throwsIllegalArgumentException.By default only returns information for public constructors, unless
ClassGraph.ignoreMethodVisibility()was called before the scan.- Returns:
- the list of
MethodInfoobjects for visible constructors declared by this class, or the empty list if no constructors were found or visible. - Throws:
java.lang.IllegalArgumentException- ifClassGraph.enableMethodInfo()was not called prior to initiating the scan.
-
getConstructorInfo
public MethodInfoList getConstructorInfo()
Returns information on visible constructors declared by this class, or by its interfaces or superclasses. Constructors have the method name of"<init>". See also:getMethodInfo(String)getDeclaredMethodInfo(String)getMethodInfo()getDeclaredMethodInfo()getDeclaredConstructorInfo()getMethodAndConstructorInfo()getDeclaredMethodAndConstructorInfo()
There may be more than one method of a given name with different type signatures, due to overloading.
Requires that
ClassGraph.enableMethodInfo()be called before scanning, otherwise throwsIllegalArgumentException.By default only returns information for public methods, unless
ClassGraph.ignoreMethodVisibility()was called before the scan.- Returns:
- the list of
MethodInfoobjects for visible constructors of this class and its superclasses, or the empty list if no methods were found. - Throws:
java.lang.IllegalArgumentException- ifClassGraph.enableMethodInfo()was not called prior to initiating the scan.
-
getDeclaredMethodAndConstructorInfo
public MethodInfoList getDeclaredMethodAndConstructorInfo()
Returns information on visible methods and constructors declared by this class, but not by its interfaces or superclasses. Constructors have the method name of"<init>"and static initializer blocks have the name of"<clinit>". See also:getMethodInfo(String)getDeclaredMethodInfo(String)getMethodInfo()getDeclaredMethodInfo()getConstructorInfo()getDeclaredConstructorInfo()getMethodAndConstructorInfo()
There may be more than one method or constructor or method of a given name with different type signatures, due to overloading.
Requires that
ClassGraph.enableMethodInfo()be called before scanning, otherwise throwsIllegalArgumentException.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
MethodInfoobjects for visible methods and constructors of this class, or the empty list if no methods or constructors were found or visible. - Throws:
java.lang.IllegalArgumentException- ifClassGraph.enableMethodInfo()was not called prior to initiating the scan.
-
getMethodAndConstructorInfo
public MethodInfoList getMethodAndConstructorInfo()
Returns information on visible constructors declared by this class, or by its interfaces or superclasses. Constructors have the method name of"<init>"and static initializer blocks have the name of"<clinit>". See also:getMethodInfo(String)getDeclaredMethodInfo(String)getMethodInfo()getDeclaredMethodInfo()getConstructorInfo()getDeclaredConstructorInfo()getDeclaredMethodAndConstructorInfo()
There may be more than one method of a given name with different type signatures, due to overloading.
Requires that
ClassGraph.enableMethodInfo()be called before scanning, otherwise throwsIllegalArgumentException.By default only returns information for public methods, unless
ClassGraph.ignoreMethodVisibility()was called before the scan.- Returns:
- the list of
MethodInfoobjects for visible methods and constructors of this class, its interfaces and superclasses, or the empty list if no methods were found. - Throws:
java.lang.IllegalArgumentException- ifClassGraph.enableMethodInfo()was not called prior to initiating the scan.
-
getDeclaredMethodInfo
public MethodInfoList getDeclaredMethodInfo(java.lang.String methodName)
Returns information on the method(s) or constructor(s) of the given name declared by this class, but not by its interfaces or superclasses. Constructors have the method name of"<init>". See also:getMethodInfo(String)getMethodInfo()getDeclaredMethodInfo()getConstructorInfo()getDeclaredConstructorInfo()getMethodAndConstructorInfo()getDeclaredMethodAndConstructorInfo()
Requires that
ClassGraph.enableMethodInfo()be called before scanning, otherwise throwsIllegalArgumentException.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
MethodInfoobjects 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:
java.lang.IllegalArgumentException- ifClassGraph.enableMethodInfo()was not called prior to initiating the scan.
-
getMethodInfo
public MethodInfoList getMethodInfo(java.lang.String methodName)
Returns information on the method(s) or constructor(s) of the given name declared by this class, but not by its interfaces or superclasses. Constructors have the method name of"<init>". See also:getDeclaredMethodInfo(String)getMethodInfo()getDeclaredMethodInfo()getConstructorInfo()getDeclaredConstructorInfo()getMethodAndConstructorInfo()getDeclaredMethodAndConstructorInfo()
Requires that
ClassGraph.enableMethodInfo()be called before scanning, otherwise throwsIllegalArgumentException.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
MethodInfoobjects 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:
java.lang.IllegalArgumentException- ifClassGraph.enableMethodInfo()was not called prior to initiating the scan.
-
getMethodAnnotations
public ClassInfoList getMethodAnnotations()
Get the method annotations.- Returns:
- A list of annotations or meta-annotations on methods declared by the class, (not including methods
declared by the interfaces or superclasses of this class), as a list of
ClassInfoobjects, or the empty list if none. N.B. these annotations do not contain specific annotation parameters -- callMethodInfo.getAnnotationInfo()to get details on specific method annotation instances.
-
getClassesWithMethodAnnotation
public ClassInfoList getClassesWithMethodAnnotation()
Get the classes that have this class as a method annotation.- Returns:
- A list of classes that have a declared method with this annotation or meta-annotation, or the empty list if none.
-
getDeclaredFieldInfo
public FieldInfoList getDeclaredFieldInfo()
Returns information on all visible fields declared by this class, but not by its superclasses. See also:Requires that
ClassGraph.enableFieldInfo()be called before scanning, otherwise throwsIllegalArgumentException.By default only returns information for public methods, unless
ClassGraph.ignoreFieldVisibility()was called before the scan.- Returns:
- the list of FieldInfo objects for visible fields declared by this class, or the empty list if no fields were found or visible.
- Throws:
java.lang.IllegalArgumentException- ifClassGraph.enableFieldInfo()was not called prior to initiating the scan.
-
getFieldInfo
public FieldInfoList getFieldInfo()
Returns information on all visible fields declared by this class, or by its superclasses. See also:Requires that
ClassGraph.enableFieldInfo()be called before scanning, otherwise throwsIllegalArgumentException.By default only returns information for public methods, unless
ClassGraph.ignoreFieldVisibility()was called before the scan.- Returns:
- the list of FieldInfo objects for visible fields of this class or its superclases, or the empty list if no fields were found or visible.
- Throws:
java.lang.IllegalArgumentException- ifClassGraph.enableFieldInfo()was not called prior to initiating the scan.
-
getDeclaredFieldInfo
public FieldInfo getDeclaredFieldInfo(java.lang.String fieldName)
Returns information on the named field declared by the class, but not by its superclasses. See also:Requires that
ClassGraph.enableFieldInfo()be called before scanning, otherwise throwsIllegalArgumentException.By default only returns information for public fields, unless
ClassGraph.ignoreFieldVisibility()was called before the scan.- Parameters:
fieldName- The field name.- Returns:
- the
FieldInfoobject for the named field declared by this class, or null if the field was not found in this class (or is not visible). - Throws:
java.lang.IllegalArgumentException- ifClassGraph.enableFieldInfo()was not called prior to initiating the scan.
-
getFieldInfo
public FieldInfo getFieldInfo(java.lang.String fieldName)
Returns information on the named filed declared by this class, or by its superclasses. See also:Requires that
ClassGraph.enableFieldInfo()be called before scanning, otherwise throwsIllegalArgumentException.By default only returns information for public methods, unless
ClassGraph.ignoreFieldVisibility()was called before the scan.- Parameters:
fieldName- The field name.- Returns:
- the
FieldInfoobject for the named field of this class or its superclases, or the empty list if no fields were found or visible. - Throws:
java.lang.IllegalArgumentException- ifClassGraph.enableFieldInfo()was not called prior to initiating the scan.
-
getFieldAnnotations
public ClassInfoList getFieldAnnotations()
Get the classes that annotate fields of this class.- Returns:
- A list of annotations on fields of 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()
Get the classes that have this class as a field annotation or meta-annotation.- 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()
Get the type signature of the class.- Returns:
- The class type signature, if available, otherwise returns null.
-
getClasspathElementURL
public java.net.URL getClasspathElementURL()
Get theURLof the classpath element that this class was found within.- Returns:
- The
URLof the classpath element that this class was found within.
-
getClasspathElementFile
public java.io.File getClasspathElementFile()
Get theFilefor 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 alsogetModuleRef().)- Returns:
- The
Filefor 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 alsogetModuleRef().)
-
getModuleRef
public ModuleRef getModuleRef()
Get the module that this class was found within, as aModuleRef, or null if this class was found in a directory or jar in the classpath. (See alsogetClasspathElementFile().)- Returns:
- The module 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 alsogetClasspathElementFile().)
-
getResource
public Resource getResource()
TheResourcefor the classfile of this class.- Returns:
- The
Resourcefor the classfile of this class, or null if this is an "external" class (a blacklisted class, or a class in a blacklisted package, or a class that was referenced as a superclass, interface or annotation, but that wasn't in the scanned path).
-
loadClass
public <T> java.lang.Class<T> loadClass(java.lang.Class<T> superclassOrInterfaceType, boolean ignoreExceptions)Obtain aClass<?>reference for the class named by thisClassInfoobject, 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
superclassOrInterfaceTypeis a class reference for an already-loaded class, it is critical thatsuperclassOrInterfaceTypeis loaded by the same classloader as the class referred to by thisClassInfoobject, otherwise the class cast will fail.- Type Parameters:
T- the superclass or interface type- Parameters:
superclassOrInterfaceType- TheClassreference for 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 resultingClass<?>reference to the requested superclass or interface type fails. If false,IllegalArgumentExceptionis 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:
java.lang.IllegalArgumentException- if ignoreExceptions is false and there were problems loading the class, or casting it to the requested type.
-
loadClass
public <T> java.lang.Class<T> loadClass(java.lang.Class<T> superclassOrInterfaceType)
Obtain aClass<?>reference for the class named by thisClassInfoobject, 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
superclassOrInterfaceTypeis a class reference for an already-loaded class, it is critical thatsuperclassOrInterfaceTypeis loaded by the same classloader as the class referred to by thisClassInfoobject, otherwise the class cast will fail.- Type Parameters:
T- The superclass or interface type- Parameters:
superclassOrInterfaceType- The type to cast the loaded class to.- Returns:
- The class reference.
- Throws:
java.lang.IllegalArgumentException- if there were problems loading the class or casting it to the requested type.
-
loadClass
public java.lang.Class<?> loadClass(boolean ignoreExceptions)
Obtain aClass<?>reference for the class named by thisClassInfoobject. Causes the ClassLoader to load the class, if it is not already loaded.- Parameters:
ignoreExceptions- Whether or not to ignore exceptions- Returns:
- The class reference, or null, if ignoreExceptions is true and there was an exception or error loading the class.
- Throws:
java.lang.IllegalArgumentException- if ignoreExceptions is false and there were problems loading the class.
-
loadClass
public java.lang.Class<?> loadClass()
Obtain aClass<?>reference for the class named by thisClassInfoobject. Causes the ClassLoader to load the class, if it is not already loaded.- Returns:
- The class reference.
- Throws:
java.lang.IllegalArgumentException- if there were problems loading the class.
-
getClassName
protected java.lang.String getClassName()
The name of the class (used bygetClassInfo()to fetch theClassInfoobject for the class).- Returns:
- The class name.
-
getClassInfo
protected ClassInfo getClassInfo()
-
findReferencedClassNames
protected void findReferencedClassNames(java.util.Set<java.lang.String> referencedClassNames)
Get the names of any classes referenced in this class' type descriptor, or the type descriptors of fields, methods or annotations.- Parameters:
referencedClassNames- the referenced class names
-
getClassDependencies
public ClassInfoList getClassDependencies()
Get the class dependencies.- Returns:
- A
ClassInfoListofClassInfoobjects for all classes referenced by this class. Note that you need to callClassGraph.enableInterClassDependencies()beforeClassGraph.scan()for this method to work. You should also callClassGraph.enableExternalClasses()beforeClassGraph.scan()if you want non-whitelisted classes to appear in the result.
-
compareTo
public int compareTo(ClassInfo o)
Compare based on class name.- Specified by:
compareToin interfacejava.lang.Comparable<ClassInfo>- Parameters:
o- the other object- Returns:
- the comparison result
-
equals
public boolean equals(java.lang.Object obj)
Use class name for equals().- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the other object- Returns:
- Whether the objects were equal.
-
hashCode
public int hashCode()
Use hash code of class name.- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hashcode
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-