diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2005-02-27 15:01:18 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2005-02-27 15:01:18 +0000 |
commit | bf8c6f9ca9884e77b0ea328a7b49a008f7f84c39 (patch) | |
tree | d7a7566fb39b9e85ecf02b1fdbfad8eff8f875f7 /src/main/javassist/bytecode/annotation | |
parent | 16ecc51f8205e1cfb39d475a7ddddc820f78fff6 (diff) | |
download | javassist-bf8c6f9ca9884e77b0ea328a7b49a008f7f84c39.tar.gz javassist-bf8c6f9ca9884e77b0ea328a7b49a008f7f84c39.zip |
add support for obtaining default annotation member values (the same patch as Bill's but more javadoc comments)
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@161 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist/bytecode/annotation')
15 files changed, 82 insertions, 34 deletions
diff --git a/src/main/javassist/bytecode/annotation/Annotation.java b/src/main/javassist/bytecode/annotation/Annotation.java index 3373edb4..b9c63b9b 100644 --- a/src/main/javassist/bytecode/annotation/Annotation.java +++ b/src/main/javassist/bytecode/annotation/Annotation.java @@ -109,36 +109,42 @@ public class Annotation { } } - private MemberValue createMemberValue(ConstPool cp, CtClass returnType) + /** + * Makes an instance of <code>MemberValue</code>. + * + * @param cp the constant pool table. + * @param type the type of the member. + */ + public static MemberValue createMemberValue(ConstPool cp, CtClass type) throws javassist.NotFoundException { - if (returnType == CtClass.booleanType) + if (type == CtClass.booleanType) return new BooleanMemberValue(cp); - else if (returnType == CtClass.byteType) + else if (type == CtClass.byteType) return new ByteMemberValue(cp); - else if (returnType == CtClass.charType) + else if (type == CtClass.charType) return new CharMemberValue(cp); - else if (returnType == CtClass.shortType) + else if (type == CtClass.shortType) return new ShortMemberValue(cp); - else if (returnType == CtClass.intType) + else if (type == CtClass.intType) return new IntegerMemberValue(cp); - else if (returnType == CtClass.longType) + else if (type == CtClass.longType) return new LongMemberValue(cp); - else if (returnType == CtClass.floatType) + else if (type == CtClass.floatType) return new FloatMemberValue(cp); - else if (returnType == CtClass.doubleType) + else if (type == CtClass.doubleType) return new DoubleMemberValue(cp); - else if (returnType.getName().equals("java.lang.Class")) + else if (type.getName().equals("java.lang.Class")) return new ClassMemberValue(cp); - else if (returnType.getName().equals("java.lang.String")) + else if (type.getName().equals("java.lang.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 (type.isArray()) { + CtClass arrayType = type.getComponentType(); + MemberValue member = createMemberValue(cp, arrayType); + return new ArrayMemberValue(member, cp); } - else if (returnType.isInterface()) { - Annotation info = new Annotation(cp, returnType); + else if (type.isInterface()) { + Annotation info = new Annotation(cp, type); return new AnnotationMemberValue(info, cp); } else { @@ -146,7 +152,7 @@ public class Annotation { // but JBoss has an Annotation Compiler for JDK 1.4 // and I want it to work with that. - Bill Burke EnumMemberValue emv = new EnumMemberValue(cp); - emv.setType(returnType.getName()); + emv.setType(type.getName()); return emv; } } diff --git a/src/main/javassist/bytecode/annotation/AnnotationMemberValue.java b/src/main/javassist/bytecode/annotation/AnnotationMemberValue.java index 6d99ef33..92b3e2d4 100644 --- a/src/main/javassist/bytecode/annotation/AnnotationMemberValue.java +++ b/src/main/javassist/bytecode/annotation/AnnotationMemberValue.java @@ -63,7 +63,10 @@ public class AnnotationMemberValue extends MemberValue { return value.toString(); } - void write(AnnotationsWriter writer) throws IOException { + /** + * Writes the value. + */ + public void write(AnnotationsWriter writer) throws IOException { writer.annotationValue(); value.write(writer); } diff --git a/src/main/javassist/bytecode/annotation/ArrayMemberValue.java b/src/main/javassist/bytecode/annotation/ArrayMemberValue.java index 27c8ddc0..351ffc56 100644 --- a/src/main/javassist/bytecode/annotation/ArrayMemberValue.java +++ b/src/main/javassist/bytecode/annotation/ArrayMemberValue.java @@ -89,7 +89,10 @@ public class ArrayMemberValue extends MemberValue { return buf.toString(); } - void write(AnnotationsWriter writer) throws IOException { + /** + * Writes the value. + */ + public void write(AnnotationsWriter writer) throws IOException { int num = values.length; writer.arrayValue(num); for (int i = 0; i < num; ++i) diff --git a/src/main/javassist/bytecode/annotation/BooleanMemberValue.java b/src/main/javassist/bytecode/annotation/BooleanMemberValue.java index 64b1e2f7..4f6507e5 100644 --- a/src/main/javassist/bytecode/annotation/BooleanMemberValue.java +++ b/src/main/javassist/bytecode/annotation/BooleanMemberValue.java @@ -76,7 +76,10 @@ public class BooleanMemberValue extends MemberValue { return getValue() ? "true" : "false"; } - void write(AnnotationsWriter writer) throws IOException { + /** + * Writes the value. + */ + public void write(AnnotationsWriter writer) throws IOException { writer.constValueIndex(getValue()); } diff --git a/src/main/javassist/bytecode/annotation/ByteMemberValue.java b/src/main/javassist/bytecode/annotation/ByteMemberValue.java index 5b9cd3ca..043f1d21 100644 --- a/src/main/javassist/bytecode/annotation/ByteMemberValue.java +++ b/src/main/javassist/bytecode/annotation/ByteMemberValue.java @@ -76,7 +76,10 @@ public class ByteMemberValue extends MemberValue { return Byte.toString(getValue()); } - void write(AnnotationsWriter writer) throws IOException { + /** + * Writes the value. + */ + public void write(AnnotationsWriter writer) throws IOException { writer.constValueIndex(getValue()); } diff --git a/src/main/javassist/bytecode/annotation/CharMemberValue.java b/src/main/javassist/bytecode/annotation/CharMemberValue.java index 8bca8183..c01b7b78 100644 --- a/src/main/javassist/bytecode/annotation/CharMemberValue.java +++ b/src/main/javassist/bytecode/annotation/CharMemberValue.java @@ -77,7 +77,10 @@ public class CharMemberValue extends MemberValue { return Character.toString(getValue()); } - void write(AnnotationsWriter writer) throws IOException { + /** + * Writes the value. + */ + public void write(AnnotationsWriter writer) throws IOException { writer.constValueIndex(getValue()); } diff --git a/src/main/javassist/bytecode/annotation/ClassMemberValue.java b/src/main/javassist/bytecode/annotation/ClassMemberValue.java index 0be36b24..90da2c41 100644 --- a/src/main/javassist/bytecode/annotation/ClassMemberValue.java +++ b/src/main/javassist/bytecode/annotation/ClassMemberValue.java @@ -85,7 +85,10 @@ public class ClassMemberValue extends MemberValue { return "<" + getValue() + " class>"; } - void write(AnnotationsWriter writer) throws IOException { + /** + * Writes the value. + */ + public void write(AnnotationsWriter writer) throws IOException { writer.classInfoIndex(valueIndex); } diff --git a/src/main/javassist/bytecode/annotation/DoubleMemberValue.java b/src/main/javassist/bytecode/annotation/DoubleMemberValue.java index b4658bbb..131e35f8 100644 --- a/src/main/javassist/bytecode/annotation/DoubleMemberValue.java +++ b/src/main/javassist/bytecode/annotation/DoubleMemberValue.java @@ -23,7 +23,7 @@ import java.io.IOException; * * @author <a href="mailto:bill@jboss.org">Bill Burke</a> * @author Shigeru Chiba - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ */ public class DoubleMemberValue extends MemberValue { int valueIndex; @@ -78,7 +78,10 @@ public class DoubleMemberValue extends MemberValue { return Double.toString(getValue()); } - void write(AnnotationsWriter writer) throws IOException { + /** + * Writes the value. + */ + public void write(AnnotationsWriter writer) throws IOException { writer.constValueIndex(getValue()); } diff --git a/src/main/javassist/bytecode/annotation/EnumMemberValue.java b/src/main/javassist/bytecode/annotation/EnumMemberValue.java index 95c617ad..44430781 100644 --- a/src/main/javassist/bytecode/annotation/EnumMemberValue.java +++ b/src/main/javassist/bytecode/annotation/EnumMemberValue.java @@ -88,7 +88,10 @@ public class EnumMemberValue extends MemberValue { return getType() + "." + getValue(); } - void write(AnnotationsWriter writer) throws IOException { + /** + * Writes the value. + */ + public void write(AnnotationsWriter writer) throws IOException { writer.enumConstValue(getType(), getValue()); } diff --git a/src/main/javassist/bytecode/annotation/FloatMemberValue.java b/src/main/javassist/bytecode/annotation/FloatMemberValue.java index 5496e379..87e12ab7 100644 --- a/src/main/javassist/bytecode/annotation/FloatMemberValue.java +++ b/src/main/javassist/bytecode/annotation/FloatMemberValue.java @@ -23,7 +23,7 @@ import java.io.IOException; * * @author <a href="mailto:bill@jboss.org">Bill Burke</a> * @author Shigeru Chiba - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ */ public class FloatMemberValue extends MemberValue { int valueIndex; @@ -78,7 +78,10 @@ public class FloatMemberValue extends MemberValue { return Float.toString(getValue()); } - void write(AnnotationsWriter writer) throws IOException { + /** + * Writes the value. + */ + public void write(AnnotationsWriter writer) throws IOException { writer.constValueIndex(getValue()); } diff --git a/src/main/javassist/bytecode/annotation/IntegerMemberValue.java b/src/main/javassist/bytecode/annotation/IntegerMemberValue.java index 9268ee69..e8846276 100644 --- a/src/main/javassist/bytecode/annotation/IntegerMemberValue.java +++ b/src/main/javassist/bytecode/annotation/IntegerMemberValue.java @@ -83,7 +83,10 @@ public class IntegerMemberValue extends MemberValue { return Integer.toString(getValue()); } - void write(AnnotationsWriter writer) throws IOException { + /** + * Writes the value. + */ + public void write(AnnotationsWriter writer) throws IOException { writer.constValueIndex(getValue()); } diff --git a/src/main/javassist/bytecode/annotation/LongMemberValue.java b/src/main/javassist/bytecode/annotation/LongMemberValue.java index c7ec125c..4842792f 100644 --- a/src/main/javassist/bytecode/annotation/LongMemberValue.java +++ b/src/main/javassist/bytecode/annotation/LongMemberValue.java @@ -77,7 +77,10 @@ public class LongMemberValue extends MemberValue { return Long.toString(getValue()); } - void write(AnnotationsWriter writer) throws IOException { + /** + * Writes the value. + */ + public void write(AnnotationsWriter writer) throws IOException { writer.constValueIndex(getValue()); } diff --git a/src/main/javassist/bytecode/annotation/MemberValue.java b/src/main/javassist/bytecode/annotation/MemberValue.java index f2265522..4d0c3554 100644 --- a/src/main/javassist/bytecode/annotation/MemberValue.java +++ b/src/main/javassist/bytecode/annotation/MemberValue.java @@ -38,7 +38,10 @@ public abstract class MemberValue { */ public abstract void accept(MemberValueVisitor visitor); - abstract void write(AnnotationsWriter w) throws IOException; + /** + * Writes the value. + */ + public abstract void write(AnnotationsWriter w) throws IOException; } diff --git a/src/main/javassist/bytecode/annotation/ShortMemberValue.java b/src/main/javassist/bytecode/annotation/ShortMemberValue.java index cd9f9429..fc0a1702 100644 --- a/src/main/javassist/bytecode/annotation/ShortMemberValue.java +++ b/src/main/javassist/bytecode/annotation/ShortMemberValue.java @@ -77,7 +77,10 @@ public class ShortMemberValue extends MemberValue { return Short.toString(getValue()); } - void write(AnnotationsWriter writer) throws IOException { + /** + * Writes the value. + */ + public void write(AnnotationsWriter writer) throws IOException { writer.constValueIndex(getValue()); } diff --git a/src/main/javassist/bytecode/annotation/StringMemberValue.java b/src/main/javassist/bytecode/annotation/StringMemberValue.java index 5e5c9580..4a32e433 100644 --- a/src/main/javassist/bytecode/annotation/StringMemberValue.java +++ b/src/main/javassist/bytecode/annotation/StringMemberValue.java @@ -77,7 +77,10 @@ public class StringMemberValue extends MemberValue { return "\"" + getValue() + "\""; } - void write(AnnotationsWriter writer) throws IOException { + /** + * Writes the value. + */ + public void write(AnnotationsWriter writer) throws IOException { writer.constValueIndex(getValue()); } |