public class ClassInfo extends Object implements Comparable<ClassInfo>, HasName
Modifier and Type | Method and Description |
---|---|
int |
compareTo(ClassInfo o)
Compare based on class name.
|
boolean |
equals(Object obj)
Use class name for equals().
|
boolean |
extendsSuperclass(Class<?> superclass)
Checks if this class extends the superclass.
|
boolean |
extendsSuperclass(String superclassName)
Checks if this class extends the named superclass.
|
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(Class<? extends Annotation> annotation)
Get a the non-
Repeatable annotation on this class, or null if the class does not have the annotation. |
AnnotationInfo |
getAnnotationInfo(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(Class<? extends Annotation> annotation)
Get a the
Repeatable annotation on this class, or the empty list if the class does not have the
annotation. |
AnnotationInfoList |
getAnnotationInfoRepeatable(String annotationName)
Get a the named
Repeatable 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.
|
ClassInfoList |
getClassesWithFieldAnnotation()
Get the classes that have this class as a field annotation or meta-annotation.
|
ClassInfoList |
getClassesWithMethodAnnotation()
Get all classes that have this class as a method annotation, and their subclasses, if the method is
non-private.
|
ClassInfoList |
getClassesWithMethodParameterAnnotation()
Get all classes that have this class as a method parameter annotation, and their subclasses, if the method is
non-private.
|
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.
|
File |
getClasspathElementFile()
Get 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. |
URI |
getClasspathElementURI()
Get the
URI of the classpath element that this class was found within. |
URL |
getClasspathElementURL()
Get the
URL 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(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(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.
|
List<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(String fieldName)
Returns information on the named filed declared by this class, or by its superclasses.
|
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(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.
|
ClassInfoList |
getMethodParameterAnnotations()
Get all method parameter annotations.
|
int |
getModifiers()
Get the class modifier bits.
|
String |
getModifiersStr()
Get the class modifiers as a String.
|
ModuleInfo |
getModuleInfo()
Get the
ModuleInfo object for the class. |
ModuleRef |
getModuleRef()
Get 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. |
String |
getName()
Get the name of the class.
|
ClassInfoList |
getOuterClasses()
Get the containing outer classes, if this is an inner class.
|
PackageInfo |
getPackageInfo()
Get the
PackageInfo object for the class. |
String |
getPackageName()
Get the name of the class' package.
|
Resource |
getResource()
The
Resource for the classfile of this class. |
String |
getSimpleName()
Get the simple name of the class.
|
String |
getSourceFile()
Returns the name of the source file this class has been compiled from, such as
ClassInfo.java or
KClass.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 including
Object
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.
|
String |
getTypeSignatureStr()
Get the type signature string for the class.
|
boolean |
hasAnnotation(Class<? extends Annotation> annotation)
Checks whether this class has the annotation.
|
boolean |
hasAnnotation(String annotationName)
Checks whether this class has the named annotation.
|
boolean |
hasDeclaredField(String fieldName)
Checks whether this class has the named declared field.
|
boolean |
hasDeclaredFieldAnnotation(Class<? extends Annotation> annotation)
Checks whether this class declares a field with the annotation.
|
boolean |
hasDeclaredFieldAnnotation(String fieldAnnotationName)
Checks whether this class declares a field with the named annotation.
|
boolean |
hasDeclaredMethod(String methodName)
Checks whether this class declares a method of the given name.
|
boolean |
hasDeclaredMethodAnnotation(Class<? extends Annotation> methodAnnotation)
Checks whether this class declares a method with the annotation.
|
boolean |
hasDeclaredMethodAnnotation(String methodAnnotationName)
Checks whether this class declares a method with the named annotation.
|
boolean |
hasDeclaredMethodParameterAnnotation(Class<? extends Annotation> methodParameterAnnotation)
Checks whether this class declares a method with the annotation.
|
boolean |
hasDeclaredMethodParameterAnnotation(String methodParameterAnnotationName)
Checks whether this class declares a method with the named annotation.
|
boolean |
hasField(String fieldName)
Checks whether this class or one of its superclasses has the named field.
|
boolean |
hasFieldAnnotation(Class<? extends Annotation> fieldAnnotation)
Checks whether this class or one of its superclasses declares a field with the annotation.
|
boolean |
hasFieldAnnotation(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(String methodName)
Checks whether this class or one of its superclasses or interfaces declares a method of the given name.
|
boolean |
hasMethodAnnotation(Class<? extends Annotation> methodAnnotation)
Checks whether this class or one of its superclasses or interfaces declares a method with the annotation.
|
boolean |
hasMethodAnnotation(String methodAnnotationName)
Checks whether this class or one of its superclasses or interfaces declares a method with the named
annotation.
|
boolean |
hasMethodParameterAnnotation(Class<? extends Annotation> methodParameterAnnotation)
Checks whether this class or one of its superclasses or interfaces has a method with the annotation.
|
boolean |
hasMethodParameterAnnotation(String methodParameterAnnotationName)
Checks whether this class or one of its superclasses or interfaces has a method with the named annotation.
|
boolean |
implementsInterface(Class<?> interfaceClazz)
Checks whether this class implements the interface.
|
boolean |
implementsInterface(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 an
Enum . |
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.
|
Class<?> |
loadClass()
Obtain a
Class<?> reference for the class named by this ClassInfo object. |
Class<?> |
loadClass(boolean ignoreExceptions)
Obtain a
Class<?> reference for the class named by this ClassInfo object. |
<T> Class<T> |
loadClass(Class<T> superclassOrInterfaceType)
Obtain a
Class<?> reference for the class named by this ClassInfo object, casting it to the
requested interface or superclass type. |
<T> Class<T> |
loadClass(Class<T> superclassOrInterfaceType,
boolean ignoreExceptions)
Obtain a
Class<?> reference for the class named by this ClassInfo object, casting it to the
requested interface or superclass type. |
String |
toString()
Render to string.
|
String |
toStringWithSimpleNames()
Render to string, using only simple
names for classes.
|
public String getName()
public String getSimpleName()
Class.getSimpleName()
, which returns "" for anonymous classes.)public ModuleInfo getModuleInfo()
ModuleInfo
object for the class.ModuleInfo
object for the class, or null if the class is not part of a named module.public PackageInfo getPackageInfo()
PackageInfo
object for the class.PackageInfo
object for the package that contains the class.public String getPackageName()
public boolean isExternalClass()
public int getClassfileMinorVersion()
ClassInfo
object is a placeholder for a referenced class that was not found or not accepted during the scan.public int getClassfileMajorVersion()
ClassInfo
object is a placeholder for a referenced class that was not found or not accepted during the scan.public int getModifiers()
Modifier.PUBLIC
.public String getModifiersStr()
getModifiers()
.public boolean isPublic()
public boolean isPrivate()
public boolean isProtected()
public boolean isPackageVisible()
public boolean isAbstract()
public boolean isSynthetic()
public boolean isFinal()
public boolean isStatic()
public boolean isAnnotation()
public boolean isInterface()
public boolean isInterfaceOrAnnotation()
public boolean isEnum()
Enum
.Enum
.public boolean isRecord()
public boolean isStandardClass()
public boolean isArrayClass()
ClassInfo
is an instance of
ArrayClassInfo
.public boolean extendsSuperclass(Class<?> superclass)
superclass
- A superclass.public boolean extendsSuperclass(String superclassName)
superclassName
- The name of a superclass.public boolean isInnerClass()
isAnonymousInnerClass()
to test if this is an anonymous
inner class). If true, the containing class can be determined by calling getOuterClasses()
.public boolean isOuterClass()
getInnerClasses()
.public boolean isAnonymousInnerClass()
getFullyQualifiedDefiningMethodName()
.public boolean isImplementedInterface()
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.
public boolean implementsInterface(Class<?> interfaceClazz)
interfaceClazz
- An interface.public boolean implementsInterface(String interfaceName)
interfaceName
- The name of an interface.public boolean hasAnnotation(Class<? extends Annotation> annotation)
annotation
- An annotation.public boolean hasAnnotation(String annotationName)
annotationName
- The name of an annotation.public boolean hasDeclaredField(String fieldName)
fieldName
- The name of a field.public boolean hasField(String fieldName)
fieldName
- The name of a field.public boolean hasDeclaredFieldAnnotation(Class<? extends Annotation> annotation)
annotation
- A field annotation.public boolean hasDeclaredFieldAnnotation(String fieldAnnotationName)
fieldAnnotationName
- The name of a field annotation.public boolean hasFieldAnnotation(Class<? extends Annotation> fieldAnnotation)
fieldAnnotation
- A field annotation.public boolean hasFieldAnnotation(String fieldAnnotationName)
fieldAnnotationName
- The name of a field annotation.public boolean hasDeclaredMethod(String methodName)
methodName
- The name of a method.public boolean hasMethod(String methodName)
methodName
- The name of a method.public boolean hasDeclaredMethodAnnotation(Class<? extends Annotation> methodAnnotation)
methodAnnotation
- A method annotation.public boolean hasDeclaredMethodAnnotation(String methodAnnotationName)
methodAnnotationName
- The name of a method annotation.public boolean hasMethodAnnotation(Class<? extends Annotation> methodAnnotation)
methodAnnotation
- A method annotation.public boolean hasMethodAnnotation(String methodAnnotationName)
methodAnnotationName
- The name of a method annotation.public boolean hasDeclaredMethodParameterAnnotation(Class<? extends Annotation> methodParameterAnnotation)
methodParameterAnnotation
- A method annotation.public boolean hasDeclaredMethodParameterAnnotation(String methodParameterAnnotationName)
methodParameterAnnotationName
- The name of a method annotation.public boolean hasMethodParameterAnnotation(Class<? extends Annotation> methodParameterAnnotation)
methodParameterAnnotation
- A method annotation.public boolean hasMethodParameterAnnotation(String methodParameterAnnotationName)
methodParameterAnnotationName
- The name of a method annotation.public ClassInfoList getSubclasses()
ClassInfoList.directOnly()
to get
direct subclasses.
If this class represents Object
, then returns only standard classes, not interfaces, since interfaces
don't extend Object
.public ClassInfoList getSuperclasses()
Object
for simplicity, since that is the superclass of all classes.
Also does not include superinterfaces, if this is an interface (use getInterfaces()
to get
superinterfaces of an interface.}public ClassInfo getSuperclass()
getInterfaces()
to get superinterfaces of an interface.}public ClassInfoList getOuterClasses()
public ClassInfoList getInnerClasses()
public String getFullyQualifiedDefiningMethodName()
public ClassInfoList getInterfaces()
public ClassInfoList getClassesImplementing()
public ClassInfoList getAnnotations()
getAnnotationInfo()
instead, if you
need the parameter values of annotations, rather than just the annotation classes.)
Also handles the Inherited
meta-annotation, which causes an annotation to annotate a class and all of
its subclasses.
Filters out meta-annotations in the java.lang.annotation
package.
public AnnotationInfoList getAnnotationInfo()
Also handles the Inherited
meta-annotation, which causes an annotation to annotate a class and all of
its subclasses.
AnnotationInfo
objects for the annotations on this class, or the empty list if
none.public AnnotationInfo getAnnotationInfo(Class<? extends Annotation> annotation)
Repeatable
annotation on this class, or null if the class does not have the annotation.
(Use getAnnotationInfoRepeatable(String)
for Repeatable
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 returned AnnotationInfoList
, so that the returned list doesn't have
to be built multiple times.
annotation
- The annotation.AnnotationInfo
object representing the annotation on this class, or null if the class does
not have the annotation.public AnnotationInfo getAnnotationInfo(String annotationName)
Repeatable
annotation on this class, or null if the class does not have the named
annotation. (Use getAnnotationInfoRepeatable(String)
for Repeatable
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 returned AnnotationInfoList
, so that the returned list
doesn't have to be built multiple times.
annotationName
- The annotation name.AnnotationInfo
object representing the named annotation on this class, or null if the
class does not have the named annotation.public AnnotationInfoList getAnnotationInfoRepeatable(Class<? extends Annotation> annotation)
Repeatable
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 returned AnnotationInfoList
, so that the returned list doesn't have
to be built multiple times.
annotation
- The annotation.AnnotationInfoList
of all instances of the annotation on this class, or the empty list if
the class does not have the annotation.public AnnotationInfoList getAnnotationInfoRepeatable(String annotationName)
Repeatable
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 returned AnnotationInfoList
, so that the returned list
doesn't have to be built multiple times.
annotationName
- The annotation name.AnnotationInfoList
of all instances of the named annotation on this class, or the empty
list if the class does not have the named annotation.public AnnotationParameterValueList getAnnotationDefaultParameterValues()
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.public ClassInfoList getClassesWithAnnotation()
Inherited
meta-annotation,
which causes an annotation on a class to be inherited by all of its subclasses.public MethodInfoList getDeclaredMethodInfo()
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 throws
IllegalArgumentException
.
By default only returns information for public methods, unless ClassGraph.ignoreMethodVisibility()
was called before the scan.
MethodInfo
objects for visible methods declared by this class, or the empty list
if no methods were found.IllegalArgumentException
- if ClassGraph.enableMethodInfo()
was not called prior to initiating the scan.public MethodInfoList getMethodInfo()
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 throws
IllegalArgumentException
.
By default only returns information for public methods, unless ClassGraph.ignoreMethodVisibility()
was called before the scan.
MethodInfo
objects for visible methods of this class, its interfaces and
superclasses, or the empty list if no methods were found.IllegalArgumentException
- if ClassGraph.enableMethodInfo()
was not called prior to initiating the scan.public MethodInfoList getDeclaredConstructorInfo()
"<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 throws
IllegalArgumentException
.
By default only returns information for public constructors, unless
ClassGraph.ignoreMethodVisibility()
was called before the scan.
MethodInfo
objects for visible constructors declared by this class, or the empty
list if no constructors were found or visible.IllegalArgumentException
- if ClassGraph.enableMethodInfo()
was not called prior to initiating the scan.public MethodInfoList getConstructorInfo()
"<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 throws
IllegalArgumentException
.
By default only returns information for public methods, unless ClassGraph.ignoreMethodVisibility()
was called before the scan.
MethodInfo
objects for visible constructors of this class and its superclasses,
or the empty list if no methods were found.IllegalArgumentException
- if ClassGraph.enableMethodInfo()
was not called prior to initiating the scan.public MethodInfoList getDeclaredMethodAndConstructorInfo()
"<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 throws
IllegalArgumentException
.
By default only returns information for public methods and constructors, unless
ClassGraph.ignoreMethodVisibility()
was called before the scan. If method visibility is ignored, the
result may include a reference to a private static class initializer block, with a method name of
"<clinit>"
.
MethodInfo
objects for visible methods and constructors of this class, or the
empty list if no methods or constructors were found or visible.IllegalArgumentException
- if ClassGraph.enableMethodInfo()
was not called prior to initiating the scan.public MethodInfoList getMethodAndConstructorInfo()
"<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 throws
IllegalArgumentException
.
By default only returns information for public methods, unless ClassGraph.ignoreMethodVisibility()
was called before the scan.
MethodInfo
objects for visible methods and constructors of this class, its
interfaces and superclasses, or the empty list if no methods were found.IllegalArgumentException
- if ClassGraph.enableMethodInfo()
was not called prior to initiating the scan.public MethodInfoList getDeclaredMethodInfo(String methodName)
"<init>"
. See also:
getMethodInfo(String)
getMethodInfo()
getDeclaredMethodInfo()
getConstructorInfo()
getDeclaredConstructorInfo()
getMethodAndConstructorInfo()
getDeclaredMethodAndConstructorInfo()
Requires that ClassGraph.enableMethodInfo()
be called before scanning, otherwise throws
IllegalArgumentException
.
By default only returns information for public methods, unless ClassGraph.ignoreMethodVisibility()
was called before the scan.
May return info for multiple methods with the same name (with different type signatures).
methodName
- The method name to query.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).IllegalArgumentException
- if ClassGraph.enableMethodInfo()
was not called prior to initiating the scan.public MethodInfoList getMethodInfo(String methodName)
"<init>"
. See also:
getDeclaredMethodInfo(String)
getMethodInfo()
getDeclaredMethodInfo()
getConstructorInfo()
getDeclaredConstructorInfo()
getMethodAndConstructorInfo()
getDeclaredMethodAndConstructorInfo()
Requires that ClassGraph.enableMethodInfo()
be called before scanning, otherwise throws
IllegalArgumentException
.
By default only returns information for public methods, unless ClassGraph.ignoreMethodVisibility()
was called before the scan.
May return info for multiple methods with the same name (with different type signatures).
methodName
- The method name to query.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).IllegalArgumentException
- if ClassGraph.enableMethodInfo()
was not called prior to initiating the scan.public ClassInfoList getMethodAnnotations()
ClassInfo
objects, or the empty list if none. N.B. these annotations do not contain specific annotation
parameters -- call ClassMemberInfo.getAnnotationInfo()
to get details on specific method
annotation instances.public ClassInfoList getMethodParameterAnnotations()
ClassInfo
objects, or the empty list if none. N.B. these annotations do not contain specific annotation
parameters -- call ClassMemberInfo.getAnnotationInfo()
to get details on specific method
annotation instances.public ClassInfoList getClassesWithMethodAnnotation()
public ClassInfoList getClassesWithMethodParameterAnnotation()
public FieldInfoList getDeclaredFieldInfo()
Requires that ClassGraph.enableFieldInfo()
be called before scanning, otherwise throws
IllegalArgumentException
.
By default only returns information for public fields, unless ClassGraph.ignoreFieldVisibility()
was
called before the scan.
IllegalArgumentException
- if ClassGraph.enableFieldInfo()
was not called prior to initiating the scan.public FieldInfoList getFieldInfo()
Requires that ClassGraph.enableFieldInfo()
be called before scanning, otherwise throws
IllegalArgumentException
.
By default only returns information for public fields, unless ClassGraph.ignoreFieldVisibility()
was
called before the scan.
IllegalArgumentException
- if ClassGraph.enableFieldInfo()
was not called prior to initiating the scan.public FieldInfoList getEnumConstants()
FieldInfo
objects (enum constants are stored
as fields in Java classes).public List<Object> getEnumConstantObjects()
public FieldInfo getDeclaredFieldInfo(String fieldName)
Requires that ClassGraph.enableFieldInfo()
be called before scanning, otherwise throws
IllegalArgumentException
.
By default only returns information for public fields, unless ClassGraph.ignoreFieldVisibility()
was
called before the scan.
fieldName
- The field name.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).IllegalArgumentException
- if ClassGraph.enableFieldInfo()
was not called prior to initiating the scan.public FieldInfo getFieldInfo(String fieldName)
Requires that ClassGraph.enableFieldInfo()
be called before scanning, otherwise throws
IllegalArgumentException
.
By default only returns information for public fields, unless ClassGraph.ignoreFieldVisibility()
was
called before the scan.
fieldName
- The field name.FieldInfo
object for the named field of this class or its superclases, or the empty list
if no fields were found or visible.IllegalArgumentException
- if ClassGraph.enableFieldInfo()
was not called prior to initiating the scan.public ClassInfoList getFieldAnnotations()
ClassMemberInfo.getAnnotationInfo()
to get
details on specific field annotation instances.public ClassInfoList getClassesWithFieldAnnotation()
public ClassTypeSignature getTypeSignature()
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).public String getTypeSignatureStr()
public ClassTypeSignature getTypeSignatureOrTypeDescriptor()
public ClassTypeSignature getTypeDescriptor()
public String getSourceFile()
ClassInfo.java
or
KClass.kt
.
This field may be null
.
null
if not availablepublic URI getClasspathElementURI()
URI
of the classpath element that this class was found within.URI
of the classpath element that this class was found within.IllegalArgumentException
- if the classpath element does not have a valid URI (e.g. for modules whose location URI is null).public URL getClasspathElementURL()
URL
of the classpath element or module that this class was found within. Use
getClasspathElementURI()
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 by URL
, and this will cause IllegalArgumentException
to be thrown.URL
of the classpath element that this class was found within.IllegalArgumentException
- if the classpath element URI cannot be converted to a URL
(in particular, if the URI has
a jrt:/
scheme).public File getClasspathElementFile()
File
for the classpath element package root dir or jar that this class was found within, or
null if this class was found in a module. (See also getModuleRef()
.)File
for the classpath element package root dir or jar that this class was found within,
or null if this class was found in a module (see getModuleRef()
). 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).public ModuleRef getModuleRef()
ModuleRef
, or null if this class was found in a
directory or jar in the classpath. (See also getClasspathElementFile()
.)ModuleRef
, or null if this class was found
in a directory or jar in the classpath. (See also getClasspathElementFile()
.)public Resource getResource()
Resource
for the classfile of this class.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.public <T> Class<T> loadClass(Class<T> superclassOrInterfaceType, boolean ignoreExceptions)
Class<?>
reference for the class named by this ClassInfo
object, casting it to the
requested interface or superclass type. Causes the ClassLoader to load the class, if it is not already
loaded.
Important note: since superclassOrInterfaceType
is a class reference for an already-loaded
class, it is critical that superclassOrInterfaceType
is loaded by the same classloader as the class
referred to by this ClassInfo
object, otherwise the class cast will fail.
T
- the superclass or interface typesuperclassOrInterfaceType
- The Class
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 resulting Class<?>
reference to the requested superclass or interface type fails.
If false, IllegalArgumentException
is thrown if the class could not be loaded or could not
be cast to the requested type.IllegalArgumentException
- if ignoreExceptions is false and there were problems loading the class, or casting it to the
requested type.public <T> Class<T> loadClass(Class<T> superclassOrInterfaceType)
Class<?>
reference for the class named by this ClassInfo
object, casting it to the
requested interface or superclass type. Causes the ClassLoader to load the class, if it is not already
loaded.
Important note: since superclassOrInterfaceType
is a class reference for an already-loaded
class, it is critical that superclassOrInterfaceType
is loaded by the same classloader as the class
referred to by this ClassInfo
object, otherwise the class cast will fail.
T
- The superclass or interface typesuperclassOrInterfaceType
- The type to cast the loaded class to.IllegalArgumentException
- if there were problems loading the class or casting it to the requested type.public Class<?> loadClass(boolean ignoreExceptions)
Class<?>
reference for the class named by this ClassInfo
object. Causes the
ClassLoader to load the class, if it is not already loaded.ignoreExceptions
- Whether or not to ignore exceptionsIllegalArgumentException
- if ignoreExceptions is false and there were problems loading the class.public Class<?> loadClass()
Class<?>
reference for the class named by this ClassInfo
object. Causes the
ClassLoader to load the class, if it is not already loaded.IllegalArgumentException
- if there were problems loading the class.public ClassInfoList getClassDependencies()
ClassInfoList
of ClassInfo
objects for all classes referenced by this class. Note
that you need to call ClassGraph.enableInterClassDependencies()
before
ClassGraph.scan()
for this method to work. You should also call
ClassGraph.enableExternalClasses()
before ClassGraph.scan()
if you want non-accepted
classes to appear in the result.public int compareTo(ClassInfo o)
compareTo
in interface Comparable<ClassInfo>
o
- the other objectpublic boolean equals(Object obj)
public int hashCode()
public String toStringWithSimpleNames()
Copyright © 2024. All rights reserved.