Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.bcel.classfile
Class Code

    java.lang.Object
      |
      +--org.apache.bcel.classfile.Attribute
            |
            +--org.apache.bcel.classfile.Code

All Implemented Interfaces:
  java.lang.Cloneable, Node, java.io.Serializable

public final class Code
extends Attribute

This class represents a chunk of Java byte code contained in a method. It is instantiated by the Attribute.readAttribute() method. A Code attribute contains informations about operand stack, local variables, byte code and the exceptions handled within this method. This attribute has attributes itself, namely LineNumberTable which is used for debugging purposes and LocalVariableTable which contains information about the local variables.

Version:
  $Id: Code.java,v 1.2 2002/03/11 16:16:35 mdahm Exp $
Author:
  M. Dahm
See Also:
  `Attribute`, `CodeException`, `LineNumberTable`, `LocalVariableTable`, Serialized Form

Field Summary

Fields inherited from class org.apache.bcel.classfile.Attribute
`constant_pool, length, name_index, tag`

Constructor Summary
`Code(Code c)` Initialize from another object.
`Code(int name_index, int length, int max_stack, int max_locals, byte[] code, CodeException[] exception_table, Attribute[] attributes, ConstantPool constant_pool)`

Method Summary
`void` | `accept(Visitor v)` Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class.
`Attribute` | `copy(ConstantPool constant_pool)`
`void` | `dump(java.io.DataOutputStream file)` Dump code attribute to file stream in binary format.
`Attribute[]` | `getAttributes()`
`byte[]` | `getCode()`
`CodeException[]` | `getExceptionTable()`
`LineNumberTable` | `getLineNumberTable()`
`LocalVariableTable` | `getLocalVariableTable()`
`int` | `getMaxLocals()`
`int` | `getMaxStack()`
`void` | `setAttributes(Attribute[] attributes)`
`void` | `setCode(byte[] code)`
`void` | `setExceptionTable(CodeException[] exception_table)`
`void` | `setMaxLocals(int max_locals)`
`void` | `setMaxStack(int max_stack)`
`java.lang.String` | `toString()`
`java.lang.String` | `toString(boolean verbose)`

Methods inherited from class org.apache.bcel.classfile.Attribute
`addAttributeReader, clone, getConstantPool, getLength, getNameIndex, getTag, readAttribute, removeAttributeReader, setConstantPool, setLength, setNameIndex`

Methods inherited from class java.lang.Object
`equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### Code

    public Code(Code c)

  Initialize from another object. Note that both objects use the same references (shallow copy). Use copy() for a physical copy.

### Code

    public Code(int name_index,
                int length,
                int max_stack,
                int max_locals,
                byte[] code,
                CodeException[] exception_table,
                Attribute[] attributes,
                ConstantPool constant_pool)

Parameters:
  `name_index` - Index pointing to the name Code
  `length` - Content length in bytes
  `max_stack` - Maximum size of stack
  `max_locals` - Number of local variables
  `code` - Actual byte code
  `exception_table` - Table of handled exceptions
  `attributes` - Attributes of code: LineNumber or LocalVariable
  `constant_pool` - Array of constants

Method Detail

### accept

    public void accept(Visitor v)

  Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class. I.e., the hierarchy of methods, fields, attributes, etc. spawns a tree of objects.

  Specified by:
    `accept` in interface `Node`
  Specified by:
    `accept` in class `Attribute`
  Parameters:
    `v` - Visitor object

### dump

    public final void dump(java.io.DataOutputStream file)
                    throws java.io.IOException

  Dump code attribute to file stream in binary format.

  Overrides:
    `dump` in class `Attribute`
  Parameters:
    `file` - Output file stream
  Throws:
    `java.io.IOException`

### getAttributes

    public final Attribute[] getAttributes()

  Returns:
    Collection of code attributes.
  See Also:
    `Attribute`

### getLineNumberTable

    public LineNumberTable getLineNumberTable()

  Returns:
    LineNumberTable of Code, if it has one

### getLocalVariableTable

    public LocalVariableTable getLocalVariableTable()

  Returns:
    LocalVariableTable of Code, if it has one

### getCode

    public final byte[] getCode()

  Returns:
    Actual byte code of the method.

### getExceptionTable

    public final CodeException[] getExceptionTable()

  Returns:
    Table of handled exceptions.
  See Also:
    `CodeException`

### getMaxLocals

    public final int getMaxLocals()

  Returns:
    Number of local variables.

### getMaxStack

    public final int getMaxStack()

  Returns:
    Maximum size of stack used by this method.

### setAttributes

    public final void setAttributes(Attribute[] attributes)

### setCode

    public final void setCode(byte[] code)

  Parameters:
    `code` - byte code

### setExceptionTable

    public final void setExceptionTable(CodeException[] exception_table)

  Parameters:
    `exception_table` - exception table

### setMaxLocals

    public final void setMaxLocals(int max_locals)

  Parameters:
    `max_locals` - maximum number of local variables

### setMaxStack

    public final void setMaxStack(int max_stack)

  Parameters:
    `max_stack` - maximum stack size

### toString

    public final java.lang.String toString(boolean verbose)

  Returns:
    String representation of code chunk.

### toString

    public final java.lang.String toString()

  Overrides:
    `toString` in class `Attribute`
  Returns:
    String representation of code chunk.

### copy

    public Attribute copy(ConstantPool constant_pool)

  Specified by:
    `copy` in class `Attribute`
  Returns:
    deep copy of this attribute

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2002-2003 Apache Software Foundation. All Rights Reserved.