* Comment
*
* @author <a href="mailto:bill@jboss.org">Bill Burke</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*
**/
public class AnnotationInfo
}
+ private MemberValue createMemberValue(ConstPool cp, CtClass returnType) throws javassist.NotFoundException
+ {
+ if (returnType.equals(CtPrimitiveType.booleanType))
+ {
+ return new BooleanMemberValue(cp);
+ }
+ else if (returnType.equals(CtPrimitiveType.byteType))
+ {
+ return new ByteMemberValue(cp);
+ }
+ else if (returnType.equals(CtPrimitiveType.charType))
+ {
+ return new CharMemberValue(cp);
+ }
+ else if (returnType.equals(CtPrimitiveType.doubleType))
+ {
+ return new DoubleMemberValue(cp);
+ }
+ else if (returnType.equals(CtPrimitiveType.floatType))
+ {
+ return new FloatMemberValue(cp);
+ }
+ else if (returnType.equals(CtPrimitiveType.intType))
+ {
+ return new IntegerMemberValue(cp);
+ }
+ else if (returnType.equals(CtPrimitiveType.longType))
+ {
+ return new LongMemberValue(cp);
+ }
+ else if (returnType.equals(CtPrimitiveType.shortType))
+ {
+ return new ShortMemberValue(cp);
+ }
+ else if (returnType.getName().equals("java.lang.Class"))
+ {
+ return new ClassMemberValue(cp);
+ }
+ else if (returnType.getName().equals("java.lang.String") || returnType.getName().equals("String"))
+ {
+ return new StringMemberValue(cp);
+ }
+ else if (returnType.isArray())
+ {
+ CtClass arrayType = returnType.getComponentType();
+ MemberValue type = createMemberValue(cp, arrayType);
+ return new ArrayMemberValue(type, cp);
+ }
+ else if (returnType.isInterface())
+ {
+ AnnotationInfo info = new AnnotationInfo(cp, returnType);
+ return new AnnotationMemberValue(info, cp);
+ }
+ else
+ {
+ throw new RuntimeException("cannot handle member type: " + returnType.getName());
+ }
+ }
+
/**
* todo Enums are not supported right now.
* This is for creation at runtime
for (int i = 0; i < methods.length; i++)
{
CtClass returnType = methods[i].getReturnType();
- if (returnType.equals(CtPrimitiveType.booleanType))
- {
- addMemberValue(methods[i].getName(), new BooleanMemberValue((short) -1));
- }
- else if (returnType.equals(CtPrimitiveType.byteType))
- {
- addMemberValue(methods[i].getName(), new ByteMemberValue((short) -1));
- }
- else if (returnType.equals(CtPrimitiveType.charType))
- {
- addMemberValue(methods[i].getName(), new CharMemberValue((short) -1));
- }
- else if (returnType.equals(CtPrimitiveType.doubleType))
- {
- addMemberValue(methods[i].getName(), new DoubleMemberValue((short) -1));
- }
- else if (returnType.equals(CtPrimitiveType.floatType))
- {
- addMemberValue(methods[i].getName(), new FloatMemberValue((short) -1));
- }
- else if (returnType.equals(CtPrimitiveType.intType))
- {
- addMemberValue(methods[i].getName(), new IntegerMemberValue((short) -1));
- }
- else if (returnType.equals(CtPrimitiveType.longType))
- {
- addMemberValue(methods[i].getName(), new LongMemberValue((short) -1));
- }
- else if (returnType.equals(CtPrimitiveType.shortType))
- {
- addMemberValue(methods[i].getName(), new ShortMemberValue((short) -1));
- }
- else if (returnType.getName().equals("java.lang.Class"))
- {
- addMemberValue(methods[i].getName(), new ClassMemberValue((short) -1));
- }
- else if (returnType.getName().equals("java.lang.String") || returnType.getName().equals("String"))
- {
- addMemberValue(methods[i].getName(), new StringMemberValue((short) -1));
- }
- else if (returnType.isArray())
- {
- addMemberValue(methods[i].getName(), new ArrayMemberValue());
- }
- else if (returnType.isInterface())
- {
- addMemberValue(methods[i].getName(), new AnnotationMemberValue(null));
- }
- else
- {
- throw new RuntimeException("cannot handle member type: " + returnType.getName());
- }
+ addMemberValue(methods[i].getName(), createMemberValue(cp, returnType));
}
}
public void write(DataOutputStream dos) throws IOException
{
dos.writeShort(type_index);
+ if (members == null)
+ {
+ dos.writeShort((short)0);
+ return;
+ }
dos.writeShort(members.size());
Iterator it = members.keySet().iterator();
while (it.hasNext())
*/
package javassist.bytecode.annotation;
+import javassist.bytecode.ConstPool;
+
import java.io.DataOutputStream;
import java.io.IOException;
* Comment
*
* @author <a href="mailto:bill@jboss.org">Bill Burke</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*
**/
public class AnnotationMemberValue extends MemberValue
{
AnnotationInfo annotation;
- public AnnotationMemberValue(AnnotationInfo a)
+ public AnnotationMemberValue(AnnotationInfo a, ConstPool cp)
{
- tag = '@';
+ super('@', cp);
this.annotation = a;
}
+ public AnnotationMemberValue(ConstPool cp)
+ {
+ super('@', cp);
+ }
+
public AnnotationInfo getNestedAnnotation()
{
return annotation;
super.write(dos);
annotation.write(dos);
}
+
+ public void accept(MemberValueVisitor visitor)
+ {
+ visitor.visitAnnotationMemberValue(this);
+ }
+
}
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.StringTokenizer;
/**
* Comment
*
* @author <a href="mailto:bill@jboss.org">Bill Burke</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*
**/
public class ArrayMemberValue extends MemberValue
{
MemberValue[] values;
- public ArrayMemberValue()
+ MemberValue type;
+
+ private ArrayMemberValue(ConstPool cp)
+ {
+ super('[', cp);
+
+ }
+
+ public ArrayMemberValue(MemberValue type, ConstPool cp)
{
- tag = '[';
+ this(cp);
+ this.type = type;
}
public MemberValue[] getValue()
public void setValue(MemberValue[] values)
{
+ if (values != null && values.length > 0) type = values[0];
this.values = values;
}
+ public MemberValue getType()
+ {
+ return type;
+ }
+
public static ArrayMemberValue readArray(ConstPool cp, DataInput di) throws java.io.IOException
{
- ArrayMemberValue rtn = new ArrayMemberValue();
+ ArrayMemberValue rtn = new ArrayMemberValue(cp);
int length = di.readShort();
ArrayList values = new ArrayList(length);
for (int i = 0; i < length; i++)
{
- values.add(MemberValue.readMemberValue(cp, di));
+ MemberValue type = MemberValue.readMemberValue(cp, di);
+ rtn.type = type;
+ values.add(type);
}
- rtn.values = (MemberValue[])values.toArray(new MemberValue[length]);
+ rtn.values = (MemberValue[]) values.toArray(new MemberValue[length]);
return rtn;
}
public void write(DataOutputStream dos) throws IOException
{
super.write(dos);
+ if (values == null)
+ {
+ dos.writeShort(0);
+ return;
+ }
dos.writeShort(values.length);
for (int i = 0; i < values.length; i++)
{
values[i].write(dos);
}
}
+
public String toString()
{
StringBuffer buf = new StringBuffer("{");
- for (int i = 0; i < values.length; i++)
+ if (values != null)
{
- buf.append(values[i].toString());
- if (i + 1 < values.length) buf.append(", ");
+ for (int i = 0; i < values.length; i++)
+ {
+ buf.append(values[i].toString());
+ if (i + 1 < values.length) buf.append(", ");
+ }
}
buf.append("}");
return buf.toString();
}
+
+ public void accept(MemberValueVisitor visitor)
+ {
+ visitor.visitArrayMemberValue(this);
+ }
}
*/
package javassist.bytecode.annotation;
+import javassist.bytecode.ConstPool;
+
import java.io.DataOutputStream;
import java.io.IOException;
* Comment
*
* @author <a href="mailto:bill@jboss.org">Bill Burke</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*
**/
public class BooleanMemberValue extends MemberValue
{
short const_value_index;
- public BooleanMemberValue(short cvi)
+ public BooleanMemberValue(short cvi, ConstPool cp)
{
- tag = 'Z';
+ super('Z', cp);
this.const_value_index = cvi;
}
+ public BooleanMemberValue(ConstPool cp)
+ {
+ super('Z', cp);
+ setValue(false);
+ }
+
public boolean getValue()
{
return cp.getIntegerInfo(const_value_index) == 1;
super.write(dos);
dos.writeShort(const_value_index);
}
+ public void accept(MemberValueVisitor visitor)
+ {
+ visitor.visitBooleanMemberValue(this);
+ }
}
*/
package javassist.bytecode.annotation;
+import javassist.bytecode.ConstPool;
+
import java.io.DataOutputStream;
import java.io.IOException;
* Comment
*
* @author <a href="mailto:bill@jboss.org">Bill Burke</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*
**/
public class ByteMemberValue extends MemberValue
{
short const_value_index;
- public ByteMemberValue(short const_value_index)
+ public ByteMemberValue(short const_value_index, ConstPool cp)
{
- tag = 'B';
+ super('B', cp);
this.const_value_index = const_value_index;
}
+ public ByteMemberValue(ConstPool cp)
+ {
+ super('B', cp);
+ setValue((byte)0);
+ }
+
public byte getValue()
{
return (byte)cp.getIntegerInfo(const_value_index);
super.write(dos);
dos.writeShort(const_value_index);
}
+ public void accept(MemberValueVisitor visitor)
+ {
+ visitor.visitByteMemberValue(this);
+ }
}
*/
package javassist.bytecode.annotation;
+import javassist.bytecode.ConstPool;
+
import java.io.DataOutputStream;
import java.io.IOException;
* Comment
*
* @author <a href="mailto:bill@jboss.org">Bill Burke</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*
**/
public class CharMemberValue extends MemberValue
{
short const_value_index;
- public CharMemberValue(short cvi)
+ public CharMemberValue(short cvi, ConstPool cp)
{
- tag = 'C';
+ super('C', cp);
this.const_value_index = cvi;
}
+ public CharMemberValue(ConstPool cp)
+ {
+ super('C', cp);
+ setValue('\0');
+ }
+
public char getValue()
{
return (char)cp.getIntegerInfo(const_value_index);
super.write(dos);
dos.writeShort(const_value_index);
}
+ public void accept(MemberValueVisitor visitor)
+ {
+ visitor.visitCharMemberValue(this);
+ }
}
*/
package javassist.bytecode.annotation;
+import javassist.bytecode.ConstPool;
+
import java.io.DataOutputStream;
import java.io.IOException;
* Comment
*
* @author <a href="mailto:bill@jboss.org">Bill Burke</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*
**/
public class ClassMemberValue extends MemberValue
{
short class_info_index;
- public ClassMemberValue(short cii)
+ public ClassMemberValue(short cii, ConstPool cp)
{
- tag = 'c';
+ super('c', cp);
this.class_info_index = cii;
}
+ public ClassMemberValue(ConstPool cp)
+ {
+ super('c', cp);
+ setClassName("java.lang.Class");
+ }
+
public String getClassName()
{
return cp.getClassInfo(class_info_index);
super.write(dos);
dos.writeShort(class_info_index);
}
+ public void accept(MemberValueVisitor visitor)
+ {
+ visitor.visitClassMemberValue(this);
+ }
}
*/
package javassist.bytecode.annotation;
+import javassist.bytecode.ConstPool;
+
import java.io.DataOutputStream;
import java.io.IOException;
* Comment
*
* @author <a href="mailto:bill@jboss.org">Bill Burke</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*
**/
public class DoubleMemberValue extends MemberValue
{
short const_value_index;
- public DoubleMemberValue(short cvi)
+ public DoubleMemberValue(short cvi, ConstPool cp)
{
- tag = 'D';
+ super('D', cp);
this.const_value_index = cvi;
}
+ public DoubleMemberValue(ConstPool cp)
+ {
+ super('D', cp);
+ setValue(0);
+ }
+
public double getValue()
{
return cp.getDoubleInfo(const_value_index);
super.write(dos);
dos.writeShort(const_value_index);
}
+ public void accept(MemberValueVisitor visitor)
+ {
+ visitor.visitDoubleMemberValue(this);
+ }
}
*/
package javassist.bytecode.annotation;
+import javassist.bytecode.ConstPool;
+
import java.io.DataOutputStream;
import java.io.IOException;
* Comment
*
* @author <a href="mailto:bill@jboss.org">Bill Burke</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*
**/
public class EnumMemberValue extends MemberValue
short type_name_index;
short const_name_index;
- public EnumMemberValue(short type, short cni)
+ public EnumMemberValue(short type, short cni, ConstPool cp)
{
- tag = 'e';
+ super('e', cp);
this.type_name_index = type;
this.const_name_index = cni;
}
dos.writeShort(type_name_index);
dos.writeShort(const_name_index);
}
+ public void accept(MemberValueVisitor visitor)
+ {
+ visitor.visitEnumMemberValue(this);
+ }
}
*/
package javassist.bytecode.annotation;
+import javassist.bytecode.ConstPool;
+
import java.io.DataOutputStream;
import java.io.IOException;
* Comment
*
* @author <a href="mailto:bill@jboss.org">Bill Burke</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*
**/
public class FloatMemberValue extends MemberValue
{
short const_value_index;
- public FloatMemberValue(short cvi)
+ public FloatMemberValue(short cvi, ConstPool cp)
{
- tag = 'F';
+ super('F', cp);
this.const_value_index = cvi;
}
+ public FloatMemberValue(ConstPool cp)
+ {
+ super('F', cp);
+ setValue(0);
+ }
+
public float getValue()
{
return cp.getFloatInfo(const_value_index);
super.write(dos);
dos.writeShort(const_value_index);
}
+ public void accept(MemberValueVisitor visitor)
+ {
+ visitor.visitFloatMemberValue(this);
+ }
}
*/
package javassist.bytecode.annotation;
+import javassist.bytecode.ConstPool;
+
import java.io.DataOutputStream;
import java.io.IOException;
* Comment
*
* @author <a href="mailto:bill@jboss.org">Bill Burke</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*
**/
public class IntegerMemberValue extends MemberValue
{
short const_value_index;
- public IntegerMemberValue(short cvi)
+ public IntegerMemberValue(short cvi, ConstPool cp)
{
- tag = 'I';
+ super('I', cp);
this.const_value_index = cvi;
}
+ public IntegerMemberValue(ConstPool cp)
+ {
+ super('I', cp);
+ setValue(0);
+ }
+
public int getValue()
{
return cp.getIntegerInfo(const_value_index);
super.write(dos);
dos.writeShort(const_value_index);
}
+ public void accept(MemberValueVisitor visitor)
+ {
+ visitor.visitIntegerMemberValue(this);
+ }
}
*/
package javassist.bytecode.annotation;
+import javassist.bytecode.ConstPool;
+
import java.io.DataOutputStream;
import java.io.IOException;
* Comment
*
* @author <a href="mailto:bill@jboss.org">Bill Burke</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*
**/
public class LongMemberValue extends MemberValue
{
short const_value_index;
- public LongMemberValue(short cvi)
+ public LongMemberValue(short cvi, ConstPool cp)
{
- tag = 'J';
+ super('J', cp);
this.const_value_index = cvi;
}
+ public LongMemberValue(ConstPool cp)
+ {
+ super('J', cp);
+ setValue(0);
+ }
+
public long getValue()
{
return cp.getLongInfo(const_value_index);
super.write(dos);
dos.writeShort(const_value_index);
}
+ public void accept(MemberValueVisitor visitor)
+ {
+ visitor.visitLongMemberValue(this);
+ }
}
* Comment
*
* @author <a href="mailto:bill@jboss.org">Bill Burke</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*
**/
public abstract class MemberValue
ConstPool cp;
char tag;
+ protected MemberValue(char tag, ConstPool cp)
+ {
+ this.cp = cp;
+ this.tag = tag;
+ }
+
+ public abstract void accept(MemberValueVisitor visitor);
public void write(DataOutputStream dos) throws IOException
{
byte btag = (byte)tag;
dos.writeByte(btag);
}
+
public static MemberValue readMemberValue(ConstPool cp, DataInput di) throws java.io.IOException
{
byte btag = di.readByte();
switch (tag)
{
case 'B':
- rtn = new ByteMemberValue(di.readShort());
+ rtn = new ByteMemberValue(di.readShort(), cp);
break;
case 'C':
- rtn = new CharMemberValue(di.readShort());
+ rtn = new CharMemberValue(di.readShort(), cp);
break;
case 'D':
- rtn = new DoubleMemberValue(di.readShort());
+ rtn = new DoubleMemberValue(di.readShort(), cp);
break;
case 'F':
- rtn = new FloatMemberValue(di.readShort());
+ rtn = new FloatMemberValue(di.readShort(), cp);
break;
case 'I':
- rtn = new IntegerMemberValue(di.readShort());
+ rtn = new IntegerMemberValue(di.readShort(), cp);
break;
case 'J':
- rtn = new LongMemberValue(di.readShort());
+ rtn = new LongMemberValue(di.readShort(), cp);
break;
case 'S':
- rtn = new ShortMemberValue(di.readShort());
+ rtn = new ShortMemberValue(di.readShort(), cp);
break;
case 'Z':
- rtn = new BooleanMemberValue(di.readShort());
+ rtn = new BooleanMemberValue(di.readShort(), cp);
break;
case 's':
- rtn = new StringMemberValue(di.readShort());
+ rtn = new StringMemberValue(di.readShort(), cp);
break;
case 'e':
- rtn = new EnumMemberValue(di.readShort(), di.readShort());
+ rtn = new EnumMemberValue(di.readShort(), di.readShort(), cp);
break;
case 'c':
- rtn = new ClassMemberValue(di.readShort());
+ rtn = new ClassMemberValue(di.readShort(), cp);
break;
case '@':
- rtn = new AnnotationMemberValue(AnnotationInfo.readAnnotationInfo(cp, di));
+ rtn = new AnnotationMemberValue(AnnotationInfo.readAnnotationInfo(cp, di), cp);
break;
case '[':
rtn = ArrayMemberValue.readArray(cp, di);
--- /dev/null
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package javassist.bytecode.annotation;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
+ * @version $Revision: 1.1 $
+ *
+ **/
+public interface MemberValueVisitor
+{
+ public void visitAnnotationMemberValue(AnnotationMemberValue node);
+ public void visitArrayMemberValue(ArrayMemberValue node);
+ public void visitBooleanMemberValue(BooleanMemberValue node);
+ public void visitByteMemberValue(ByteMemberValue node);
+ public void visitCharMemberValue(CharMemberValue node);
+ public void visitDoubleMemberValue(DoubleMemberValue node);
+ public void visitEnumMemberValue(EnumMemberValue node);
+ public void visitFloatMemberValue(FloatMemberValue node);
+ public void visitIntegerMemberValue(IntegerMemberValue node);
+ public void visitLongMemberValue(LongMemberValue node);
+ public void visitShortMemberValue(ShortMemberValue node);
+ public void visitStringMemberValue(StringMemberValue node);
+ public void visitClassMemberValue(ClassMemberValue node);
+}
*/
package javassist.bytecode.annotation;
+import javassist.bytecode.ConstPool;
+
import java.io.DataOutputStream;
import java.io.IOException;
* Comment
*
* @author <a href="mailto:bill@jboss.org">Bill Burke</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*
**/
public class ShortMemberValue extends MemberValue
{
short const_value_index;
- public ShortMemberValue(short cvi)
+ public ShortMemberValue(short cvi, ConstPool cp)
{
- tag = 'S';
+ super('S', cp);
this.const_value_index = cvi;
}
+ public ShortMemberValue(ConstPool cp)
+ {
+ super('S', cp);
+ setValue((short)0);
+ }
+
public short getValue()
{
return (short)cp.getIntegerInfo(const_value_index);
super.write(dos);
dos.writeShort(const_value_index);
}
+ public void accept(MemberValueVisitor visitor)
+ {
+ visitor.visitShortMemberValue(this);
+ }
}
*/
package javassist.bytecode.annotation;
+import javassist.bytecode.ConstPool;
+
import java.io.DataOutputStream;
import java.io.IOException;
* Comment
*
* @author <a href="mailto:bill@jboss.org">Bill Burke</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*
**/
public class StringMemberValue extends MemberValue
{
short const_value_index;
- public StringMemberValue(short cvi)
+ public StringMemberValue(short cvi, ConstPool cp)
{
- tag = 's';
+ super('s', cp);
this.const_value_index = cvi;
}
+ public StringMemberValue(ConstPool cp)
+ {
+ super('s', cp);
+ setValue("");
+ }
+
public String getValue()
{
return cp.getUtf8Info(const_value_index);
super.write(dos);
dos.writeShort(const_value_index);
}
+ public void accept(MemberValueVisitor visitor)
+ {
+ visitor.visitStringMemberValue(this);
+ }
}