Initial commit from SVN.

This commit is contained in:
wcrisman
2014-05-30 10:31:51 -07:00
commit b45e56b890
1968 changed files with 370949 additions and 0 deletions

View File

@@ -0,0 +1,112 @@
package com.de22.javabytecode.constant;
import java.io.IOException;
import com.de22.javabytecode.*;
/**
* Copyright Wynne Crisman 1999,2006<p>
*/
public class ConstantDouble extends Constant {
private double value = 0;
/**
* ConstantDouble constructor.
* @param type The class this constant is a member of.
*/
public ConstantDouble(Type type) {
super(type);
}//ConstantDouble()//
/**
* ConstantDouble constructor.
* @param type The class this constant is a member of.
* @param value The value of the constant.
*/
public ConstantDouble(Type type, double value) {
super(type);
this.value = value;
}//ConstantDouble()//
/**
* Gets the value for this associated with this constant.
* @return The double value.
*/
public double getValue() {
return value;
}//getValue()//
/**
* Determines whether the two objects are logically equal.
* @param object The object to compare with this object.
* @return Whether they are logically equal.
*/
public boolean equals(Object object) {
return (object instanceof ConstantDouble) && (value == ((ConstantDouble) object).value);
}//equals()//
/**
* Gets the size in number of bytes of the component and all subcomponents.
* @return The number of bytes required to represent the component and all subcomponents.
*/
public int getSize() {
return 8;
}//getSize()//
/**
* Gets this class' identifying constant.
* @return The constant value that identifies this constant object type.
*/
public byte getTag() {
return CONSTANT_DOUBLE;
}//getTag()//
/**
* Gets the hash code for the constant.
* @return The constant hash code.
*/
public int hashCode() {
return (int) Double.doubleToLongBits(value);
}//hashCode()//
/**
* 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 true;
}//isDoubleSize()//
/**
* 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 {
super.readExternal(in);
value = in.readDouble();
}//readExternal()//
/* (non-Javadoc)
* @see com.de22.javabytecode.Constant#getPrettyValue()
*/
public String getPrettyValue() {
return Double.toString(value) + " (Double)";
}//getPrettyValue()//
/**
* Gets a string representation of this object.
* @return A string that represents this object.
*/
public String toString() {
return "Double: " + Double.toString(value);
}//toString()//
/**
* @see Component.toString(StringBuffer, int)
*/
public void toString(StringBuffer buffer, int tabCount) {
appendTabs(buffer, tabCount);
buffer.append("Double Constant (");
buffer.append(value);
buffer.append(')');
appendEndOfLine(buffer);
}//toString()//
/**
* 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 {
super.writeExternal(out);
out.writeDouble(value);
}//writeExternal()//
}//ConstantDouble//

View File

@@ -0,0 +1,154 @@
package com.de22.javabytecode.constant;
import java.io.IOException;
import com.de22.javabytecode.*;
/**
* Copyright Wynne Crisman 1999,2006<p>
*/
public class ConstantFieldRef extends Constant {
/** The reference to the class that defines the field. */
private short classIndex = 0;
/** The reference to the name and signature of the method. */
private short nameAndTypeIndex = 0;
/**
* ConstantFieldRef constructor.
* @param type The class this constant is a member of.
*/
public ConstantFieldRef(Type type) {
super(type);
}//ConstantFieldRef()//
/**
* ConstantFieldRef constructor.
* @param type The class this constant is a member of.
* @param classIndex The index of the class constant.
* @param nameAndTypeIndex The index of the name and type descriptor constant.
*/
public ConstantFieldRef(Type type, short classIndex, short nameAndTypeIndex) {
super(type);
this.classIndex = classIndex;
this.nameAndTypeIndex = nameAndTypeIndex;
}//ConstantFieldRef()//
/**
* Gets the constant pool index for the class that defines the field (a ConstantType instance).
* @return The pool index of the class constant.
*/
public short getClassIndex() {
return classIndex;
}//getClassIndex()//
/**
* Gets the constant pool index for the name and type for the field (a ConstantNameAndType instance).
* @return The pool index of the name and type constant.
*/
public short getNameAndTypeIndex() {
return nameAndTypeIndex;
}//getNameAndTypeIndex()//
/**
* Determines whether the two objects are logically equal.
* @param object The object to compare with this object.
* @return Whether they are logically equal.
*/
public boolean equals(Object object) {
return (object instanceof ConstantFieldRef) && (((ConstantFieldRef) object).classIndex == classIndex) && (((ConstantFieldRef) object).nameAndTypeIndex == nameAndTypeIndex);
}//equals()//
/**
* Gets the size in number of bytes of the component and all subcomponents.
* @return The number of bytes required to represent the component and all subcomponents.
*/
public int getSize() {
return 4;
}//getSize()//
/**
* Gets this class' identifying constant.
* @return The constant value that identifies this constant object type.
*/
public byte getTag() {
return CONSTANT_FIELD_REF;
}//getTag()//
/**
* Gets the hash code for the constant.
* @return The constant hash code.
*/
public int hashCode() {
return (classIndex << 4) | nameAndTypeIndex;
}//hashCode()//
/**
* 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 {
super.readExternal(in);
classIndex = in.readShort();
nameAndTypeIndex = in.readShort();
}//readExternal()//
/* (non-Javadoc)
* @see com.de22.javabytecode.Constant#getPrettyValue()
*/
public String getPrettyValue() {
Constant definingTypeConstant = getType().getConstant(classIndex);
Constant nameAndTypeConstant = getType().getConstant(nameAndTypeIndex);
Constant fieldTypeConstant = null;
Constant fieldNameConstant = null;
if(definingTypeConstant instanceof ConstantType) {
definingTypeConstant = getType().getConstant(((ConstantType) definingTypeConstant).getNameIndex());
}//if//
if(definingTypeConstant instanceof ConstantString) {
definingTypeConstant = getType().getConstant(((ConstantString) definingTypeConstant).getStringIndex());
}//if//
if(nameAndTypeConstant instanceof ConstantNameAndType) {
fieldNameConstant = getType().getConstant(((ConstantNameAndType) nameAndTypeConstant).getNameIndex());
fieldTypeConstant = getType().getConstant(((ConstantNameAndType) nameAndTypeConstant).getDescriptorIndex());
}//if//
//Shouldn't ever be this type of constant.. but we will add it just in case.//
if(fieldTypeConstant instanceof ConstantType) {
fieldTypeConstant = getType().getConstant(((ConstantType) fieldTypeConstant).getNameIndex());
}//if//
//Shouldn't ever be this type of constant.. but we will add it just in case.//
if(fieldTypeConstant instanceof ConstantString) {
fieldTypeConstant = getType().getConstant(((ConstantString) fieldTypeConstant).getStringIndex());
}//if//
//Shouldn't ever be this type of constant.. but we will add it just in case.//
if(fieldNameConstant instanceof ConstantString) {
fieldNameConstant = getType().getConstant(((ConstantString) fieldNameConstant).getStringIndex());
}//if//
return definingTypeConstant instanceof ConstantUtf8 && fieldTypeConstant instanceof ConstantUtf8 && fieldNameConstant instanceof ConstantUtf8 ? ((ConstantUtf8) definingTypeConstant).getValue() + "." + ((ConstantUtf8) fieldNameConstant).getValue() + " (Field Name)" : "Error: Unexpected Constant Reference";
}//getPrettyValue()//
/**
* Gets a string representation of this object.
* @return A string that represents this object.
*/
public String toString() {
return "Field Reference (classIndex: " + classIndex + " nameAndTypeIndex: " + nameAndTypeIndex;
}//toString()//
/**
* @see Component.toString(StringBuffer, int)
*/
public void toString(StringBuffer buffer, int tabCount) {
appendTabs(buffer, tabCount);
buffer.append("Field Reference Constant (classIndex=");
buffer.append(classIndex);
buffer.append(" nameAndTypeIndex=");
buffer.append(nameAndTypeIndex);
buffer.append(')');
appendEndOfLine(buffer);
}//toString()//
/**
* 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 {
super.writeExternal(out);
out.writeShort(classIndex);
out.writeShort(nameAndTypeIndex);
}//writeExternal()//
}//ConstantFieldRef//

View File

@@ -0,0 +1,105 @@
package com.de22.javabytecode.constant;
import java.io.IOException;
import com.de22.javabytecode.*;
/**
* Copyright Wynne Crisman 1999,2006<p>
*/
public class ConstantFloat extends Constant {
private float value = 0;
/**
* ConstantType constructor.
* @param type The class this constant is a member of.
*/
public ConstantFloat(Type type) {
super(type);
}//ConstantFloat()//
/**
* ConstantType constructor.
* @param type The class this constant is a member of.
* @param value The value of the constant.
*/
public ConstantFloat(Type type, float value) {
super(type);
this.value = value;
}//ConstantFloat()//
/**
* Gets the value for this associated with this constant.
* @return The float value.
*/
public float getValue() {
return value;
}//getValue()//
/**
* Determines whether the two objects are logically equal.
* @param object The object to compare with this object.
* @return Whether they are logically equal.
*/
public boolean equals(Object object) {
return (object instanceof ConstantFloat) && (value == ((ConstantFloat) object).value);
}//equals()//
/**
* Gets the size in number of bytes of the component and all subcomponents.
* @return The number of bytes required to represent the component and all subcomponents.
*/
public int getSize() {
return 4;
}//getSize()//
/**
* Gets this class' identifying constant.
* @return The constant value that identifies this constant object type.
*/
public byte getTag() {
return CONSTANT_FLOAT;
}//getTag()//
/**
* Gets the hash code for the constant.
* @return The constant hash code.
*/
public int hashCode() {
return Float.floatToIntBits(value);
}//hashCode()//
/**
* 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 {
super.readExternal(in);
value = in.readFloat();
}//readExternal()//
/**
* Gets a string representation of this object.
* @return A string that represents this object.
*/
public String toString() {
return "Float: " + Float.toString(value);
}//toString()//
/* (non-Javadoc)
* @see com.de22.javabytecode.Constant#getPrettyValue()
*/
public String getPrettyValue() {
return Float.toString(value) + " (Float)";
}//getPrettyValue()//
/**
* @see Component.toString(StringBuffer, int)
*/
public void toString(StringBuffer buffer, int tabCount) {
appendTabs(buffer, tabCount);
buffer.append("Float Constant (");
buffer.append(value);
buffer.append(')');
appendEndOfLine(buffer);
}//toString()//
/**
* 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 {
super.writeExternal(out);
out.writeFloat(value);
}//writeExternal()//
}//ConstantFloat//

View File

@@ -0,0 +1,105 @@
package com.de22.javabytecode.constant;
import java.io.IOException;
import com.de22.javabytecode.*;
/**
* Copyright Wynne Crisman 1999,2006<p>
*/
public class ConstantInteger extends Constant {
private int value = 0;
/**
* ConstantInteger constructor.
* @param type The class this constant is a member of.
*/
public ConstantInteger(Type type) {
super(type);
}//ConstantInteger()//
/**
* ConstantInteger constructor.
* @param type The class this constant is a member of.
* @param value The value of the constant.
*/
public ConstantInteger(Type type, int value) {
super(type);
this.value = value;
}//ConstantInteger()//
/**
* Gets the value for this associated with this constant.
* @return The integer value.
*/
public int getValue() {
return value;
}//getValue()//
/**
* Determines whether the two objects are logically equal.
* @param object The object to compare with this object.
* @return Whether they are logically equal.
*/
public boolean equals(Object object) {
return (object instanceof ConstantInteger) && (value == ((ConstantInteger) object).value);
}//equals()//
/**
* Gets the size in number of bytes of the component and all subcomponents.
* @return The number of bytes required to represent the component and all subcomponents.
*/
public int getSize() {
return 4;
}//getSize()//
/**
* Gets this class' identifying constant.
* @return The constant value that identifies this constant object type.
*/
public byte getTag() {
return CONSTANT_INTEGER;
}//getTag()//
/**
* Gets the hash code for the constant.
* @return The constant hash code.
*/
public int hashCode() {
return value;
}//hashCode()//
/**
* 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 {
super.readExternal(in);
value = in.readInt();
}//readExternal()//
/* (non-Javadoc)
* @see com.de22.javabytecode.Constant#getPrettyValue()
*/
public String getPrettyValue() {
return Integer.toString(value) + " (Integer)";
}//getPrettyValue()//
/**
* Gets a string representation of this object.
* @return A string that represents this object.
*/
public String toString() {
return "Integer: " + Integer.toString(value);
}//toString()//
/**
* @see Component.toString(StringBuffer, int)
*/
public void toString(StringBuffer buffer, int tabCount) {
appendTabs(buffer, tabCount);
buffer.append("Integer Constant (");
buffer.append(value);
buffer.append(')');
appendEndOfLine(buffer);
}//toString()//
/**
* 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 {
super.writeExternal(out);
out.writeInt(value);
}//writeExternal()//
}//ConstantInteger//

View File

@@ -0,0 +1,149 @@
package com.de22.javabytecode.constant;
import java.io.IOException;
import com.de22.javabytecode.*;
/**
* Copyright Wynne Crisman 1999,2006<p>
* A reference to a method that is defined by an interface.
*/
public class ConstantInterfaceMethodRef extends Constant {
/** The reference to the interface that defines the method. */
private short classIndex = 0;
/** The reference to the name and signature of the method. */
private short nameAndTypeIndex = 0;
/**
* ConstantInterfaceMethodRef constructor.
* @param type The class this constant is a member of.
*/
public ConstantInterfaceMethodRef(Type type) {
super(type);
}//ConstantInterfaceMethodRef()//
/**
* ConstantInterfaceMethodRef constructor.
* @param type The class this constant is a member of.
* @param classIndex The index of the class constant.
* @param nameAndTypeIndex The index of the name and type descriptor constant.
*/
public ConstantInterfaceMethodRef(Type type, short classIndex, short nameAndTypeIndex) {
super(type);
this.classIndex = classIndex;
this.nameAndTypeIndex = nameAndTypeIndex;
}//ConstantInterfaceMethodRef()//
/**
* Gets the constant pool index for the interface that defines the method (a ConstantType instance).
* @return The pool index of the class constant.
*/
public short getClassIndex() {
return classIndex;
}//getClassIndex()//
/**
* Gets the constant pool index for the name and type for the method (a ConstantNameAndType instance).
* @return The pool index of the name and type constant.
*/
public short getNameAndTypeIndex() {
return nameAndTypeIndex;
}//getNameAndTypeIndex()//
/**
* Determines whether the two objects are logically equal.
* @param object The object to compare with this object.
* @return Whether they are logically equal.
*/
public boolean equals(Object object) {
return (object instanceof ConstantInterfaceMethodRef) && (((ConstantInterfaceMethodRef) object).classIndex == classIndex) && (((ConstantInterfaceMethodRef) object).nameAndTypeIndex == nameAndTypeIndex);
}//equals()//
/**
* Gets the size in number of bytes of the component and all subcomponents.
* @return The number of bytes required to represent the component and all subcomponents.
*/
public int getSize() {
return 4;
}//getSize()//
/**
* Gets this class' identifying constant.
* @return The constant value that identifies this constant object type.
*/
public byte getTag() {
return CONSTANT_INTERFACE_METHOD_REF;
}//getTag()//
/**
* Gets the hash code for the constant.
* @return The constant hash code.
*/
public int hashCode() {
return (classIndex << 4) | nameAndTypeIndex;
}//hashCode()//
/**
* 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 {
super.readExternal(in);
classIndex = in.readShort();
nameAndTypeIndex = in.readShort();
}//readExternal()//
/* (non-Javadoc)
* @see com.de22.javabytecode.Constant#getPrettyValue()
*/
public String getPrettyValue() {
Constant definingTypeConstant = getType().getConstant(classIndex);
Constant nameAndTypeConstant = getType().getConstant(nameAndTypeIndex);
Constant methodSignatureConstant = null;
Constant methodNameConstant = null;
if(definingTypeConstant instanceof ConstantType) {
definingTypeConstant = getType().getConstant(((ConstantType) definingTypeConstant).getNameIndex());
}//if//
if(definingTypeConstant instanceof ConstantString) {
definingTypeConstant = getType().getConstant(((ConstantString) definingTypeConstant).getStringIndex());
}//if//
if(nameAndTypeConstant instanceof ConstantNameAndType) {
methodNameConstant = getType().getConstant(((ConstantNameAndType) nameAndTypeConstant).getNameIndex());
methodSignatureConstant = getType().getConstant(((ConstantNameAndType) nameAndTypeConstant).getDescriptorIndex());
}//if//
//Shouldn't ever be this type of constant.. but we will add it just in case.//
if(methodSignatureConstant instanceof ConstantString) {
methodSignatureConstant = getType().getConstant(((ConstantString) methodSignatureConstant).getStringIndex());
}//if//
//Shouldn't ever be this type of constant.. but we will add it just in case.//
if(methodNameConstant instanceof ConstantString) {
methodNameConstant = getType().getConstant(((ConstantString) methodNameConstant).getStringIndex());
}//if//
return definingTypeConstant instanceof ConstantUtf8 && methodNameConstant instanceof ConstantUtf8 && methodSignatureConstant instanceof ConstantUtf8 ? ((ConstantUtf8) definingTypeConstant).getValue() + "." + ((ConstantUtf8) methodNameConstant).getValue() + ((ConstantUtf8) methodSignatureConstant).getValue() + " (Interface Method Name)" : "Error: Unexpected Constant Reference";
}//getPrettyValue()//
/**
* Gets a string representation of this object.
* @return A string that represents this object.
*/
public String toString() {
return "Interface Method Reference (classIndex: " + classIndex + " nameAndTypeIndex: " + nameAndTypeIndex;
}//toString()//
/**
* @see Component.toString(StringBuffer, int)
*/
public void toString(StringBuffer buffer, int tabCount) {
appendTabs(buffer, tabCount);
buffer.append("Interface Method Reference Constant (classIndex=");
buffer.append(classIndex);
buffer.append(" nameAndTypeIndex=");
buffer.append(nameAndTypeIndex);
appendEndOfLine(buffer);
}//toString()//
/**
* 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 {
super.writeExternal(out);
out.writeShort(classIndex);
out.writeShort(nameAndTypeIndex);
}//writeExternal()//
}//ConstantInterfaceMethodRef//

View File

@@ -0,0 +1,112 @@
package com.de22.javabytecode.constant;
import java.io.IOException;
import com.de22.javabytecode.*;
/**
* Copyright Wynne Crisman 1999,2006<p>
*/
public class ConstantLong extends Constant {
private long value = 0;
/**
* ConstantLong constructor.
* @param type The class this constant is a member of.
*/
public ConstantLong(Type type) {
super(type);
}//ConstantLong()//
/**
* ConstantLong constructor.
* @param type The class this constant is a member of.
* @param value The value of the constant.
*/
public ConstantLong(Type type, long value) {
super(type);
this.value = value;
}//ConstantLong()//
/**
* Gets the value for this associated with this constant.
* @return The long value.
*/
public long getValue() {
return value;
}//getValue()//
/**
* Determines whether the two objects are logically equal.
* @param object The object to compare with this object.
* @return Whether they are logically equal.
*/
public boolean equals(Object object) {
return (object instanceof ConstantLong) && (value == ((ConstantLong) object).value);
}//equals()//
/**
* Gets the size in number of bytes of the component and all subcomponents.
* @return The number of bytes required to represent the component and all subcomponents.
*/
public int getSize() {
return 8;
}//getSize()//
/**
* Gets this class' identifying constant.
* @return The constant value that identifies this constant object type.
*/
public byte getTag() {
return CONSTANT_LONG;
}//getTag()//
/**
* Gets the hash code for the constant.
* @return The constant hash code.
*/
public int hashCode() {
return (int) value;
}//hashCode()//
/**
* 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 true;
}//isDoubleSize()//
/**
* 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 {
super.readExternal(in);
value = in.readLong();
}//readExternal()//
/* (non-Javadoc)
* @see com.de22.javabytecode.Constant#getPrettyValue()
*/
public String getPrettyValue() {
return Long.toString(value) + " (Long)";
}//getPrettyValue()//
/**
* Gets a string representation of this object.
* @return A string that represents this object.
*/
public String toString() {
return "Long: " + Long.toString(value);
}//toString()//
/**
* @see Component.toString(StringBuffer, int)
*/
public void toString(StringBuffer buffer, int tabCount) {
appendTabs(buffer, tabCount);
buffer.append("Long Constant (");
buffer.append(value);
buffer.append(')');
appendEndOfLine(buffer);
}//toString()//
/**
* 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 {
super.writeExternal(out);
out.writeLong(value);
}//writeExternal()//
}//ConstantLong//

View File

@@ -0,0 +1,142 @@
package com.de22.javabytecode.constant;
import java.io.IOException;
import com.de22.javabytecode.*;
/**
* Copyright Wynne Crisman 1999,2006<p>
* A reference to a method that is part of another class.
*/
public class ConstantMethodRef extends Constant {
/** The reference to the class that defines the method. */
private short classIndex = 0;
/** The reference to the name and signature of the method. */
private short nameAndTypeIndex = 0;
/**
* ConstantMethodRef constructor.
* @param type The class this constant is a member of.
*/
public ConstantMethodRef(Type type) {
super(type);
}//ConstantMethodRef()//
/**
* ConstantMethodRef constructor.
* @param type The class this constant is a member of.
* @param classIndex The index of the class constant.
* @param nameAndTypeIndex The index of the name and type descriptor constant.
*/
public ConstantMethodRef(Type type, short classIndex, short nameAndTypeIndex) {
super(type);
this.classIndex = classIndex;
this.nameAndTypeIndex = nameAndTypeIndex;
}//ConstantMethodRef()//
/**
* Gets the constant pool index for the class that defines the method (a ConstantType instance).
* @return The pool index of the class constant.
*/
public short getClassIndex() {
return classIndex;
}//getClassIndex()//
/**
* Gets the constant pool index for the name and type for the method (a ConstantNameAndType instance).
* @return The pool index of the name and type constant.
*/
public short getNameAndTypeIndex() {
return nameAndTypeIndex;
}//getNameAndTypeIndex()//
/* (non-Javadoc)
* @see com.de22.javabytecode.ITypeComponent#getSize()
*/
public int getSize() {
return 4;
}//getSize()//
/* (non-Javadoc)
* @see com.de22.javabytecode.Constant#getTag()
*/
public byte getTag() {
return CONSTANT_METHOD_REF;
}//getTag()//
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return (classIndex << 4) | nameAndTypeIndex;
}//hashCode()//
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object object) {
return (object instanceof ConstantMethodRef) && (((ConstantMethodRef) object).classIndex == classIndex) && (((ConstantMethodRef) object).nameAndTypeIndex == nameAndTypeIndex);
}//equals()//
/* (non-Javadoc)
* @see java.io.Externalizable#readExternal(java.io.ObjectInput)
*/
public void readExternal(java.io.ObjectInput in) throws IOException, ClassNotFoundException {
super.readExternal(in);
classIndex = in.readShort();
nameAndTypeIndex = in.readShort();
}//readExternal()//
/* (non-Javadoc)
* @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
*/
public void writeExternal(java.io.ObjectOutput out) throws IOException {
super.writeExternal(out);
out.writeShort(classIndex);
out.writeShort(nameAndTypeIndex);
}//writeExternal()//
/* (non-Javadoc)
* @see com.de22.javabytecode.Constant#getPrettyValue()
*/
public String getPrettyValue() {
Constant definingTypeConstant = getType().getConstant(classIndex);
Constant nameAndTypeConstant = getType().getConstant(nameAndTypeIndex);
Constant methodSignatureConstant = null;
Constant methodNameConstant = null;
if(definingTypeConstant instanceof ConstantType) {
definingTypeConstant = getType().getConstant(((ConstantType) definingTypeConstant).getNameIndex());
}//if//
if(definingTypeConstant instanceof ConstantString) {
definingTypeConstant = getType().getConstant(((ConstantString) definingTypeConstant).getStringIndex());
}//if//
if(nameAndTypeConstant instanceof ConstantNameAndType) {
methodNameConstant = getType().getConstant(((ConstantNameAndType) nameAndTypeConstant).getNameIndex());
methodSignatureConstant = getType().getConstant(((ConstantNameAndType) nameAndTypeConstant).getDescriptorIndex());
}//if//
//Shouldn't ever be this type of constant.. but we will add it just in case.//
if(methodSignatureConstant instanceof ConstantString) {
methodSignatureConstant = getType().getConstant(((ConstantString) methodSignatureConstant).getStringIndex());
}//if//
//Shouldn't ever be this type of constant.. but we will add it just in case.//
if(methodNameConstant instanceof ConstantString) {
methodNameConstant = getType().getConstant(((ConstantString) methodNameConstant).getStringIndex());
}//if//
return definingTypeConstant instanceof ConstantUtf8 && methodNameConstant instanceof ConstantUtf8 && methodSignatureConstant instanceof ConstantUtf8 ? ((ConstantUtf8) definingTypeConstant).getValue() + "." + ((ConstantUtf8) methodNameConstant).getValue() + ((ConstantUtf8) methodSignatureConstant).getValue() + " (Method Name)" : "Error: Unexpected Constant Reference";
}//getPrettyValue()//
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
return "Method Reference (classIndex: " + classIndex + " nameAndTypeIndex: " + nameAndTypeIndex;
}//toString()//
/* (non-Javadoc)
* @see com.de22.javabytecode.Component#toString(java.lang.StringBuffer, int)
*/
public void toString(StringBuffer buffer, int tabCount) {
appendTabs(buffer, tabCount);
buffer.append("Method Reference Constant (classIndex=");
buffer.append(classIndex);
buffer.append(" nameAndTypeIndex=");
buffer.append(nameAndTypeIndex);
buffer.append(')');
appendEndOfLine(buffer);
}//toString()//
}//ConstantMethodRef//

View File

@@ -0,0 +1,138 @@
package com.de22.javabytecode.constant;
import java.io.IOException;
import com.de22.javabytecode.*;
/**
* Copyright Wynne Crisman 1999,2006<p>
* A reference to a method or field name and signature (descriptor).
*/
public class ConstantNameAndType extends Constant {
/** The index of the name of the method (ie: 'parseInt'). */
private short nameIndex = 0;
/** The index of the method or field descriptor (ie: '(Ljava/lang/String;)I' or for a field: 'Ljava/lang/String;' without quotes of course). */
private short descriptorIndex = 0;
/**
* ConstantNameAndType constructor.
* @param type The class this constant is a member of.
*/
public ConstantNameAndType(Type type) {
super(type);
}//ConstantNameAndType()//
/**
* ConstantNameAndType constructor.
* @param type The class this constant is a member of.
* @param nameIndex The index of the name constant.
* @param descriptorIndex The descriptor constant index.
*/
public ConstantNameAndType(Type type, short nameIndex, short descriptorIndex) {
super(type);
this.nameIndex = nameIndex;
this.descriptorIndex = descriptorIndex;
}//ConstantNameAndType()//
/**
* Gets the constant pool index for the name.
* @return The index in the type's constant pool for the name which should be a ConstantUtf8.
*/
public short getNameIndex() {
return nameIndex;
}//getNameIndex()//
/**
* Gets the constant pool index for the descriptor.
* @return The index in the type's constant pool for the descriptor.
*/
public short getDescriptorIndex() {
return descriptorIndex;
}//getDescriptorIndex()//
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return (nameIndex << 4) | descriptorIndex;
}//hashCode()//
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object object) {
return (object instanceof ConstantNameAndType) && (((ConstantNameAndType) object).nameIndex == nameIndex) && (((ConstantNameAndType) object).descriptorIndex == descriptorIndex);
}//equals()//
/* (non-Javadoc)
* @see com.de22.javabytecode.ITypeComponent#getSize()
*/
public int getSize() {
return 4;
}//getSize()//
/* (non-Javadoc)
* @see com.de22.javabytecode.Constant#getTag()
*/
public byte getTag() {
return CONSTANT_NAME_AND_TYPE;
}//getTag()//
/* (non-Javadoc)
* @see java.io.Externalizable#readExternal(java.io.ObjectInput)
*/
public void readExternal(java.io.ObjectInput in) throws IOException, ClassNotFoundException {
super.readExternal(in);
nameIndex = in.readShort();
descriptorIndex = in.readShort();
}//readExternal()//
/* (non-Javadoc)
* @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
*/
public void writeExternal(java.io.ObjectOutput out) throws IOException {
super.writeExternal(out);
out.writeShort(nameIndex);
out.writeShort(descriptorIndex);
}//writeExternal()//
/* (non-Javadoc)
* @see com.de22.javabytecode.Constant#getPrettyValue()
*/
public String getPrettyValue() {
Constant fieldTypeConstant = getType().getConstant(getDescriptorIndex());
Constant fieldNameConstant = getType().getConstant(getNameIndex());
//Shouldn't ever be this type of constant.. but we will add it just in case.//
if(fieldTypeConstant instanceof ConstantType) {
fieldTypeConstant = getType().getConstant(((ConstantType) fieldTypeConstant).getNameIndex());
}//if//
//Shouldn't ever be this type of constant.. but we will add it just in case.//
if(fieldTypeConstant instanceof ConstantString) {
fieldTypeConstant = getType().getConstant(((ConstantString) fieldTypeConstant).getStringIndex());
}//if//
//Shouldn't ever be this type of constant.. but we will add it just in case.//
if(fieldNameConstant instanceof ConstantString) {
fieldNameConstant = getType().getConstant(((ConstantString) fieldNameConstant).getStringIndex());
}//if//
return fieldTypeConstant instanceof ConstantUtf8 && fieldNameConstant instanceof ConstantUtf8 ? ((ConstantUtf8) fieldTypeConstant).getValue() + " " + ((ConstantUtf8) fieldNameConstant).getValue() + " (Name & Type)" : "Error: Unexpected Constant Reference";
}//getPrettyValue()//
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
Constant descriptorConstant = getType().getConstant(descriptorIndex);
Constant nameConstant = getType().getConstant(nameIndex);
return "Descriptor: " + (descriptorConstant instanceof ConstantNameAndType ? (" DescriptorIndex: " + descriptorIndex + "<--ERROR") : descriptorConstant.toString()) + (nameConstant instanceof ConstantNameAndType ? (" NameIndex: " + nameIndex + "<--ERROR") : (" Name: " + getType().getConstant(nameIndex)));
}//toString()//
/* (non-Javadoc)
* @see com.de22.javabytecode.Component#toString(java.lang.StringBuffer, int)
*/
public void toString(StringBuffer buffer, int tabCount) {
appendTabs(buffer, tabCount);
buffer.append("Name & Type Constant (nameIndex=");
buffer.append(nameIndex);
buffer.append(" descriptorIndex=");
buffer.append(descriptorIndex);
buffer.append(" value='");
buffer.append(toString());
buffer.append('\'');
buffer.append(')');
appendEndOfLine(buffer);
}//toString()//
}//ConstantNameAndType//

View File

@@ -0,0 +1,110 @@
package com.de22.javabytecode.constant;
import java.io.IOException;
import com.de22.javabytecode.*;
/**
* Copyright Wynne Crisman 1999,2006<p>
* References a string in the constant pool.
*/
public class ConstantString extends Constant {
private short stringIndex = 0;
/**
* ConstantString constructor.
* @param type The class this constant is a member of.
*/
public ConstantString(Type type) {
super(type);
}//ConstantString()//
/**
* ConstantString constructor.
* @param type The class this constant is a member of.
*/
public ConstantString(Type type, short stringIndex) {
super(type);
this.stringIndex = stringIndex;
}//ConstantString()//
/**
* Determines whether the two objects are logically equal.
* @param object The object to compare with this object.
* @return Whether they are logically equal.
*/
public boolean equals(Object object) {
return (object instanceof ConstantString) && (((ConstantString) object).stringIndex == stringIndex);
}//equals()//
/**
* Gets the size in number of bytes of the component and all subcomponents.
* @return The number of bytes required to represent the component and all subcomponents.
*/
public int getSize() {
return 2;
}//getSize()//
/**
* Gets the constant pool index of the string which should be a ConstantUtf8 object.
* @return The index in the constant pool of the actual string.
*/
public short getStringIndex() {
return stringIndex;
}//getStringIndex()//
/**
* Gets this class' identifying constant.
* @return The constant value that identifies this constant object type.
*/
public byte getTag() {
return CONSTANT_STRING;
}//getTag()//
/**
* Gets the hash code for the constant.
* @return The constant hash code.
*/
public int hashCode() {
return stringIndex;
}//hashCode()//
/**
* 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 {
super.readExternal(in);
stringIndex = in.readShort();
}//readExternal()//
/* (non-Javadoc)
* @see com.de22.javabytecode.Constant#getPrettyValue()
*/
public String getPrettyValue() {
Constant constant = getType().getConstant(stringIndex);
return constant instanceof ConstantUtf8 ? "\"" + ((ConstantUtf8) constant).getValue().replaceAll("\n", "\\\\n").replaceAll("\r", "\\\\r").replace("\t", "\\\\t") + "\" (String w/o Quotes)" : "Error: Unexpected Constant Reference";
}//getPrettyValue()//
/**
* Gets a string representation of this object.
* @return A string that represents this object.
*/
public String toString() {
return "String" + (getType().getConstant(stringIndex) instanceof ConstantString ? " Index: " + stringIndex + " <--ERROR" : ": " + getType().getConstant(stringIndex));
}//toString()//
/**
* @see Component.toString(StringBuffer, int)
*/
public void toString(StringBuffer buffer, int tabCount) {
appendTabs(buffer, tabCount);
buffer.append("String Constant (index=");
buffer.append(stringIndex);
buffer.append(" value='");
buffer.append(getType().getConstant(stringIndex).toString());
buffer.append('\'');
buffer.append(')');
appendEndOfLine(buffer);
}//toString()//
/**
* 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 {
super.writeExternal(out);
out.writeShort(stringIndex);
}//writeExternal()//
}//ConstantString//

View File

@@ -0,0 +1,106 @@
package com.de22.javabytecode.constant;
import java.io.IOException;
import com.de22.javabytecode.*;
/**
* Copyright Wynne Crisman 1999,2006<p>
* A reference to a class name constant.
*/
public class ConstantType extends Constant {
/** The index of the class name (ie: 'com/common/util/LiteList'). */
private short nameIndex = 0;
/**
* ConstantType constructor.
*/
public ConstantType(Type type) {
super(type);
}//ConstantType()//
/**
* ConstantType constructor.
* @param type The class this constant is a member of. <b>Warning: This type must be in the class file format for class names.</b>
*/
public ConstantType(Type type, short nameIndex) {
super(type);
this.nameIndex = nameIndex;
}//ConstantType()//
/**
* Gets the class name's index within the type's constant pool.
* @return The constant pool index of the class name.
*/
public short getNameIndex() {
return nameIndex;
}//getNameIndex()//
/* (non-Javadoc)
* @see com.de22.javabytecode.ITypeComponent#getSize()
*/
public int getSize() {
return 2;
}//getSize()//
/* (non-Javadoc)
* @see com.de22.javabytecode.Constant#getTag()
*/
public byte getTag() {
return CONSTANT_CLASS;
}//getTag()//
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return nameIndex;
}//hashCode()//
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object object) {
return (object instanceof ConstantType) && (((ConstantType) object).nameIndex == nameIndex);
}//equals()//
/* (non-Javadoc)
* @see java.io.Externalizable#readExternal(java.io.ObjectInput)
*/
public void readExternal(java.io.ObjectInput in) throws IOException, ClassNotFoundException {
super.readExternal(in);
nameIndex = in.readShort();
}//readExternal()//
/* (non-Javadoc)
* @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
*/
public void writeExternal(java.io.ObjectOutput out) throws IOException {
super.writeExternal(out);
out.writeShort(nameIndex);
}//writeExternal()//
/* (non-Javadoc)
* @see com.de22.javabytecode.Constant#getPrettyValue()
*/
public String getPrettyValue() {
Constant constant = getType().getConstant(nameIndex);
if(constant instanceof ConstantString) {
constant = getType().getConstant(((ConstantString) constant).getStringIndex());
}//if//
return constant instanceof ConstantUtf8 ? "\"" + ((ConstantUtf8) constant).getValue() + "\" (Type w/o Quotes)" : "Error: Unexpected Constant Reference";
}//getPrettyValue()//
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
return getType().getConstant(nameIndex) instanceof ConstantType ? "NameIndex: " + nameIndex + " <--ERROR" : "Name: " + getType().getConstant(nameIndex);
}//toString()//
/* (non-Javadoc)
* @see com.de22.javabytecode.Component#toString(java.lang.StringBuffer, int)
*/
public void toString(StringBuffer buffer, int tabCount) {
appendTabs(buffer, tabCount);
buffer.append("Class Constant (index=");
buffer.append(nameIndex);
buffer.append(" value='");
buffer.append(getType().getConstant(nameIndex).toString());
buffer.append('\'');
buffer.append(')');
appendEndOfLine(buffer);
}//toString()//
}//ConstantType//

View File

@@ -0,0 +1,154 @@
package com.de22.javabytecode.constant;
import java.io.IOException;
import com.common.debug.*;
import com.de22.javabytecode.*;
/**
* Copyright Wynne Crisman 1999,2006<p>
*/
public class ConstantUtf8 extends Constant {
private static final String UTF8_ENCODING = "UTF8";
private byte[] bytes = null;
private String value = null;
/**
* ConstantUtf8 constructor.
* @param type The class this constant is a member of.
*/
public ConstantUtf8(Type type) {
super(type);
}//ConstantUtf8()//
/**
* ConstantUtf8 constructor.
* @param type The class this constant is a member of.
* @param value The value of the constant.
*/
public ConstantUtf8(Type type, String value) {
super(type);
setValue(value);
}//ConstantUtf8()//
/**
* Determines whether the two objects are logically equal.
* @param object The object to compare with this object.
* @return Whether they are logically equal.
*/
public boolean equals(Object object) {
return (object instanceof ConstantUtf8) && (((((ConstantUtf8) object).getValue() == null) && (getValue() == null)) || ((((ConstantUtf8) object).getValue() != null) && ((ConstantUtf8) object).getValue().equals(getValue())));
}//equals()//
/**
* Gets the size in number of bytes of the component and all subcomponents.
* @return The number of bytes required to represent the component and all subcomponents.
*/
public int getSize() {
return getValueBytes().length + 2;
}//getSize()//
/**
* Gets this class' identifying constant.
* @return The constant value that identifies this constant object type.
*/
public byte getTag() {
return CONSTANT_UTF8;
}//getTag()//
/**
* Gets the value for this associated with this constant.
* @return The string value.
*/
public String getValue() {
return value;
}//getValue()//
/**
* Gets the byte array value for the string. The bytes will be created if they have not yet.
* @return The string value as a byte array.
*/
public byte[] getValueBytes() {
if(bytes == null) {
try {
bytes = value.getBytes(UTF8_ENCODING);
}//try//
catch(java.io.UnsupportedEncodingException e) {
Debug.log(e);
Debug.halt();
}//catch//
}//if//
return bytes;
}//getValueBytes()//
/**
* Gets the hash code for the constant.
* @return The constant hash code.
*/
public int hashCode() {
return value != null ? value.hashCode() : 0;
}//hashCode()//
/**
* 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 {
super.readExternal(in);
int readCount = 0;
int size = (((int) (((byte) in.read()) & 0xFF) << 8) + ((int) (((byte) in.read()) & 0xFF)));
bytes = new byte[size];
while(readCount != bytes.length) {
readCount += in.read(bytes, readCount, bytes.length - readCount);
}//while//
convertToString(bytes);
}//readExternal()//
/**
* Converts the bytes into a UTF8 string.
* <p>Note: This method was created to house this one line of code due to a VM error or compiler error in JDK 1.5_08. For some strange reason separating the line allows the app to not crash and a correct value to be returned.</p>
* @param bytes
* @throws IOException
* @throws ClassNotFoundException
*/
private void convertToString(byte[] bytes) throws IOException, ClassNotFoundException {
value = new String(bytes, UTF8_ENCODING);
}//convertToString()//
/**
* Sets the value for this associated with this constant.
* @param value The string value.
*/
public void setValue(String value) {
this.value = value;
this.bytes = null;
}//getValue()//
/* (non-Javadoc)
* @see com.de22.javabytecode.Constant#getPrettyValue()
*/
public String getPrettyValue() {
return "\"" + value.replaceAll("\n", "\\\\n").replaceAll("\r", "\\\\r").replaceAll("\t", "\\\\t") + "\" (UTF8 w/o Quotes)";
}//getPrettyValue()//
/**
* Provides a debug output string representing this object.
* @return A debug string representing this object.
*/
public String toString() {
return value.replaceAll("\n", "\\\\n").replaceAll("\r", "\\\\r").replaceAll("\t", "\\\\t");
}//toString()//
/**
* @see Component.toString(StringBuffer, int)
*/
public void toString(StringBuffer buffer, int tabCount) {
appendTabs(buffer, tabCount);
buffer.append("UTF8 Constant (");
buffer.append(value.replaceAll("\n", "\\\\n").replaceAll("\r", "\\\\r").replaceAll("\t", "\\\\t"));
buffer.append(')');
appendEndOfLine(buffer);
}//toString()//
/**
* 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 {
super.writeExternal(out);
out.writeShort((short) getValueBytes().length);
out.write(getValueBytes());
}//writeExternal()//
}//ConstantUtf8//