Class ClassFile
java.lang.Object
org.fife.rsta.ac.java.classreader.ClassFile
- All Implemented Interfaces:
AccessFlags
Class representing a
ClassFile structure.- Version:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intPermissions and properties of this class or interface.private AttributeInfo[]Attributes of this class or interface.static final Stringprivate ConstantPoolInfo[]Constant pool infos.private static final booleanprivate booleanWhether this class is deprecated.static final Stringstatic final Stringprivate FieldInfo[]Structures giving complete descriptions of the fields in this class or interface.private static final byte[]The 4-byte class file header, "CAFEBABE".static final String(package private) int[]Indices intoconstantPoolforConstantClassInfos representing the implemented interfaces of this class or interface.private intThe class file's major version number.private MethodInfo[]Structures giving complete descriptions of the methods in this class or interface.private intThe class file's minor version number.Parameter types, such as "String" inList<String>.static final Stringstatic final Stringstatic final Stringprivate intIndex intoconstantPoolfor aConstantClassInfostructure representing the superclass of this class or interface.private intIndex intoconstantPoolfor aConstantClassInfostructure representing the class or interface defined in this class file.A mapping of type parameters to type arguments.Fields 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voiddebugPrint(String text) intReturns the access flags for this class or interface.getAttribute(int index) Returns the specified attribute of this class file.intReturns the number of attributes of this class file.getClassName(boolean fullyQualified) Returns the name of this class or interface.protected 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.intReturns the size of the constant pool, plus1.getConstantPoolInfo(int index) Returns the constant pool entry at the specified index.intReturns the number of fields declared in this class file.getFieldInfo(int index) Returns the specified field's information.getFieldInfoByName(String name) Returns a field's information by name.intReturns the number of interfaces this class or interface implements.getImplementedInterfaceName(int index, boolean fullyQualified) Returns the specified interface implemented by this class or interface.intReturns the number of methods defined/declared in this class or interface.getMethodInfo(int index) Returns information about the specified method defined/declared in this class file.getMethodInfoByName(String name) Returns all method overloads with the specified name.getMethodInfoByName(String name, int argCount) Returns all method overloads with the specified name and number of arguments.Returns the package for this class or interface.getSuperClassName(boolean fullyQualified) Returns the fully-qualified name of the superclass of this class or interface.getTypeArgument(String typeParam) Returns the currently set type argument for the specified type parameter.getUtf8ValueFromConstantPool(int index) Returns the string value represented by aConstantUtf8Infoentry in the constant pool.Returns the version number of this class, as a string.private voidinit(DataInputStream in) Parses the class file from a given input stream.booleanReturns whether this class is deprecated.private voidReads this class or interface's access flags.private AttributeInfoReads a single attribute of this class file.private voidReads this class file's attributes.private voidReads the constant pool.private voidReads the "fields" information.private voidReads the0xCAFEBABEclass file header.private voidReads the array of indices into the constant pool for the names of the interfaces implemented by this class or interface.private voidprivate voidprivate voidprivate voidReads the class file's major and minor version numbers.voidsetTypeParamsToTypeArgs(Map<String, String> typeMap) Sets a mapping of type parameters of this class to type arguments for a particular instance of this class.toString()
-
Field Details
-
DEBUG
private static final boolean DEBUG- See Also:
-
minorVersion
private int minorVersionThe class file's minor version number. -
majorVersion
private int majorVersionThe class file's major version number. -
constantPool
Constant pool infos. -
accessFlags
private int accessFlagsPermissions and properties of this class or interface. -
thisClass
private int thisClassIndex intoconstantPoolfor aConstantClassInfostructure representing the class or interface defined in this class file. -
superClass
private int superClassIndex 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[] interfacesIndices intoconstantPoolforConstantClassInfos representing the implemented interfaces of this class or interface. -
fields
Structures giving complete descriptions of the fields in this class or interface. -
methods
Structures giving complete descriptions of the methods in this class or interface. -
deprecated
private boolean deprecatedWhether this class is deprecated. -
attributes
Attributes of this class or interface. -
paramTypes
-
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
- See Also:
-
ENCLOSING_METHOD
- See Also:
-
INNER_CLASSES
- See Also:
-
RUNTIME_VISIBLE_ANNOTATIONS
- See Also:
-
SIGNATURE
- See Also:
-
SOURCE_FILE
- See Also:
-
BOOTSTRAP_METHODS
- See Also:
-
HEADER
private static final byte[] HEADERThe 4-byte class file header, "CAFEBABE".
-
-
Constructor Details
-
ClassFile
- Throws:
IOException
-
ClassFile
- Throws:
IOException
-
-
Method Details
-
debugPrint
-
getAccessFlags
public int getAccessFlags()Returns the access flags for this class or interface.- Returns:
- The access flags, as a bit field.
- See Also:
-
getAttribute
Returns the specified attribute of this class file.- Parameters:
index- The index of the attribute.- Returns:
- The attribute.
- See Also:
-
getAttributeCount
public int getAttributeCount()Returns the number of attributes of this class file.- Returns:
- The number of attributes.
- See Also:
-
getClassName
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:
-
getClassNameFromConstantPool
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
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:
-
getFieldCount
public int getFieldCount()Returns the number of fields declared in this class file.- Returns:
- The number of fields.
- See Also:
-
getFieldInfo
Returns the specified field's information.- Parameters:
index- The index of the field info.- Returns:
- The field's information.
- See Also:
-
getFieldInfoByName
-
getImplementedInterfaceCount
public int getImplementedInterfaceCount()Returns the number of interfaces this class or interface implements.- Returns:
- The number of implemented interfaces.
- See Also:
-
getImplementedInterfaceName
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:
-
getMethodCount
public int getMethodCount()Returns the number of methods defined/declared in this class or interface.- Returns:
- The number of methods.
- See Also:
-
getMethodInfo
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:
-
getMethodInfoByName
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
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:
-
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:
-
getParamTypes
-
getSuperClassName
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:
-
getTypeArgument
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:
-
getUtf8ValueFromConstantPool
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
Returns the version number of this class, as a string.- Returns:
- The class's version number, in the form
major.minor.
-
init
Parses the class file from a given input stream.- Parameters:
in- The input stream to read from.- Throws:
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
Reads this class or interface's access flags.- Parameters:
in- The input stream to read from.- Throws:
IOException- If an error occurs reading the access flags.
-
readAttribute
Reads a single attribute of this class file.- Parameters:
in- The input stream to read from.- Returns:
- The attribute.
- Throws:
IOException- If an IO error occurs.
-
readAttributes
Reads this class file's attributes.- Parameters:
in- The input stream to read from.- Throws:
IOException- If an IO error occurs.
-
readConstantPoolInfos
Reads the constant pool.- Parameters:
in- The input stream to read from.- Throws:
IOException- If an IO error occurs.
-
readFields
Reads the "fields" information.- Parameters:
in- The input stream to read from.- Throws:
IOException- If an IO error occurs.
-
readHeader
Reads the0xCAFEBABEclass file header.- Parameters:
in- The input stream to read from.- Throws:
IOException- If the header is invalid.
-
readInterfaces
Reads 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:
IOException- If an IO error occurs reading the input stream.
-
readMethods
- Throws:
IOException
-
readSuperClass
- Throws:
IOException
-
readThisClass
- Throws:
IOException
-
readVersion
Reads the class file's major and minor version numbers.- Parameters:
in- The input stream to read from.- Throws:
IOException- If the version numbers are invalid.
-
setTypeParamsToTypeArgs
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:
-
toString
-