Class MethodInfo

All Implemented Interfaces:
HasName, Comparable<MethodInfo>

public class MethodInfo extends ClassMemberInfo 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.
  • 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
      Overrides:
      getName in class ClassMemberInfo
      Returns:
      The name of the method.
    • getModifiersStr

      public String getModifiersStr()
      Get the method modifiers as a String, e.g. "public static final". For the modifier bits, call ClassMemberInfo.getModifiers().
      Specified by:
      getModifiersStr in class ClassMemberInfo
      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, call getTypeSignature() instead.
      Specified by:
      getTypeDescriptor in class ClassMemberInfo
      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.
      Specified by:
      getTypeSignature in class ClassMemberInfo
      Returns:
      The parsed type signature for the method, or null if not available.
      Throws:
      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:
      getTypeSignatureOrTypeDescriptor in class ClassMemberInfo
      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 a ClassInfoList.
      Returns:
      The list of exceptions thrown by the method, as a ClassInfoList (the list may be empty).
    • getThrownExceptionNames

      public 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 MethodParameterInfo objects for the method parameters, one per parameter.
    • hasParameterAnnotation

      public boolean hasParameterAnnotation(Class<? extends 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(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. Only call this if isConstructor() returns false, otherwise an IllegalArgumentException will be thrown. Instead call loadClassAndGetConstructor() for constructors.
      Returns:
      The Method reference for this method.
      Throws:
      IllegalArgumentException - if the method does not exist, or if the method is a constructor.
    • loadClassAndGetConstructor

      public Constructor<?> loadClassAndGetConstructor() throws IllegalArgumentException
      Load the class this constructor is associated with, and get the 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.
      Returns:
      The Constructor reference for this constructor.
      Throws:
      IllegalArgumentException - if the constructor does not exist, or if the method is not a constructor.
    • 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.
    • toStringWithSimpleNames

      public String toStringWithSimpleNames()
      Render to string, using only simple names for classes.
      Returns:
      the string representation, using simple names for classes.
    • toString

      public String toString()
      Render to string.
      Overrides:
      toString in class Object
      Returns:
      the string representation.