com.vladium.jcd.cls
Class ClassDef

java.lang.Object
  extended bycom.vladium.jcd.cls.ClassDef
All Implemented Interfaces:
java.lang.Cloneable, IAccessFlags, IClassFormatOutput

public final class ClassDef
extends java.lang.Object
implements java.lang.Cloneable, IAccessFlags, IClassFormatOutput

This class represents the abstract syntax table (AST) that ClassDefParser produces from bytecode. Most elements are either settable or extendible. This class also implements IClassFormatOutput and works with ClassWriter to produce bytecode without an external compiler.

MT-safety: this class and all interfaces used by it are not safe for access from multiple concurrent threads.

Author:
(C) 2001, Vlad Roubtsov

Nested Class Summary
private static class ClassDef.ConstructorDescriptor
           
private static class ClassDef.FieldDescriptor
           
private static class ClassDef.MethodDescriptor
           
 
Field Summary
private static boolean DEBUG_SUID
           
private  int m_access_flags
           
private  IAttributeCollection m_attributes
           
private  IConstantCollection m_constants
           
private  long m_declaredSUID
           
private  IFieldCollection m_fields
           
private  IInterfaceCollection m_interfaces
           
private  long m_magic
           
private  IMethodCollection m_methods
           
private  int m_super_class_index
           
private  int m_this_class_index
           
private  int[] m_version
           
 
Fields inherited from interface com.vladium.jcd.cls.IAccessFlags
ACC_ABSTRACT, ACC_BRIDGE, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_SUPER, ACC_SYNCHRONIZED, ACC_TRANSIENT, ACC_VOLATILE, ALL_ACC, ALL_ACC_NAMES
 
Constructor Summary
ClassDef()
           
 
Method Summary
 void accept(IClassDefVisitor visitor, java.lang.Object ctx)
           
 int addClassref(java.lang.String classJVMName)
           
 int addCONSTANT_Utf8(java.lang.String value, boolean keepUnique)
           
 int addField(java.lang.String name, java.lang.String descriptor, int access_flags)
          Adds a new declared field to this class [with no attributes]
 int addField(java.lang.String name, java.lang.String descriptor, int access_flags, IAttributeCollection attributes)
          Adds a new declared field to this class [with given attributes]
 int addFieldref(Field_info field)
          Adds a reference to a field declared by this class.
 int addFieldref(int offset)
          Adds a reference to a field declared by this class.
 int addMethod(Method_info method)
           
 int addNameType(java.lang.String name, java.lang.String typeDescriptor)
           
 int addStringConstant(java.lang.String value)
           
 java.lang.Object clone()
          Performs a deep copy.
 long computeSUID(boolean skipCLINIT)
          This follows the spec at http://java.sun.com/j2se/1.4.1/docs/guide/serialization/spec/class.doc6.html#4100 as well as undocumented hacks used by Sun's 1.4.2 J2SDK
 int getAccessFlags()
           
 IAttributeCollection getAttributes()
           
 IConstantCollection getConstants()
           
 long getDeclaredSUID()
           
 IFieldCollection getFields()
           
 int[] getFields(java.lang.String name)
           
 IInterfaceCollection getInterfaces()
           
 long getMagic()
           
 IMethodCollection getMethods()
           
 int[] getMethods(java.lang.String name)
           
 java.lang.String getName()
           
 CONSTANT_Class_info getSuperClass()
           
 int getSuperClassIndex()
           
 CONSTANT_Class_info getThisClass()
           
 int getThisClassIndex()
           
 int[] getVersion()
           
 boolean isInterface()
           
 boolean isNested(int[] nestedAccessFlags)
           
 boolean isSynthetic()
           
 Method_info newEmptyMethod(java.lang.String name, java.lang.String descriptor, int access_flags)
           
 void setAccessFlags(int flags)
           
 void setDeclaredSUID(long suid)
           
 void setMagic(long magic)
           
 void setSuperClassIndex(int super_class_index)
           
 void setThisClassIndex(int this_class_index)
           
 void setVersion(int[] version)
           
 void writeInClassFormat(UDataOutputStream out)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_magic

private long m_magic

m_version

private int[] m_version

m_access_flags

private int m_access_flags

m_this_class_index

private int m_this_class_index

m_super_class_index

private int m_super_class_index

m_constants

private IConstantCollection m_constants

m_interfaces

private IInterfaceCollection m_interfaces

m_fields

private IFieldCollection m_fields

m_methods

private IMethodCollection m_methods

m_attributes

private IAttributeCollection m_attributes

m_declaredSUID

private long m_declaredSUID

DEBUG_SUID

private static final boolean DEBUG_SUID
See Also:
Constant Field Values
Constructor Detail

ClassDef

public ClassDef()
Method Detail

accept

public void accept(IClassDefVisitor visitor,
                   java.lang.Object ctx)

getMagic

public long getMagic()

setMagic

public void setMagic(long magic)

getVersion

public int[] getVersion()

setVersion

public void setVersion(int[] version)

setDeclaredSUID

public final void setDeclaredSUID(long suid)

getThisClassIndex

public int getThisClassIndex()

setThisClassIndex

public void setThisClassIndex(int this_class_index)

getThisClass

public CONSTANT_Class_info getThisClass()

getSuperClass

public CONSTANT_Class_info getSuperClass()

getName

public java.lang.String getName()

getSuperClassIndex

public int getSuperClassIndex()

setSuperClassIndex

public void setSuperClassIndex(int super_class_index)

getAccessFlags

public final int getAccessFlags()
Specified by:
getAccessFlags in interface IAccessFlags

setAccessFlags

public final void setAccessFlags(int flags)
Specified by:
setAccessFlags in interface IAccessFlags

isInterface

public boolean isInterface()

isSynthetic

public boolean isSynthetic()

isNested

public boolean isNested(int[] nestedAccessFlags)

getConstants

public IConstantCollection getConstants()

getInterfaces

public IInterfaceCollection getInterfaces()

getFields

public IFieldCollection getFields()

getMethods

public IMethodCollection getMethods()

getAttributes

public IAttributeCollection getAttributes()

getFields

public int[] getFields(java.lang.String name)

getMethods

public int[] getMethods(java.lang.String name)

clone

public java.lang.Object clone()
Performs a deep copy.


writeInClassFormat

public void writeInClassFormat(UDataOutputStream out)
                        throws java.io.IOException
Specified by:
writeInClassFormat in interface IClassFormatOutput
Throws:
java.io.IOException

getDeclaredSUID

public final long getDeclaredSUID()

computeSUID

public final long computeSUID(boolean skipCLINIT)
This follows the spec at http://java.sun.com/j2se/1.4.1/docs/guide/serialization/spec/class.doc6.html#4100 as well as undocumented hacks used by Sun's 1.4.2 J2SDK


addCONSTANT_Utf8

public int addCONSTANT_Utf8(java.lang.String value,
                            boolean keepUnique)

addStringConstant

public int addStringConstant(java.lang.String value)

addNameType

public int addNameType(java.lang.String name,
                       java.lang.String typeDescriptor)

addClassref

public int addClassref(java.lang.String classJVMName)

addField

public int addField(java.lang.String name,
                    java.lang.String descriptor,
                    int access_flags)
Adds a new declared field to this class [with no attributes]


addField

public int addField(java.lang.String name,
                    java.lang.String descriptor,
                    int access_flags,
                    IAttributeCollection attributes)
Adds a new declared field to this class [with given attributes]


newEmptyMethod

public Method_info newEmptyMethod(java.lang.String name,
                                  java.lang.String descriptor,
                                  int access_flags)

addMethod

public int addMethod(Method_info method)

addFieldref

public int addFieldref(Field_info field)
Adds a reference to a field declared by this class.

Returns:
constant pool index of the reference

addFieldref

public int addFieldref(int offset)
Adds a reference to a field declared by this class.

Returns:
constant pool index of the reference