Class MethodInfo

java.lang.Object
org.fife.rsta.ac.java.classreader.MemberInfo
org.fife.rsta.ac.java.classreader.MethodInfo
All Implemented Interfaces:
AccessFlags

public class MethodInfo extends MemberInfo implements AccessFlags
Implementation of the "method_info" structure as defined in the JVM specification.
Version:
1.0
  • Field Details

    • nameIndex

      private int nameIndex
      An index into the constant pool of a
      invalid reference
      ConstantUtf8Info
      structure representing either one of the special method names ( "<init>" or "<clinit>") or a valid method name in the Java programming language, stored as a simple name.
    • descriptorIndex

      private int descriptorIndex
      An index into the constant pool of a
      invalid reference
      ConstantUtf8Info
      structure representing a valid method descriptor.
    • signatureAttr

      private Signature signatureAttr
      The Signature attribute, or null if there isn't one for this method.
    • codeAttr

      private Code codeAttr
      The Code attribute, or null if this method is abstract or native.
    • attributes

      private List<AttributeInfo> attributes
      All attributes of this method that aren't explicitly covered by the private members signatureAttr and codeAttr.
    • paramTypes

      private String[] paramTypes
      The type of all parameters to this method. Note that this cache will be short-lived, as classes that take type parameters will pass their type arguments down to individual MethodInfos when doing completions, to ensure types are as correct as possible.
    • returnType

      private String returnType
      Cached return type.
    • nameAndParameters

      private String nameAndParameters
      Cached string representing the name and parameters for this method.
    • SPECIAL_NAME_CONSTRUCTOR

      private static final String SPECIAL_NAME_CONSTRUCTOR
      Used in class files to denote constructors.
      See Also:
    • CODE

      public static final String CODE
      See Also:
    • EXCEPTIONS

      public static final String EXCEPTIONS
      See Also:
  • Constructor Details

    • MethodInfo

      public MethodInfo(ClassFile cf, int accessFlags, int nameIndex, int descriptorIndex)
      Constructor.
      Parameters:
      cf - The class file defining this method.
      accessFlags - The access flags.
      nameIndex - The name index.
      descriptorIndex - The descriptor index.
  • Method Details

    • addAttribute

      private void addAttribute(AttributeInfo info)
      Adds the specified attribute to this field.
      Parameters:
      info - Information about the attribute.
    • appendParamDescriptors

      private void appendParamDescriptors(StringBuilder sb)
    • clearParamTypeInfo

      void clearParamTypeInfo()
      Called internally by ClassFile whenever its ClassFile.setTypeParamsToTypeArgs(Map) method is called. This clears this method's local cache of parameter/return types. They'll be lazily recomputed the next time they are needed. This allows this MethodInfo to be used for code completion for instances of the same class initialized with different type arguments.

      Note that if this method does not have parameterized arguments or return type, calling this method won't affect its behavior.

    • createParamTypes

      private String[] createParamTypes()
      Creates and returns an array of types of all parameters of this method. If this method takes any generic type arguments, these types are grabbed from the parent ClassFile instance, whose type argument values should have been initialized via ClassFile.setTypeParamsToTypeArgs(Map).
      Returns:
      The array of parameter types.
      See Also:
    • createParamTypesFromDescriptor

      private String[] createParamTypesFromDescriptor(boolean qualified)
      Creates an array of types of each parameter by looking at the method's descriptor field. This technique should work with Java 1.0+, but won't pick up on generic types added in Java 5.
      Returns:
      The parameter types.
      See Also:
    • createParamTypesFromTypeSignature

      private String[] createParamTypesFromTypeSignature()
      Creates an array of types of each parameter by looking at the method's Signature attribute, and querying the parent ClassFile instance for any type argument values. This attribute was introduced in Java 5, and is the only way to detect generic parameters.
      Returns:
      The parameter types.
      See Also:
    • getAttribute

      public AttributeInfo getAttribute(int index)
      Returns the specified attribute.
      Parameters:
      index - The index of the attribute.
      Returns:
      The attribute.
    • getAttributeCount

      public int getAttributeCount()
      Returns the number of attributes of this field.
      Returns:
      The number of attributes.
    • getDescriptor

      public String getDescriptor()
      Description copied from class: MemberInfo
      Returns the descriptor of this member.
      Specified by:
      getDescriptor in class MemberInfo
      Returns:
      The descriptor of this member.
    • getName

      public String getName()
      Description copied from class: MemberInfo
      Returns the name of this member.
      Specified by:
      getName in class MemberInfo
      Returns:
      The name of this member.
    • getNameAndParameters

      public String getNameAndParameters()
      Returns the name and parameters of this method, in the form performAction(String, int, Runnable).
      Returns:
      The name and parameters of this method.
    • getParameterCount

      public int getParameterCount()
      Returns the number of parameters this method takes.
      Returns:
      The number of parameters this method takes.
      See Also:
    • getParameterName

      public String getParameterName(int index)
      If debugging was enabled during compilation, this method returns the name of the given parameter to this method. Otherwise, null is returned.
      Parameters:
      index - The index of the parameter.
      Returns:
      The name of the parameter, or null.
    • getParameterType

      public String getParameterType(int index, boolean fullyQualified)
      Returns a string representing the type of parameter to this method.
      Parameters:
      index - The index of the parameter.
      fullyQualified - Whether the returned type should be fully qualified. Note that if fully qualified information is not available for the parameters to this method, this parameter will be ignored (but I'm not sure that ever happens).
      Returns:
      The type of the parameter.
      See Also:
    • getParameterTypes

      public String[] getParameterTypes()
      Returns an array if strings representing the types of all parameters to this method. If this method takes no parameters, a zero-length array is returned.
      Returns:
      The array. These types will likely be fully qualified.
      See Also:
    • getReturnTypeString

      public String getReturnTypeString(boolean fullyQualified)
      Returns the return type of this method.
      Parameters:
      fullyQualified - Whether the returned value should be fully-qualified.
      Returns:
      The return type of this method.
    • getReturnTypeStringFromDescriptor

      private String getReturnTypeStringFromDescriptor(boolean qualified)
      Returns the return type of this method, as determined by a snippet of the method descriptor. This should work with all class files created in Java 1.0+, but won't discover the generic types added in Java 5.
      Returns:
      The return type of this method.
      See Also:
    • getReturnTypeStringFromTypeSignature

      private String getReturnTypeStringFromTypeSignature(boolean qualified)
      Returns the return type of this method, as determined by the Signature attribute that was added in Java 5. This allows us to check for generic types.
      Returns:
      The return type of this method.
      See Also:
    • getSignature

      public String getSignature()
      Returns the signature of this method, as determined from its method descriptor.
      Returns:
      The signature of this method.
    • isAbstract

      public boolean isAbstract()
      Returns whether this method is abstract.
      Returns:
      Whether this method is abstract.
    • isConstructor

      public boolean isConstructor()
      Returns whether this method is a constructor.
      Returns:
      Whether this method is a constructor.
    • isNative

      public boolean isNative()
      Returns whether this method is native.
      Returns:
      Whether this method is native.
    • isStatic

      public boolean isStatic()
      Returns whether this method is static.
      Overrides:
      isStatic in class MemberInfo
      Returns:
      Whether this method is static.
    • read

      public static MethodInfo read(ClassFile cf, DataInputStream in) throws IOException
      Reads a MethodInfo from an input stream.
      Parameters:
      cf - The class file defining the method.
      in - The input stream to read from.
      Returns:
      The method information read.
      Throws:
      IOException - If an IO error occurs.
    • readAttribute

      private AttributeInfo readAttribute(DataInputStream in) throws IOException
      Reads an attribute for this method from the specified input stream.
      Parameters:
      in - The input stream to read from.
      Returns:
      The attribute read, possibly null if it was known to be unimportant for our purposes.
      Throws:
      IOException - If an IO error occurs.