Package org.apache.bcel.classfile
Class Constant
- java.lang.Object
-
- org.apache.bcel.classfile.Constant
-
- All Implemented Interfaces:
java.lang.Cloneable,Node
- Direct Known Subclasses:
ConstantClass,ConstantCP,ConstantDouble,ConstantFloat,ConstantInteger,ConstantLong,ConstantMethodHandle,ConstantMethodType,ConstantModule,ConstantNameAndType,ConstantPackage,ConstantString,ConstantUtf8
public abstract class Constant extends java.lang.Object implements java.lang.Cloneable, Node
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.
-
-
Field Summary
Fields Modifier and Type Field Description private static BCELComparator<Constant>bcelComparator(package private) static Constant[]EMPTY_ARRAYprotected bytetagDeprecated.(since 6.0) will be made private; do not access directly, use getter/setter.
-
Constructor Summary
Constructors Constructor Description Constant(byte tag)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidaccept(Visitor v)Called by objects that are traversing the nodes of the tree implicitly defined by the contents of a Java class.java.lang.Objectclone()Constantcopy()Creates a deep copy of this constant.abstract voiddump(java.io.DataOutputStream file)Dumps constant to file stream in binary format.booleanequals(java.lang.Object obj)Returns value as defined by given BCELComparator strategy.static BCELComparator<Constant>getComparator()Gets the comparison strategy object.bytegetTag()Gets the tag of constant.inthashCode()Returns value as defined by given BCELComparator strategy.static ConstantreadConstant(java.io.DataInput dataInput)Reads one constant from the given input, the type depends on a tag byte.static voidsetComparator(BCELComparator<Constant> comparator)Sets the comparison strategy object.java.lang.StringtoString()
-
-
-
Field Detail
-
EMPTY_ARRAY
static final Constant[] EMPTY_ARRAY
-
bcelComparator
private static BCELComparator<Constant> bcelComparator
-
tag
@Deprecated protected byte tag
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter.
-
-
Method Detail
-
getComparator
public static BCELComparator<Constant> getComparator()
Gets the comparison strategy object.- Returns:
- Comparison strategy object.
-
readConstant
public static Constant readConstant(java.io.DataInput dataInput) throws java.io.IOException, ClassFormatException
Reads one constant from the given input, the type depends on a tag byte.- Parameters:
dataInput- Input stream.- Returns:
- Constant object.
- Throws:
java.io.IOException- if an I/O error occurs reading from the givendataInput.ClassFormatException- if the next byte is not recognized- Since:
- 6.0 made public
-
setComparator
public static void setComparator(BCELComparator<Constant> comparator)
Sets the comparison strategy object.- Parameters:
comparator- Comparison strategy object.
-
accept
public abstract void accept(Visitor v)
Called by objects that are traversing the nodes of the tree implicitly defined by the contents of a Java class. I.e., the hierarchy of methods, fields, attributes, etc. spawns a tree of objects.
-
clone
public java.lang.Object clone()
- Overrides:
clonein classjava.lang.Object
-
copy
public Constant copy()
Creates a deep copy of this constant.- Returns:
- deep copy of this constant.
-
dump
public abstract void dump(java.io.DataOutputStream file) throws java.io.IOExceptionDumps constant to file stream in binary format.- Parameters:
file- the output stream.- Throws:
java.io.IOException- if an I/O error occurs.
-
equals
public boolean equals(java.lang.Object obj)
Returns value as defined by given BCELComparator strategy. By default two Constant objects are said to be equal when the result of toString() is equal.- Overrides:
equalsin classjava.lang.Object- See Also:
Object.equals(Object)
-
getTag
public final byte getTag()
Gets the tag of constant.- Returns:
- Tag of constant, that is, its type. No setTag() method to avoid confusion.
-
hashCode
public int hashCode()
Returns value as defined by given BCELComparator strategy. By default return the hash code of the result of toString().- Overrides:
hashCodein classjava.lang.Object- See Also:
Object.hashCode()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object- Returns:
- String representation.
-
-