polyglot.types.reflect
Class ClassFile

java.lang.Object
  extended by polyglot.types.reflect.ClassFile

public class ClassFile
extends java.lang.Object

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

Author:
Nate Nystrom
See Also:
Attribute, ConstantValue, Field, Method

Field Summary
protected  Attribute[] attrs
           
protected  java.io.File classFileSource
           
protected  Constant[] constants
           
protected  ExtensionInfo extensionInfo
           
protected  Field[] fields
           
protected  polyglot.types.reflect.InnerClasses innerClasses
           
protected  int[] interfaces
           
protected  java.util.Map jlcInfoCache
           
protected  Method[] methods
           
protected  int modifiers
           
protected  int superClass
           
protected  int thisClass
           
 
Constructor Summary
ClassFile(java.io.File classFileSource, byte[] code, ExtensionInfo ext)
          Constructor.
 
Method Summary
 java.lang.String classNameCP(int index)
          Get the class name at the given constant pool index.
 java.lang.String compilerVersion(java.lang.String ts)
          Get the encoded compiler version used to compile the source.
 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 typeSystemKey)
          Get the encoded class type for the given type system.
 Attribute[] getAttrs()
           
 Constant[] getConstants()
           
 Field[] getFields()
           
 polyglot.types.reflect.InnerClasses getInnerClasses()
           
 int[] getInterfaces()
           
 Method[] getMethods()
           
 int getModifiers()
           
 int getSuperClass()
           
 int getThisClass()
           
 java.lang.String name()
          Get the name of the class, including the package name.
 void readAttributes(java.io.DataInputStream in)
          Read the class's attributes.
 long sourceLastModified(java.lang.String ts)
          Get the encoded source modified time.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

constants

protected Constant[] constants

modifiers

protected int modifiers

thisClass

protected int thisClass

superClass

protected int superClass

interfaces

protected int[] interfaces

fields

protected Field[] fields

methods

protected Method[] methods

attrs

protected Attribute[] attrs

innerClasses

protected polyglot.types.reflect.InnerClasses innerClasses

classFileSource

protected java.io.File classFileSource

extensionInfo

protected ExtensionInfo extensionInfo

jlcInfoCache

protected java.util.Map jlcInfoCache
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

sourceLastModified

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


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 typeSystemKey)
Get the encoded class type for the given type system.


classNameCP

public java.lang.String classNameCP(int index)
Get the class name at the given constant pool index.


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.

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

getAttrs

public Attribute[] getAttrs()

getConstants

public Constant[] getConstants()

getFields

public Field[] getFields()

getInnerClasses

public polyglot.types.reflect.InnerClasses getInnerClasses()

getInterfaces

public int[] getInterfaces()

getMethods

public Method[] getMethods()

getModifiers

public int getModifiers()

getSuperClass

public int getSuperClass()

getThisClass

public int getThisClass()

toString

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