From: aclement Date: Sat, 26 Feb 2005 15:20:51 +0000 (+0000) Subject: More accessors for the different types of value. X-Git-Tag: V1_5_0M2~127 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=13e4bfbf76d0caba1ca4f4d61901017fc800f6cb;p=aspectj.git More accessors for the different types of value. --- diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/SimpleElementValue.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/SimpleElementValue.java index 339365e54..452f15199 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/SimpleElementValue.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/SimpleElementValue.java @@ -56,6 +56,56 @@ public class SimpleElementValue extends ElementValue { return c.getBytes(); } + public byte getValueByte() { + 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.getBytes(); + } + + public char getValueChar() { + 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.getBytes(); + } + + public long getValueLong() { + if (type != PRIMITIVE_LONG) + throw new RuntimeException("Dont call getValueLong() on a non LONG ElementValue"); + ConstantLong j = (ConstantLong)cpool.getConstant(idx); + return j.getBytes(); + } + + public float getValueFloat() { + if (type != PRIMITIVE_FLOAT) + throw new RuntimeException("Dont call getValueFloat() on a non FLOAT ElementValue"); + ConstantFloat f = (ConstantFloat)cpool.getConstant(idx); + return f.getBytes(); + } + + + public double getValueDouble() { + if (type != PRIMITIVE_DOUBLE) + throw new RuntimeException("Dont call getValueDouble() on a non DOUBLE ElementValue"); + ConstantDouble d = (ConstantDouble)cpool.getConstant(idx); + return d.getBytes(); + } + + public boolean getValueBoolean() { + if (type != PRIMITIVE_BOOLEAN) + throw new RuntimeException("Dont call getValueBoolean() on a non BOOLEAN ElementValue"); + ConstantInteger bo = (ConstantInteger)cpool.getConstant(idx); + return (bo.getBytes()!=0); + } + + public short getValueShort() { + if (type != PRIMITIVE_SHORT) + throw new RuntimeException("Dont call getValueShort() on a non SHORT ElementValue"); + ConstantInteger s = (ConstantInteger)cpool.getConstant(idx); + return (short)s.getBytes(); + } + public String toString() { return stringifyValue(); }