org.fife.rsta.ac.java.classreader
Class ClassFile

java.lang.Object
  extended by org.fife.rsta.ac.java.classreader.ClassFile
All Implemented Interfaces:
AccessFlags

public class ClassFile
extends Object
implements AccessFlags

Class representing a ClassFile structure.

Version:
1.0
Author:
Robert Futrell

Field Summary
static String SIGNATURE
           
static String SOURCE_FILE
           
 
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
ClassFile(DataInputStream in)
           
ClassFile(File classFile)
           
 
Method Summary
 int getAccessFlags()
          Returns the access flags for this class or interface.
 AttributeInfo getAttribute(int index)
          Returns the specified attribute of this class file.
 int getAttributeCount()
          Returns the number of attributes of this class file.
 String getClassName(boolean fullyQualified)
          Returns the name of this class or interface.
protected  String getClassNameFromConstantPool(int cpIndex, boolean fullyQualified)
          Given an index into the constant pool of a ConstantClassInfo, this method returns the fully-qualified name of the class it points to.
 int getConstantPoolCount()
          Returns the size of the constant pool, plus 1.
 ConstantPoolInfo getConstantPoolInfo(int index)
          Returns the constant pool entry at the specified index.
 int getFieldCount()
          Returns the number of fields declared in this class file.
 FieldInfo getFieldInfo(int index)
          Returns the specified field's information.
 int getImplementedInterfaceCount()
          Returns the number of interfaces this class or interface implements.
 String getImplementedInterfaceName(int index, boolean fullyQualified)
          Returns the specified interface implemented by this class or interface.
 int getMethodCount()
          Returns the number of methods defined/declared in this class or interface.
 MethodInfo getMethodInfo(int index)
          Returns information about the specified method defined/declared in this class file.
 String getPackageName()
          Returns the package for this class or interface.
 List getParamTypes()
           
 String getSuperClassName(boolean fullyQualified)
          Returns the fully-qualified name of the superclass of this class or interface.
 String getTypeArgument(String typeParam)
          Returns the currently set type argument for the specified type parameter.
 String getUtf8ValueFromConstantPool(int index)
          Returns the string value represented by a ConstantUtf8Info entry in the constant pool.
 String getVersionString()
          Returns the version number of this class, as a string.
 void setTypeParamsToTypeArgs(Map typeMap)
          Sets a mapping of type parameters of this class to type arguments for a particular instance of this class.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SIGNATURE

public static final String SIGNATURE
See Also:
Constant Field Values

SOURCE_FILE

public static final String SOURCE_FILE
See Also:
Constant Field Values
Constructor Detail

ClassFile

public ClassFile(File classFile)
          throws IOException
Throws:
IOException

ClassFile

public ClassFile(DataInputStream in)
          throws IOException
Throws:
IOException
Method Detail

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 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 String getClassNameFromConstantPool(int cpIndex,
                                              boolean fullyQualified)
Given an index into the constant pool of a ConstantClassInfo, 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 is 1-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, plus 1.

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 are 1-based (that is, valid indices are 1 - getConstantPoolCount()-1).

Parameters:
index - The index into the constant pool to retrieve.
Returns:
The constant pool entry, or null if index is 0 (e.g. this ClassFile object represents java.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.

getImplementedInterfaceCount

public int getImplementedInterfaceCount()
Returns the number of interfaces this class or interface implements.

Returns:
The number of implemented interfaces.
See Also:
#getImplementedInterfaceName(int)

getImplementedInterfaceName

public 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()

getPackageName

public String getPackageName()
Returns the package for this class or interface.

Returns:
The package, or null if this class or interface is not in a package.
See Also:
getClassName(boolean)

getParamTypes

public List getParamTypes()

getSuperClassName

public 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 represents java.lang.Object, then null is returned.
See Also:
getClassName(boolean)

getTypeArgument

public String getTypeArgument(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 to Object. The code completion API may set the type argument mapping to null if no type arguments are scanned, thus we need to return Object in this case.
See Also:
setTypeParamsToTypeArgs(Map)

getUtf8ValueFromConstantPool

public String getUtf8ValueFromConstantPool(int index)
Returns the string value represented by a ConstantUtf8Info entry in the constant pool.

Parameters:
index - The index into the constant pool of a ConstantUtf8Info structure. This should be 1-based.
Returns:
The string represented.

getVersionString

public String getVersionString()
Returns the version number of this class, as a string.

Returns:
The class's version number, in the form major.minor.

setTypeParamsToTypeArgs

public void setTypeParamsToTypeArgs(Map typeMap)
Sets a mapping of type parameters of this class to type arguments for a particular instance of this class. Note that ClassFile does 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 the MethodInfo class).

Parameters:
typeMap - A mapping of type parameters to type arguments (both Strings).
See Also:
getTypeArgument(String)

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2003-2011. All Rights Reserved.