Bläddra i källkod

278496: toString modifications for expected output testing

tags/V1_6_10RC1
aclement 14 år sedan
förälder
incheckning
2e48780fab

+ 8
- 1
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/EnumElementValue.java Visa fil

@@ -32,8 +32,9 @@ public class EnumElementValue extends ElementValue {
*/
protected EnumElementValue(int typeIdx, int valueIdx, ConstantPool cpool) {
super(ElementValue.ENUM_CONSTANT, cpool);
if (type != ENUM_CONSTANT)
if (type != ENUM_CONSTANT) {
throw new RuntimeException("Only element values of type enum can be built with this ctor");
}
this.typeIdx = typeIdx;
this.valueIdx = valueIdx;
}
@@ -83,6 +84,12 @@ public class EnumElementValue extends ElementValue {
return sb.toString();
}

/* public String toString() {
StringBuilder s = new StringBuilder("E(");
s.append(getEnumTypeString()).append(" ").append(getEnumValueString()).append(")");
return s.toString();
}
*/
// BCELBUG: Should we need to call utility.signatureToString() on the output here?
public String getEnumTypeString() {
// Constant cc = getConstantPool().getConstant(typeIdx);

+ 75
- 13
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/SimpleElementValue.java Visa fil

@@ -78,10 +78,11 @@ public class SimpleElementValue extends ElementValue {

public SimpleElementValue(int type, ConstantPool cpGen, boolean value) {
super(type, cpGen);
if (value)
if (value) {
idx = cpGen.addInteger(1);
else
} else {
idx = cpGen.addInteger(0);
}
}

public SimpleElementValue(int type, ConstantPool cpGen, String value) {
@@ -90,50 +91,57 @@ public class SimpleElementValue extends ElementValue {
}

public byte getValueByte() {
if (type != PRIMITIVE_BYTE)
if (type != PRIMITIVE_BYTE) {
throw new RuntimeException("Dont call getValueByte() on a non BYTE ElementValue");
}
ConstantInteger c = (ConstantInteger) cpool.getConstant(idx, Constants.CONSTANT_Integer);
return (byte) c.getIntValue();
}

public char getValueChar() {
if (type != PRIMITIVE_CHAR)
if (type != PRIMITIVE_CHAR) {
throw new RuntimeException("Dont call getValueChar() on a non CHAR ElementValue");
}
ConstantInteger c = (ConstantInteger) cpool.getConstant(idx, Constants.CONSTANT_Integer);
return (char) c.getIntValue();
}

public long getValueLong() {
if (type != PRIMITIVE_LONG)
if (type != PRIMITIVE_LONG) {
throw new RuntimeException("Dont call getValueLong() on a non LONG ElementValue");
}
ConstantLong j = (ConstantLong) cpool.getConstant(idx);
return j.getValue();
}

public float getValueFloat() {
if (type != PRIMITIVE_FLOAT)
if (type != PRIMITIVE_FLOAT) {
throw new RuntimeException("Dont call getValueFloat() on a non FLOAT ElementValue");
}
ConstantFloat f = (ConstantFloat) cpool.getConstant(idx);
return f.getValue();
}

public double getValueDouble() {
if (type != PRIMITIVE_DOUBLE)
if (type != PRIMITIVE_DOUBLE) {
throw new RuntimeException("Dont call getValueDouble() on a non DOUBLE ElementValue");
}
ConstantDouble d = (ConstantDouble) cpool.getConstant(idx);
return d.getValue();
}

public boolean getValueBoolean() {
if (type != PRIMITIVE_BOOLEAN)
if (type != PRIMITIVE_BOOLEAN) {
throw new RuntimeException("Dont call getValueBoolean() on a non BOOLEAN ElementValue");
}
ConstantInteger bo = (ConstantInteger) cpool.getConstant(idx);
return (bo.getValue() != 0);
}

public short getValueShort() {
if (type != PRIMITIVE_SHORT)
if (type != PRIMITIVE_SHORT) {
throw new RuntimeException("Dont call getValueShort() on a non SHORT ElementValue");
}
ConstantInteger s = (ConstantInteger) cpool.getConstant(idx);
return (short) s.getIntValue();
}
@@ -192,15 +200,17 @@ public class SimpleElementValue extends ElementValue {
}

public String getValueString() {
if (type != STRING)
if (type != STRING) {
throw new RuntimeException("Dont call getValueString() on a non STRING ElementValue");
}
ConstantUtf8 c = (ConstantUtf8) cpool.getConstant(idx);
return c.getValue();
}

public int getValueInt() {
if (type != PRIMITIVE_INT)
if (type != PRIMITIVE_INT) {
throw new RuntimeException("Dont call getValueString() on a non STRING ElementValue");
}
ConstantInteger c = (ConstantInteger) cpool.getConstant(idx);
return c.getValue();
}
@@ -232,10 +242,11 @@ public class SimpleElementValue extends ElementValue {
return new Character((char) ch.getIntValue()).toString();
case PRIMITIVE_BOOLEAN:
ConstantInteger bo = (ConstantInteger) cpool.getConstant(idx);
if (bo.getValue() == 0)
if (bo.getValue() == 0) {
return "false";
else
} else {
return "true";
}
case STRING:
ConstantUtf8 cu8 = (ConstantUtf8) cpool.getConstant(idx);
return cu8.getValue();
@@ -245,6 +256,57 @@ public class SimpleElementValue extends ElementValue {
}
}

@Override
public String toString() {
StringBuilder s = new StringBuilder();
switch (type) {
case PRIMITIVE_INT:
ConstantInteger c = (ConstantInteger) cpool.getConstant(idx);
s.append("(int)").append(Integer.toString(c.getValue()));
break;
case PRIMITIVE_LONG:
ConstantLong j = (ConstantLong) cpool.getConstant(idx);
s.append("(long)").append(Long.toString(j.getValue()));
break;
case PRIMITIVE_DOUBLE:
ConstantDouble d = (ConstantDouble) cpool.getConstant(idx);
s.append("(double)").append(d.getValue().toString());
break;
case PRIMITIVE_FLOAT:
ConstantFloat f = (ConstantFloat) cpool.getConstant(idx);
s.append("(float)").append(Float.toString(f.getValue()));
break;
case PRIMITIVE_SHORT:
ConstantInteger ci = (ConstantInteger) cpool.getConstant(idx);
s.append("(short)").append(Integer.toString(ci.getValue()));
break;
case PRIMITIVE_BYTE:
ConstantInteger b = (ConstantInteger) cpool.getConstant(idx);
s.append("(byte)").append(Integer.toString(b.getValue()));
break;
case PRIMITIVE_CHAR:
ConstantInteger ch = (ConstantInteger) cpool.getConstant(idx);
s.append("(char)").append(new Character((char) ch.getIntValue()).toString());
break;
case PRIMITIVE_BOOLEAN:
ConstantInteger bo = (ConstantInteger) cpool.getConstant(idx);
s.append("(boolean)");
if (bo.getValue() == 0) {
s.append("false");
} else {
s.append("true");
}
break;
case STRING:
ConstantUtf8 cu8 = (ConstantUtf8) cpool.getConstant(idx);
s.append("(string)").append(cu8.getValue());
break;
default:
throw new RuntimeException("SimpleElementValueGen class does not know how to stringify type " + type);
}
return s.toString();
}

@Override
public void dump(DataOutputStream dos) throws IOException {
dos.writeByte(type); // u1 kind of value

Laddar…
Avbryt
Spara