Package io.github.classgraph
Class MethodInfo
- java.lang.Object
-
- io.github.classgraph.ScanResultObject
-
- io.github.classgraph.ClassMemberInfo
-
- io.github.classgraph.MethodInfo
-
- All Implemented Interfaces:
HasName,java.lang.Comparable<MethodInfo>
public class MethodInfo extends ClassMemberInfo implements java.lang.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 private booleanhasBodyTrue if this method has a body.private intmaxLineNumThe maximum line number for the body of this method, or 0 if unknown.private intminLineNumThe minimum line number for the body of this method, or 0 if unknown.(package private) AnnotationInfo[][]parameterAnnotationInfoUnaligned parameter annotations.private MethodParameterInfo[]parameterInfoAligned method parameter info.private int[]parameterModifiersUnaligned parameter modifiers.private java.lang.String[]parameterNamesUnaligned parameter names.private java.lang.String[]thrownExceptionNamesprivate ClassInfoListthrownExceptionsprivate java.util.List<Classfile.MethodTypeAnnotationDecorator>typeAnnotationDecoratorsThe type annotation decorators for theMethodTypeSignatureinstance.private MethodTypeSignaturetypeDescriptorThe parsed type descriptor.private MethodTypeSignaturetypeSignatureThe parsed type signature (or null if none).-
Fields inherited from class io.github.classgraph.ClassMemberInfo
annotationInfo, declaringClassName, modifiers, name, typeDescriptorStr, typeSignatureStr
-
Fields inherited from class io.github.classgraph.ScanResultObject
classRef, scanResult
-
-
Constructor Summary
Constructors Constructor Description MethodInfo()Default constructor for deserialization.MethodInfo(java.lang.String definingClassName, java.lang.String methodName, AnnotationInfoList methodAnnotationInfo, int modifiers, java.lang.String typeDescriptorStr, java.lang.String typeSignatureStr, java.lang.String[] parameterNames, int[] parameterModifiers, AnnotationInfo[][] parameterAnnotationInfo, boolean hasBody, int minLineNum, int maxLineNum, java.util.List<Classfile.MethodTypeAnnotationDecorator> methodTypeAnnotationDecorators, java.lang.String[] thrownExceptionNames)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(MethodInfo other)Sort in order of class name, method name, then type descriptor.booleanequals(java.lang.Object obj)Test class name, method name and type descriptor for equals().protected voidfindReferencedClassInfo(java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo, java.util.Set<ClassInfo> refdClassInfo, LogNode log)GetClassInfoobjects for any classes referenced in the type descriptor or type signature.intgetMaxLineNum()The line number of the last non-empty line in the body of this method, or 0 if unknown.intgetMinLineNum()The line number of the first non-empty line in the body of this method, or 0 if unknown.java.lang.StringgetModifiersStr()Get the method modifiers as a String, e.g.java.lang.StringgetName()Returns the name of the method.MethodParameterInfo[]getParameterInfo()Get the available information on method parameters.java.lang.String[]getThrownExceptionNames()Returns the exceptions thrown by the method, as an array.ClassInfoListgetThrownExceptions()Returns the list of exceptions thrown by the method, as aClassInfoList.MethodTypeSignaturegetTypeDescriptor()Returns the parsed type descriptor for the method, which will not include type parameters.MethodTypeSignaturegetTypeSignature()Returns the parsed type signature for the method, possibly including type parameters.MethodTypeSignaturegetTypeSignatureOrTypeDescriptor()Returns the parsed type signature for the method, possibly including type parameters.(package private) voidhandleRepeatableAnnotations(java.util.Set<java.lang.String> allRepeatableAnnotationNames)HandleRepeatableannotations.booleanhasBody()Returns true if this method has a body (i.e.inthashCode()Use hashcode of class name, method name and type descriptor.booleanhasParameterAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)Check if this method has a parameter with the annotation.booleanhasParameterAnnotation(java.lang.String annotationName)Check if this method has a parameter with the named annotation.booleanisAbstract()Returns true if this method is abstract.booleanisBridge()Returns true if this method is a bridge method.booleanisConstructor()Returns true if this method is a constructor.booleanisDefault()Returns true if this is a default method (i.e.booleanisNative()Returns true if this method is a native method.booleanisStrict()Returns true if this method is strict.booleanisSynchronized()Returns true if this method is synchronized.booleanisVarArgs()Returns true if this method is a varargs method.java.lang.reflect.Constructor<?>loadClassAndGetConstructor()Load the class this constructor is associated with, and get theConstructorreference for this constructor.java.lang.reflect.MethodloadClassAndGetMethod()Load the class this method is associated with, and get theMethodreference for this method.private java.lang.Class<?>[]loadParameterClasses()Load and return the classes of each of the method parameters.(package private) voidsetScanResult(ScanResult scanResult)Set ScanResult backreferences in info objects after scan has completed.protected voidtoString(boolean useSimpleNames, java.lang.StringBuilder buf)Get a string representation of the method.-
Methods inherited from class io.github.classgraph.ClassMemberInfo
getAnnotationInfo, getAnnotationInfo, getAnnotationInfo, getAnnotationInfoRepeatable, getAnnotationInfoRepeatable, getClassInfo, getClassName, getModifiers, getTypeDescriptorStr, getTypeSignatureOrTypeDescriptorStr, getTypeSignatureStr, hasAnnotation, hasAnnotation, isFinal, isPrivate, isProtected, isPublic, isStatic, isSynthetic
-
Methods inherited from class io.github.classgraph.ScanResultObject
findReferencedClassInfo, loadClass, loadClass, loadClass, loadClass, toString, toString, toStringWithSimpleNames
-
-
-
-
Field Detail
-
typeDescriptor
private transient MethodTypeSignature typeDescriptor
The parsed type descriptor.
-
typeSignature
private transient MethodTypeSignature typeSignature
The parsed type signature (or null if none). Method parameter types are unaligned.
-
parameterNames
private java.lang.String[] parameterNames
Unaligned parameter names. These are only produced in JDK8+, and only if the commandline switch `-parameters` is provided at compiletime.
-
parameterModifiers
private int[] parameterModifiers
Unaligned parameter modifiers. These are only produced in JDK8+, and only if the commandline switch `-parameters` is provided at compiletime.
-
parameterAnnotationInfo
AnnotationInfo[][] parameterAnnotationInfo
Unaligned parameter annotations.
-
parameterInfo
private transient MethodParameterInfo[] parameterInfo
Aligned method parameter info.
-
hasBody
private boolean hasBody
True if this method has a body.
-
minLineNum
private int minLineNum
The minimum line number for the body of this method, or 0 if unknown.
-
maxLineNum
private int maxLineNum
The maximum line number for the body of this method, or 0 if unknown.
-
typeAnnotationDecorators
private transient java.util.List<Classfile.MethodTypeAnnotationDecorator> typeAnnotationDecorators
The type annotation decorators for theMethodTypeSignatureinstance.
-
thrownExceptionNames
private java.lang.String[] thrownExceptionNames
-
thrownExceptions
private transient ClassInfoList thrownExceptions
-
-
Constructor Detail
-
MethodInfo
MethodInfo()
Default constructor for deserialization.
-
MethodInfo
MethodInfo(java.lang.String definingClassName, java.lang.String methodName, AnnotationInfoList methodAnnotationInfo, int modifiers, java.lang.String typeDescriptorStr, java.lang.String typeSignatureStr, java.lang.String[] parameterNames, int[] parameterModifiers, AnnotationInfo[][] parameterAnnotationInfo, boolean hasBody, int minLineNum, int maxLineNum, java.util.List<Classfile.MethodTypeAnnotationDecorator> methodTypeAnnotationDecorators, java.lang.String[] thrownExceptionNames)Constructor.- Parameters:
definingClassName- The name of the enclosing class.methodName- The name of the method.methodAnnotationInfo- The list ofAnnotationInfoobjects for any annotations on the method.modifiers- The method modifier bits.typeDescriptorStr- The internal method type descriptor string.typeSignatureStr- The internal method type signature string, or null if none.parameterNames- The parameter names.parameterModifiers- The parameter modifiers.parameterAnnotationInfo- The parameterAnnotationInfo.hasBody- True if this method has a body.minLineNum- The minimum line number for the body of this method, or 0 if unknown.maxLineNum- The maximum line number for the body of this method, or 0 if unknown.methodTypeAnnotationDecorators- Decorator lambdas for method type annotations.thrownExceptionNames- exceptions thrown by this method.
-
-
Method Detail
-
getName
public java.lang.String getName()
Returns the name of the method. Note that constructors are named"<init>", and private static class initializer blocks are named"<clinit>".- Specified by:
getNamein interfaceHasName- Overrides:
getNamein classClassMemberInfo- Returns:
- The name of the method.
-
getModifiersStr
public java.lang.String getModifiersStr()
Get the method modifiers as a String, e.g. "public static final". For the modifier bits, callClassMemberInfo.getModifiers().- Specified by:
getModifiersStrin classClassMemberInfo- Returns:
- The modifiers for the method, as a String.
-
getTypeDescriptor
public MethodTypeSignature getTypeDescriptor()
Returns the parsed type descriptor for the method, which will not include type parameters. If you need generic type parameters, callgetTypeSignature()instead.- Specified by:
getTypeDescriptorin classClassMemberInfo- 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, callgetTypeDescriptor()instead.- Specified by:
getTypeSignaturein classClassMemberInfo- Returns:
- The parsed type signature for the method, or null if not available.
- Throws:
java.lang.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).
-
getTypeSignatureOrTypeDescriptor
public MethodTypeSignature 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.- Specified by:
getTypeSignatureOrTypeDescriptorin classClassMemberInfo- Returns:
- The parsed type signature for the method, or if not available, the parsed type descriptor for the method.
-
getThrownExceptions
public ClassInfoList getThrownExceptions()
Returns the list of exceptions thrown by the method, as aClassInfoList.- Returns:
- The list of exceptions thrown by the method, as a
ClassInfoList(the list may be empty).
-
getThrownExceptionNames
public java.lang.String[] getThrownExceptionNames()
Returns the exceptions thrown by the method, as an array.- Returns:
- The exceptions thrown by the method, as an array (the array may be empty).
-
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.
-
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.
-
isAbstract
public boolean isAbstract()
Returns true if this method is abstract.- Returns:
- True if this method is abstract.
-
isStrict
public boolean isStrict()
Returns true if this method is strict.- Returns:
- True if this method is strict.
-
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.
-
getMinLineNum
public int getMinLineNum()
The line number of the first non-empty line in the body of this method, or 0 if unknown.- Returns:
- The line number of the first non-empty line in the body of this method, or 0 if unknown.
-
getMaxLineNum
public int getMaxLineNum()
The line number of the last non-empty line in the body of this method, or 0 if unknown.- Returns:
- The line number of the last non-empty line in the body of this method, or 0 if unknown.
-
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
MethodParameterInfoobjects for the method parameters, one per parameter.
-
hasParameterAnnotation
public boolean hasParameterAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotation)
Check if this method has a parameter with the annotation.- Parameters:
annotation- The method parameter annotation.- Returns:
- true if this method has a parameter with the annotation.
-
hasParameterAnnotation
public boolean hasParameterAnnotation(java.lang.String annotationName)
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.
-
loadParameterClasses
private java.lang.Class<?>[] loadParameterClasses()
Load and return the classes of each of the method parameters.- Returns:
- An array of the
Classreferences for each method parameter.
-
loadClassAndGetMethod
public java.lang.reflect.Method loadClassAndGetMethod() throws java.lang.IllegalArgumentExceptionLoad the class this method is associated with, and get theMethodreference for this method. Only call this ifisConstructor()returns false, otherwise anIllegalArgumentExceptionwill be thrown. Instead callloadClassAndGetConstructor()for constructors.- Returns:
- The
Methodreference for this method. - Throws:
java.lang.IllegalArgumentException-- If the method's class can't be loaded
- If the method does not exist
- If the method is a constructor
- If one of the method's parameters references an unknown class
- If the method's return type references an unknown class
-
loadClassAndGetConstructor
public java.lang.reflect.Constructor<?> loadClassAndGetConstructor() throws java.lang.IllegalArgumentExceptionLoad the class this constructor is associated with, and get theConstructorreference for this constructor. Only call this ifisConstructor()returns true, otherwise anIllegalArgumentExceptionwill be thrown. Instead callloadClassAndGetMethod()for non-method constructors.- Returns:
- The
Constructorreference for this constructor. - Throws:
java.lang.IllegalArgumentException-- If the method's class can't be loaded
- If the constructor does not exist
- If the method is not a constructor
- If one of the constructor's parameters references an unknown class
-
handleRepeatableAnnotations
void handleRepeatableAnnotations(java.util.Set<java.lang.String> allRepeatableAnnotationNames)
HandleRepeatableannotations.- Parameters:
allRepeatableAnnotationNames- the names of all repeatable annotations
-
setScanResult
void setScanResult(ScanResult scanResult)
Description copied from class:ScanResultObjectSet ScanResult backreferences in info objects after scan has completed.- Overrides:
setScanResultin classScanResultObject- Parameters:
scanResult- the scan result
-
findReferencedClassInfo
protected void findReferencedClassInfo(java.util.Map<java.lang.String,ClassInfo> classNameToClassInfo, java.util.Set<ClassInfo> refdClassInfo, LogNode log)
GetClassInfoobjects for any classes referenced in the type descriptor or type signature.- Overrides:
findReferencedClassInfoin classScanResultObject- Parameters:
classNameToClassInfo- the map from class name toClassInfo.refdClassInfo- the referenced class infolog- the log
-
equals
public boolean equals(java.lang.Object obj)
Test class name, method name and type descriptor for equals().- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the object to compare for equality- Returns:
- true if equal
-
hashCode
public int hashCode()
Use hashcode of class name, method name and type descriptor.- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hashcode
-
compareTo
public int compareTo(MethodInfo other)
Sort in order of class name, method name, then type descriptor.- Specified by:
compareToin interfacejava.lang.Comparable<MethodInfo>- Parameters:
other- the otherMethodInfoto compare.- Returns:
- the result of the comparison.
-
toString
protected void toString(boolean useSimpleNames, java.lang.StringBuilder buf)Get a string representation of the method. Note that constructors are named"<init>", and private static class initializer blocks are named"<clinit>".- Specified by:
toStringin classScanResultObject- Parameters:
useSimpleNames- the use simple namesbuf- the buf
-
-