alt.jiapi.file
Class ClassFile

java.lang.Object
  extended by alt.jiapi.file.ProgramElement
      extended by alt.jiapi.file.ClassFile

public class ClassFile
extends ProgramElement

ClassFile is a low level representation of Java class file. Class file format is specified by JSR-202.

Author:
Mika Riekkinen

Field Summary
static int ACC_ABSTRACT
          Class is abstract
static int ACC_ANNOTATION
          Class is an Annotation
static int ACC_ENUM
          Class is an Enum
static int ACC_FINAL
          Final.
static int ACC_INTERFACE
          Class is an interface
static int ACC_PUBLIC
          Public access.
static int ACC_SUPER
          Super bit.
static int ACC_SYNTHETIC
          Class is synthetic
 
Fields inherited from class alt.jiapi.file.ProgramElement
access_flags, attributes, constantPool
 
Constructor Summary
ClassFile(java.lang.String className)
          Constructor to build ClassFile from scratch.
 
Method Summary
 void addInterface(java.lang.String name)
          Adds a new interface, that class represented by this ClassFile implements.
 java.lang.String getClassName()
          Gets the name of the class represented by this ClassFile.
 ConstantPool getConstantPool()
          Gets the constant pool of this ClassFile.
 java.util.List getFields()
          Gets all the Fields of this class file
 java.util.List getInterfaces()
          Gets all the Interfaces of this class file
 int getMagicNumber()
          Gets the magic number
 short getMajorVersion()
          Gets the major version of the class file
 java.util.List getMethods()
          Gets all the Methods of this class file
 short getMinorVersion()
          Gets the minor version of the class file
 short getSuperClassIndex()
          Gets the index in constant-pool, that holds a class-info for super class of this class.
 java.lang.String getSuperclassName()
          Gets the name of the superclass of the class represented by this ClassFile.
 short getThisClassIndex()
          Gets the index in constant-pool, that holds a class-info of this class.
static void main(java.lang.String[] args)
          Used for testing purposes.
static ClassFile parse(java.io.InputStream is)
          Parse InputStream and create an instance of ClassFile from stream.
static ClassFile parse(java.lang.String fileName)
          Parse given file and create an instance of ClassFile from it.
 void setAccessFlags(short access_flags)
           
 byte[] toBytes()
          Converts this ClassFile into bytes.
 
Methods inherited from class alt.jiapi.file.ProgramElement
getAccessFlags, getAttribute, getAttributes, readAttributes, writeAttributes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACC_ABSTRACT

public static final int ACC_ABSTRACT
Class is abstract

See Also:
Constant Field Values

ACC_ANNOTATION

public static final int ACC_ANNOTATION
Class is an Annotation

See Also:
Constant Field Values

ACC_ENUM

public static final int ACC_ENUM
Class is an Enum

See Also:
Constant Field Values

ACC_FINAL

public static final int ACC_FINAL
Final.

See Also:
Constant Field Values

ACC_INTERFACE

public static final int ACC_INTERFACE
Class is an interface

See Also:
Constant Field Values

ACC_PUBLIC

public static final int ACC_PUBLIC
Public access.

See Also:
Constant Field Values

ACC_SUPER

public static final int ACC_SUPER
Super bit.

See Also:
Constant Field Values

ACC_SYNTHETIC

public static final int ACC_SYNTHETIC
Class is synthetic

See Also:
Constant Field Values
Constructor Detail

ClassFile

public ClassFile(java.lang.String className)
Constructor to build ClassFile from scratch.

Parameters:
className - fully qualified name of the class.
Method Detail

addInterface

public void addInterface(java.lang.String name)
Adds a new interface, that class represented by this ClassFile implements.

Parameters:
fully - qualified name of the interface to implement

getClassName

public java.lang.String getClassName()
Gets the name of the class represented by this ClassFile.

Returns:
Name of the class

getConstantPool

public ConstantPool getConstantPool()
Gets the constant pool of this ClassFile.

Overrides:
getConstantPool in class ProgramElement
Returns:
ConstantPool

getFields

public java.util.List getFields()
Gets all the Fields of this class file

Returns:
a List of Fields

getInterfaces

public java.util.List getInterfaces()
Gets all the Interfaces of this class file

Returns:
a List of Interfaces

getMagicNumber

public int getMagicNumber()
Gets the magic number

Returns:
magic number

getMajorVersion

public short getMajorVersion()
Gets the major version of the class file

Returns:
Major version

getMethods

public java.util.List getMethods()
Gets all the Methods of this class file

Returns:
a List of Methods

getMinorVersion

public short getMinorVersion()
Gets the minor version of the class file

Returns:
Minor version

getSuperClassIndex

public short getSuperClassIndex()
Gets the index in constant-pool, that holds a class-info for super class of this class. This method returns 0, if this ClassFile represents java.lang.Object. Note, that indexing in constant-pool starts from 1.

Returns:
index into constant pool

getSuperclassName

public java.lang.String getSuperclassName()
Gets the name of the superclass of the class represented by this ClassFile.

Returns:
Name of the superclass, or null if this ClassFile represents java.lang.Object

getThisClassIndex

public short getThisClassIndex()
Gets the index in constant-pool, that holds a class-info of this class.

Returns:
index into constant pool

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Used for testing purposes.

Parameters:
args - args[0] is a path to java class file
Throws:
java.lang.Exception

parse

public static ClassFile parse(java.io.InputStream is)
                       throws ParseException,
                              java.io.IOException
Parse InputStream and create an instance of ClassFile from stream.

Parameters:
is - InputStream
Returns:
an instance of ClassFile, that conforms to java virtual machine specification classfile format.
Throws:
ParseException - is thrown, if classfile parser cannot understand parsed stream.
java.io.IOException - is thrown, if there was problems in reading the stream.

parse

public static ClassFile parse(java.lang.String fileName)
                       throws ParseException,
                              java.io.IOException
Parse given file and create an instance of ClassFile from it.

Parameters:
fileName - name of the file, that is read.
Returns:
an instance of ClassFile, that conforms to java virtual machine specification classfile format.
Throws:
ParseException - is thrown, if classfile parser cannot understand parsed stream.
java.io.IOException - is thrown, if there was problems in reading the stream.

setAccessFlags

public void setAccessFlags(short access_flags)

toBytes

public byte[] toBytes()
Converts this ClassFile into bytes. No checking against the class file format specification is made.

Returns:
bytes representing a Java class.


Copyright © 2001. Documenation generated August 26 2011.