Class ClassInfo
- All Implemented Interfaces:
HasName, Comparable<ClassInfo>
- Direct Known Subclasses:
ArrayClassInfo
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ResourceTheResourcefor the classfile of this class.protected Class<?> The class ref, once the class is loaded.protected booleanIf true, this class is only being referenced by another class' classfile as a superclass / implemented interface / annotation, but this class is not itself an accepted (non-rejected) class, or in a accepted (non-rejected) package.protected booleanSet to true when the class is actually scanned (as opposed to just referenced as a superclass, interface or annotation of a scanned class).protected StringThe name of the class.protected ScanResultThe scan result.protected StringThe class type signature string. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintCompare based on class name.booleanUse class name for equals().booleanextendsSuperclass(Class<?> superclass) Checks if this class extends the superclass.booleanextendsSuperclass(String superclassName) Checks if this class extends the named superclass.protected voidfindReferencedClassInfo(Map<String, ClassInfo> classNameToClassInfo, Set<ClassInfo> refdClassInfo, nonapi.io.github.classgraph.utils.LogNode log) GetClassInfoobjects for any classes referenced in this class' type descriptor, or the type descriptors of fields, methods or annotations.Get the default parameter values for this annotation, if this is an annotation class.Get a list of the annotations on this class, or the empty list if none.getAnnotationInfo(Class<? extends Annotation> annotation) Get a the non-Repeatableannotation on this class, or null if the class does not have the annotation.getAnnotationInfo(String annotationName) Get a the named non-Repeatableannotation on this class, or null if the class does not have the named annotation.getAnnotationInfoRepeatable(Class<? extends Annotation> annotation) Get a theRepeatableannotation on this class, or the empty list if the class does not have the annotation.getAnnotationInfoRepeatable(String annotationName) Get a the namedRepeatableannotation on this class, or the empty list if the class does not have the named annotation.Get the annotations and meta-annotations on this class.Get the class dependencies.Get the classes (and their subclasses) that implement this interface, if this is an interface.Get the classes that have this class as an annotation.Get the classes that have this class as a field annotation or meta-annotation.Get all classes that have this class as a method annotation, and their subclasses, if the method is non-private.Get all classes that have this class as a method parameter annotation, and their subclasses, if the method is non-private.intGet the major version of the classfile format for this class' classfile.intGet the minor version of the classfile format for this class' classfile.protected ClassInfoprotected StringThe name of the class (used byScanResultObject.getClassInfo()to fetch theClassInfoobject for the class).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.Get theURIof the classpath element that this class was found within.Get theURLof the classpath element or module that this class was found within.Returns information on visible constructors declared by this class, or by its interfaces or superclasses.Returns information on visible constructors declared by this class, but not by its interfaces or superclasses.Returns information on all visible fields declared by this class, but not by its superclasses.getDeclaredFieldInfo(String fieldName) Returns information on the named field declared by the class, but not by its superclasses.Returns information on visible methods and constructors declared by this class, but not by its interfaces or superclasses.Returns information on visible methods declared by this class, but not by its interfaces or superclasses, that are not constructors.getDeclaredMethodInfo(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.Get all field annotations.Returns information on all visible fields declared by this class, or by its superclasses.getFieldInfo(String fieldName) Returns information on the named filed declared by this class, or by its superclasses.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.Get the inner classes contained within this class, if this is an outer class.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 information on visible constructors declared by this class, or by its interfaces or superclasses.Get all method annotations.Returns information on visible methods declared by this class, or by its interfaces or superclasses, that are not constructors.getMethodInfo(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.Get all method parameter annotations.intGet the class modifier bits.Get the class modifiers as a String.Get theModuleInfoobject for the class.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.getName()Get the name of the class.Get the containing outer classes, if this is an inner class.Get thePackageInfoobject for the class.Get the name of the class' package.TheResourcefor the classfile of this class.Get the simple name of the class.Returns the name of the source file this class has been compiled from, such asClassInfo.javaorKClass.kt.Get the subclasses of this class, sorted in order of name.Get the single direct superclass of this class, or null if none.Get all superclasses of this class, in ascending order in the class hierarchy, not includingObjectfor simplicity, since that is the superclass of all classes.Returns a synthetic type descriptor for the method, created from the class name, superclass name, and implemented interfaces.Get the parsed type signature for the class.Returns the parsed type signature for this class, possibly including type parameters.Get the type signature string for the class.booleanhasAnnotation(Class<? extends Annotation> annotation) Checks whether this class has the annotation.booleanhasAnnotation(String annotationName) Checks whether this class has the named annotation.booleanhasDeclaredField(String fieldName) Checks whether this class has the named declared field.booleanhasDeclaredFieldAnnotation(Class<? extends Annotation> annotation) Checks whether this class declares a field with the annotation.booleanhasDeclaredFieldAnnotation(String fieldAnnotationName) Checks whether this class declares a field with the named annotation.booleanhasDeclaredMethod(String methodName) Checks whether this class declares a method of the given name.booleanhasDeclaredMethodAnnotation(Class<? extends Annotation> methodAnnotation) Checks whether this class declares a method with the annotation.booleanhasDeclaredMethodAnnotation(String methodAnnotationName) Checks whether this class declares a method with the named annotation.booleanhasDeclaredMethodParameterAnnotation(Class<? extends Annotation> methodParameterAnnotation) Checks whether this class declares a method with the annotation.booleanhasDeclaredMethodParameterAnnotation(String methodParameterAnnotationName) Checks whether this class declares a method with the named annotation.booleanChecks whether this class or one of its superclasses has the named field.booleanhasFieldAnnotation(Class<? extends Annotation> fieldAnnotation) Checks whether this class or one of its superclasses declares a field with the annotation.booleanhasFieldAnnotation(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.booleanChecks whether this class or one of its superclasses or interfaces declares a method of the given name.booleanhasMethodAnnotation(Class<? extends Annotation> methodAnnotation) Checks whether this class or one of its superclasses or interfaces declares a method with the annotation.booleanhasMethodAnnotation(String methodAnnotationName) Checks whether this class or one of its superclasses or interfaces declares a method with the named annotation.booleanhasMethodParameterAnnotation(Class<? extends Annotation> methodParameterAnnotation) Checks whether this class or one of its superclasses or interfaces has a method with the annotation.booleanhasMethodParameterAnnotation(String methodParameterAnnotationName) Checks whether this class or one of its superclasses or interfaces has a method with the named annotation.booleanimplementsInterface(Class<?> interfaceClazz) Checks whether this class implements the interface.booleanimplementsInterface(String interfaceName) Checks whether this class implements the named interface.booleanChecks if the class is abstract.booleanChecks if the class is an annotation.booleanChecks if this class is an anonymous inner class.booleanChecks if this class is an array class.booleanisEnum()Checks if is the class is anEnum.booleanChecks if this is an external class.booleanisFinal()Checks if the class is final.booleanChecks 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).booleanChecks if this class is an inner class.booleanChecks if is the class an interface and is not an annotation.booleanChecks if is an interface or an annotation.booleanChecks if this class is an outer class.booleanChecks if the class has default (package) visibility.booleanChecks if the class is private.booleanChecks if the class is protected.booleanisPublic()Checks if the class is public.booleanisRecord()Checks if is the class is a record (JDK 14+).booleanChecks if this class is a standard class.booleanisStatic()Checks if the class is static.booleanChecks if the class is synthetic.Class<?> Obtain aClass<?>reference for the class named by thisClassInfoobject.Class<?> loadClass(boolean ignoreExceptions) Obtain aClass<?>reference for the class named by thisClassInfoobject.<T> Class<T> Obtain aClass<?>reference for the class named by thisClassInfoobject, casting it to the requested interface or superclass type.<T> Class<T> Obtain aClass<?>reference for the class named by thisClassInfoobject, casting it to the requested interface or superclass type.toString()Render to string.protected voidtoString(boolean useSimpleNames, StringBuilder buf) To string.Render to string, using only simple names for classes.
-
Field Details
-
name
The name of the class. -
typeSignatureStr
The class type signature string. -
isExternalClass
protected boolean isExternalClassIf true, this class is only being referenced by another class' classfile as a superclass / implemented interface / annotation, but this class is not itself an accepted (non-rejected) class, or in a accepted (non-rejected) package. If false, this classfile was matched during scanning (i.e. its classfile contents read), i.e. this class is a accepted (and non-rejected) class in an accepted (and non-rejected) package. -
isScannedClass
protected boolean isScannedClassSet to true when the class is actually scanned (as opposed to just referenced as a superclass, interface or annotation of a scanned class). -
classfileResource
-
scanResult
The scan result. -
classRef
The class ref, once the class is loaded.
-
-
Constructor Details
-
ClassInfo
-
-
Method Details
-
getName
-
getSimpleName
Get the simple name of the class. Returns everything after the last '.' in the class name, or the whole string if the class is in the root package. (Note that this is not the same as the result ofClass.getSimpleName(), which returns "" for anonymous classes.)- Returns:
- The simple name of the class.
-
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
Get thePackageInfoobject for the class.- Returns:
- the
PackageInfoobject for the package that contains the class.
-
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 an accepted class as a superclass, interface, or annotation, but is not itself an accepted class.
-
getClassfileMinorVersion
public int getClassfileMinorVersion()Get the minor version of the classfile format for this class' classfile.- Returns:
- The minor version of the classfile format for this class' classfile, or 0 if this
ClassInfoobject is a placeholder for a referenced class that was not found or not accepted during the scan.
-
getClassfileMajorVersion
public int getClassfileMajorVersion()Get the major version of the classfile format for this class' classfile.- Returns:
- The major version of the classfile format for this class' classfile, or 0 if this
ClassInfoobject is a placeholder for a referenced class that was not found or not accepted during the scan.
-
getModifiers
public int getModifiers()Get the class modifier bits.- Returns:
- The class modifier bits, e.g.
Modifier.PUBLIC.
-
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.
-
isPrivate
public boolean isPrivate()Checks if the class is private.- Returns:
- true if this class is a private class.
-
isProtected
public boolean isProtected()Checks if the class is protected.- Returns:
- true if this class is a protected class.
-
isPackageVisible
public boolean isPackageVisible()Checks if the class has default (package) visibility.- Returns:
- true if this class is only visible within its package.
-
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
-
isRecord
public boolean isRecord()Checks if is the class is a record (JDK 14+).- Returns:
- true if this class is a record.
-
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).
-
isArrayClass
public boolean isArrayClass()Checks if this class is an array class. Returns false unless thisClassInfois an instance ofArrayClassInfo.- Returns:
- true if this is an array class.
-
extendsSuperclass
Checks if this class extends the superclass.- Parameters:
superclass- A superclass.- Returns:
- true if this class extends the superclass.
-
extendsSuperclass
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
Checks whether this class implements the interface.- Parameters:
interfaceClazz- An interface.- Returns:
- true if this class implements the interface.
-
implementsInterface
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
Checks whether this class has the annotation.- Parameters:
annotation- An annotation.- Returns:
- true if this class has the annotation.
-
hasAnnotation
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
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
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
Checks whether this class declares a field with the annotation.- Parameters:
annotation- A field annotation.- Returns:
- true if this class declares a field with the annotation.
-
hasDeclaredFieldAnnotation
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
Checks whether this class or one of its superclasses declares a field with the annotation.- Parameters:
fieldAnnotation- A field annotation.- Returns:
- true if this class or one of its superclasses declares a field with the annotation.
-
hasFieldAnnotation
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
Checks whether this class declares a method of the given name.- Parameters:
methodName- The name of a method.- Returns:
- true if this class declares a method of the given name.
-
hasMethod
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
Checks whether this class declares a method with the annotation.- Parameters:
methodAnnotation- A method annotation.- Returns:
- true if this class declares a method with the annotation.
-
hasDeclaredMethodAnnotation
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
Checks whether this class or one of its superclasses or interfaces declares a method with the annotation.- Parameters:
methodAnnotation- A method annotation.- Returns:
- true if this class or one of its superclasses or interfaces declares a method with the annotation.
-
hasMethodAnnotation
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(Class<? extends Annotation> methodParameterAnnotation) Checks whether this class declares a method with the annotation.- Parameters:
methodParameterAnnotation- A method annotation.- Returns:
- true if this class declares a method with the annotation.
-
hasDeclaredMethodParameterAnnotation
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
Checks whether this class or one of its superclasses or interfaces has a method with the annotation.- Parameters:
methodParameterAnnotation- A method annotation.- Returns:
- true if this class or one of its superclasses or interfaces has a method with the annotation.
-
hasMethodParameterAnnotation
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
Get the subclasses of this class, sorted in order of name. CallClassInfoList.directOnly()to get direct subclasses. If this class representsObject, then returns only standard classes, not interfaces, since interfaces don't extendObject.- Returns:
- the list of subclasses of this class, or the empty list if none.
-
getSuperclasses
Get all superclasses of this class, in ascending order in the class hierarchy, not includingObjectfor simplicity, since that is the superclass of all classes. Also 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
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
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
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
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
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
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
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.Filters out meta-annotations in the
java.lang.annotationpackage.- Returns:
- the list of annotations and meta-annotations on this class.
-
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
Get a the non-Repeatableannotation on this class, or null if the class does not have the 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 annotations, it is faster to call
getAnnotationInfo(), and then get the annotations from the returnedAnnotationInfoList, so that the returned list doesn't have to be built multiple times.- Parameters:
annotation- The annotation.- Returns:
- An
AnnotationInfoobject representing the annotation on this class, or null if the class does not have the annotation.
-
getAnnotationInfo
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
Get a theRepeatableannotation on this class, or the empty list if the class does not have the 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 annotations, it is faster to call
getAnnotationInfo(), and then get the annotations from the returnedAnnotationInfoList, so that the returned list doesn't have to be built multiple times.- Parameters:
annotation- The annotation.- Returns:
- An
AnnotationInfoListof all instances of the annotation on this class, or the empty list if the class does not have the annotation.
-
getAnnotationInfoRepeatable
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
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
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
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:
IllegalArgumentException- ifClassGraph.enableMethodInfo()was not called prior to initiating the scan.
-
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:
IllegalArgumentException- ifClassGraph.enableMethodInfo()was not called prior to initiating the scan.
-
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:
IllegalArgumentException- ifClassGraph.enableMethodInfo()was not called prior to initiating the scan.
-
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:
IllegalArgumentException- ifClassGraph.enableMethodInfo()was not called prior to initiating the scan.
-
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:
IllegalArgumentException- ifClassGraph.enableMethodInfo()was not called prior to initiating the scan.
-
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:
IllegalArgumentException- ifClassGraph.enableMethodInfo()was not called prior to initiating the scan.
-
getDeclaredMethodInfo
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:
IllegalArgumentException- ifClassGraph.enableMethodInfo()was not called prior to initiating the scan.
-
getMethodInfo
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:
IllegalArgumentException- ifClassGraph.enableMethodInfo()was not called prior to initiating the scan.
-
getMethodAnnotations
Get all method annotations.- Returns:
- A list of all 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 -- callClassMemberInfo.getAnnotationInfo()to get details on specific method annotation instances.
-
getMethodParameterAnnotations
Get all method parameter annotations.- Returns:
- A list of all 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 -- callClassMemberInfo.getAnnotationInfo()to get details on specific method annotation instances.
-
getClassesWithMethodAnnotation
Get all classes that have this class as a method annotation, and their subclasses, if the method is non-private.- Returns:
- A list of classes that have a declared method with this annotation or meta-annotation, or the empty list if none.
-
getClassesWithMethodParameterAnnotation
Get all classes that have this class as a method parameter annotation, and their subclasses, if the method is non-private.- Returns:
- A list of classes that have a declared method with a parameter that is annotated with this annotation or meta-annotation, or the empty list if none.
-
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 fields, 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:
IllegalArgumentException- ifClassGraph.enableFieldInfo()was not called prior to initiating the scan.
-
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 fields, 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:
IllegalArgumentException- ifClassGraph.enableFieldInfo()was not called prior to initiating the scan.
-
getEnumConstants
- Returns:
- All enum constants of an enum class as a list of
FieldInfoobjects (enum constants are stored as fields in Java classes).
-
getEnumConstantObjects
-
getDeclaredFieldInfo
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:
IllegalArgumentException- ifClassGraph.enableFieldInfo()was not called prior to initiating the scan.
-
getFieldInfo
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 fields, 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:
IllegalArgumentException- ifClassGraph.enableFieldInfo()was not called prior to initiating the scan.
-
getFieldAnnotations
Get all field annotations.- Returns:
- A list of all annotations on fields of this class, or the empty list if none. N.B. these annotations
do not contain specific annotation parameters -- call
ClassMemberInfo.getAnnotationInfo()to get details on specific field annotation instances.
-
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
Get the parsed type signature for the class.- Returns:
- The parsed type signature for the class, including any generic type parameters, or null if not available (probably indicating the class is not generic).
- Throws:
IllegalArgumentException- if the class type signature cannot be parsed (this should only be thrown in the case of classfile corruption, or a compiler bug that causes an invalid type signature to be written to the classfile).
-
getTypeSignatureStr
Get the type signature string for the class.- Returns:
- The type signature string for the class, including any generic type parameters, or null if not available (probably indicating the class is not generic).
-
getTypeSignatureOrTypeDescriptor
Returns the parsed type signature for this class, possibly including type parameters. If the type signature is not present for this class, indicating that this is not a generic class, then a type descriptor will be synthesized and returned, as if there were a type descriptor (classfiles may have a type signature but do not contain a type descriptor). May include type annotations on the superclass or interface(s).- Returns:
- The parsed generic type signature for the class, or if not available, the synthetic type descriptor for the class.
-
getTypeDescriptor
Returns a synthetic type descriptor for the method, created from the class name, superclass name, and implemented interfaces. May include type annotations on the superclass or interface(s).- Returns:
- The synthetic type descriptor for the class.
-
getSourceFile
Returns the name of the source file this class has been compiled from, such asClassInfo.javaorKClass.kt.This field may be
null.- Returns:
- The name of the source file of this class, or
nullif not available
-
getClasspathElementURI
Get theURIof the classpath element that this class was found within.- Returns:
- The
URIof the classpath element that this class was found within. - Throws:
IllegalArgumentException- if the classpath element does not have a valid URI (e.g. for modules whose location URI is null).
-
getClasspathElementURL
Get theURLof the classpath element or module that this class was found within. UsegetClasspathElementURI()instead if the resource may have come from a system module, or if this is a jlink'd runtime image, since "jrt:" URI schemes used by system modules and jlink'd runtime images are not suppored byURL, and this will causeIllegalArgumentExceptionto be thrown.- Returns:
- The
URLof the classpath element that this class was found within. - Throws:
IllegalArgumentException- if the classpath element URI cannot be converted to aURL(in particular, if the URI has ajrt:/scheme).
-
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 (seegetModuleRef()). May also return null if the classpath element was an http/https URL, and the jar was downloaded directly to RAM, rather than to a temp file on disk (e.g. if the temp dir is not writeable).
-
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
-
loadClass
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:
IllegalArgumentException- if ignoreExceptions is false and there were problems loading the class, or casting it to the requested type.
-
loadClass
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:
IllegalArgumentException- if there were problems loading the class or casting it to the requested type.
-
loadClass
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:
IllegalArgumentException- if ignoreExceptions is false and there were problems loading the 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:
IllegalArgumentException- if there were problems loading the class.
-
getClassName
-
getClassInfo
-
findReferencedClassInfo
protected void findReferencedClassInfo(Map<String, ClassInfo> classNameToClassInfo, Set<ClassInfo> refdClassInfo, nonapi.io.github.classgraph.utils.LogNode log) GetClassInfoobjects for any classes referenced in this class' type descriptor, or the type descriptors of fields, methods or annotations.- Parameters:
classNameToClassInfo- the map from class name toClassInfo.refdClassInfo- the referenced class infolog- the log
-
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-accepted classes to appear in the result.
-
compareTo
Compare based on class name.- Specified by:
compareToin interfaceComparable<ClassInfo>- Parameters:
o- the other object- Returns:
- the comparison result
-
equals
-
hashCode
-
toString
To string.- Parameters:
useSimpleNames- use simple namesbuf- the buf
-
toStringWithSimpleNames
Render to string, using only simple names for classes.- Returns:
- the string representation, using simple names for classes.
-
toString
-