|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.janino.ClassFile
An object that represents the JavaTM "class file" format.
ClassFile(InputStream)
creates a ClassFile
object from the bytecode
read from the given java.io.InputStream
.
store(OutputStream)
generates JavaTM bytecode
which is suitable for being processed by a JavaTM virtual
machine.
Inner Class Summary | |
class |
ClassFile.CodeAttribute
A representation of a "Code" attribute. |
class |
ClassFile.LineNumberTableAttribute
|
class |
ClassFile.LineNumberTableEntry
|
class |
ClassFile.MethodInfo
This class represents a "method_info" structure, as defined by the JVM specification. |
class |
ClassFile.OtherAttribute
|
class |
ClassFile.SourceFileAttribute
|
Field Summary | |
short |
accessFlags
|
java.util.List |
constantPool
|
java.util.List |
fieldInfos
|
short[] |
interfaces
|
static short |
MAJOR_VERSION_JDK_1_1
|
static short |
MAJOR_VERSION_JDK_1_2
|
static short |
MAJOR_VERSION_JDK_1_3
|
static short |
MAJOR_VERSION_JDK_1_4
|
java.util.List |
methodInfos
|
static short |
MINOR_VERSION_JDK_1_1
|
static short |
MINOR_VERSION_JDK_1_2
|
static short |
MINOR_VERSION_JDK_1_3
|
static short |
MINOR_VERSION_JDK_1_4
|
short |
superclass
|
short |
thisClass
|
Constructor Summary | |
ClassFile(java.io.InputStream inputStream)
Read "class file" data from a java.io.InputStream and construct a
ClassFile object from it.
|
|
ClassFile(short accessFlags,
java.lang.String thisClassFD,
java.lang.String superclassFD,
java.lang.String[] interfaceFDs)
Construct from parsed components. |
Method Summary | |
short |
addConstantClassInfo(java.lang.String typeFD)
Add a "CONSTANT_Class_info" structure to the class file. |
short |
addConstantDoubleInfo(double value)
Add a "CONSTANT_Double_info" structure to the class file. |
short |
addConstantFieldrefInfo(java.lang.String classFD,
java.lang.String fieldName,
java.lang.String fieldFD)
Add a "CONSTANT_Fieldref_info" structure to the class file. |
short |
addConstantFloatInfo(float value)
Add a "CONSTANT_Float_info" structure to the class file. |
short |
addConstantIntegerInfo(int value)
Add a "CONSTANT_Integer_info" structure to the class file. |
short |
addConstantInterfaceMethodrefInfo(java.lang.String classFD,
java.lang.String methodName,
java.lang.String methodMD)
Add a "CONSTANT_InterfaceMethodref_info" structure to the class file. |
short |
addConstantLongInfo(long value)
Add a "CONSTANT_Long_info" structure to the class file. |
short |
addConstantMethodrefInfo(java.lang.String classFD,
java.lang.String methodName,
java.lang.String methodMD)
Add a "CONSTANT_Methodref_info" structure to the class file. |
short |
addConstantStringInfo(java.lang.String string)
Add a "CONSTANT_String_info" structure to the class file. |
void |
addFieldInfo(short accessFlags,
java.lang.String fieldName,
java.lang.String fieldTypeFD,
java.lang.Object optionalConstantValue)
|
ClassFile.MethodInfo |
addMethodInfo(short accessFlags,
java.lang.String methodName,
java.lang.String methodMD)
|
void |
addSourceFileAttribute(java.lang.String sourceFileName)
|
java.lang.String |
getConstantClassName(short index)
|
net.janino.ClassFile.ConstantPoolInfo |
getConstantPoolInfo(short index)
|
java.lang.String |
getConstantUtf8(short index)
|
short |
getMajorVersion()
Returns the current major class file version number. |
short |
getMinorVersion()
Returns the current minor class file version number. |
static java.lang.String |
getSourceResourceName(java.lang.String className)
Construct the name of a resource that could contain the source code of the class with the given name. |
java.lang.String |
getThisClassName()
|
static boolean |
isRecognizedVersion(short majorVersion,
short minorVersion)
|
void |
setVersion(short majorVersion,
short minorVersion)
Sets the major and minor class file version numbers (JVMS 4.1). |
void |
store(java.io.OutputStream os)
Write ClassFile to an OutputStream , in "class file" format.
|
byte[] |
toByteArray()
Return the byte code of this ClassFile as a byte array. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final short MAJOR_VERSION_JDK_1_1
public static final short MINOR_VERSION_JDK_1_1
public static final short MAJOR_VERSION_JDK_1_2
public static final short MINOR_VERSION_JDK_1_2
public static final short MAJOR_VERSION_JDK_1_3
public static final short MINOR_VERSION_JDK_1_3
public static final short MAJOR_VERSION_JDK_1_4
public static final short MINOR_VERSION_JDK_1_4
public java.util.List constantPool
public short accessFlags
public short thisClass
public short superclass
public short[] interfaces
public java.util.List fieldInfos
public java.util.List methodInfos
Constructor Detail |
public ClassFile(short accessFlags, java.lang.String thisClassFD, java.lang.String superclassFD, java.lang.String[] interfaceFDs)
accessFlags
- as defined by Mod
thisClassFD
- the field descriptor for this classsuperclassFD
- the field descriptor for the extended class (e.g. "Ljava/lang/Object;")interfaceFDs
- the field descriptors for the implemented interfacespublic ClassFile(java.io.InputStream inputStream) throws java.io.IOException, java.lang.ClassFormatError
java.io.InputStream
and construct a
ClassFile
object from it.
If the ClassFile
is created with this constructor, then most modifying operations
lead to a java.lang.UnsupportedOperationException
; only fields, methods and
attributes can be added.
inputStream
- java.io.IOException
- java.lang.ClassFormatError
- Method Detail |
public void addSourceFileAttribute(java.lang.String sourceFileName)
public java.lang.String getThisClassName()
public void setVersion(short majorVersion, short minorVersion)
majorVersion
- minorVersion
- public short getMajorVersion()
public short getMinorVersion()
public static boolean isRecognizedVersion(short majorVersion, short minorVersion)
public short addConstantClassInfo(java.lang.String typeFD)
public short addConstantFieldrefInfo(java.lang.String classFD, java.lang.String fieldName, java.lang.String fieldFD)
public short addConstantMethodrefInfo(java.lang.String classFD, java.lang.String methodName, java.lang.String methodMD)
public short addConstantInterfaceMethodrefInfo(java.lang.String classFD, java.lang.String methodName, java.lang.String methodMD)
public short addConstantStringInfo(java.lang.String string)
public short addConstantIntegerInfo(int value)
public short addConstantFloatInfo(float value)
public short addConstantLongInfo(long value)
public short addConstantDoubleInfo(double value)
public void addFieldInfo(short accessFlags, java.lang.String fieldName, java.lang.String fieldTypeFD, java.lang.Object optionalConstantValue)
public ClassFile.MethodInfo addMethodInfo(short accessFlags, java.lang.String methodName, java.lang.String methodMD)
public net.janino.ClassFile.ConstantPoolInfo getConstantPoolInfo(short index)
public java.lang.String getConstantClassName(short index)
index
- Index to a CONSTANT_Class_info in the constant pool
Returns:
The name of the denoted class in "internal form" (see JVMS 4.2)
getConstantUtf8
public java.lang.String getConstantUtf8(short index)
- Parameters:
index
- Index to a CONSTANT_Utf8_info
in the constant pool- Returns:
- The string represented by the structure
store
public void store(java.io.OutputStream os)
throws java.io.IOException
- Write
ClassFile
to an OutputStream
, in "class file" format.
Notice that if an java.io.IOException
is thrown, the class file is
probably written incompletely and thus invalid. The calling method must take
care of this situation, e.g. by closing the output stream and then deleting the
file.
- Parameters:
os
- - Throws:
java.io.IOException
-
getSourceResourceName
public static java.lang.String getSourceResourceName(java.lang.String className)
- Construct the name of a resource that could contain the source code of the class with the given
name.
Notice that member types are declared inside a different type, so the relevant source file
is that of the outermost declaring class.
- Parameters:
className
- Fully qualified class name, e.g. "pkg1.pkg2.Outer$Inner"- Returns:
- the name of the resource, e.g. "pkg1/pkg2/Outer.java"
toByteArray
public byte[] toByteArray()
- Return the byte code of this
ClassFile
as a byte array.
Overview
Package
Class
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD