Class MethodInfo
java.lang.Object
org.fife.rsta.ac.java.classreader.MemberInfo
org.fife.rsta.ac.java.classreader.MethodInfo
- All Implemented Interfaces:
AccessFlags
Implementation of the "
method_info" structure as defined in
the JVM specification.- Version:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate List<AttributeInfo> All attributes of this method that aren't explicitly covered by the private memberssignatureAttrandcodeAttr.static final Stringprivate CodeTheCodeattribute, ornullif this method is abstract or native.private intAn index into the constant pool of astructure representing a valid method descriptor.invalid reference
ConstantUtf8Infostatic final Stringprivate StringCached string representing the name and parameters for this method.private intAn index into the constant pool of astructure representing either one of the special method names ( "invalid reference
ConstantUtf8Info<init>" or "<clinit>") or a valid method name in the Java programming language, stored as a simple name.private String[]The type of all parameters to this method.private StringCached return type.private SignatureTheSignatureattribute, ornullif there isn't one for this method.private static final StringUsed in class files to denote constructors.Fields inherited from class MemberInfo
cf, DEPRECATED, RUNTIME_VISIBLE_ANNOTATIONS, SIGNATUREFields inherited from interface 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
ConstructorsConstructorDescriptionMethodInfo(ClassFile cf, int accessFlags, int nameIndex, int descriptorIndex) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddAttribute(AttributeInfo info) Adds the specified attribute to this field.private void(package private) voidCalled internally byClassFilewhenever itsClassFile.setTypeParamsToTypeArgs(Map)method is called.private String[]Creates and returns an array of types of all parameters of this method.private String[]createParamTypesFromDescriptor(boolean qualified) Creates an array of types of each parameter by looking at the method's descriptor field.private String[]Creates an array of types of each parameter by looking at the method'sSignatureattribute, and querying the parentClassFileinstance for any type argument values.getAttribute(int index) Returns the specified attribute.intReturns the number of attributes of this field.Returns the descriptor of this member.getName()Returns the name of this member.Returns the name and parameters of this method, in the formperformAction(String, int, Runnable).intReturns the number of parameters this method takes.getParameterName(int index) If debugging was enabled during compilation, this method returns the name of the given parameter to this method.getParameterType(int index, boolean fullyQualified) Returns a string representing the type of parameter to this method.String[]Returns an array if strings representing the types of all parameters to this method.getReturnTypeString(boolean fullyQualified) Returns the return type of this method.private StringgetReturnTypeStringFromDescriptor(boolean qualified) Returns the return type of this method, as determined by a snippet of the method descriptor.private StringgetReturnTypeStringFromTypeSignature(boolean qualified) Returns the return type of this method, as determined by theSignatureattribute that was added in Java 5.Returns the signature of this method, as determined from its method descriptor.booleanReturns whether this method is abstract.booleanReturns whether this method is a constructor.booleanisNative()Returns whether this method is native.booleanisStatic()Returns whether this method is static.static MethodInforead(ClassFile cf, DataInputStream in) Reads aMethodInfofrom an input stream.private AttributeInfoReads an attribute for this method from the specified input stream.Methods inherited from class MemberInfo
getAccessFlags, getClassFile, isDeprecated, isFinal, readAttribute
-
Field Details
-
nameIndex
private int nameIndexAn index into the constant pool of astructure representing either one of the special method names ( "invalid reference
ConstantUtf8Info<init>" or "<clinit>") or a valid method name in the Java programming language, stored as a simple name. -
descriptorIndex
private int descriptorIndexAn index into the constant pool of astructure representing a valid method descriptor.invalid reference
ConstantUtf8Info -
signatureAttr
TheSignatureattribute, ornullif there isn't one for this method. -
codeAttr
TheCodeattribute, ornullif this method is abstract or native. -
attributes
All attributes of this method that aren't explicitly covered by the private memberssignatureAttrandcodeAttr. -
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
Cached return type. -
nameAndParameters
Cached string representing the name and parameters for this method. -
SPECIAL_NAME_CONSTRUCTOR
Used in class files to denote constructors.- See Also:
-
CODE
- See Also:
-
EXCEPTIONS
- See Also:
-
-
Constructor Details
-
MethodInfo
Constructor.- Parameters:
cf- The class file defining this method.accessFlags- The access flags.nameIndex- The name index.descriptorIndex- The descriptor index.
-
-
Method Details
-
addAttribute
Adds the specified attribute to this field.- Parameters:
info- Information about the attribute.
-
appendParamDescriptors
-
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
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
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
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:
-
getAttribute
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
Description copied from class:MemberInfoReturns the descriptor of this member.- Specified by:
getDescriptorin classMemberInfo- Returns:
- The descriptor of this member.
-
getName
Description copied from class:MemberInfoReturns the name of this member.- Specified by:
getNamein classMemberInfo- Returns:
- The name of this member.
-
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:
-
getParameterName
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
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
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
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
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
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:
-
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
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:
IOException- If an IO error occurs.
-
readAttribute
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:
IOException- If an IO error occurs.
-