Package io.github.classgraph
Class MethodInfo
- java.lang.Object
-
- io.github.classgraph.MethodInfo
-
- All Implemented Interfaces:
Comparable<MethodInfo>
public class MethodInfo extends Object implements Comparable<MethodInfo>
Holds metadata about methods of a class encountered during a scan. All values are taken directly out of the classfile for the class.
-
-
Field Summary
Fields Modifier and Type Field Description protected ScanResult
scanResult
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(MethodInfo other)
Sort in order of class name, method name, then type descriptor.boolean
equals(Object obj)
Test class name, method name and type descriptor for equals().AnnotationInfoList
getAnnotationInfo()
Get a list of annotations on this method, along with any annotation parameter values.AnnotationInfo
getAnnotationInfo(String annotationName)
Get a the named annotation on this method, or null if the method does not have the named annotation.protected String
getClassName()
Returns the defining class name, so that super.getClassInfo() returns theClassInfo
object for the defining class.protected void
getClassNamesFromTypeDescriptors(Set<String> classNames)
Get the names of any classes in the type descriptor or type signature.ClassInfo
getDefiningClassInfo()
Get the class this method is defined within.String
getDefiningClassName()
Get the name of the class this method is defined within.int
getModifiers()
Returns the modifier bits for the method.String
getModifiersStr()
Get the method modifiers as a String, e.g.String
getName()
Returns the name of the method.MethodParameterInfo[]
getParameterInfo()
Get the available information on method parameters.MethodTypeSignature
getTypeDescriptor()
Returns the parsed type descriptor for the method, which will not include type parameters.MethodTypeSignature
getTypeSignature()
Returns the parsed type signature for the method, possibly including type parameters.MethodTypeSignature
getTypeSignatureOrTypeDescriptor()
Returns the parsed type signature for the method, possibly including type parameters.boolean
hasAnnotation(String annotationName)
boolean
hasBody()
Returns true if this method has a body (i.e.int
hashCode()
Use hash code of class name, method name and type descriptor.boolean
hasParameterAnnotation(String annotationName)
boolean
isBridge()
Returns true if this method is a bridge method.boolean
isConstructor()
Returns true if this method is a constructor.boolean
isDefault()
Returns true if this is a default method (i.e.boolean
isFinal()
Returns true if this method is final.boolean
isNative()
Returns true if this method is a native method.boolean
isPublic()
Returns true if this method is public.boolean
isStatic()
Returns true if this method is static.boolean
isSynchronized()
Returns true if this method is synchronized.boolean
isVarArgs()
Returns true if this method is a varargs method.Method
loadClassAndGetMethod()
Load the class this method is associated with, and get theMethod
reference for this method.String
toString()
Get a string representation of the method.
-
-
-
Field Detail
-
scanResult
protected transient ScanResult scanResult
-
-
Method Detail
-
getName
public String getName()
Returns the name of the method. Note that constructors are named"<init>"
, and private static class initializer blocks are named"<clinit>"
.- Returns:
- The name of the method.
-
getModifiers
public int getModifiers()
Returns the modifier bits for the method.- Returns:
- The modifier bits for the method.
-
getModifiersStr
public String getModifiersStr()
Get the method modifiers as a String, e.g. "public static final". For the modifier bits, callgetModifiers()
.- Returns:
- The modifiers for the method, as a String.
-
getDefiningClassName
public String getDefiningClassName()
Get the name of the class this method is defined within.- Returns:
- The name of the enclosing class.
-
getDefiningClassInfo
public ClassInfo getDefiningClassInfo()
Get the class this method is defined within.- Returns:
- The class this method is defined within.
-
getTypeDescriptor
public MethodTypeSignature getTypeDescriptor()
Returns the parsed type descriptor for the method, which will not include type parameters. If you need generic type parameters, call getTypeSignature() instead.- Returns:
- The parsed type descriptor for the method.
-
getTypeSignature
public MethodTypeSignature getTypeSignature()
Returns the parsed type signature for the method, possibly including type parameters. If this returns null, indicating that no type signature information is available for this method, call getTypeDescriptor() instead.- Returns:
- The parsed type signature for the method, or null if not available.
-
getTypeSignatureOrTypeDescriptor
public MethodTypeSignature getTypeSignatureOrTypeDescriptor()
Returns the parsed type signature for the method, possibly including type parameters. If the parsed type signature is null, indicating that no type signature information is available for this method, returns the parsed type descriptor instead.- Returns:
- The parsed type signature for the method, or if not available, the parsed type descriptor for the method.
-
isConstructor
public boolean isConstructor()
Returns true if this method is a constructor. Constructors have the method name"<init>"
. This returns false for private static class initializer blocks, which are named"<clinit>"
.- Returns:
- True if this method is a constructor.
-
isPublic
public boolean isPublic()
Returns true if this method is public.- Returns:
- True if this method is public.
-
isStatic
public boolean isStatic()
Returns true if this method is static.- Returns:
- True if this method is static.
-
isFinal
public boolean isFinal()
Returns true if this method is final.- Returns:
- True if this method is final.
-
isSynchronized
public boolean isSynchronized()
Returns true if this method is synchronized.- Returns:
- True if this method is synchronized.
-
isBridge
public boolean isBridge()
Returns true if this method is a bridge method.- Returns:
- True if this is a bridge method.
-
isVarArgs
public boolean isVarArgs()
Returns true if this method is a varargs method.- Returns:
- True if this is a varargs method.
-
isNative
public boolean isNative()
Returns true if this method is a native method.- Returns:
- True if this method is native.
-
hasBody
public boolean hasBody()
Returns true if this method has a body (i.e. has an implementation in the containing class).- Returns:
- True if this method has a body.
-
isDefault
public boolean isDefault()
Returns true if this is a default method (i.e. if this is a method in an interface and the method has a body).- Returns:
- True if this is a default method.
-
getParameterInfo
public MethodParameterInfo[] getParameterInfo()
Get the available information on method parameters.- Returns:
- The
MethodParameterInfo
objects for the method parameters, one per parameter.
-
getAnnotationInfo
public AnnotationInfoList getAnnotationInfo()
Get a list of annotations on this method, along with any annotation parameter values.- Returns:
- a list of annotations on this method, along with any annotation parameter values, wrapped in
AnnotationInfo
objects, or the empty list if none.
-
getAnnotationInfo
public AnnotationInfo getAnnotationInfo(String annotationName)
Get a the named annotation on this method, or null if the method does not have the named annotation.- Parameters:
annotationName
- The annotation name.- Returns:
- An
AnnotationInfo
object representing the named annotation on this method, or null if the method does not have the named annotation.
-
hasAnnotation
public boolean hasAnnotation(String annotationName)
- Parameters:
annotationName
- The name of an annotation.- Returns:
- true if this method has the named annotation.
-
hasParameterAnnotation
public boolean hasParameterAnnotation(String annotationName)
- Parameters:
annotationName
- The name of a method parameter annotation.- Returns:
- true if this method has a parameter with the named annotation.
-
loadClassAndGetMethod
public Method loadClassAndGetMethod() throws IllegalArgumentException
Load the class this method is associated with, and get theMethod
reference for this method.- Returns:
- The
Method
reference for this field. - Throws:
IllegalArgumentException
- if the method does not exist.
-
getClassName
protected String getClassName()
Returns the defining class name, so that super.getClassInfo() returns theClassInfo
object for the defining class.- Returns:
- The class name.
-
getClassNamesFromTypeDescriptors
protected void getClassNamesFromTypeDescriptors(Set<String> classNames)
Get the names of any classes in the type descriptor or type signature.
-
equals
public boolean equals(Object obj)
Test class name, method name and type descriptor for equals().
-
hashCode
public int hashCode()
Use hash code of class name, method name and type descriptor.
-
compareTo
public int compareTo(MethodInfo other)
Sort in order of class name, method name, then type descriptor.- Specified by:
compareTo
in interfaceComparable<MethodInfo>
-
-