Class MethodInfo
- java.lang.Object
-
- io.github.lukehutch.fastclasspathscanner.scanner.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.
-
-
Constructor Summary
Constructors Constructor Description MethodInfo(String className, String methodName, List<AnnotationInfo> methodAnnotationInfo, int modifiers, String typeDescriptorStr, String typeSignatureStr, String[] parameterNames, int[] parameterModifiers, AnnotationInfo[][] parameterAnnotationInfo)
-
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().List<AnnotationInfo>
getAnnotationInfo()
Get a list of annotations on this method, along with any annotation parameter values.List<String>
getAnnotationNames()
Returns the names of annotations on the method.List<Class<?>>
getAnnotationTypes()
Returns a list ofClass<?>
references for the annotations on this method.String
getClassName()
Get the name of the class this method is part of.String
getMethodName()
Returns the name of the method.int
getModifiers()
Returns the modifier bits for the method.String
getModifiersStr()
Get the method modifiers as a String, e.g.int
getNumParameters()
Get the number of parameters of the method.AnnotationInfo[][]
getParameterAnnotationInfo()
Returns the annotations on each method parameter (along with any annotation parameters, wrapped in AnnotationInfo objects) if any parameters have annotations, else returns null.String[][]
getParameterAnnotationNames()
Returns the unique annotation names for annotations on each method parameter, if any parameters have annotations, else returns null.Class<?>[][]
getParameterAnnotationTypes()
Returns the unique annotation types for annotations on each method parameter, if any parameters have annotations, else returns null.MethodParameterInfo[]
getParameterInfo()
Get the available information on method parameters.int[]
getParameterModifiers()
Returns the parameter modifiers, if available (only available in classfiles compiled in JDK8 or above using the -parameters commandline switch, or code compiled with Kotlin or some other language), otherwise returns null if the parameter modifiers are not known.String[]
getParameterModifierStrs()
Returns the parameter modifiers as a string (e.g.String[]
getParameterNames()
Returns the method parameter names, if available (only available in classfiles compiled in JDK8 or above using the -parameters commandline switch), otherwise returns null if the parameter names are not known.Class<?>[]
getParameterTypes()
Returns the parameter types for the method.TypeSignature[]
getParameterTypeSignatures()
Returns the parameter type signatures for the method.Class<?>
getResultType()
Returns the return type for the method as a Class reference.TypeSignature
getResultTypeDescriptor()
Returns the result type descriptor for the method (without any type parameters).TypeSignature
getResultTypeSignature()
Returns the result type signature for the method (with type parameters, if present).Class<?>[]
getThrowsTypes()
Returns the types of exceptions the method may throw.ClassRefOrTypeVariableSignature[]
getThrowsTypeSignatures()
Returns the types of exceptions the method may throw, in string representation, e.g.String[]
getThrowsTypeStrs()
Returns the types of exceptions the method may throw, in string representation, e.g.MethodTypeSignature
getTypeDescriptor()
Returns the parsed type descriptor for the method, which will not include type parameters.String
getTypeDescriptorStr()
Returns the low-level internal type descriptor for the method, e.g.TypeParameter[]
getTypeParameters()
Returns the type parameters of the method.String[]
getTypeParameterStrs()
Returns the type parameters of the method, in string representation, e.g.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
getTypeSignatureStr()
Returns the low-level internal type Signature for the method, e.g.int
hashCode()
Use hash code of class name, method name and type descriptor.boolean
isBridge()
Returns true if this method is a bridge method.boolean
isConstructor()
Returns true if this method is a constructor.boolean
isFinal()
Returns true if this method is final.boolean
isNative()
Returns true if this method is a native method.boolean
isPackagePrivate()
Returns true if this method is package-private.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
isSynchronized()
Returns true if this method is synchronized.boolean
isVarArgs()
Returns true if this method is a varargs method.String
toString()
Get a string representation of the method.
-
-
-
Constructor Detail
-
MethodInfo
public MethodInfo(String className, String methodName, List<AnnotationInfo> methodAnnotationInfo, int modifiers, String typeDescriptorStr, String typeSignatureStr, String[] parameterNames, int[] parameterModifiers, AnnotationInfo[][] parameterAnnotationInfo)
- Parameters:
className
- The name of the enclosing class.methodName
- The name of the method.methodAnnotationInfo
- The list ofAnnotationInfo
objects 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
.
-
-
Method Detail
-
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.
-
getClassName
public String getClassName()
Get the name of the class this method is part of.- Returns:
- The name of the enclosing class.
-
getMethodName
public String getMethodName()
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.
-
getTypeDescriptorStr
public String getTypeDescriptorStr()
Returns the low-level internal type descriptor for the method, e.g."(Ljava/util/List;)V"
. This is the internal type descriptor used by the JVM, so does not include type parameters (due to type erasure), and does include any synthetic and/or mandated parameters generated by the compiler. See alsogetTypeDescriptor()
.- Returns:
- The internal type descriptor for the method.
-
getTypeSignatureStr
public String getTypeSignatureStr()
Returns the low-level internal type Signature for the method, e.g."(Ljava/util/List<Ljava/lang/String;>)V"
. This may or may not include synthetic and/or mandated parameters, depending on the compiler. May be null, if there is no type signature in the classfile. See alsogetTypeDescriptorStr()
.- Returns:
- The internal type signature for the method, or null if not available.
-
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.
-
isPrivate
public boolean isPrivate()
Returns true if this method is private.- Returns:
- True if this method is private.
-
isProtected
public boolean isProtected()
Returns true if this method is protected.- Returns:
- True if this method is protected.
-
isPackagePrivate
public boolean isPackagePrivate()
Returns true if this method is package-private.- Returns:
- True if this method is package-private.
-
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.
-
getParameterInfo
public MethodParameterInfo[] getParameterInfo()
Get the available information on method parameters.- Returns:
- The
MethodParameterInfo
objects for the method parameters, one per parameter.
-
getNumParameters
public int getNumParameters()
Get the number of parameters of the method.- Returns:
- The number of method parameters, i.e.
getParameterInfo().size()
.
-
getParameterTypes
public Class<?>[] getParameterTypes() throws IllegalArgumentException
Returns the parameter types for the method. If the method has no parameters, returns a zero-sized array. Note that it is always faster to callgetParameterInfo()
and get the parameter information from the returned list ofMethodParameterInfo
objects, since this method calls that to compile its results.Note that this calls Class.forName() on the parameter types, which will cause the class to be loaded, and possibly initialized. If the class is initialized, this can trigger side effects.
- Returns:
- The list of
Class<?>
references for the method parameter types. - Throws:
IllegalArgumentException
- if the parameter types of the method could not be loaded.
-
getParameterTypeSignatures
public TypeSignature[] getParameterTypeSignatures()
Returns the parameter type signatures for the method. If the method has no parameters, returns a zero-sized array. Note that it is always faster to callgetParameterInfo()
and get the parameter information from the returned list ofMethodParameterInfo
objects, since this method calls that to compile its results.- Returns:
- The method parameter types, as an array of parsed type signatures.
-
getParameterNames
public String[] getParameterNames()
Returns the method parameter names, if available (only available in classfiles compiled in JDK8 or above using the -parameters commandline switch), otherwise returns null if the parameter names are not known. Note that even when a non-null String array is returned, one or more individual array elements may be null, representing unnamed parameters. Note that it is always faster to callgetParameterInfo()
and get the parameter information from the returned list ofMethodParameterInfo
objects, since this method calls that to compile its results.- Returns:
- The method parameter names, as an array of Strings, or null if parameter names are not available.
-
getParameterModifiers
public int[] getParameterModifiers()
Returns the parameter modifiers, if available (only available in classfiles compiled in JDK8 or above using the -parameters commandline switch, or code compiled with Kotlin or some other language), otherwise returns null if the parameter modifiers are not known.Flag bits:
- 0x0010 (ACC_FINAL): Indicates that the formal parameter was declared final.
- 0x1000 (ACC_SYNTHETIC): Indicates that the formal parameter was not explicitly or implicitly declared in source code, according to the specification of the language in which the source code was written (JLS §13.1). (The formal parameter is an implementation artifact of the compiler which produced this class file.)
- 0x8000 (ACC_MANDATED): Indicates that the formal parameter was implicitly declared in source code, according to the specification of the language in which the source code was written (JLS §13.1). (The formal parameter is mandated by a language specification, so all compilers for the language must emit it.)
getParameterInfo()
and get the parameter information from the returned list ofMethodParameterInfo
objects, since this method calls that to compile its results.- Returns:
- The method parameter modifiers, as an array of integers, or null if parameter modifiers are not available.
-
getParameterModifierStrs
public String[] getParameterModifierStrs()
Returns the parameter modifiers as a string (e.g. ["final", ""], if available (only available in classfiles compiled in JDK8 or above using the -parameters commandline switch), otherwise returns null if the parameter modifiers are not known. Note that it is always faster to callgetParameterInfo()
and get the parameter information from the returned list ofMethodParameterInfo
objects, since this method calls that to compile its results.- Returns:
- The method parameter modifiers, in string representation, as an array of Strings, or null if the parameter modifiers are not available.
-
getParameterAnnotationInfo
public AnnotationInfo[][] getParameterAnnotationInfo()
Returns the annotations on each method parameter (along with any annotation parameters, wrapped in AnnotationInfo objects) if any parameters have annotations, else returns null. Note that it is always faster to callgetParameterInfo()
and get the parameter information from the returned list ofMethodParameterInfo
objects, since this method calls that to compile its results.- Returns:
- The method parameter annotations, as an array of
AnnotationInfo
objects, or null if no parameter annotations are present.
-
getParameterAnnotationNames
public String[][] getParameterAnnotationNames()
Returns the unique annotation names for annotations on each method parameter, if any parameters have annotations, else returns null. Note that it is always faster to callgetParameterInfo()
and get the parameter information from the returned list ofMethodParameterInfo
objects, since this method calls that to compile its results.- Returns:
- The method parameter annotation names, as an array of Strings, or null if no parameter annotations are presest.
-
getParameterAnnotationTypes
public Class<?>[][] getParameterAnnotationTypes()
Returns the unique annotation types for annotations on each method parameter, if any parameters have annotations, else returns null. Note that it is always faster to callgetParameterInfo()
and get the parameter information from the returned list ofMethodParameterInfo
objects, since this method calls that to compile its results.- Returns:
- The method parameter annotation types, as an array of Strings, or null if no parameter annotations are present.
-
getResultTypeSignature
public TypeSignature getResultTypeSignature()
Returns the result type signature for the method (with type parameters, if present). If this is a constructor, the returned type will be void.- Returns:
- The type signature of the result of this method, or null if type signature information is not available.
-
getResultTypeDescriptor
public TypeSignature getResultTypeDescriptor()
Returns the result type descriptor for the method (without any type parameters). If this is a constructor, the returned type will be void.- Returns:
- The type descriptor of the result of this method.
-
getResultType
public Class<?> getResultType() throws IllegalArgumentException
Returns the return type for the method as a Class reference. If this is a constructor, the return type will be void.class. Note that this callsClass.forName()
on the return type, which will cause the class to be loaded, and possibly initialized. If the class is initialized, this can trigger side effects.- Returns:
- The result type of the method as a
Class<?>
reference. - Throws:
IllegalArgumentException
- if the return type for the method could not be loaded.
-
getThrowsTypeSignatures
public ClassRefOrTypeVariableSignature[] getThrowsTypeSignatures()
Returns the types of exceptions the method may throw, in string representation, e.g.["com.abc.BadException", "<X>"]
.- Returns:
- The types of exceptions the method may throw. If the method throws no exceptions, returns a zero-sized array.
-
getThrowsTypes
public Class<?>[] getThrowsTypes()
Returns the types of exceptions the method may throw.- Returns:
- The types of exceptions the method may throw. If the method throws no exceptions, returns a zero-sized array.
-
getThrowsTypeStrs
public String[] getThrowsTypeStrs()
Returns the types of exceptions the method may throw, in string representation, e.g.["com.abc.BadException", "<X>"]
.- Returns:
- The types of exceptions the method may throw, as Strings. If the method throws no exceptions, returns a zero-sized array.
-
getTypeParameters
public TypeParameter[] getTypeParameters()
Returns the type parameters of the method.- Returns:
- The type parameters of the method. If the method has no type parameters, returns a zero-sized array.
-
getTypeParameterStrs
public String[] getTypeParameterStrs()
Returns the type parameters of the method, in string representation, e.g.["<X>", "<Y>"]
.- Returns:
- The type parameters of the method, in string representation, e.g.
["<X>", "<Y>"]
. If the method has no type parameters, returns a zero-sized array.
-
getAnnotationNames
public List<String> getAnnotationNames()
Returns the names of annotations on the method.- Returns:
- The names of annotations on this method, or the empty list if none.
-
getAnnotationTypes
public List<Class<?>> getAnnotationTypes() throws IllegalArgumentException
Returns a list ofClass<?>
references for the annotations on this method. Note that this calls Class.forName() on the annotation types, which will cause each annotation class to be loaded.- Returns:
- a list of
Class<?>
references for the annotations on this method, or the empty list if none. - Throws:
IllegalArgumentException
- if the annotation type could not be loaded.
-
getAnnotationInfo
public List<AnnotationInfo> 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.
-
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>
-
-