org.apache.bcel.classfile

Class Constant

Implemented Interfaces:
Cloneable, Node, Serializable
Known Direct Subclasses:
ConstantClass, ConstantCP, ConstantDouble, ConstantFloat, ConstantInteger, ConstantLong, ConstantNameAndType, ConstantString, ConstantUtf8

public abstract class Constant
extends java.lang.Object
implements Cloneable, Node, Serializable

Abstract superclass for classes to represent the different constant types in the constant pool of a class file. The classes keep closely to the JVM specification.
Version:
$Id: Constant.java 386056 2006-03-15 11:31:56Z tcurdt $
Author:
M. Dahm

Field Summary

private static BCELComparator
_cmp
protected byte
tag

Constructor Summary

Constant(byte tag)

Method Summary

abstract void
accept(Visitor v)
Called by objects that are traversing the nodes of the tree implicitely defined by the contents of a Java class.
Object
clone()
Constant
copy()
abstract void
dump(DataOutputStream file)
boolean
equals(Object obj)
Return value as defined by given BCELComparator strategy.
static BCELComparator
getComparator()
byte
getTag()
int
hashCode()
Return value as defined by given BCELComparator strategy.
(package private) static Constant
readConstant(DataInputStream file)
Read one constant from the given file, the type depends on a tag byte.
static void
setComparator(BCELComparator comparator)
String
toString()

Field Details

_cmp

private static BCELComparator _cmp

tag

protected byte tag

Constructor Details

Constant

(package private)  Constant(byte tag)

Method Details

accept

public abstract 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
Parameters:
v - Visitor object

clone

public Object clone()
            throws CloneNotSupportedException

copy

public Constant copy()
Returns:
deep copy of this constant

dump

public abstract void dump(DataOutputStream file)
            throws IOException

equals

public boolean equals(Object obj)
Return value as defined by given BCELComparator strategy. By default two Constant objects are said to be equal when the result of toString() is equal.
See Also:
java.lang.Object.equals(java.lang.Object)

getComparator

public static BCELComparator getComparator()
Returns:
Comparison strategy object

getTag

public final byte getTag()
Returns:
Tag of constant, i.e., its type. No setTag() method to avoid confusion.

hashCode

public int hashCode()
Return value as defined by given BCELComparator strategy. By default return the hashcode of the result of toString().
See Also:
java.lang.Object.hashCode()

readConstant

(package private) static final Constant readConstant(DataInputStream file)
            throws IOException,
                   ClassFormatException
Read one constant from the given file, the type depends on a tag byte.
Parameters:
file - Input stream
Returns:
Constant object

setComparator

public static void setComparator(BCELComparator comparator)
Parameters:
comparator - Comparison strategy object

toString

public String toString()
Returns:
String representation.