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 Details

    • 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>".
      Specified by:
      getName in interface HasName
      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, call getModifiers().
      Returns:
      The modifiers for the method, as a String.
    • getClassInfo

      public ClassInfo getClassInfo()
      Get the ClassInfo 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

      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.
    • getTypeDescriptorStr

      public String getTypeDescriptorStr()
      Returns the type descriptor string for the method, which will not include type parameters. If you need generic type parameters, call getTypeSignatureStr() instead.
      Returns:
      The type descriptor string 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.
    • getTypeSignatureStr

      public String 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, call getTypeDescriptorStr() instead.
      Returns:
      The type signature string 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 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

      public String 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

      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 non-Repeatable annotation on this method, or null if the method does not have the named annotation. (Use getAnnotationInfoRepeatable(String) for Repeatable 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

      public 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.
      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

      public boolean hasAnnotation​(String annotationName)
      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

      public boolean hasParameterAnnotation​(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.
    • loadClassAndGetMethod

      public Method loadClassAndGetMethod() throws IllegalArgumentException
      Load the class this method is associated with, and get the Method reference for this method.
      Returns:
      The Method reference for this field.
      Throws:
      IllegalArgumentException - if the method does not exist.
    • equals

      public boolean equals​(Object obj)
      Test class name, method name and type descriptor for equals().
      Overrides:
      equals in class 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:
      hashCode in class Object
      Returns:
      the hashcode
    • compareTo

      public int compareTo​(MethodInfo other)
      Sort in order of class name, method name, then type descriptor.
      Specified by:
      compareTo in interface Comparable<MethodInfo>
      Parameters:
      other - the other MethodInfo to compare.
      Returns:
      the result of the comparison.
    • toString

      public String toString()
      Get a string representation of the method. Note that constructors are named "<init>", and private static class initializer blocks are named "<clinit>".
      Overrides:
      toString in class Object
      Returns:
      the string representation of the method.