All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class espresso.classfile.javaclass.ClassParser

java.lang.Object
   |
   +----espresso.classfile.javaclass.ClassParser

public final class ClassParser
extends Object
implements Constants
Wrapper class that parses a given Java .class file. The method parse returns a JavaClass object on success. When an I/O error or an inconsistency occurs an appropiate exception is propagated back to the caller. The structure and the names comply, except for a few conveniences, exactly with the JVM specification 1.0. See this paper for further details about the structure of a bytecode file.


Variable Index

 o access_flags
 o attributes
 o class_name_index
 o constant_pool
 o fields
 o file
 o file_name
 o interfaces
 o major
 o methods
 o minor
 o superclass_name_index

Constructor Index

 o ClassParser(InputStream, String)
Parse class from the given stream.
 o ClassParser(String)
Parse class from given .class file.
 o ClassParser(String, String)
Parse class from given .class file in a ZIP-archive

Method Index

 o parse()
Parse the given Java class file and return an object that represents the contained data, i.e.
 o readAttributes()
Read information about the attributes of the attributes of the class.
 o readClassInfo()
Read information about the class and its super class.
 o readConstantPool()
Read constant pool entries.
 o readFields()
Read information about the fields of the class, i.e.
 o readID()
Check whether the header of the file is ok.
 o readInterfaces()
Read information about the interfaces implemented by this class.
 o readMethods()
Read information about the methods of the class.
 o readVersion()
Read major and minor version of compiler which created the file.

Variables

 o file
 private DataInputStream file
 o file_name
 private String file_name
 o class_name_index
 private int class_name_index
 o superclass_name_index
 private int superclass_name_index
 o major
 private int major
 o minor
 private int minor
 o access_flags
 private int access_flags
 o interfaces
 private int interfaces[]
 o constant_pool
 private ConstantPool constant_pool
 o fields
 private Field fields[]
 o methods
 private Method methods[]
 o attributes
 private Attribute attributes[]

Constructors

 o ClassParser
 public ClassParser(InputStream file,
                    String file_name)
Parse class from the given stream.

Parameters:
file - Input stream
file_name - File name
 o ClassParser
 public ClassParser(String file_name) throws IOException
Parse class from given .class file.

Parameters:
file_name - file name
 o ClassParser
 public ClassParser(String zip_file,
                    String file_name) throws IOException
Parse class from given .class file in a ZIP-archive

Parameters:
file_name - file name

Methods

 o parse
 public JavaClass parse() throws IOException, ClassFormatError
Parse the given Java class file and return an object that represents the contained data, i.e. constants, methods, fields and commands. A ClassFormatError is raised, if the file is not a valid .class file. (This does not include verification of the byte code as it is performed by the java interpreter).

Returns:
Class object representing the parsed class file
 o readAttributes
 private final void readAttributes() throws IOException, ClassFormatError
Read information about the attributes of the attributes of the class.

 o readClassInfo
 private final void readClassInfo() throws IOException, ClassFormatError
Read information about the class and its super class.

 o readConstantPool
 private final void readConstantPool() throws IOException, ClassFormatError
Read constant pool entries.

 o readFields
 private final void readFields() throws IOException, ClassFormatError
Read information about the fields of the class, i.e. its variables.

 o readID
 private final void readID() throws IOException, ClassFormatError
Check whether the header of the file is ok. Of course, this has to be the first action on successive file reads.

 o readInterfaces
 private final void readInterfaces() throws IOException, ClassFormatError
Read information about the interfaces implemented by this class.

 o readMethods
 private final void readMethods() throws IOException, ClassFormatError
Read information about the methods of the class.

 o readVersion
 private final void readVersion() throws IOException, ClassFormatError
Read major and minor version of compiler which created the file.


All Packages  Class Hierarchy  This Package  Previous  Next  Index