Package io.github.classgraph
Class MethodInfo
java.lang.Object
io.github.classgraph.MethodInfo
- All Implemented Interfaces:
HasName
,Comparable<MethodInfo>
public class MethodInfo extends Object implements Comparable<MethodInfo>, HasName
Holds metadata about methods of a class encountered during a scan. All values are taken directly out of the
classfile for the class.
-
Method Summary
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 non-Repeatable
annotation on this method, or null if the method does not have the named annotation.AnnotationInfoList
getAnnotationInfoRepeatable(String annotationName)
Get a the namedRepeatable
annotation on this method, or the empty list if the method does not have the named annotation.ClassInfo
getClassInfo()
Get theClassInfo
object for the declaring class (i.e.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.String
getTypeDescriptorStr()
Returns the type descriptor string 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.String
getTypeSignatureOrTypeDescriptorStr()
Returns the type signature string for the method, possibly including type parameters.String
getTypeSignatureStr()
Returns the type signature string for the method, possibly including type parameters.boolean
hasAnnotation(String annotationName)
Check if this method has the named annotation.boolean
hasBody()
Returns true if this method has a body (i.e.int
hashCode()
Use hashcode of class name, method name and type descriptor.boolean
hasParameterAnnotation(String annotationName)
Check if this method has a parameter with the named annotation.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
isSynthetic()
Returns true if this method is synthetic.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.
-
Method Details
-
getName
Returns the name of the method. Note that constructors are named"<init>"
, and private static class initializer blocks are named"<clinit>"
. -
getModifiers
public int getModifiers()Returns the modifier bits for the method.- Returns:
- The modifier bits for the method.
-
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.
-
getClassInfo
Get theClassInfo
object for the declaring class (i.e. the class that declares this method).- Returns:
- The
ClassInfo
object for the declaring class (i.e. the class that declares this method).
-
getTypeDescriptor
Returns the parsed type descriptor for the method, which will not include type parameters. If you need generic type parameters, callgetTypeSignature()
instead.- Returns:
- The parsed type descriptor for the method.
-
getTypeDescriptorStr
Returns the type descriptor string for the method, which will not include type parameters. If you need generic type parameters, callgetTypeSignatureStr()
instead.- Returns:
- The type descriptor string for the method.
-
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, callgetTypeDescriptor()
instead.- Returns:
- The parsed type signature for the method, or null if not available.
-
getTypeSignatureStr
Returns the type signature string for the method, possibly including type parameters. If this returns null, indicating that no type signature information is available for this method, callgetTypeDescriptorStr()
instead.- Returns:
- The type signature string for the method, or null if not available.
-
getTypeSignatureOrTypeDescriptor
Returns the parsed type signature for the method, possibly including type parameters. If the type signature string 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.
-
getTypeSignatureOrTypeDescriptorStr
Returns the type signature string for the method, possibly including type parameters. If the type signature string is null, indicating that no type signature information is available for this method, returns the type descriptor string instead.- Returns:
- The type signature string for the method, or if not available, the type descriptor string 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.
-
isSynthetic
public boolean isSynthetic()Returns true if this method is synthetic.- Returns:
- True if this is synthetic.
-
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
Get the available information on method parameters.- Returns:
- The
MethodParameterInfo
objects for the method parameters, one per parameter.
-
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
Get a the named non-Repeatable
annotation on this method, or null if the method does not have the named annotation. (UsegetAnnotationInfoRepeatable(String)
forRepeatable
annotations.)- 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.
-
getAnnotationInfoRepeatable
Get a the namedRepeatable
annotation on this method, or the empty list if the method does not have the named annotation.- Parameters:
annotationName
- The annotation name.- Returns:
- An
AnnotationInfoList
containing all instances of the named annotation on this method, or the empty list if the method does not have the named annotation.
-
hasAnnotation
Check if this method has the named annotation.- Parameters:
annotationName
- The name of an annotation.- Returns:
- true if this method has the named annotation.
-
hasParameterAnnotation
Check if this method has a parameter with the named annotation.- Parameters:
annotationName
- The name of a method parameter annotation.- Returns:
- true if this method has a parameter with the named annotation.
-
loadClassAndGetMethod
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.
-
equals
Test class name, method name and type descriptor for equals(). -
hashCode
public int hashCode()Use hashcode of class name, method name and type descriptor. -
compareTo
Sort in order of class name, method name, then type descriptor.- Specified by:
compareTo
in interfaceComparable<MethodInfo>
- Parameters:
other
- the otherMethodInfo
to compare.- Returns:
- the result of the comparison.
-
toString
Get a string representation of the method. Note that constructors are named"<init>"
, and private static class initializer blocks are named"<clinit>"
.
-