Class ClassFile
- java.lang.Object
-
- org.fife.rsta.ac.java.classreader.ClassFile
-
- All Implemented Interfaces:
AccessFlags
public class ClassFile extends java.lang.Object implements AccessFlags
Class representing aClassFilestructure.- Version:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description private intaccessFlagsPermissions and properties of this class or interface.private AttributeInfo[]attributesAttributes of this class or interface.static java.lang.StringBOOTSTRAP_METHODSprivate ConstantPoolInfo[]constantPoolConstant pool infos.private static booleanDEBUGprivate booleandeprecatedWhether this class is deprecated.static java.lang.StringDEPRECATEDstatic java.lang.StringENCLOSING_METHODprivate FieldInfo[]fieldsStructures giving complete descriptions of the fields in this class or interface.private static byte[]HEADERThe 4-byte class file header, "CAFEBABE".static java.lang.StringINNER_CLASSES(package private) int[]interfacesIndices intoconstantPoolforConstantClassInfos representing the implemented interfaces of this class or interface.private intmajorVersionThe class file's major version number.private MethodInfo[]methodsStructures giving complete descriptions of the methods in this class or interface.private intminorVersionThe class file's minor version number.private java.util.List<java.lang.String>paramTypesParameter types, such as "String" inList<String>.static java.lang.StringRUNTIME_VISIBLE_ANNOTATIONSstatic java.lang.StringSIGNATUREstatic java.lang.StringSOURCE_FILEprivate intsuperClassIndex intoconstantPoolfor aConstantClassInfostructure representing the superclass of this class or interface.private intthisClassIndex intoconstantPoolfor aConstantClassInfostructure representing the class or interface defined in this class file.private java.util.Map<java.lang.String,java.lang.String>typeMapA mapping of type parameters to type arguments.-
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
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voiddebugPrint(java.lang.String text)intgetAccessFlags()Returns the access flags for this class or interface.AttributeInfogetAttribute(int index)Returns the specified attribute of this class file.intgetAttributeCount()Returns the number of attributes of this class file.java.lang.StringgetClassName(boolean fullyQualified)Returns the name of this class or interface.protected java.lang.StringgetClassNameFromConstantPool(int cpIndex, boolean fullyQualified)Given an index into the constant pool of aConstantClassInfo, this method returns the fully-qualified name of the class it points to.intgetConstantPoolCount()Returns the size of the constant pool, plus1.ConstantPoolInfogetConstantPoolInfo(int index)Returns the constant pool entry at the specified index.intgetFieldCount()Returns the number of fields declared in this class file.FieldInfogetFieldInfo(int index)Returns the specified field's information.FieldInfogetFieldInfoByName(java.lang.String name)Returns a field's information by name.intgetImplementedInterfaceCount()Returns the number of interfaces this class or interface implements.java.lang.StringgetImplementedInterfaceName(int index, boolean fullyQualified)Returns the specified interface implemented by this class or interface.intgetMethodCount()Returns the number of methods defined/declared in this class or interface.MethodInfogetMethodInfo(int index)Returns information about the specified method defined/declared in this class file.java.util.List<MethodInfo>getMethodInfoByName(java.lang.String name)Returns all method overloads with the specified name.java.util.List<MethodInfo>getMethodInfoByName(java.lang.String name, int argCount)Returns all method overloads with the specified name and number of arguments.java.lang.StringgetPackageName()Returns the package for this class or interface.java.util.List<java.lang.String>getParamTypes()java.lang.StringgetSuperClassName(boolean fullyQualified)Returns the fully-qualified name of the superclass of this class or interface.java.lang.StringgetTypeArgument(java.lang.String typeParam)Returns the currently set type argument for the specified type parameter.java.lang.StringgetUtf8ValueFromConstantPool(int index)Returns the string value represented by aConstantUtf8Infoentry in the constant pool.java.lang.StringgetVersionString()Returns the version number of this class, as a string.private voidinit(java.io.DataInputStream in)Parses the class file from a given input stream.booleanisDeprecated()Returns whether this class is deprecated.private voidreadAccessFlags(java.io.DataInputStream in)Reads this class or interface's access flags.private AttributeInforeadAttribute(java.io.DataInputStream in)Reads a single attribute of this class file.private voidreadAttributes(java.io.DataInputStream in)Reads this class file's attributes.private voidreadConstantPoolInfos(java.io.DataInputStream in)Reads the constant pool.private voidreadFields(java.io.DataInputStream in)Reads the "fields" information.private voidreadHeader(java.io.DataInputStream in)Reads the0xCAFEBABEclass file header.private voidreadInterfaces(java.io.DataInputStream in)Reads the array of indices into the constant pool for the names of the interfaces implemented by this class or interface.private voidreadMethods(java.io.DataInputStream in)private voidreadSuperClass(java.io.DataInputStream in)private voidreadThisClass(java.io.DataInputStream in)private voidreadVersion(java.io.DataInputStream in)Reads the class file's major and minor version numbers.voidsetTypeParamsToTypeArgs(java.util.Map<java.lang.String,java.lang.String> typeMap)Sets a mapping of type parameters of this class to type arguments for a particular instance of this class.java.lang.StringtoString()
-
-
-
Field Detail
-
DEBUG
private static final boolean DEBUG
- See Also:
- Constant Field Values
-
minorVersion
private int minorVersion
The class file's minor version number.
-
majorVersion
private int majorVersion
The class file's major version number.
-
constantPool
private ConstantPoolInfo[] constantPool
Constant pool infos.
-
accessFlags
private int accessFlags
Permissions and properties of this class or interface.
-
thisClass
private int thisClass
Index intoconstantPoolfor aConstantClassInfostructure representing the class or interface defined in this class file.
-
superClass
private int superClass
Index intoconstantPoolfor aConstantClassInfostructure representing the superclass of this class or interface. If this value is0then this class must be classjava.lang.Object. If this is an interface, then this index must point to information about classjava.lang.Object.
-
interfaces
int[] interfaces
Indices intoconstantPoolforConstantClassInfos representing the implemented interfaces of this class or interface.
-
fields
private FieldInfo[] fields
Structures giving complete descriptions of the fields in this class or interface.
-
methods
private MethodInfo[] methods
Structures giving complete descriptions of the methods in this class or interface.
-
deprecated
private boolean deprecated
Whether this class is deprecated.
-
attributes
private AttributeInfo[] attributes
Attributes of this class or interface.
-
paramTypes
private java.util.List<java.lang.String> paramTypes
Parameter types, such as "String" inList<String>.
-
typeMap
private java.util.Map<java.lang.String,java.lang.String> typeMap
A mapping of type parameters to type arguments. This is set viasetTypeParamsToTypeArgs(Map)during code completion of members of an instance variable whose type is represented by this class file. ThisClassFiledoesn't use this field itself; rather, it's there for consumers (such as the Java code completion API) to use.
-
DEPRECATED
public static final java.lang.String DEPRECATED
- See Also:
- Constant Field Values
-
ENCLOSING_METHOD
public static final java.lang.String ENCLOSING_METHOD
- See Also:
- Constant Field Values
-
INNER_CLASSES
public static final java.lang.String INNER_CLASSES
- See Also:
- Constant Field Values
-
RUNTIME_VISIBLE_ANNOTATIONS
public static final java.lang.String RUNTIME_VISIBLE_ANNOTATIONS
- See Also:
- Constant Field Values
-
SIGNATURE
public static final java.lang.String SIGNATURE
- See Also:
- Constant Field Values
-
SOURCE_FILE
public static final java.lang.String SOURCE_FILE
- See Also:
- Constant Field Values
-
BOOTSTRAP_METHODS
public static final java.lang.String BOOTSTRAP_METHODS
- See Also:
- Constant Field Values
-
HEADER
private static final byte[] HEADER
The 4-byte class file header, "CAFEBABE".
-
-
Method Detail
-
debugPrint
private void debugPrint(java.lang.String text)
-
getAccessFlags
public int getAccessFlags()
Returns the access flags for this class or interface.- Returns:
- The access flags, as a bit field.
- See Also:
AccessFlags
-
getAttribute
public AttributeInfo getAttribute(int index)
Returns the specified attribute of this class file.- Parameters:
index- The index of the attribute.- Returns:
- The attribute.
- See Also:
getAttributeCount()
-
getAttributeCount
public int getAttributeCount()
Returns the number of attributes of this class file.- Returns:
- The number of attributes.
- See Also:
getAttribute(int)
-
getClassName
public java.lang.String getClassName(boolean fullyQualified)
Returns the name of this class or interface.- Parameters:
fullyQualified- Whether the name should be fully-qualified.- Returns:
- The name of this class or interface.
- See Also:
getSuperClassName(boolean)
-
getClassNameFromConstantPool
protected java.lang.String getClassNameFromConstantPool(int cpIndex, boolean fullyQualified)Given an index into the constant pool of aConstantClassInfo, this method returns the fully-qualified name of the class it points to.- Parameters:
cpIndex- The index into the constant pool. Note that this value is1-based.fullyQualified- Whether the returned class name should be fully qualified.- Returns:
- The fully-qualified class or interface name.
-
getConstantPoolCount
public int getConstantPoolCount()
Returns the size of the constant pool, plus1.- Returns:
- The size of the constant pool, plus
1. - See Also:
getConstantPoolInfo(int)
-
getConstantPoolInfo
public ConstantPoolInfo getConstantPoolInfo(int index)
Returns the constant pool entry at the specified index. Note that constant pool entries are1-based (that is, valid indices are1 - getConstantPoolCount()-1).- Parameters:
index- The index into the constant pool to retrieve.- Returns:
- The constant pool entry, or
nullifindexis0(e.g. thisClassFileobject representsjava.lang.Object). - See Also:
getConstantPoolCount()
-
getFieldCount
public int getFieldCount()
Returns the number of fields declared in this class file.- Returns:
- The number of fields.
- See Also:
getFieldInfo(int)
-
getFieldInfo
public FieldInfo getFieldInfo(int index)
Returns the specified field's information.- Parameters:
index- The index of the field info.- Returns:
- The field's information.
- See Also:
getFieldCount(),getFieldInfoByName(String)
-
getFieldInfoByName
public FieldInfo getFieldInfoByName(java.lang.String name)
Returns a field's information by name.- Parameters:
name- The name of the field.- Returns:
- The field's information.
- See Also:
getFieldCount(),getFieldInfo(int)
-
getImplementedInterfaceCount
public int getImplementedInterfaceCount()
Returns the number of interfaces this class or interface implements.- Returns:
- The number of implemented interfaces.
- See Also:
getImplementedInterfaceName(int, boolean)
-
getImplementedInterfaceName
public java.lang.String getImplementedInterfaceName(int index, boolean fullyQualified)Returns the specified interface implemented by this class or interface.- Parameters:
index- The index of the interface.fullyQualified- Whether the returned interface name should be fully qualified.- Returns:
- The interface name.
- See Also:
getImplementedInterfaceCount()
-
getMethodCount
public int getMethodCount()
Returns the number of methods defined/declared in this class or interface.- Returns:
- The number of methods.
- See Also:
getMethodInfo(int)
-
getMethodInfo
public MethodInfo getMethodInfo(int index)
Returns information about the specified method defined/declared in this class file.- Parameters:
index- The index of the method.- Returns:
- Information about the method.
- See Also:
getMethodCount()
-
getMethodInfoByName
public java.util.List<MethodInfo> getMethodInfoByName(java.lang.String name)
Returns all method overloads with the specified name.- Parameters:
name- The method name.- Returns:
- Any method overloads with the given name, or
nullif none. This is a list ofMethodInfos. - See Also:
getMethodInfoByName(String, int)
-
getMethodInfoByName
public java.util.List<MethodInfo> getMethodInfoByName(java.lang.String name, int argCount)
Returns all method overloads with the specified name and number of arguments.- Parameters:
name- The method name.argCount- The number of arguments. If this is less than zero, all overloads will be returned, regardless of argument count.- Returns:
- Any method overloads with the given name and argument count, or
nullif none. This is a list ofMethodInfos. - See Also:
getMethodInfoByName(String)
-
getPackageName
public java.lang.String getPackageName()
Returns the package for this class or interface.- Returns:
- The package, or
nullif this class or interface is not in a package. - See Also:
getClassName(boolean)
-
getParamTypes
public java.util.List<java.lang.String> getParamTypes()
-
getSuperClassName
public java.lang.String getSuperClassName(boolean fullyQualified)
Returns the fully-qualified name of the superclass of this class or interface.- Parameters:
fullyQualified- Whether the returned value should be fully qualified.- Returns:
- The name of the superclass of this class or interface. If this
is an interface, then "
java.lang.Object" is returned. If this class file representsjava.lang.Object, thennullis returned. - See Also:
getClassName(boolean)
-
getTypeArgument
public java.lang.String getTypeArgument(java.lang.String typeParam)
Returns the currently set type argument for the specified type parameter.- Parameters:
typeParam- The type parameter.- Returns:
- The type argument, or "
Object" if no type parameters have been set. This is because, if the user types, say, "java.util.List list;" in Java 5+, the type defaults toObject. The code completion API may set the type argument mapping tonullif no type arguments are scanned, thus we need to returnObjectin this case. - See Also:
setTypeParamsToTypeArgs(Map)
-
getUtf8ValueFromConstantPool
public java.lang.String getUtf8ValueFromConstantPool(int index)
Returns the string value represented by aConstantUtf8Infoentry in the constant pool.- Parameters:
index- The index into the constant pool of aConstantUtf8Infostructure. This should be1-based.- Returns:
- The string represented.
-
getVersionString
public java.lang.String getVersionString()
Returns the version number of this class, as a string.- Returns:
- The class's version number, in the form
major.minor.
-
init
private void init(java.io.DataInputStream in) throws java.io.IOExceptionParses the class file from a given input stream.- Parameters:
in- The input stream to read from.- Throws:
java.io.IOException- If an error occurs reading the class file.
-
isDeprecated
public boolean isDeprecated()
Returns whether this class is deprecated.- Returns:
- Whether this class is deprecated.
-
readAccessFlags
private void readAccessFlags(java.io.DataInputStream in) throws java.io.IOExceptionReads this class or interface's access flags.- Parameters:
in- The input stream to read from.- Throws:
java.io.IOException- If an error occurs reading the access flags.
-
readAttribute
private AttributeInfo readAttribute(java.io.DataInputStream in) throws java.io.IOException
Reads a single attribute of this class file.- Parameters:
in- The input stream to read from.- Returns:
- The attribute.
- Throws:
java.io.IOException- If an IO error occurs.
-
readAttributes
private void readAttributes(java.io.DataInputStream in) throws java.io.IOExceptionReads this class file's attributes.- Parameters:
in- The input stream to read from.- Throws:
java.io.IOException- If an IO error occurs.
-
readConstantPoolInfos
private void readConstantPoolInfos(java.io.DataInputStream in) throws java.io.IOExceptionReads the constant pool.- Parameters:
in- The input stream to read from.- Throws:
java.io.IOException- If an IO error occurs.
-
readFields
private void readFields(java.io.DataInputStream in) throws java.io.IOExceptionReads the "fields" information.- Parameters:
in- The input stream to read from.- Throws:
java.io.IOException- If an IO error occurs.
-
readHeader
private void readHeader(java.io.DataInputStream in) throws java.io.IOExceptionReads the0xCAFEBABEclass file header.- Parameters:
in- The input stream to read from.- Throws:
java.io.IOException- If the header is invalid.
-
readInterfaces
private void readInterfaces(java.io.DataInputStream in) throws java.io.IOExceptionReads the array of indices into the constant pool for the names of the interfaces implemented by this class or interface.- Parameters:
in- The input stream to read from.- Throws:
java.io.IOException- If an IO error occurs reading the input stream.
-
readMethods
private void readMethods(java.io.DataInputStream in) throws java.io.IOException- Throws:
java.io.IOException
-
readSuperClass
private void readSuperClass(java.io.DataInputStream in) throws java.io.IOException- Throws:
java.io.IOException
-
readThisClass
private void readThisClass(java.io.DataInputStream in) throws java.io.IOException- Throws:
java.io.IOException
-
readVersion
private void readVersion(java.io.DataInputStream in) throws java.io.IOExceptionReads the class file's major and minor version numbers.- Parameters:
in- The input stream to read from.- Throws:
java.io.IOException- If the version numbers are invalid.
-
setTypeParamsToTypeArgs
public void setTypeParamsToTypeArgs(java.util.Map<java.lang.String,java.lang.String> typeMap)
Sets a mapping of type parameters of this class to type arguments for a particular instance of this class. Note thatClassFiledoes not directly use this field; it is there for code completion API's to use to extract the necessary types of arguments, return values, etc., of methods (see theMethodInfoclass).- Parameters:
typeMap- A mapping of type parameters to type arguments (bothStrings).- See Also:
getTypeArgument(String)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-