polyglot.types.reflect
Class ClassFile

java.lang.Object
  extended by polyglot.types.reflect.ClassFile
All Implemented Interfaces:
LazyClassInitializer

public class ClassFile
extends java.lang.Object
implements LazyClassInitializer

ClassFile basically represents a Java classfile as it is found on disk. The classfile is modeled according to the Java Virtual Machine Specification. Methods are provided to edit the classfile at a very low level.

Author:
Nate Nystrom (nystrom@cs.purdue.edu)
See Also:
Attribute, Constant, Field, Method

Field Summary
protected  Attribute[] attrs
           
protected  Constant[] constants
           
protected  Field[] fields
           
protected  InnerClasses innerClasses
           
protected  Method[] methods
           
 
Constructor Summary
ClassFile(java.io.File classFileSource, byte[] code, ExtensionInfo ext)
          Constructor.
 
Method Summary
 java.lang.String compilerVersion(java.lang.String ts)
          Get the encoded compiler version used to compile the source.
 Constant[] constants()
           
 Attribute createAttribute(java.io.DataInputStream in, java.lang.String name, int nameIndex, int length)
           
 Field createField(java.io.DataInputStream in)
           
 Method createMethod(java.io.DataInputStream in)
           
 java.lang.String encodedClassType(java.lang.String ts)
          Get the encoded class type.
 boolean fromClassFile()
          Return true if the class is from a class file.
 void initConstructors(ParsedClassType ct)
          Initialize ct's constructors.
 void initFields(ParsedClassType ct)
          Initialize ct's fields.
 void initInterfaces(ParsedClassType ct)
          Initialize ct's interfaces.
 void initMemberClasses(ParsedClassType ct)
          Initialize ct's member classes.
 void initMethods(ParsedClassType ct)
          Initialize ct's methods.
 java.lang.String name()
          Get the name of the class, including the package name.
 Position position()
          Create a position for the class file.
 long rawSourceLastModified()
           
 void readAttributes(java.io.DataInputStream in)
          Read the class's attributes.
 long sourceLastModified(java.lang.String ts)
          Get the encoded source modified time.
 ParsedClassType type(TypeSystem ts)
          Extract the class type from the class file.
 ClassType typeForName(TypeSystem ts, java.lang.String name)
          Convert a String into a type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

constants

protected Constant[] constants

fields

protected Field[] fields

methods

protected Method[] methods

attrs

protected Attribute[] attrs

innerClasses

protected InnerClasses innerClasses
Constructor Detail

ClassFile

public ClassFile(java.io.File classFileSource,
                 byte[] code,
                 ExtensionInfo ext)
Constructor. This constructor parses the class file from the byte array

Parameters:
code - A byte array containing the class data
Method Detail

createMethod

public Method createMethod(java.io.DataInputStream in)
                    throws java.io.IOException
Throws:
java.io.IOException

createField

public Field createField(java.io.DataInputStream in)
                  throws java.io.IOException
Throws:
java.io.IOException

createAttribute

public Attribute createAttribute(java.io.DataInputStream in,
                                 java.lang.String name,
                                 int nameIndex,
                                 int length)
                          throws java.io.IOException
Throws:
java.io.IOException

constants

public Constant[] constants()

fromClassFile

public boolean fromClassFile()
Description copied from interface: LazyClassInitializer
Return true if the class is from a class file.

Specified by:
fromClassFile in interface LazyClassInitializer

sourceLastModified

public long sourceLastModified(java.lang.String ts)
Get the encoded source modified time.


rawSourceLastModified

public long rawSourceLastModified()

compilerVersion

public java.lang.String compilerVersion(java.lang.String ts)
Get the encoded compiler version used to compile the source.


encodedClassType

public java.lang.String encodedClassType(java.lang.String ts)
Get the encoded class type.


type

public ParsedClassType type(TypeSystem ts)
                     throws SemanticException
Extract the class type from the class file.

Throws:
SemanticException

initMemberClasses

public void initMemberClasses(ParsedClassType ct)
Initialize ct's member classes.

Specified by:
initMemberClasses in interface LazyClassInitializer

initInterfaces

public void initInterfaces(ParsedClassType ct)
Initialize ct's interfaces.

Specified by:
initInterfaces in interface LazyClassInitializer

initFields

public void initFields(ParsedClassType ct)
Initialize ct's fields.

Specified by:
initFields in interface LazyClassInitializer

initMethods

public void initMethods(ParsedClassType ct)
Initialize ct's methods.

Specified by:
initMethods in interface LazyClassInitializer

initConstructors

public void initConstructors(ParsedClassType ct)
Initialize ct's constructors.

Specified by:
initConstructors in interface LazyClassInitializer

typeForName

public ClassType typeForName(TypeSystem ts,
                             java.lang.String name)
                      throws SemanticException
Convert a String into a type. Throws a SemanticException if this cannot be done.

Throws:
SemanticException

position

public Position position()
Create a position for the class file.


name

public java.lang.String name()
Get the name of the class, including the package name.

Returns:
The name of the class.

readAttributes

public void readAttributes(java.io.DataInputStream in)
                    throws java.io.IOException
Read the class's attributes. Since none of the attributes are required, just read the length of each attribute and skip that many bytes.

Parameters:
in - The stream from which to read.
Throws:
java.io.IOException - If an error occurs while reading.