harpoon.IR.RawClass
Class ClassFile

java.lang.Object
  extended by harpoon.IR.RawClass.ClassFile

public class ClassFile
extends Object

Represents a java bytecode class file.

Drawn from The Java Virtual Machine Specification.

Version:
$Id: ClassFile.java,v 1.3 2002/02/26 08:02:29 cananian Exp $
Author:
C. Scott Ananian <cananian@alumni.princeton.edu>
See Also:
HClass

Field Summary
 AccessFlags access_flags
          The value of the access_flags item is a mask of modifiers used with class and interface declarations.
 Attribute[] attributes
          Each value of the attributes table must be a variable-length attribute structure.
 Constant[] constant_pool
          The constant_pool is a table of variable-length structures representing various string constants, class names, field names, and other constants that are referred to within the ClassFile structure and its substructures.
 FieldInfo[] fields
          Each value in the fields table must be a variable-length field_info structure giving a complete description of a field in the class or interface type.
 int[] interfaces
          Each value in the interfaces array must be a valid index into the constant_pool table.
 int major_version
          The major version number of the compiler that produced this class file.
 MethodInfo[] methods
          Each value in the methods table must be a variable-length method_info structure giving a complete description of and Java Virtual Machine code for a method in the class or interface.
 int minor_version
          The minor version number of the compiler that produced this class file.
 int super_class
          For a class, the value of the super_class item either must be zero or must be a valid index into the constant_pool table.
 int this_class
          The value of the this_class item must be a valid index into the constant_pool table.
 
Constructor Summary
ClassFile(ClassDataInputStream in)
          Create a ClassFile object by reading data from a bytecode file.
ClassFile(InputStream in)
          Create a ClassFile object by reading data from a bytecode file.
 
Method Summary
 int attributes_count()
           
 int constant_pool_count()
           
 int fields_count()
           
static void indent(PrintWriter pw, int indent, String s)
          Output string s to PrintWriter pw at the given indentation level indent.
 int interfaces_count()
           
 ConstantClass interfaces(int i)
          Return the CONSTANT_Class_info entry in the constant_pool corresponding to the value in interfaces[i].
 int methods_count()
           
 void print(PrintWriter pw)
          Pretty print this classfile structure.
 void print(PrintWriter pw, int indent)
           
 void read(ClassDataInputStream in)
           
 ConstantClass super_class()
          Return the CONSTANT_Class_info entry in the constant_pool corresponding to the value of super_class, or null if super_class == 0.
 ConstantClass this_class()
          Return the CONSTANT_Class_info entry in the constant_pool corresponding to the value of this_class.
 void write(ClassDataOutputStream out)
          Write a class file object out to a java bytecode file.
 void write(OutputStream out)
          Write a class file object out to a java bytecode file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

minor_version

public int minor_version
The minor version number of the compiler that produced this class file.


major_version

public int major_version
The major version number of the compiler that produced this class file.


constant_pool

public Constant[] constant_pool
The constant_pool is a table of variable-length structures representing various string constants, class names, field names, and other constants that are referred to within the ClassFile structure and its substructures. The first entry of the constant_pool table, constant_pool[0], is reserved for internal use by a Java Virtual Machine Implementation. That entry is not present in the class file.


access_flags

public AccessFlags access_flags
The value of the access_flags item is a mask of modifiers used with class and interface declarations.


this_class

public int this_class
The value of the this_class item must be a valid index into the constant_pool table. The constant_pool entry at that index must be a CONSTANT_Class_info structure representing the class or interface defined by this class file.


super_class

public int super_class
For a class, the value of the super_class item either must be zero or must be a valid index into the constant_pool table. If the value of the super_class item is nonzero, the constant_pool entry at that index must be a CONSTANT_Class_info structure representing the superclass of the class defined by this class file. Neither the superclass nor any of its superclasses may be a final class.

If the value of super_class is zero, then this class file must represent that class java.lang.Object, the only class or interface without a superclass.

For an interface, the value of super_class must always be a valid index into the constant_pool table. The constant_pool entry at that index must be a CONSTANT_Class_info structure representing the class java.lang.Object.


interfaces

public int[] interfaces
Each value in the interfaces array must be a valid index into the constant_pool table. The constant_pool entry at each value of interfaces[i] must be a CONSTANT_Class_info structure representing an interface which is a direct superinterface of this class or interface type, in the left-to-right order given in the source for the type.


fields

public FieldInfo[] fields
Each value in the fields table must be a variable-length field_info structure giving a complete description of a field in the class or interface type. The fields table includes only those fields that are declared by this class or interface. It does not include items representing fields that are inherited from superclasses or superinterfaces.


methods

public MethodInfo[] methods
Each value in the methods table must be a variable-length method_info structure giving a complete description of and Java Virtual Machine code for a method in the class or interface.

The method_info structures represent all methods, both instance methods and, for classes, class (static) methods, declared by this class or interface type. The methods table only includes those items that are explicitly declared by this class. Interfaces have only the single method <clinit>, the interface initialization method. The methods table does not include items representing methods that are inherited from superclasses or superinterfaces.


attributes

public Attribute[] attributes
Each value of the attributes table must be a variable-length attribute structure. A ClassFile structure can have any number of attributes associated with it.

The only attribute defined by this specification for the attributes table of a ClassFile structure is the SourceFile attribute.

Constructor Detail

ClassFile

public ClassFile(ClassDataInputStream in)
Create a ClassFile object by reading data from a bytecode file.


ClassFile

public ClassFile(InputStream in)
Create a ClassFile object by reading data from a bytecode file.

Method Detail

read

public void read(ClassDataInputStream in)
          throws IOException
Throws:
IOException

write

public void write(ClassDataOutputStream out)
           throws IOException
Write a class file object out to a java bytecode file.

Throws:
IOException

write

public void write(OutputStream out)
           throws IOException
Write a class file object out to a java bytecode file.

Throws:
IOException

this_class

public ConstantClass this_class()
Return the CONSTANT_Class_info entry in the constant_pool corresponding to the value of this_class.


super_class

public ConstantClass super_class()
Return the CONSTANT_Class_info entry in the constant_pool corresponding to the value of super_class, or null if super_class == 0.


interfaces

public ConstantClass interfaces(int i)
Return the CONSTANT_Class_info entry in the constant_pool corresponding to the value in interfaces[i].


constant_pool_count

public int constant_pool_count()

interfaces_count

public int interfaces_count()

fields_count

public int fields_count()

methods_count

public int methods_count()

attributes_count

public int attributes_count()

print

public void print(PrintWriter pw)
Pretty print this classfile structure.


print

public void print(PrintWriter pw,
                  int indent)

indent

public static void indent(PrintWriter pw,
                          int indent,
                          String s)
Output string s to PrintWriter pw at the given indentation level indent.

Parameters:
pw - the output destination.
indent - the indentation level to use.
s - the string to write.