public class MethodInfo extends Object implements Comparable<MethodInfo>, HasName
Modifier and Type | Method and 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(Class<? extends Annotation> annotation)
Get a the non-
Repeatable annotation on this method, or null if the method does not have the
annotation. |
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(Class<? extends Annotation> annotation)
Get a the
Repeatable annotation on this method, or the empty list if the method does not have the
annotation. |
AnnotationInfoList |
getAnnotationInfoRepeatable(String annotationName)
Get a the named
Repeatable annotation on this method, or the empty list if the method does not have
the named annotation. |
ClassInfo |
getClassInfo()
Get the
ClassInfo object for the class that declares this method. |
String |
getClassName()
Get the name of the class that declares this method.
|
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.
|
String[] |
getThrownExceptionNames()
Returns the exceptions thrown by the method, as an array.
|
ClassInfoList |
getThrownExceptions()
Returns the list of exceptions thrown by the method, as a
ClassInfoList . |
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(Class<? extends Annotation> annotation)
Check if this method has the annotation.
|
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(Class<? extends Annotation> annotation)
Check if this method has a parameter with the annotation.
|
boolean |
hasParameterAnnotation(String annotationName)
Check if this method has a parameter with the named annotation.
|
boolean |
isAbstract()
Returns true if this method is abstract.
|
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 |
isPrivate()
Returns true if this method is private.
|
boolean |
isProtected()
Returns true if this method is protected.
|
boolean |
isPublic()
Returns true if this method is public.
|
boolean |
isStatic()
Returns true if this method is static.
|
boolean |
isStrict()
Returns true if this method is strict.
|
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.
|
Constructor<?> |
loadClassAndGetConstructor()
Load the class this constructor is associated with, and get the
Constructor reference for this
constructor. |
Method |
loadClassAndGetMethod()
Load the class this method is associated with, and get the
Method reference for this method. |
String |
toString()
Render to string.
|
String |
toStringWithSimpleNames()
Render to string, using only simple
names for classes.
|
public String getName()
"<init>"
, and private static class
initializer blocks are named "<clinit>"
.public int getModifiers()
public String getModifiersStr()
getModifiers()
.public ClassInfo getClassInfo()
ClassInfo
object for the class that declares this method.ClassInfo
object for the declaring class.getClassName()
public MethodTypeSignature getTypeDescriptor()
getTypeSignature()
instead.public String getTypeDescriptorStr()
getTypeSignatureStr()
instead.public MethodTypeSignature getTypeSignature()
getTypeDescriptor()
instead.IllegalArgumentException
- if the method 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()
getTypeDescriptorStr()
instead.public MethodTypeSignature getTypeSignatureOrTypeDescriptor()
public String getTypeSignatureOrTypeDescriptorStr()
public ClassInfoList getThrownExceptions()
ClassInfoList
.ClassInfoList
(the list may be empty).public String[] getThrownExceptionNames()
public boolean isConstructor()
"<init>"
. This returns false for private static class initializer blocks, which are named
"<clinit>"
.public boolean isPublic()
public boolean isPrivate()
public boolean isProtected()
public boolean isStatic()
public boolean isFinal()
public boolean isSynchronized()
public boolean isBridge()
public boolean isSynthetic()
public boolean isVarArgs()
public boolean isNative()
public boolean isAbstract()
public boolean isStrict()
public boolean hasBody()
public boolean isDefault()
public MethodParameterInfo[] getParameterInfo()
MethodParameterInfo
objects for the method parameters, one per parameter.public AnnotationInfoList getAnnotationInfo()
AnnotationInfo
objects, or the empty list if none.public AnnotationInfo getAnnotationInfo(Class<? extends Annotation> annotation)
Repeatable
annotation on this method, or null if the method does not have the
annotation. (Use getAnnotationInfoRepeatable(Class)
for Repeatable
annotations.)annotation
- The annotation.AnnotationInfo
object representing the annotation on this method, or null if the method
does not have the annotation.public AnnotationInfo getAnnotationInfo(String annotationName)
Repeatable
annotation on this method, or null if the method does not have the
named annotation. (Use getAnnotationInfoRepeatable(String)
for Repeatable
annotations.)annotationName
- The annotation name.AnnotationInfo
object representing the named annotation on this method, or null if the
method does not have the named annotation.public AnnotationInfoList getAnnotationInfoRepeatable(Class<? extends Annotation> annotation)
Repeatable
annotation on this method, or the empty list if the method does not have the
annotation.annotation
- The annotation.AnnotationInfoList
containing all instances of the annotation on this method, or the empty
list if the method does not have the annotation.public AnnotationInfoList getAnnotationInfoRepeatable(String annotationName)
Repeatable
annotation on this method, or the empty list if the method does not have
the named annotation.annotationName
- The annotation name.AnnotationInfoList
containing all instances of the named annotation on this method, or the
empty list if the method does not have the named annotation.public boolean hasAnnotation(Class<? extends Annotation> annotation)
annotation
- The annotation.public boolean hasAnnotation(String annotationName)
annotationName
- The name of an annotation.public boolean hasParameterAnnotation(Class<? extends Annotation> annotation)
annotation
- The method parameter annotation.public boolean hasParameterAnnotation(String annotationName)
annotationName
- The name of a method parameter annotation.public Method loadClassAndGetMethod() throws IllegalArgumentException
Method
reference for this method. Only
call this if isConstructor()
returns false, otherwise an IllegalArgumentException
will be
thrown. Instead call loadClassAndGetConstructor()
for constructors.Method
reference for this method.IllegalArgumentException
- if the method does not exist, or if the method is a constructor.public Constructor<?> loadClassAndGetConstructor() throws IllegalArgumentException
Constructor
reference for this
constructor. Only call this if isConstructor()
returns true, otherwise an
IllegalArgumentException
will be thrown. Instead call loadClassAndGetMethod()
for non-method
constructors.Constructor
reference for this constructor.IllegalArgumentException
- if the constructor does not exist, or if the method is not a constructor.public String getClassName()
getClassInfo()
public boolean equals(Object obj)
public int hashCode()
public int compareTo(MethodInfo other)
compareTo
in interface Comparable<MethodInfo>
other
- the other MethodInfo
to compare.public String toStringWithSimpleNames()
Copyright © 2022. All rights reserved.