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 Summary
Fields Modifier and Type Field Description private java.util.List<AttributeInfo>attributesAll attributes of this method that aren't explicitly covered by the private memberssignatureAttrandcodeAttr.static java.lang.StringCODEprivate CodecodeAttrTheCodeattribute, ornullif this method is abstract or native.private intdescriptorIndexAn index into the constant pool of aConstantUtf8Infostructure representing a valid method descriptor.static java.lang.StringEXCEPTIONSprivate java.lang.StringnameAndParametersCached string representing the name and parameters for this method.private intnameIndexAn index into the constant pool of aConstantUtf8Infostructure 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.private java.lang.String[]paramTypesThe type of all parameters to this method.private java.lang.StringreturnTypeCached return type.private SignaturesignatureAttrTheSignatureattribute, ornullif there isn't one for this method.private static java.lang.StringSPECIAL_NAME_CONSTRUCTORUsed in class files to denote constructors.-
Fields inherited from class org.fife.rsta.ac.java.classreader.MemberInfo
cf, DEPRECATED, RUNTIME_VISIBLE_ANNOTATIONS, SIGNATURE
-
Fields inherited from interface org.fife.rsta.ac.java.classreader.AccessFlags
ACC_ABSTRACT, ACC_ANNOTATION, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_VOLATILE
-
-
Constructor Summary
Constructors Constructor Description MethodInfo(ClassFile cf, int accessFlags, int nameIndex, int descriptorIndex)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddAttribute(AttributeInfo info)Adds the specified attribute to this field.private voidappendParamDescriptors(java.lang.StringBuilder sb)(package private) voidclearParamTypeInfo()Called internally byClassFilewhenever itsClassFile.setTypeParamsToTypeArgs(Map)method is called.private java.lang.String[]createParamTypes()Creates and returns an array of types of all parameters of this method.private java.lang.String[]createParamTypesFromDescriptor(boolean qualified)Creates an array of types of each parameter by looking at the method's descriptor field.private java.lang.String[]createParamTypesFromTypeSignature()Creates an array of types of each parameter by looking at the method'sSignatureattribute, and querying the parentClassFileinstance for any type argument values.AttributeInfogetAttribute(int index)Returns the specified attribute.intgetAttributeCount()Returns the number of attributes of this field.java.lang.StringgetDescriptor()Returns the descriptor of this member.java.lang.StringgetName()Returns the name of this member.java.lang.StringgetNameAndParameters()Returns the name and parameters of this method, in the formperformAction(String, int, Runnable).intgetParameterCount()Returns the number of parameters this method takes.java.lang.StringgetParameterName(int index)If debugging was enabled during compilation, this method returns the name of the given parameter to this method.java.lang.StringgetParameterType(int index, boolean fullyQualified)Returns a string representing the type of parameter to this method.java.lang.String[]getParameterTypes()Returns an array if strings representing the types of all parameters to this method.java.lang.StringgetReturnTypeString(boolean fullyQualified)Returns the return type of this method.private java.lang.StringgetReturnTypeStringFromDescriptor(boolean qualified)Returns the return type of this method, as determined by a snippet of the method descriptor.private java.lang.StringgetReturnTypeStringFromTypeSignature(boolean qualified)Returns the return type of this method, as determined by theSignatureattribute that was added in Java 5.java.lang.StringgetSignature()Returns the signature of this method, as determined from its method descriptor.booleanisAbstract()Returns whether this method is abstract.booleanisConstructor()Returns whether this method is a constructor.booleanisNative()Returns whether this method is native.booleanisStatic()Returns whether this method is static.static MethodInforead(ClassFile cf, java.io.DataInputStream in)Reads aMethodInfofrom an input stream.private AttributeInforeadAttribute(java.io.DataInputStream in)Reads an attribute for this method from the specified input stream.-
Methods inherited from class org.fife.rsta.ac.java.classreader.MemberInfo
getAccessFlags, getClassFile, isDeprecated, isFinal, readAttribute
-
-
-
-
Field Detail
-
nameIndex
private int nameIndex
An index into the constant pool of aConstantUtf8Infostructure 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 aConstantUtf8Infostructure representing a valid method descriptor.
-
signatureAttr
private Signature signatureAttr
TheSignatureattribute, ornullif there isn't one for this method.
-
codeAttr
private Code codeAttr
TheCodeattribute, ornullif this method is abstract or native.
-
attributes
private java.util.List<AttributeInfo> attributes
All attributes of this method that aren't explicitly covered by the private memberssignatureAttrandcodeAttr.
-
paramTypes
private java.lang.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 individualMethodInfos when doing completions, to ensure types are as correct as possible.
-
returnType
private java.lang.String returnType
Cached return type.
-
nameAndParameters
private java.lang.String nameAndParameters
Cached string representing the name and parameters for this method.
-
SPECIAL_NAME_CONSTRUCTOR
private static final java.lang.String SPECIAL_NAME_CONSTRUCTOR
Used in class files to denote constructors.- See Also:
- Constant Field Values
-
CODE
public static final java.lang.String CODE
- See Also:
- Constant Field Values
-
EXCEPTIONS
public static final java.lang.String EXCEPTIONS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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 Detail
-
addAttribute
private void addAttribute(AttributeInfo info)
Adds the specified attribute to this field.- Parameters:
info- Information about the attribute.
-
appendParamDescriptors
private void appendParamDescriptors(java.lang.StringBuilder sb)
-
clearParamTypeInfo
void clearParamTypeInfo()
Called internally byClassFilewhenever itsClassFile.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 thisMethodInfoto 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 java.lang.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 parentClassFileinstance, whose type argument values should have been initialized viaClassFile.setTypeParamsToTypeArgs(Map).- Returns:
- The array of parameter types.
- See Also:
createParamTypesFromDescriptor(boolean),createParamTypesFromTypeSignature()
-
createParamTypesFromDescriptor
private java.lang.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()
-
createParamTypesFromTypeSignature
private java.lang.String[] createParamTypesFromTypeSignature()
Creates an array of types of each parameter by looking at the method'sSignatureattribute, and querying the parentClassFileinstance 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:
createParamTypesFromDescriptor(boolean)
-
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 java.lang.String getDescriptor()
Description copied from class:MemberInfoReturns the descriptor of this member.- Specified by:
getDescriptorin classMemberInfo- Returns:
- The descriptor of this member.
-
getName
public java.lang.String getName()
Description copied from class:MemberInfoReturns the name of this member.- Specified by:
getNamein classMemberInfo- Returns:
- The name of this member.
-
getNameAndParameters
public java.lang.String getNameAndParameters()
Returns the name and parameters of this method, in the formperformAction(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:
getParameterTypes(),getParameterType(int, boolean)
-
getParameterName
public java.lang.String getParameterName(int index)
If debugging was enabled during compilation, this method returns the name of the given parameter to this method. Otherwise,nullis returned.- Parameters:
index- The index of the parameter.- Returns:
- The name of the parameter, or
null.
-
getParameterType
public java.lang.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:
getParameterCount(),getParameterTypes()
-
getParameterTypes
public java.lang.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:
getParameterCount(),getParameterType(int, boolean)
-
getReturnTypeString
public java.lang.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 java.lang.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(boolean)
-
getReturnTypeStringFromTypeSignature
private java.lang.String getReturnTypeStringFromTypeSignature(boolean qualified)
Returns the return type of this method, as determined by theSignatureattribute that was added in Java 5. This allows us to check for generic types.- Returns:
- The return type of this method.
- See Also:
getReturnTypeStringFromDescriptor(boolean)
-
getSignature
public java.lang.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:
isStaticin classMemberInfo- Returns:
- Whether this method is static.
-
read
public static MethodInfo read(ClassFile cf, java.io.DataInputStream in) throws java.io.IOException
Reads aMethodInfofrom an input stream.- Parameters:
cf- The class file defining the method.in- The input stream to read from.- Returns:
- The method information read.
- Throws:
java.io.IOException- If an IO error occurs.
-
readAttribute
private AttributeInfo readAttribute(java.io.DataInputStream in) throws java.io.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
nullif it was known to be unimportant for our purposes. - Throws:
java.io.IOException- If an IO error occurs.
-
-