public class ClassFile extends java.lang.Object implements AccessFlags
ClassFile structure.| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
BOOTSTRAP_METHODS |
static java.lang.String |
DEPRECATED |
static java.lang.String |
ENCLOSING_METHOD |
static java.lang.String |
INNER_CLASSES |
static java.lang.String |
RUNTIME_VISIBLE_ANNOTATIONS |
static java.lang.String |
SIGNATURE |
static java.lang.String |
SOURCE_FILE |
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 and Description |
|---|
ClassFile(java.io.DataInputStream in) |
ClassFile(java.io.File classFile) |
| Modifier and Type | Method and Description |
|---|---|
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.
|
java.lang.String |
getClassName(boolean fullyQualified)
Returns the name of this class or interface.
|
protected java.lang.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.
|
FieldInfo |
getFieldInfoByName(java.lang.String name)
Returns a field's information by name.
|
int |
getImplementedInterfaceCount()
Returns the number of interfaces this class or interface implements.
|
java.lang.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.
|
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.String |
getPackageName()
Returns the package for this class or interface.
|
java.util.List<java.lang.String> |
getParamTypes() |
java.lang.String |
getSuperClassName(boolean fullyQualified)
Returns the fully-qualified name of the superclass of this class or
interface.
|
java.lang.String |
getTypeArgument(java.lang.String typeParam)
Returns the currently set type argument for the specified type parameter.
|
java.lang.String |
getUtf8ValueFromConstantPool(int index)
Returns the string value represented by a
ConstantUtf8Info
entry in the constant pool. |
java.lang.String |
getVersionString()
Returns the version number of this class, as a string.
|
boolean |
isDeprecated()
Returns whether this class is deprecated.
|
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.
|
java.lang.String |
toString() |
public static final java.lang.String DEPRECATED
public static final java.lang.String ENCLOSING_METHOD
public static final java.lang.String INNER_CLASSES
public static final java.lang.String RUNTIME_VISIBLE_ANNOTATIONS
public static final java.lang.String SIGNATURE
public static final java.lang.String SOURCE_FILE
public static final java.lang.String BOOTSTRAP_METHODS
public ClassFile(java.io.File classFile)
throws java.io.IOException
java.io.IOExceptionpublic ClassFile(java.io.DataInputStream in)
throws java.io.IOException
java.io.IOExceptionpublic int getAccessFlags()
AccessFlagspublic AttributeInfo getAttribute(int index)
index - The index of the attribute.getAttributeCount()public int getAttributeCount()
getAttribute(int)public java.lang.String getClassName(boolean fullyQualified)
fullyQualified - Whether the name should be fully-qualified.getSuperClassName(boolean)protected java.lang.String getClassNameFromConstantPool(int cpIndex,
boolean fullyQualified)
ConstantClassInfo,
this method returns the fully-qualified name of the class it points to.cpIndex - The index into the constant pool. Note that
this value is 1-based.fullyQualified - Whether the returned class name should be fully
qualified.public int getConstantPoolCount()
1.1.getConstantPoolInfo(int)public ConstantPoolInfo getConstantPoolInfo(int index)
1-based (that is, valid indices
are 1 - getConstantPoolCount()-1).index - The index into the constant pool to retrieve.null if
index is 0 (e.g. this
ClassFile object represents
java.lang.Object).getConstantPoolCount()public int getFieldCount()
getFieldInfo(int)public FieldInfo getFieldInfo(int index)
index - The index of the field info.getFieldCount(),
getFieldInfoByName(String)public FieldInfo getFieldInfoByName(java.lang.String name)
name - The name of the field.getFieldCount(),
getFieldInfo(int)public int getImplementedInterfaceCount()
getImplementedInterfaceName(int, boolean)public java.lang.String getImplementedInterfaceName(int index,
boolean fullyQualified)
index - The index of the interface.fullyQualified - Whether the returned interface name should be
fully qualified.getImplementedInterfaceCount()public int getMethodCount()
getMethodInfo(int)public MethodInfo getMethodInfo(int index)
index - The index of the method.getMethodCount()public java.util.List<MethodInfo> getMethodInfoByName(java.lang.String name)
name - The method name.null
if none. This is a list of MethodInfos.getMethodInfoByName(String, int)public java.util.List<MethodInfo> getMethodInfoByName(java.lang.String name, int argCount)
name - The method name.argCount - The number of arguments. If this is less than zero,
all overloads will be returned, regardless of argument count.null if none. This is a list of
MethodInfos.getMethodInfoByName(String)public java.lang.String getPackageName()
null if this class or interface
is not in a package.getClassName(boolean)public java.util.List<java.lang.String> getParamTypes()
public java.lang.String getSuperClassName(boolean fullyQualified)
fullyQualified - Whether the returned value should be fully
qualified.java.lang.Object" is
returned. If this class file represents
java.lang.Object, then null is
returned.getClassName(boolean)public java.lang.String getTypeArgument(java.lang.String typeParam)
typeParam - The type parameter.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.setTypeParamsToTypeArgs(Map)public java.lang.String getUtf8ValueFromConstantPool(int index)
ConstantUtf8Info
entry in the constant pool.index - The index into the constant pool of a
ConstantUtf8Info structure. This should be
1-based.public java.lang.String getVersionString()
major.minor.public boolean isDeprecated()
public void setTypeParamsToTypeArgs(java.util.Map<java.lang.String,java.lang.String> typeMap)
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).typeMap - A mapping of type parameters to type arguments (both
Strings).getTypeArgument(String)public java.lang.String toString()
toString in class java.lang.Object