Class ClassInfo
- java.lang.Object
-
- io.github.classgraph.ScanResultObject
-
- io.github.classgraph.ClassInfo
-
- Direct Known Subclasses:
ArrayClassInfo
public class ClassInfo extends ScanResultObject implements java.lang.Comparable<ClassInfo>, HasName
Holds metadata about a class encountered during a scan.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ClassInfo.ClassType
The class type to return.(package private) static class
ClassInfo.ReachableAndDirectlyRelatedClasses
A set of classes that indirectly reachable through a directed path, for a given relationship type, and a set of classes that is directly related (only one relationship step away).(package private) static class
ClassInfo.RelType
How classes are related.
-
Field Summary
Fields Modifier and Type Field Description private static int
ANNOTATION_CLASS_MODIFIER
The modifier bit for annotations.(package private) AnnotationParameterValueList
annotationDefaultParamValues
For annotations, the default values of parameters.(package private) boolean
annotationDefaultParamValuesHasBeenConvertedToPrimitive
Set to true once any Object[] arrays of boxed types in annotationDefaultParamValues have been lazily converted to primitive arrays.(package private) AnnotationInfoList
annotationInfo
Info on class annotations, including optional annotation param values.private int
classfileMajorVersion
The major version of the classfile format for this class' classfile.private int
classfileMinorVersion
The minor version of the classfile format for this class' classfile.protected Resource
classfileResource
TheResource
for the classfile of this class.(package private) java.lang.ClassLoader
classLoader
The classloader this class was obtained from.(package private) ClasspathElement
classpathElement
The classpath element that this class was found within.(package private) FieldInfoList
fieldInfo
Info on fields.private java.lang.String
fullyQualifiedDefiningMethodName
The fully-qualified defining method name, for anonymous inner classes.protected boolean
isExternalClass
If 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.(package private) boolean
isInherited
This annotation has theInherited
meta-annotation, which means that any class that this annotation is applied to also implicitly causes the annotation to annotate all subclasses too.private boolean
isRecord
True if the class is a record.protected boolean
isScannedClass
Set to true when the class is actually scanned (as opposed to just referenced as a superclass, interface or annotation of a scanned class).(package private) MethodInfoList
methodInfo
Info on fields.private java.util.List<ClassInfo>
methodOverrideOrder
The override order for a class' methods (base class, followed by superclasses, followed by interfaces).private int
modifiers
Class modifier flags, e.g.(package private) ModuleInfo
moduleInfo
Info on the class module.protected java.lang.String
name
The name of the class.private static ClassInfo.ReachableAndDirectlyRelatedClasses
NO_REACHABLE_CLASSES
The constant empty return value used when no classes are reachable.private java.util.List<ClassInfo>
overrideOrder
The override order for a class' fields or methods (base class, followed by interfaces, followed by superclasses).(package private) PackageInfo
packageInfo
Info on the package containing the class.private ClassInfoList
referencedClasses
A list of ClassInfo objects for classes referenced by this class.private java.util.Set<java.lang.String>
referencedClassNames
Names of classes referenced by this class in class refs and type signatures in the constant pool of the classfile.private java.util.Map<ClassInfo.RelType,java.util.Set<ClassInfo>>
relatedClasses
The set of classes related to this one.private java.lang.String
sourceFile
The name of the source file this class has been compiled from(package private) java.util.List<Classfile.ClassTypeAnnotationDecorator>
typeAnnotationDecorators
The type annotation decorators for theClassTypeSignature
instance.private ClassTypeSignature
typeDescriptor
The synthetic class type descriptor.private ClassTypeSignature
typeSignature
The class type signature, parsed.protected java.lang.String
typeSignatureStr
The class type signature string.-
Fields inherited from class io.github.classgraph.ScanResultObject
classRef, scanResult
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
addAnnotationParamDefaultValues(AnnotationParameterValueList paramNamesAndValues)
Add annotation default values.(package private) void
addClassAnnotation(AnnotationInfo classAnnotationInfo, java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo)
Add an annotation to this class.(package private) static void
addClassContainment(java.util.List<Classfile.ClassContainment> classContainmentEntries, java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo)
Add class containment info.(package private) void
addFieldInfo(FieldInfoList fieldInfoList, java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo)
Add field info.private void
addFieldOrMethodAnnotationInfo(AnnotationInfoList annotationInfoList, boolean isField, int modifiers, java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo)
Add field or method annotation cross-links.(package private) void
addFullyQualifiedDefiningMethodName(java.lang.String fullyQualifiedDefiningMethodName)
Add containing method name, for anonymous inner classes.(package private) void
addImplementedInterface(java.lang.String interfaceName, java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo)
Add an implemented interface to this class.(package private) void
addMethodInfo(MethodInfoList methodInfoList, java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo)
Add method info.(package private) void
addReferencedClassNames(java.util.Set<java.lang.String> refdClassNames)
Add names of classes referenced by this class.(package private) boolean
addRelatedClass(ClassInfo.RelType relType, ClassInfo classInfo)
Add a class with a given relationship type.(package private) static ClassInfo
addScannedClass(java.lang.String className, int classModifiers, boolean isExternalClass, java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo, ClasspathElement classpathElement, Resource classfileResource)
Add a class that has just been scanned (as opposed to just referenced by a scanned class).(package private) void
addSuperclass(java.lang.String superclassName, java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo)
Add a superclass to this class.(package private) void
addTypeDecorators(java.util.List<Classfile.ClassTypeAnnotationDecorator> classTypeAnnotationDecorators)
AddClassfile.ClassTypeAnnotationDecorator
instances.int
compareTo(ClassInfo o)
Compare based on class name.boolean
equals(java.lang.Object obj)
Use class name for equals().boolean
extendsSuperclass(java.lang.Class<?> superclass)
Checks if this class extends the superclass.boolean
extendsSuperclass(java.lang.String superclassName)
Checks if this class extends the named superclass.private ClassInfo.ReachableAndDirectlyRelatedClasses
filterClassInfo(ClassInfo.RelType relType, boolean strictAccept, ClassInfo.ClassType... classTypes)
Get the classes related to this one (the transitive closure) for the given relationship type, and those directly related.private static java.util.Set<ClassInfo>
filterClassInfo(java.util.Collection<ClassInfo> classes, ScanSpec scanSpec, boolean strictAccept, ClassInfo.ClassType... classTypes)
Filter classes according to scan spec and class type.protected void
findReferencedClassInfo(java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo, java.util.Set<ClassInfo> refdClassInfo, LogNode log)
GetClassInfo
objects for any classes referenced in this class' type descriptor, or the type descriptors of fields, methods or annotations.(package private) static ClassInfoList
getAllAnnotationClasses(java.util.Collection<ClassInfo> classes, ScanSpec scanSpec)
Get all annotation classes found during the scan.(package private) static ClassInfoList
getAllClasses(java.util.Collection<ClassInfo> classes, ScanSpec scanSpec)
Get all classes found during the scan.(package private) static ClassInfoList
getAllEnums(java.util.Collection<ClassInfo> classes, ScanSpec scanSpec)
Get allEnum
classes found during the scan.(package private) static ClassInfoList
getAllImplementedInterfaceClasses(java.util.Collection<ClassInfo> classes, ScanSpec scanSpec)
Get all implemented interface (non-annotation interface) classes found during the scan.(package private) static ClassInfoList
getAllInterfacesOrAnnotationClasses(java.util.Collection<ClassInfo> classes, ScanSpec scanSpec)
Get all interface or annotation classes found during the scan.(package private) static ClassInfoList
getAllRecords(java.util.Collection<ClassInfo> classes, ScanSpec scanSpec)
Get allrecord
classes found during the scan.(package private) static ClassInfoList
getAllStandardClasses(java.util.Collection<ClassInfo> classes, ScanSpec scanSpec)
Get all standard classes found during the scan.AnnotationParameterValueList
getAnnotationDefaultParameterValues()
Get the default parameter values for this annotation, if this is an annotation class.AnnotationInfoList
getAnnotationInfo()
Get a list of the annotations on this class, or the empty list if none.AnnotationInfo
getAnnotationInfo(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
Get a the non-Repeatable
annotation on this class, or null if the class does not have the annotation.AnnotationInfo
getAnnotationInfo(java.lang.String annotationName)
Get a the named non-Repeatable
annotation on this class, or null if the class does not have the named annotation.AnnotationInfoList
getAnnotationInfoRepeatable(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
Get a theRepeatable
annotation on this class, or the empty list if the class does not have the annotation.AnnotationInfoList
getAnnotationInfoRepeatable(java.lang.String annotationName)
Get a the namedRepeatable
annotation on this class, or the empty list if the class does not have the named annotation.ClassInfoList
getAnnotations()
Get the annotations and meta-annotations on this class.ClassInfoList
getClassDependencies()
Get the class dependencies.ClassInfoList
getClassesImplementing()
Get the classes (and their subclasses) that implement this interface, if this is an interface.ClassInfoList
getClassesWithAnnotation()
Get the classes that have this class as an annotation.(package private) ClassInfoList
getClassesWithAnnotationDirectOnly()
Get the classes that have this class as a direct annotation.ClassInfoList
getClassesWithFieldAnnotation()
Get the classes that have this class as a field annotation or meta-annotation.(package private) ClassInfoList
getClassesWithFieldAnnotationDirectOnly()
Get the classes that have this class as a direct field annotation.private ClassInfoList
getClassesWithFieldOrMethodAnnotation(ClassInfo.RelType relType)
Get the classes that have this class as a field, method or method parameter annotation.ClassInfoList
getClassesWithMethodAnnotation()
Get all classes that have this class as a method annotation, and their subclasses, if the method is non-private.(package private) ClassInfoList
getClassesWithMethodAnnotationDirectOnly()
Get the classes that have this class as a direct method annotation.ClassInfoList
getClassesWithMethodParameterAnnotation()
Get all classes that have this class as a method parameter annotation, and their subclasses, if the method is non-private.(package private) ClassInfoList
getClassesWithMethodParameterAnnotationDirectOnly()
Get the classes that have this class as a direct method parameter annotation.int
getClassfileMajorVersion()
Get the major version of the classfile format for this class' classfile.int
getClassfileMinorVersion()
Get the minor version of the classfile format for this class' classfile.protected ClassInfo
getClassInfo()
Get theClassInfo
object for the referenced class, or null if the referenced class was not encountered during scanning (i.e.protected java.lang.String
getClassName()
The name of the class (used byScanResultObject.getClassInfo()
to fetch theClassInfo
object for the class).java.io.File
getClasspathElementFile()
Get theFile
for the classpath element package root dir or jar that this class was found within, or null if this class was found in a module.java.net.URI
getClasspathElementURI()
Get theURI
of the classpath element that this class was found within.java.net.URL
getClasspathElementURL()
Get theURL
of the classpath element or module that this class was found within.MethodInfoList
getConstructorInfo()
Returns information on visible constructors declared by this class, or by its interfaces or superclasses.MethodInfoList
getDeclaredConstructorInfo()
Returns information on visible constructors declared by this class, but not by its interfaces or superclasses.FieldInfoList
getDeclaredFieldInfo()
Returns information on all visible fields declared by this class, but not by its superclasses.FieldInfo
getDeclaredFieldInfo(java.lang.String fieldName)
Returns information on the named field declared by the class, but not by its superclasses.MethodInfoList
getDeclaredMethodAndConstructorInfo()
Returns information on visible methods and constructors declared by this class, but not by its interfaces or superclasses.MethodInfoList
getDeclaredMethodInfo()
Returns information on visible methods declared by this class, but not by its interfaces or superclasses, that are not constructors.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.private MethodInfoList
getDeclaredMethodInfo(java.lang.String methodName, boolean getNormalMethods, boolean getConstructorMethods, boolean getStaticInitializerMethods)
Get the declared methods, constructors, and/or static initializer methods of the class.java.util.List<java.lang.Object>
getEnumConstantObjects()
FieldInfoList
getEnumConstants()
ClassInfoList
getFieldAnnotations()
Get all field annotations.FieldInfoList
getFieldInfo()
Returns information on all visible fields declared by this class, or by its superclasses.FieldInfo
getFieldInfo(java.lang.String fieldName)
Returns information on the named filed declared by this class, or by its superclasses.private ClassInfoList
getFieldOrMethodAnnotations(ClassInfo.RelType relType)
Get the annotations or meta-annotations on fields, methods or method parametres declared by the class, (not including fields, methods or method parameters declared by the interfaces or superclasses of this class).private java.util.List<ClassInfo>
getFieldOverrideOrder()
Get the order that fields are overridden in (base class first).private java.util.List<ClassInfo>
getFieldOverrideOrder(java.util.Set<ClassInfo> visited, java.util.List<ClassInfo> overrideOrderOut)
Recurse to interfaces and superclasses to get the order that fields are overridden in.java.lang.String
getFullyQualifiedDefiningMethodName()
Gets fully-qualified method name (i.e.ClassInfoList
getInnerClasses()
Get the inner classes contained within this class, if this is an outer class.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.MethodInfoList
getMethodAndConstructorInfo()
Returns information on visible constructors declared by this class, or by its interfaces or superclasses.ClassInfoList
getMethodAnnotations()
Get all method annotations.MethodInfoList
getMethodInfo()
Returns information on visible methods declared by this class, or by its interfaces or superclasses, that are not constructors.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.private MethodInfoList
getMethodInfo(java.lang.String methodName, boolean getNormalMethods, boolean getConstructorMethods, boolean getStaticInitializerMethods)
Get the methods, constructors, and/or static initializer methods of the class.private java.util.List<ClassInfo>
getMethodOverrideOrder()
Get the order that methods are overridden in.private java.util.List<ClassInfo>
getMethodOverrideOrder(java.util.Set<ClassInfo> visited, java.util.List<ClassInfo> overrideOrderOut)
Recurse to collect classes and interfaces in the order of overridden methods, in descending priority.ClassInfoList
getMethodParameterAnnotations()
Get all method parameter annotations.int
getModifiers()
Get the class modifier bits.java.lang.String
getModifiersStr()
Get the class modifiers as a String.ModuleInfo
getModuleInfo()
Get theModuleInfo
object for the class.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.java.lang.String
getName()
Get the name of the class.(package private) static ClassInfo
getOrCreateClassInfo(java.lang.String className, java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo)
Get a ClassInfo object, or create it if it doesn't exist.ClassInfoList
getOuterClasses()
Get the containing outer classes, if this is an inner class.PackageInfo
getPackageInfo()
Get thePackageInfo
object for the class.java.lang.String
getPackageName()
Get the name of the class' package.Resource
getResource()
TheResource
for the classfile of this class.java.lang.String
getSimpleName()
Get the simple name of the class.(package private) static java.lang.String
getSimpleName(java.lang.String className)
Get simple name from fully-qualified class name.java.lang.String
getSourceFile()
Returns the name of the source file this class has been compiled from, such asClassInfo.java
orKClass.kt
.ClassInfoList
getSubclasses()
Get the subclasses of this class, sorted in order of name.ClassInfo
getSuperclass()
Get the single direct superclass of this class, or null if none.ClassInfoList
getSuperclasses()
Get all superclasses of this class, in ascending order in the class hierarchy, not includingObject
for simplicity, since that is the superclass of all classes.ClassTypeSignature
getTypeDescriptor()
Returns a synthetic type descriptor for the method, created from the class name, superclass name, and implemented interfaces.ClassTypeSignature
getTypeSignature()
Get the parsed type signature for the class.ClassTypeSignature
getTypeSignatureOrTypeDescriptor()
Returns the parsed type signature for this class, possibly including type parameters.java.lang.String
getTypeSignatureStr()
Get the type signature string for the class.(package private) void
handleRepeatableAnnotations(java.util.Set<java.lang.String> allRepeatableAnnotationNames)
HandleRepeatable
annotations.boolean
hasAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
Checks whether this class has the annotation.boolean
hasAnnotation(java.lang.String annotationName)
Checks whether this class has the named annotation.boolean
hasDeclaredField(java.lang.String fieldName)
Checks whether this class has the named declared field.boolean
hasDeclaredFieldAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
Checks whether this class declares a field with the annotation.boolean
hasDeclaredFieldAnnotation(java.lang.String fieldAnnotationName)
Checks whether this class declares a field with the named annotation.boolean
hasDeclaredMethod(java.lang.String methodName)
Checks whether this class declares a method of the given name.boolean
hasDeclaredMethodAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> methodAnnotation)
Checks whether this class declares a method with the annotation.boolean
hasDeclaredMethodAnnotation(java.lang.String methodAnnotationName)
Checks whether this class declares a method with the named annotation.boolean
hasDeclaredMethodParameterAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> methodParameterAnnotation)
Checks whether this class declares a method with the annotation.boolean
hasDeclaredMethodParameterAnnotation(java.lang.String methodParameterAnnotationName)
Checks whether this class declares a method with the named annotation.boolean
hasField(java.lang.String fieldName)
Checks whether this class or one of its superclasses has the named field.boolean
hasFieldAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> fieldAnnotation)
Checks whether this class or one of its superclasses declares a field with the annotation.boolean
hasFieldAnnotation(java.lang.String fieldAnnotationName)
Checks whether this class or one of its superclasses declares a field with the named annotation.int
hashCode()
Use hash code of class name.boolean
hasMethod(java.lang.String methodName)
Checks whether this class or one of its superclasses or interfaces declares a method of the given name.boolean
hasMethodAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> methodAnnotation)
Checks whether this class or one of its superclasses or interfaces declares a method with the annotation.boolean
hasMethodAnnotation(java.lang.String methodAnnotationName)
Checks whether this class or one of its superclasses or interfaces declares a method with the named annotation.boolean
hasMethodParameterAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> methodParameterAnnotation)
Checks whether this class or one of its superclasses or interfaces has a method with the annotation.boolean
hasMethodParameterAnnotation(java.lang.String methodParameterAnnotationName)
Checks whether this class or one of its superclasses or interfaces has a method with the named annotation.boolean
implementsInterface(java.lang.Class<?> interfaceClazz)
Checks whether this class implements the interface.boolean
implementsInterface(java.lang.String interfaceName)
Checks whether this class implements the named interface.boolean
isAbstract()
Checks if the class is abstract.boolean
isAnnotation()
Checks if the class is an annotation.boolean
isAnonymousInnerClass()
Checks if this class is an anonymous inner class.boolean
isArrayClass()
Checks if this class is an array class.boolean
isEnum()
Checks if is the class is anEnum
.boolean
isExternalClass()
Checks if this is an external class.boolean
isFinal()
Checks if the class is final.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).boolean
isInnerClass()
Checks if this class is an inner class.boolean
isInterface()
Checks if is the class an interface and is not an annotation.boolean
isInterfaceOrAnnotation()
Checks if is an interface or an annotation.boolean
isOuterClass()
Checks if this class is an outer class.boolean
isPackageVisible()
Checks if the class has default (package) visibility.boolean
isPrivate()
Checks if the class is private.boolean
isProtected()
Checks if the class is protected.boolean
isPublic()
Checks if the class is public.boolean
isRecord()
Checks if is the class is a record (JDK 14+).boolean
isStandardClass()
Checks if this class is a standard class.boolean
isStatic()
Checks if the class is static.boolean
isSynthetic()
Checks if the class is synthetic.java.lang.Class<?>
loadClass()
Obtain aClass<?>
reference for the class named by thisClassInfo
object.java.lang.Class<?>
loadClass(boolean ignoreExceptions)
Obtain aClass<?>
reference for the class named by thisClassInfo
object.<T> java.lang.Class<T>
loadClass(java.lang.Class<T> superclassOrInterfaceType)
Obtain aClass<?>
reference for the class named by thisClassInfo
object, 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 thisClassInfo
object, casting it to the requested interface or superclass type.(package private) void
setClassfileVersion(int minorVersion, int majorVersion)
Set classfile version.(package private) void
setIsAnnotation(boolean isAnnotation)
Set isAnnotation status.(package private) void
setIsInterface(boolean isInterface)
Set isInterface status.(package private) void
setIsRecord(boolean isRecord)
Set isRecord status.(package private) void
setModifiers(int modifiers)
Set class modifiers.(package private) void
setReferencedClasses(ClassInfoList refdClasses)
Set the list of ClassInfo objects for classes referenced by this class.(package private) void
setScanResult(ScanResult scanResult)
Set ScanResult backreferences in info objects after scan has completed.(package private) void
setSourceFile(java.lang.String sourceFile)
Set source file.(package private) void
setTypeSignature(java.lang.String typeSignatureStr)
Set the class type signature, including any type params.protected void
toString(boolean useSimpleNames, java.lang.StringBuilder buf)
To string.-
Methods inherited from class io.github.classgraph.ScanResultObject
findReferencedClassInfo, toString, toString, toStringWithSimpleNames
-
-
-
-
Field Detail
-
name
protected java.lang.String name
The name of the class.
-
modifiers
private int modifiers
Class modifier flags, e.g. Modifier.PUBLIC
-
isRecord
private boolean isRecord
True if the class is a record.
-
isInherited
boolean isInherited
This annotation has theInherited
meta-annotation, which means that any class that this annotation is applied to also implicitly causes the annotation to annotate all subclasses too.
-
classfileMinorVersion
private int classfileMinorVersion
The minor version of the classfile format for this class' classfile.
-
classfileMajorVersion
private int classfileMajorVersion
The major version of the classfile format for this class' classfile.
-
typeSignatureStr
protected java.lang.String typeSignatureStr
The class type signature string.
-
typeSignature
private transient ClassTypeSignature typeSignature
The class type signature, parsed.
-
typeDescriptor
private transient ClassTypeSignature typeDescriptor
The synthetic class type descriptor.
-
sourceFile
private java.lang.String sourceFile
The name of the source file this class has been compiled from
-
fullyQualifiedDefiningMethodName
private java.lang.String fullyQualifiedDefiningMethodName
The fully-qualified defining method name, for anonymous inner classes.
-
isExternalClass
protected boolean isExternalClass
If 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 isScannedClass
Set to true when the class is actually scanned (as opposed to just referenced as a superclass, interface or annotation of a scanned class).
-
classpathElement
transient ClasspathElement classpathElement
The classpath element that this class was found within.
-
classfileResource
protected transient Resource classfileResource
TheResource
for the classfile of this class.
-
classLoader
transient java.lang.ClassLoader classLoader
The classloader this class was obtained from.
-
moduleInfo
ModuleInfo moduleInfo
Info on the class module.
-
packageInfo
PackageInfo packageInfo
Info on the package containing the class.
-
annotationInfo
AnnotationInfoList annotationInfo
Info on class annotations, including optional annotation param values.
-
fieldInfo
FieldInfoList fieldInfo
Info on fields.
-
methodInfo
MethodInfoList methodInfo
Info on fields.
-
annotationDefaultParamValues
AnnotationParameterValueList annotationDefaultParamValues
For annotations, the default values of parameters.
-
typeAnnotationDecorators
transient java.util.List<Classfile.ClassTypeAnnotationDecorator> typeAnnotationDecorators
The type annotation decorators for theClassTypeSignature
instance.
-
referencedClassNames
private java.util.Set<java.lang.String> referencedClassNames
Names of classes referenced by this class in class refs and type signatures in the constant pool of the classfile.
-
referencedClasses
private ClassInfoList referencedClasses
A list of ClassInfo objects for classes referenced by this class. Derived fromreferencedClassNames
when the relevantClassInfo
objects are created.
-
annotationDefaultParamValuesHasBeenConvertedToPrimitive
transient boolean annotationDefaultParamValuesHasBeenConvertedToPrimitive
Set to true once any Object[] arrays of boxed types in annotationDefaultParamValues have been lazily converted to primitive arrays.
-
relatedClasses
private java.util.Map<ClassInfo.RelType,java.util.Set<ClassInfo>> relatedClasses
The set of classes related to this one.
-
overrideOrder
private transient java.util.List<ClassInfo> overrideOrder
The override order for a class' fields or methods (base class, followed by interfaces, followed by superclasses).
-
methodOverrideOrder
private transient java.util.List<ClassInfo> methodOverrideOrder
The override order for a class' methods (base class, followed by superclasses, followed by interfaces).
-
ANNOTATION_CLASS_MODIFIER
private static final int ANNOTATION_CLASS_MODIFIER
The modifier bit for annotations.- See Also:
- Constant Field Values
-
NO_REACHABLE_CLASSES
private static final ClassInfo.ReachableAndDirectlyRelatedClasses NO_REACHABLE_CLASSES
The constant empty return value used when no classes are reachable.
-
-
Constructor Detail
-
ClassInfo
ClassInfo()
Default constructor for deserialization.
-
ClassInfo
protected ClassInfo(java.lang.String name, int classModifiers, Resource classfileResource)
Constructor.- Parameters:
name
- the nameclassModifiers
- the class modifiersclassfileResource
- the classfile resource
-
-
Method Detail
-
addRelatedClass
boolean addRelatedClass(ClassInfo.RelType relType, ClassInfo classInfo)
Add a class with a given relationship type. Return whether the collection changed as a result of the call.- Parameters:
relType
- theClassInfo.RelType
classInfo
- theClassInfo
- Returns:
- true, if successful
-
getOrCreateClassInfo
static ClassInfo getOrCreateClassInfo(java.lang.String className, java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo)
Get a ClassInfo object, or create it if it doesn't exist. N.B. not threadsafe, so ClassInfo objects should only ever be constructed by a single thread.- Parameters:
className
- the class nameclassNameToClassInfo
- the map from class name to class info- Returns:
- the
ClassInfo
object.
-
setClassfileVersion
void setClassfileVersion(int minorVersion, int majorVersion)
Set classfile version.- Parameters:
minorVersion
- the minor version of the classfile format for this class' classfile.majorVersion
- the major version of the classfile format for this class' classfile.
-
setModifiers
void setModifiers(int modifiers)
Set class modifiers.- Parameters:
modifiers
- the class modifiers
-
setIsInterface
void setIsInterface(boolean isInterface)
Set isInterface status.- Parameters:
isInterface
- true if this is an interface
-
setIsAnnotation
void setIsAnnotation(boolean isAnnotation)
Set isAnnotation status.- Parameters:
isAnnotation
- true if this is an annotation
-
setIsRecord
void setIsRecord(boolean isRecord)
Set isRecord status.- Parameters:
isRecord
- true if this is a record
-
setSourceFile
void setSourceFile(java.lang.String sourceFile)
Set source file.- Parameters:
sourceFile
- the source file
-
addTypeDecorators
void addTypeDecorators(java.util.List<Classfile.ClassTypeAnnotationDecorator> classTypeAnnotationDecorators)
AddClassfile.ClassTypeAnnotationDecorator
instances.- Parameters:
classTypeAnnotationDecorators
-Classfile.ClassTypeAnnotationDecorator
instances.
-
addSuperclass
void addSuperclass(java.lang.String superclassName, java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo)
Add a superclass to this class.- Parameters:
superclassName
- the superclass nameclassNameToClassInfo
- the map from class name to class info
-
addImplementedInterface
void addImplementedInterface(java.lang.String interfaceName, java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo)
Add an implemented interface to this class.- Parameters:
interfaceName
- the interface nameclassNameToClassInfo
- the map from class name to class info
-
addClassContainment
static void addClassContainment(java.util.List<Classfile.ClassContainment> classContainmentEntries, java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo)
Add class containment info.- Parameters:
classContainmentEntries
- the class containment entriesclassNameToClassInfo
- the map from class name to class info
-
addFullyQualifiedDefiningMethodName
void addFullyQualifiedDefiningMethodName(java.lang.String fullyQualifiedDefiningMethodName)
Add containing method name, for anonymous inner classes.- Parameters:
fullyQualifiedDefiningMethodName
- the fully qualified defining method name
-
addClassAnnotation
void addClassAnnotation(AnnotationInfo classAnnotationInfo, java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo)
Add an annotation to this class.- Parameters:
classAnnotationInfo
- the class annotation infoclassNameToClassInfo
- the map from class name to class info
-
addFieldOrMethodAnnotationInfo
private void addFieldOrMethodAnnotationInfo(AnnotationInfoList annotationInfoList, boolean isField, int modifiers, java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo)
Add field or method annotation cross-links.- Parameters:
annotationInfoList
- the annotation info listisField
- the is fieldmodifiers
- the field or method modifiersclassNameToClassInfo
- the map from class name to class info
-
addFieldInfo
void addFieldInfo(FieldInfoList fieldInfoList, java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo)
Add field info.- Parameters:
fieldInfoList
- the field info listclassNameToClassInfo
- the map from class name to class info
-
addMethodInfo
void addMethodInfo(MethodInfoList methodInfoList, java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo)
Add method info.- Parameters:
methodInfoList
- the method info listclassNameToClassInfo
- the map from class name to class info
-
setTypeSignature
void setTypeSignature(java.lang.String typeSignatureStr)
Set the class type signature, including any type params.- Parameters:
typeSignatureStr
- the type signature str
-
addAnnotationParamDefaultValues
void addAnnotationParamDefaultValues(AnnotationParameterValueList paramNamesAndValues)
Add annotation default values. (Only called in the case of annotation class definitions, when the annotation has default parameter values.)- Parameters:
paramNamesAndValues
- the default param names and values, if this is an annotation
-
addScannedClass
static ClassInfo addScannedClass(java.lang.String className, int classModifiers, boolean isExternalClass, java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo, ClasspathElement classpathElement, Resource classfileResource)
Add a class that has just been scanned (as opposed to just referenced by a scanned class). Not threadsafe, should be run in single threaded context.- Parameters:
className
- the class nameclassModifiers
- the class modifiersisExternalClass
- true if this is an external classclassNameToClassInfo
- the map from class name to class infoclasspathElement
- the classpath elementclassfileResource
- the classfile resource- Returns:
- the class info
-
filterClassInfo
private static java.util.Set<ClassInfo> filterClassInfo(java.util.Collection<ClassInfo> classes, ScanSpec scanSpec, boolean strictAccept, ClassInfo.ClassType... classTypes)
Filter classes according to scan spec and class type.- Parameters:
classes
- the classesscanSpec
- the scan specstrictAccept
- If true, exclude class if it is external, if external classes are not enabledclassTypes
- the class types- Returns:
- the filtered classes.
-
filterClassInfo
private ClassInfo.ReachableAndDirectlyRelatedClasses filterClassInfo(ClassInfo.RelType relType, boolean strictAccept, ClassInfo.ClassType... classTypes)
Get the classes related to this one (the transitive closure) for the given relationship type, and those directly related.- Parameters:
relType
- the relationship typestrictAccept
- If true, exclude class if it is external, if external classes are not enabledclassTypes
- the class types to accept- Returns:
- the reachable and directly related classes
-
getAllClasses
static ClassInfoList getAllClasses(java.util.Collection<ClassInfo> classes, ScanSpec scanSpec)
Get all classes found during the scan.- Parameters:
classes
- the classesscanSpec
- the scan spec- Returns:
- A list of all classes found during the scan, or the empty list if none.
-
getAllEnums
static ClassInfoList getAllEnums(java.util.Collection<ClassInfo> classes, ScanSpec scanSpec)
Get allEnum
classes found during the scan.- Parameters:
classes
- the classesscanSpec
- the scan spec- Returns:
- A list of all
Enum
classes found during the scan, or the empty list if none.
-
getAllRecords
static ClassInfoList getAllRecords(java.util.Collection<ClassInfo> classes, ScanSpec scanSpec)
Get allrecord
classes found during the scan.- Parameters:
classes
- the classesscanSpec
- the scan spec- Returns:
- A list of all
record
classes found during the scan, or the empty list if none.
-
getAllStandardClasses
static ClassInfoList getAllStandardClasses(java.util.Collection<ClassInfo> classes, ScanSpec scanSpec)
Get all standard classes found during the scan.- Parameters:
classes
- the classesscanSpec
- the scan spec- Returns:
- A list of all standard classes found during the scan, or the empty list if none.
-
getAllImplementedInterfaceClasses
static ClassInfoList getAllImplementedInterfaceClasses(java.util.Collection<ClassInfo> classes, ScanSpec scanSpec)
Get all implemented interface (non-annotation interface) classes found during the scan.- Parameters:
classes
- the classesscanSpec
- the scan spec- Returns:
- A list of all annotation classes found during the scan, or the empty list if none.
-
getAllAnnotationClasses
static ClassInfoList getAllAnnotationClasses(java.util.Collection<ClassInfo> classes, ScanSpec scanSpec)
Get all annotation classes found during the scan. See also#getAllInterfacesOrAnnotationClasses(Collection, ScanSpec, ScanResult)
()}.- Parameters:
classes
- the classesscanSpec
- the scan spec- Returns:
- A list of all annotation classes found during the scan, or the empty list if none.
-
getAllInterfacesOrAnnotationClasses
static ClassInfoList getAllInterfacesOrAnnotationClasses(java.util.Collection<ClassInfo> classes, ScanSpec scanSpec)
Get all interface or annotation classes found during the scan. (Annotations are technically interfaces, and they can be implemented.)- Parameters:
classes
- the classesscanSpec
- the scan spec- Returns:
- A list of all accepted interfaces found during the scan, or the empty list if none.
-
getName
public java.lang.String getName()
Get the name of the class.
-
getSimpleName
static java.lang.String getSimpleName(java.lang.String className)
Get simple name from fully-qualified class name. Returns everything after the last '.' or 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.)- Parameters:
className
- the class name- Returns:
- The simple name of the class.
-
getSimpleName
public java.lang.String 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
public ModuleInfo getModuleInfo()
Get theModuleInfo
object for the class.- Returns:
- the
ModuleInfo
object for the class, or null if the class is not part of a named module.
-
getPackageInfo
public PackageInfo getPackageInfo()
Get thePackageInfo
object for the class.- Returns:
- the
PackageInfo
object 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 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
ClassInfo
object 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
ClassInfo
object 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
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.
-
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
public boolean isEnum()
Checks if is the class is anEnum
.- Returns:
- true if this class is an
Enum
.
-
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 thisClassInfo
is an instance ofArrayClassInfo
.- Returns:
- true if this is an array class.
-
extendsSuperclass
public boolean extendsSuperclass(java.lang.Class<?> superclass)
Checks if this class extends the superclass.- Parameters:
superclass
- A superclass.- Returns:
- true if this class extends the superclass.
-
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.Class<?> interfaceClazz)
Checks whether this class implements the interface.- Parameters:
interfaceClazz
- An interface.- Returns:
- true if this class implements the 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.Class<? extends java.lang.annotation.Annotation> annotation)
Checks whether this class has the annotation.- Parameters:
annotation
- An annotation.- Returns:
- true if this class has the annotation.
-
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.Class<? extends java.lang.annotation.Annotation> annotation)
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
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.Class<? extends java.lang.annotation.Annotation> fieldAnnotation)
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
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 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
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.Class<? extends java.lang.annotation.Annotation> methodAnnotation)
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
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.Class<? extends java.lang.annotation.Annotation> methodAnnotation)
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
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.Class<? extends java.lang.annotation.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
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.Class<? extends java.lang.annotation.Annotation> methodParameterAnnotation)
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
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.
-
getFieldOverrideOrder
private java.util.List<ClassInfo> getFieldOverrideOrder(java.util.Set<ClassInfo> visited, java.util.List<ClassInfo> overrideOrderOut)
Recurse to interfaces and superclasses to get the order that fields are overridden in.- Parameters:
visited
- visitedoverrideOrderOut
- the override order- Returns:
- the override order
-
getFieldOverrideOrder
private java.util.List<ClassInfo> getFieldOverrideOrder()
Get the order that fields are overridden in (base class first).- Returns:
- the override order
-
getMethodOverrideOrder
private java.util.List<ClassInfo> getMethodOverrideOrder(java.util.Set<ClassInfo> visited, java.util.List<ClassInfo> overrideOrderOut)
Recurse to collect classes and interfaces in the order of overridden methods, in descending priority.First collects all direct super classes, as their methods always have a higher priority than any method declared by an interface. Iterates over interfaces and inserts those extending already found interfaces before them in the output. The order of unrelated interfaces is unspecified.
See Java Language Specification 8.4.8 for details.
- Parameters:
visited
- non-null set of already visited ClassInfosoverrideOrderOut
- non-null outgoing list of ClassInfos in descending override order.- Returns:
- the overrideOrderOut instance
-
getMethodOverrideOrder
private java.util.List<ClassInfo> getMethodOverrideOrder()
Get the order that methods are overridden in.- Returns:
- the override order
-
getSubclasses
public ClassInfoList 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
public ClassInfoList getSuperclasses()
Get all superclasses of this class, in ascending order in the class hierarchy, not includingObject
for 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
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
Inherited
meta-annotation, which causes an annotation to annotate a class and all of its subclasses.Filters out meta-annotations in the
java.lang.annotation
package.- Returns:
- the list of annotations and meta-annotations on this class.
-
getFieldOrMethodAnnotations
private ClassInfoList getFieldOrMethodAnnotations(ClassInfo.RelType relType)
Get the annotations or meta-annotations on fields, methods or method parametres declared by the class, (not including fields, methods or method parameters declared by the interfaces or superclasses of this class).- Parameters:
relType
- One ofClassInfo.RelType.FIELD_ANNOTATIONS
,ClassInfo.RelType.METHOD_ANNOTATIONS
orClassInfo.RelType.METHOD_PARAMETER_ANNOTATIONS
.- Returns:
- A list of annotations or meta-annotations on fields or methods declared by the class, (not including
fields or methods declared by the interfaces or superclasses of this class), as a list of
ClassInfo
objects, or the empty list if none.
-
getClassesWithFieldOrMethodAnnotation
private ClassInfoList getClassesWithFieldOrMethodAnnotation(ClassInfo.RelType relType)
Get the classes that have this class as a field, method or method parameter annotation.- Parameters:
relType
- One ofClassInfo.RelType.CLASSES_WITH_FIELD_ANNOTATION
,ClassInfo.RelType.CLASSES_WITH_NONPRIVATE_FIELD_ANNOTATION
,ClassInfo.RelType.CLASSES_WITH_METHOD_ANNOTATION
,ClassInfo.RelType.CLASSES_WITH_NONPRIVATE_METHOD_ANNOTATION
,ClassInfo.RelType.CLASSES_WITH_METHOD_PARAMETER_ANNOTATION
, orClassInfo.RelType.CLASSES_WITH_NONPRIVATE_METHOD_PARAMETER_ANNOTATION
.- Returns:
- A list of classes that have a declared method with this annotation or meta-annotation, or the empty list if none.
-
getAnnotationInfo
public AnnotationInfoList getAnnotationInfo()
Get a list of the annotations on this class, or the empty list if none.Also handles the
Inherited
meta-annotation, which causes an annotation to annotate a class and all of its subclasses.- Returns:
- A list of
AnnotationInfo
objects for the annotations on this class, or the empty list if none.
-
getAnnotationInfo
public AnnotationInfo getAnnotationInfo(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
Get a the non-Repeatable
annotation on this class, or null if the class does not have the annotation. (UsegetAnnotationInfoRepeatable(String)
forRepeatable
annotations.)Also handles the
Inherited
meta-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
AnnotationInfo
object representing the annotation on this class, or null if the class does not have the annotation.
-
getAnnotationInfo
public AnnotationInfo getAnnotationInfo(java.lang.String annotationName)
Get a the named non-Repeatable
annotation on this class, or null if the class does not have the named annotation. (UsegetAnnotationInfoRepeatable(String)
forRepeatable
annotations.)Also handles the
Inherited
meta-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
AnnotationInfo
object representing the named annotation on this class, or null if the class does not have the named annotation.
-
getAnnotationInfoRepeatable
public AnnotationInfoList getAnnotationInfoRepeatable(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
Get a theRepeatable
annotation on this class, or the empty list if the class does not have the annotation.Also handles the
Inherited
meta-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
AnnotationInfoList
of all instances of the annotation on this class, or the empty list if the class does not have the annotation.
-
getAnnotationInfoRepeatable
public AnnotationInfoList getAnnotationInfoRepeatable(java.lang.String annotationName)
Get a the namedRepeatable
annotation on this class, or the empty list if the class does not have the named annotation.Also handles the
Inherited
meta-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
AnnotationInfoList
of 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
AnnotationParameterValue
objects for each of the default parameter values for this annotation, if this is an annotation class with default parameter values, otherwise the empty list.
-
getClassesWithAnnotation
public ClassInfoList getClassesWithAnnotation()
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
Inherited
meta-annotation, which causes an annotation on a class to be inherited by all of its subclasses.
-
getClassesWithAnnotationDirectOnly
ClassInfoList getClassesWithAnnotationDirectOnly()
Get the classes that have this class as a direct annotation.- Returns:
- The list of classes that are directly (i.e. are not meta-annotated) annotated with the requested annotation, or the empty list if none.
-
getDeclaredMethodInfo
private MethodInfoList getDeclaredMethodInfo(java.lang.String methodName, boolean getNormalMethods, boolean getConstructorMethods, boolean getStaticInitializerMethods)
Get the declared methods, constructors, and/or static initializer methods of the class.- Parameters:
methodName
- the method namegetNormalMethods
- whether to get normal methodsgetConstructorMethods
- whether to get constructor methodsgetStaticInitializerMethods
- whether to get static initializer methods- Returns:
- the declared method info
-
getMethodInfo
private MethodInfoList getMethodInfo(java.lang.String methodName, boolean getNormalMethods, boolean getConstructorMethods, boolean getStaticInitializerMethods)
Get the methods, constructors, and/or static initializer methods of the class.- Parameters:
methodName
- the method namegetNormalMethods
- whether to get normal methodsgetConstructorMethods
- whether to get constructor methodsgetStaticInitializerMethods
- whether to get static initializer methods- Returns:
- the method info
-
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
MethodInfo
objects 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
MethodInfo
objects 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
MethodInfo
objects 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
MethodInfo
objects 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
MethodInfo
objects 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
MethodInfo
objects 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
MethodInfo
objects for the method(s) with the given name, or the empty list if the method was not found in this class (or is not visible). - Throws:
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
MethodInfo
objects for the method(s) with the given name, or the empty list if the method was not found in this class (or is not visible). - Throws:
java.lang.IllegalArgumentException
- ifClassGraph.enableMethodInfo()
was not called prior to initiating the scan.
-
getMethodAnnotations
public ClassInfoList 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
ClassInfo
objects, 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
public ClassInfoList 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
ClassInfo
objects, 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
public ClassInfoList 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
public ClassInfoList 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.
-
getClassesWithMethodAnnotationDirectOnly
ClassInfoList getClassesWithMethodAnnotationDirectOnly()
Get the classes that have this class as a direct method annotation.- Returns:
- A list of classes that declare methods that are directly annotated (i.e. are not meta-annotated) with the requested method annotation, or the empty list if none.
-
getClassesWithMethodParameterAnnotationDirectOnly
ClassInfoList getClassesWithMethodParameterAnnotationDirectOnly()
Get the classes that have this class as a direct method parameter annotation.- Returns:
- A list of classes that declare methods with parameters that are directly annotated (i.e. are not meta-annotated) with the requested method 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 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:
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 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:
java.lang.IllegalArgumentException
- ifClassGraph.enableFieldInfo()
was not called prior to initiating the scan.
-
getEnumConstants
public FieldInfoList getEnumConstants()
- Returns:
- All enum constants of an enum class as a list of
FieldInfo
objects (enum constants are stored as fields in Java classes).
-
getEnumConstantObjects
public java.util.List<java.lang.Object> getEnumConstantObjects()
- Returns:
- All enum constants of an enum class as a list of objects of the same type as the enum.
-
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
FieldInfo
object 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 fields, unless
ClassGraph.ignoreFieldVisibility()
was called before the scan.- Parameters:
fieldName
- The field name.- Returns:
- the
FieldInfo
object 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 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
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.
-
getClassesWithFieldAnnotationDirectOnly
ClassInfoList getClassesWithFieldAnnotationDirectOnly()
Get the classes that have this class as a direct field annotation.- Returns:
- A list of classes that declare fields that are directly annotated (i.e. are not meta-annotated) with the requested method annotation, or the empty list if none.
-
getTypeSignature
public ClassTypeSignature 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:
java.lang.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
public java.lang.String 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
public ClassTypeSignature 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
public ClassTypeSignature 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
public java.lang.String getSourceFile()
Returns the name of the source file this class has been compiled from, such asClassInfo.java
orKClass.kt
.This field may be
null
.- Returns:
- The name of the source file of this class, or
null
if not available
-
getClasspathElementURI
public java.net.URI getClasspathElementURI()
Get theURI
of the classpath element that this class was found within.- Returns:
- The
URI
of the classpath element that this class was found within. - Throws:
java.lang.IllegalArgumentException
- if the classpath element does not have a valid URI (e.g. for modules whose location URI is null).
-
getClasspathElementURL
public java.net.URL getClasspathElementURL()
Get theURL
of 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 causeIllegalArgumentException
to be thrown.- Returns:
- The
URL
of the classpath element that this class was found within. - Throws:
java.lang.IllegalArgumentException
- if the classpath element URI cannot be converted to aURL
(in particular, if the URI has ajrt:/
scheme).
-
getClasspathElementFile
public java.io.File getClasspathElementFile()
Get theFile
for the classpath element package root dir or jar that this class was found within, or null if this class was found in a module. (See alsogetModuleRef()
.)- Returns:
- The
File
for the classpath element package root dir or jar that this class was found within, or null if this class was found in a module (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
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()
TheResource
for the classfile of this class.- Returns:
- The
Resource
for the classfile of this class. Returns null if the classfile for this class was not actually read during the scan, e.g. because this class was not itself accepted, but was referenced by an accepted class.
-
loadClass
public <T> java.lang.Class<T> loadClass(java.lang.Class<T> superclassOrInterfaceType, boolean ignoreExceptions)
Obtain aClass<?>
reference for the class named by thisClassInfo
object, casting it to the requested interface or superclass type. Causes the ClassLoader to load the class, if it is not already loaded.Important note: since
superclassOrInterfaceType
is a class reference for an already-loaded class, it is critical thatsuperclassOrInterfaceType
is loaded by the same classloader as the class referred to by thisClassInfo
object, otherwise the class cast will fail.- Overrides:
loadClass
in classScanResultObject
- Type Parameters:
T
- the superclass or interface type- Parameters:
superclassOrInterfaceType
- TheClass
reference 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,IllegalArgumentException
is thrown if the class could not be loaded or could not be cast to the requested type.- Returns:
- The class reference, or null, if ignoreExceptions is true and there was an exception or error loading the class.
- Throws:
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 thisClassInfo
object, casting it to the requested interface or superclass type. Causes the ClassLoader to load the class, if it is not already loaded.Important note: since
superclassOrInterfaceType
is a class reference for an already-loaded class, it is critical thatsuperclassOrInterfaceType
is loaded by the same classloader as the class referred to by thisClassInfo
object, otherwise the class cast will fail.- Overrides:
loadClass
in classScanResultObject
- 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 thisClassInfo
object. Causes the ClassLoader to load the class, if it is not already loaded.- Overrides:
loadClass
in classScanResultObject
- 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 thisClassInfo
object. Causes the ClassLoader to load the class, if it is not already loaded.- Overrides:
loadClass
in classScanResultObject
- Returns:
- The class reference.
- Throws:
java.lang.IllegalArgumentException
- if there were problems loading the class.
-
getClassName
protected java.lang.String getClassName()
Description copied from class:ScanResultObject
The name of the class (used byScanResultObject.getClassInfo()
to fetch theClassInfo
object for the class).- Specified by:
getClassName
in classScanResultObject
- Returns:
- The class name.
-
getClassInfo
protected ClassInfo getClassInfo()
Description copied from class:ScanResultObject
Get theClassInfo
object for the referenced class, or null if the referenced class was not encountered during scanning (i.e. no ClassInfo object was created for the class during scanning). N.B. even if this method returns null,ScanResultObject.loadClass()
may be able to load the referenced class by name.- Overrides:
getClassInfo
in classScanResultObject
- Returns:
- The
ClassInfo
object for the referenced class.
-
setScanResult
void setScanResult(ScanResult scanResult)
Description copied from class:ScanResultObject
Set ScanResult backreferences in info objects after scan has completed.- Overrides:
setScanResult
in classScanResultObject
- Parameters:
scanResult
- the scan result
-
handleRepeatableAnnotations
void handleRepeatableAnnotations(java.util.Set<java.lang.String> allRepeatableAnnotationNames)
HandleRepeatable
annotations.- Parameters:
allRepeatableAnnotationNames
- the names of all repeatable annotations
-
addReferencedClassNames
void addReferencedClassNames(java.util.Set<java.lang.String> refdClassNames)
Add names of classes referenced by this class.- Parameters:
refdClassNames
- the referenced class names
-
findReferencedClassInfo
protected void findReferencedClassInfo(java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo, java.util.Set<ClassInfo> refdClassInfo, LogNode log)
GetClassInfo
objects for any classes referenced in this class' type descriptor, or the type descriptors of fields, methods or annotations.- Overrides:
findReferencedClassInfo
in classScanResultObject
- Parameters:
classNameToClassInfo
- the map from class name toClassInfo
.refdClassInfo
- the referenced class infolog
- the log
-
setReferencedClasses
void setReferencedClasses(ClassInfoList refdClasses)
Set the list of ClassInfo objects for classes referenced by this class.- Parameters:
refdClasses
- the referenced classes
-
getClassDependencies
public ClassInfoList getClassDependencies()
Get the class dependencies.- Returns:
- A
ClassInfoList
ofClassInfo
objects 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
public int compareTo(ClassInfo o)
Compare based on class name.- Specified by:
compareTo
in 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:
equals
in 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:
hashCode
in classjava.lang.Object
- Returns:
- the hashcode
-
toString
protected void toString(boolean useSimpleNames, java.lang.StringBuilder buf)
To string.- Specified by:
toString
in classScanResultObject
- Parameters:
useSimpleNames
- use simple namesbuf
- the buf
-
-