111 lines
3.3 KiB
Java
111 lines
3.3 KiB
Java
package com.de22.javabytecode;
|
|
|
|
import java.io.IOException;
|
|
import com.common.debug.*;
|
|
import com.de22.javabytecode.constant.*;
|
|
|
|
/**
|
|
* Copyright Wynne Crisman 1999,2006<p>
|
|
*/
|
|
public abstract class Constant extends Component {
|
|
public static final byte CONSTANT_UTF8 = 0x01;
|
|
public static final byte CONSTANT_INTEGER = 0x03;
|
|
public static final byte CONSTANT_FLOAT = 0x04;
|
|
public static final byte CONSTANT_LONG = 0x05;
|
|
public static final byte CONSTANT_DOUBLE = 0x06;
|
|
public static final byte CONSTANT_CLASS = 0x07;
|
|
public static final byte CONSTANT_STRING = 0x08;
|
|
public static final byte CONSTANT_FIELD_REF = 0x09;
|
|
public static final byte CONSTANT_METHOD_REF = 0x0A;
|
|
public static final byte CONSTANT_INTERFACE_METHOD_REF = 0x0B;
|
|
public static final byte CONSTANT_NAME_AND_TYPE = 0x0C;
|
|
/**
|
|
* Constant constructor.
|
|
*/
|
|
public Constant(Type type) {
|
|
super(type);
|
|
}//Constant()//
|
|
/**
|
|
* Gets this constant's identifying constant.
|
|
* @return The constant value that identifies this constant object type.
|
|
*/
|
|
public abstract byte getTag();
|
|
/**
|
|
* Gets a display string that shows the resulting value of the constant in a viewer friendly way.
|
|
* @return The viewer friendly constant result.
|
|
*/
|
|
public abstract String getPrettyValue();
|
|
/**
|
|
* Determines whether the constant takes double the constant entries in the class bytes.
|
|
* @return Whether the constant is a double size constant.
|
|
*/
|
|
public boolean isDoubleSize() {
|
|
return false;
|
|
}//isDoubleSize()//
|
|
/**
|
|
* Reads a constant from the given stream.
|
|
* @param type The type object that the constant will belong to.
|
|
* @param in The input stream to read the constant from.
|
|
*/
|
|
protected static Constant readConstant(Type type, java.io.ObjectInput in) throws java.io.IOException, ClassNotFoundException {
|
|
Constant constant = null;
|
|
short tag = in.readByte();
|
|
|
|
switch(tag) {
|
|
case CONSTANT_CLASS:
|
|
constant = new ConstantType(type);
|
|
break;
|
|
case CONSTANT_DOUBLE:
|
|
constant = new ConstantDouble(type);
|
|
break;
|
|
case CONSTANT_FIELD_REF:
|
|
constant = new ConstantFieldRef(type);
|
|
break;
|
|
case CONSTANT_FLOAT:
|
|
constant = new ConstantFloat(type);
|
|
break;
|
|
case CONSTANT_INTEGER:
|
|
constant = new ConstantInteger(type);
|
|
break;
|
|
case CONSTANT_INTERFACE_METHOD_REF:
|
|
constant = new ConstantInterfaceMethodRef(type);
|
|
break;
|
|
case CONSTANT_LONG:
|
|
constant = new ConstantLong(type);
|
|
break;
|
|
case CONSTANT_METHOD_REF:
|
|
constant = new ConstantMethodRef(type);
|
|
break;
|
|
case CONSTANT_NAME_AND_TYPE:
|
|
constant = new ConstantNameAndType(type);
|
|
break;
|
|
case CONSTANT_STRING:
|
|
constant = new ConstantString(type);
|
|
break;
|
|
case CONSTANT_UTF8:
|
|
constant = new ConstantUtf8(type);
|
|
break;
|
|
default:
|
|
Debug.halt();
|
|
break;
|
|
}//switch//
|
|
|
|
constant.readExternal(in);
|
|
|
|
return constant;
|
|
}//readConstant()//
|
|
/**
|
|
* Reads this object from the given stream.
|
|
* @param in The input stream to read this object from.
|
|
*/
|
|
public void readExternal(java.io.ObjectInput in) throws IOException, ClassNotFoundException {
|
|
//The tag will be read by the readConstant(Type, ObjectInput) method.//
|
|
}//readExternal()//
|
|
/**
|
|
* Writes this object to the given stream.
|
|
* @param out The output stream to write this object to.
|
|
*/
|
|
public void writeExternal(java.io.ObjectOutput out) throws IOException {
|
|
out.writeByte(getTag());
|
|
}//writeExternal()//
|
|
}//Constant// |