de.fub.bytecode.classfile
Class JavaClass

java.lang.Object
  |
  +--de.fub.bytecode.classfile.AccessFlags
        |
        +--de.fub.bytecode.classfile.JavaClass
All Implemented Interfaces:
java.lang.Cloneable, Node

public class JavaClass
extends AccessFlags
implements java.lang.Cloneable, Node

Represents a Java class, i.e., the data structures, constant pool, fields, methods and commands contained in a Java .class file. See JVM specification for details.

Version:
$Id: JavaClass.java,v 1.6 2001/08/21 14:05:09 ehaase Exp $
Author:
M. Dahm

Field Summary
static byte FILE
           
static byte HEAP
           
static byte ZIP
           
 
Fields inherited from class de.fub.bytecode.classfile.AccessFlags
access_flags
 
Constructor Summary
JavaClass(int class_name_index, int superclass_name_index, java.lang.String file_name, int major, int minor, int access_flags, ConstantPool constant_pool, int[] interfaces, Field[] fields, Method[] methods, Attribute[] attributes)
          Constructor gets all contents as arguments.
JavaClass(int class_name_index, int superclass_name_index, java.lang.String file_name, int major, int minor, int access_flags, ConstantPool constant_pool, int[] interfaces, Field[] fields, Method[] methods, Attribute[] attributes, byte source)
          Constructor gets all contents as arguments.
 
Method Summary
 void accept(Visitor v)
          Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class.
 JavaClass copy()
           
 void dump(java.io.DataOutputStream file)
          Dump Java class to output stream in binary format.
 void dump(java.io.File file)
          Dump class to a file.
 void dump(java.io.OutputStream file)
          Dump Java class to output stream in binary format.
 void dump(java.lang.String file_name)
          Dump class to a file named file_name.
 Attribute[] getAttributes()
           
 byte[] getBytes()
           
 java.lang.String getClassName()
           
 int getClassNameIndex()
           
 ConstantPool getConstantPool()
           
 Field[] getFields()
           
 java.lang.String getFileName()
           
 java.lang.String[] getInterfaceNames()
           
 int[] getInterfaces()
           
 int getMajor()
           
 Method[] getMethods()
           
 int getMinor()
           
 java.lang.String getPackageName()
           
 byte getSource()
           
 java.lang.String getSourceFileName()
           
 java.lang.String getSuperclassName()
           
 int getSuperclassNameIndex()
           
 boolean instanceOf(JavaClass super_class)
           
 boolean isClass()
           
 boolean isSuper()
           
 void setAttributes(Attribute[] attributes)
           
 void setClassName(java.lang.String class_name)
           
 void setClassNameIndex(int class_name_index)
           
 void setConstantPool(ConstantPool constant_pool)
           
 void setFields(Field[] fields)
           
 void setFileName(java.lang.String file_name)
          Set File name of class, aka SourceFile attribute value
 void setInterfaceNames(java.lang.String[] interface_names)
           
 void setInterfaces(int[] interfaces)
           
 void setMajor(int major)
           
 void setMethods(Method[] methods)
           
 void setMinor(int minor)
           
 void setSourceFileName(java.lang.String source_file_name)
          Set absolute path to file this class was read from.
 void setSuperclassName(java.lang.String superclass_name)
           
 void setSuperclassNameIndex(int superclass_name_index)
           
 java.lang.String toString()
           
 
Methods inherited from class de.fub.bytecode.classfile.AccessFlags
getAccessFlags, isAbstract, isAbstract, isFinal, isFinal, isInterface, isInterface, isNative, isNative, isPrivate, isPrivate, isProtected, isProtected, isPublic, isPublic, isStatic, isStatic, isStrictfp, isStrictfp, isSynchronized, isSynchronized, isTransient, isTransient, isVolatile, isVolatile, setAccessFlags
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HEAP

public static final byte HEAP

FILE

public static final byte FILE

ZIP

public static final byte ZIP
Constructor Detail

JavaClass

public JavaClass(int class_name_index,
                 int superclass_name_index,
                 java.lang.String file_name,
                 int major,
                 int minor,
                 int access_flags,
                 ConstantPool constant_pool,
                 int[] interfaces,
                 Field[] fields,
                 Method[] methods,
                 Attribute[] attributes,
                 byte source)
Constructor gets all contents as arguments.
Parameters:
class_name - Class name
superclass_name - Superclass name
file_name - File name
major - Major compiler version
minor - Minor compiler version
access_flags - Access rights defined by bit flags
constant_pool - Array of constants
interfaces - Implemented interfaces
fields - Class fields
methods - Class methods
attributes - Class attributes
source - Read from file or generated in memory?

JavaClass

public JavaClass(int class_name_index,
                 int superclass_name_index,
                 java.lang.String file_name,
                 int major,
                 int minor,
                 int access_flags,
                 ConstantPool constant_pool,
                 int[] interfaces,
                 Field[] fields,
                 Method[] methods,
                 Attribute[] attributes)
Constructor gets all contents as arguments.
Parameters:
class_name - Class name
superclass_name - Superclass name
file_name - File name
major - Major compiler version
minor - Minor compiler version
access_flags - Access rights defined by bit flags
constant_pool - Array of constants
interfaces - Implemented interfaces
fields - Class fields
methods - Class methods
attributes - Class attributes
Method Detail

accept

public void accept(Visitor v)
Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class. I.e., the hierarchy of methods, fields, attributes, etc. spawns a tree of objects.
Specified by:
accept in interface Node
Parameters:
v - Visitor object

dump

public void dump(java.io.File file)
          throws java.io.IOException
Dump class to a file.
Parameters:
file - Output file

dump

public void dump(java.lang.String file_name)
          throws java.io.IOException
Dump class to a file named file_name.
Parameters:
file_name - Output file name
Throws:
java.io.IOException -  

getBytes

public byte[] getBytes()
Returns:
class in binary format

dump

public void dump(java.io.OutputStream file)
          throws java.io.IOException
Dump Java class to output stream in binary format.
Parameters:
file - Output stream
Throws:
java.io.IOException -  

dump

public void dump(java.io.DataOutputStream file)
          throws java.io.IOException
Dump Java class to output stream in binary format.
Parameters:
file - Output stream
Throws:
java.io.IOException -  

getAttributes

public Attribute[] getAttributes()
Returns:
Attributes of the class.

getClassName

public java.lang.String getClassName()
Returns:
Class name.

getPackageName

public java.lang.String getPackageName()
Returns:
Package name.

getClassNameIndex

public int getClassNameIndex()
Returns:
Class name index.

getConstantPool

public ConstantPool getConstantPool()
Returns:
Constant pool.

getFields

public Field[] getFields()
Returns:
Fields, i.e., variables of the class.

getFileName

public java.lang.String getFileName()
Returns:
File name of class, aka SourceFile attribute value

getInterfaceNames

public java.lang.String[] getInterfaceNames()
Returns:
Names of implemented interfaces.

getInterfaces

public int[] getInterfaces()
Returns:
Implemented interfaces.

getMajor

public int getMajor()
Returns:
Major number of compiler version.

getMethods

public Method[] getMethods()
Returns:
Methods of the class.

getMinor

public int getMinor()
Returns:
Minor number of compiler version.

getSourceFileName

public java.lang.String getSourceFileName()
Returns:
sbsolute path to file where this class was read from

getSuperclassName

public java.lang.String getSuperclassName()
Returns:
Superclass name.

getSuperclassNameIndex

public int getSuperclassNameIndex()
Returns:
Class name index.

setAttributes

public void setAttributes(Attribute[] attributes)
Parameters:
attributes. -  

setClassName

public void setClassName(java.lang.String class_name)
Parameters:
class_name. -  

setClassNameIndex

public void setClassNameIndex(int class_name_index)
Parameters:
class_name_index. -  

setConstantPool

public void setConstantPool(ConstantPool constant_pool)
Parameters:
constant_pool. -  

setFields

public void setFields(Field[] fields)
Parameters:
fields. -  

setFileName

public void setFileName(java.lang.String file_name)
Set File name of class, aka SourceFile attribute value

setInterfaceNames

public void setInterfaceNames(java.lang.String[] interface_names)
Parameters:
interface_names. -  

setInterfaces

public void setInterfaces(int[] interfaces)
Parameters:
interfaces. -  

setMajor

public void setMajor(int major)
Parameters:
major. -  

setMethods

public void setMethods(Method[] methods)
Parameters:
methods. -  

setMinor

public void setMinor(int minor)
Parameters:
minor. -  

setSourceFileName

public void setSourceFileName(java.lang.String source_file_name)
Set absolute path to file this class was read from.

setSuperclassName

public void setSuperclassName(java.lang.String superclass_name)
Parameters:
superclass_name. -  

setSuperclassNameIndex

public void setSuperclassNameIndex(int superclass_name_index)
Parameters:
superclass_name_index. -  

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
String representing class contents.

copy

public JavaClass copy()
Returns:
deep copy of this class

instanceOf

public final boolean instanceOf(JavaClass super_class)

isSuper

public final boolean isSuper()

isClass

public final boolean isClass()

getSource

public final byte getSource()
Returns:
returns either HEAP (generated), FILE, or ZIP