FileDocCategorySizeDatePackage
Constant.javaAPI DocJava SE 5 API5959Fri Aug 26 14:55:16 BST 2005com.sun.org.apache.bcel.internal.classfile

Constant

public abstract class Constant extends Object implements Node, Cloneable
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,v 1.1.1.1 2001/10/29 19:59:58 jvanzyl Exp $
author
M. Dahm

Fields Summary
protected byte
tag
Constructors Summary
Constant(byte tag)

 this.tag = tag; 
Methods Summary
public abstract voidaccept(com.sun.org.apache.bcel.internal.classfile.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.

param
v Visitor object

public java.lang.Objectclone()

    return super.clone();
  
public com.sun.org.apache.bcel.internal.classfile.Constantcopy()

return
deep copy of this constant

    try {
      return (Constant)super.clone();
    } catch(CloneNotSupportedException e) {}

    return null;
  
public abstract voiddump(java.io.DataOutputStream file)

public final bytegetTag()

return
Tag of constant, i.e., its type. No setTag() method to avoid confusion.

 return tag; 
static final com.sun.org.apache.bcel.internal.classfile.ConstantreadConstant(java.io.DataInputStream file)
Read one constant from the given file, the type depends on a tag byte.

param
file Input stream
return
Constant object

    byte b = file.readByte(); // Read tag byte

    switch(b) {
    case Constants.CONSTANT_Class:              return new ConstantClass(file);
    case Constants.CONSTANT_Fieldref:           return new ConstantFieldref(file);
    case Constants.CONSTANT_Methodref:          return new ConstantMethodref(file);
    case Constants.CONSTANT_InterfaceMethodref: return new 
					ConstantInterfaceMethodref(file);
    case Constants.CONSTANT_String:             return new ConstantString(file);
    case Constants.CONSTANT_Integer:            return new ConstantInteger(file);
    case Constants.CONSTANT_Float:              return new ConstantFloat(file);
    case Constants.CONSTANT_Long:               return new ConstantLong(file);
    case Constants.CONSTANT_Double:             return new ConstantDouble(file);
    case Constants.CONSTANT_NameAndType:        return new ConstantNameAndType(file);
    case Constants.CONSTANT_Utf8:               return new ConstantUtf8(file);
    default:                          
      throw new ClassFormatError("Invalid byte tag in constant pool: " + b);
    }
  
public java.lang.StringtoString()

return
String representation.

    return Constants.CONSTANT_NAMES[tag] + "[" + tag + "]";