public class ClassFile extends java.lang.Object implements WritableData, CompilerConstants
Modifier and Type | Field and Description |
---|---|
static int |
ACC_ABSTRACT
Abstract access flag.
|
static int |
ACC_FINAL
Final access flag.
|
static int |
ACC_INTERFACE
Interface access flag.
|
static int |
ACC_NATIVE
Native access flag.
|
static int |
ACC_PRIVATE
Private access flag.
|
static int |
ACC_PROTECTED
Protected access flag.
|
static int |
ACC_PUBLIC
Public access flag.
|
static int |
ACC_STATIC
Static access flag.
|
static int |
ACC_STRICT
Strict access flag.
|
static int |
ACC_SUPER
Super access flag.
|
static int |
ACC_SYNCHRONIZED
Synchronized access flag.
|
static int |
ACC_TRANSIENT
Transient access flag.
|
static int |
ACC_VOLATILE
Volatile access flag.
|
private int |
accessFlags
Bitwise or'ed access flags.
|
private java.util.List |
attrs
List of attributes associated with current class.
|
private java.util.List |
fields
List of fields contained within current class.
|
private java.util.List |
interfaces
List of interfaces implemented by current class.
|
private static int |
MAGIC_NUMBER
Magic number which is first four bytes of a valid class file
|
private static int |
MAJOR_VERSION
Major version expected by JVM.
|
private java.util.List |
methods
List of methods contained within current class.
|
private static int |
MINOR_VERSION
Minor version expected by JVM.
|
static java.lang.String |
OBJECT_CLASSNAME
Fully qualified name of the Object class.
|
private ConstantPool |
pool
Constant pool for this class.
|
private ClassConstant |
superClass
Class constant representing parent of class being compiled.
|
private ClassConstant |
thisClass
Class constant representing current class being compiled.
|
_aastore, _aconst_null, _aload_0, _aload_1, _aload_2, _aload_3, _anewarray, _areturn, _astore_1, _astore_2, _astore_3, _checkcast, _d2i, _d2l, _dadd, _dcmpg, _dconst_0, _dconst_1, _ddiv, _dmul, _dneg, _drem, _dreturn, _dsub, _dup, _getfield, _goto, _i2d, _i2l, _iadd, _iand, _iconst_0, _iconst_1, _iconst_2, _iconst_3, _iconst_4, _iconst_5, _idiv, _if_icmpeq, _if_icmpge, _if_icmpgt, _if_icmple, _if_icmplt, _if_icmpne, _ifeq, _ifge, _ifgt, _ifle, _iflt, _ifne, _ifnonnull, _ifnull, _imul, _ineg, _invokeinterface, _invokespecial, _invokestatic, _invokevirtual, _ior, _irem, _ireturn, _ishl, _ishr, _isub, _iushr, _ixor, _l2d, _l2i, _ladd, _land, _lcmp, _lconst_0, _lconst_1, _ldc_w, _ldc2_w, _ldiv, _lmul, _lneg, _lor, _lrem, _lshl, _lshr, _lsub, _lushr, _lxor, _new, _pop, _pop2, _return, _swap, CLASS_COMPILEDEXPRESSION, METHDESC_EXECUTE, METHNAME_EXECUTE, METHOD_INIT
Constructor and Description |
---|
ClassFile(java.lang.String className)
Constructor.
|
ClassFile(java.lang.String className,
java.lang.String superName)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
MethodInfo |
addDefaultConstructor(int accessFlags,
Compiler compiler)
This method adds a default constructor with the specified access
flags.
|
ClassConstant |
addInterface(java.lang.String name)
Add an interface to the constant pool of the current class.
|
void |
addMethod(MethodInfo methodInfo)
Add a method to the current class file.
|
ConstantPool |
getConstantPool()
Get a reference to this class file's constant pool.
|
java.lang.String |
getFullyQualifiedName()
Return the fully qualified name of the current class, substituting
. characters for / characters. |
ClassConstant |
getSuperClass()
Return class constant object for the current class' parent.
|
void |
setAccessFlags(int accessFlags)
Set the access flags for this class file.
|
void |
write(java.io.DataOutput out)
Write the class file to a binary output stream in the format defined
by the JVM specification.
|
public static final int ACC_PUBLIC
public static final int ACC_PRIVATE
public static final int ACC_PROTECTED
public static final int ACC_STATIC
public static final int ACC_FINAL
public static final int ACC_SUPER
public static final int ACC_SYNCHRONIZED
public static final int ACC_VOLATILE
public static final int ACC_TRANSIENT
public static final int ACC_NATIVE
public static final int ACC_INTERFACE
public static final int ACC_ABSTRACT
public static final int ACC_STRICT
public static final java.lang.String OBJECT_CLASSNAME
private static final int MAGIC_NUMBER
private static final int MINOR_VERSION
private static final int MAJOR_VERSION
private ConstantPool pool
private int accessFlags
private ClassConstant thisClass
private ClassConstant superClass
private java.util.List interfaces
private java.util.List fields
private java.util.List methods
private java.util.List attrs
public ClassFile(java.lang.String className)
java/lang/Object
as superclass
of class being compiled.className
- Fully qualified name of class to be compiled, in the form
package_qualifier/class_name
.public ClassFile(java.lang.String className, java.lang.String superName)
className
- Fully qualified name of class to be compiled, in the form
package_qualifier/class_name
.superName
- Fully qualified name of superclass of class to be compiled,
in the form package_qualifier/class_name
.public ConstantPool getConstantPool()
public ClassConstant getSuperClass()
public java.lang.String getFullyQualifiedName()
.
characters for /
characters.public MethodInfo addDefaultConstructor(int accessFlags, Compiler compiler)
accessFlags
- Access flags to assign to constructor.compiler
- The compiler to use.MethodInfo
object representing the constructor.public void setAccessFlags(int accessFlags)
accessFlags
- Bitwise or'ed combination of access flags.public ClassConstant addInterface(java.lang.String name)
name
- Fully qualified name of the interface to be added, in the form
package_qualifier/interface_name
.public void addMethod(MethodInfo methodInfo)
methodInfo
- Object which describes the method.public void write(java.io.DataOutput out) throws java.io.IOException
write
in interface WritableData
out
- Data output stream.java.io.IOException
- if any error writing to output stream.