From bf8c6f9ca9884e77b0ea328a7b49a008f7f84c39 Mon Sep 17 00:00:00 2001 From: chiba Date: Sun, 27 Feb 2005 15:01:18 +0000 Subject: 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 --- .../javassist/bytecode/AnnotationsAttribute.java | 53 ++++++++++++++++++---- 1 file changed, 43 insertions(+), 10 deletions(-) (limited to 'src/main/javassist/bytecode/AnnotationsAttribute.java') diff --git a/src/main/javassist/bytecode/AnnotationsAttribute.java b/src/main/javassist/bytecode/AnnotationsAttribute.java index 34c82c4c..d3cb9494 100644 --- a/src/main/javassist/bytecode/AnnotationsAttribute.java +++ b/src/main/javassist/bytecode/AnnotationsAttribute.java @@ -38,12 +38,14 @@ import javassist.bytecode.annotation.*; *

For example, * *

* @@ -51,6 +53,31 @@ import javassist.bytecode.annotation.*; * from the MethodInfo object specified by minfo. * Then, it prints the value of name in Author. * + *

If the annotation type Author is annotated by a meta annotation: + * + *

+ * + *

Then Author is visible at runtime. Therefore, the third + * statement of the code snippet above must be changed into: + * + *

+ * + *

The attribute tag must be visibleTag instead of + * invisibleTag. + * + *

If the member value of an annotation is not specified, the default value + * is used as that member value. If so, getMemberValue() in + * Annotation returns null + * since the default value is not included in the + * AnnotationsAttribute. It is included in the + * AnnotationDefaultAttribute of the method declared in the + * annotation type. + * *

If you want to record a new AnnotationAttribute object, execute the * following snippet: * @@ -65,6 +92,7 @@ import javassist.bytecode.annotation.*; * cf.addAttribute(attr); * * + * @see AnnotationDefaultAttribute * @see javassist.bytecode.annotation.Annotation */ public class AnnotationsAttribute extends AttributeInfo { @@ -448,7 +476,7 @@ public class AnnotationsAttribute extends AttributeInfo { Annotation[][] allParams; // all parameters Annotation[] allAnno; // all annotations Annotation currentAnno; // current annotation - MemberValue memberValue; + MemberValue currentMember; // current member /** * Constructs a parser. This parser constructs a parse tree of @@ -472,6 +500,11 @@ public class AnnotationsAttribute extends AttributeInfo { return allAnno; } + MemberValue parseMemberValue() throws Exception { + memberValue(0); + return currentMember; + } + void parameters(int numParam, int pos) throws Exception { Annotation[][] params = new Annotation[numParam][]; for (int i = 0; i < numParam; ++i) { @@ -500,7 +533,7 @@ public class AnnotationsAttribute extends AttributeInfo { int memberValuePair(int pos, int nameIndex) throws Exception { pos = super.memberValuePair(pos, nameIndex); - currentAnno.addMemberValue(nameIndex, memberValue); + currentAnno.addMemberValue(nameIndex, currentMember); return pos; } @@ -539,27 +572,27 @@ public class AnnotationsAttribute extends AttributeInfo { throw new RuntimeException("unknown tag:" + tag); } - memberValue = m; + currentMember = m; super.constValueMember(tag, index); } void enumMemberValue(int typeNameIndex, int constNameIndex) throws Exception { - memberValue = new EnumMemberValue(typeNameIndex, + currentMember = new EnumMemberValue(typeNameIndex, constNameIndex, pool); super.enumMemberValue(typeNameIndex, constNameIndex); } void classMemberValue(int index) throws Exception { - memberValue = new ClassMemberValue(index, pool); + currentMember = new ClassMemberValue(index, pool); super.classMemberValue(index); } int annotationMemberValue(int pos) throws Exception { Annotation anno = currentAnno; pos = super.annotationMemberValue(pos); - memberValue = new AnnotationMemberValue(currentAnno, pool); + currentMember = new AnnotationMemberValue(currentAnno, pool); currentAnno = anno; return pos; } @@ -569,11 +602,11 @@ public class AnnotationsAttribute extends AttributeInfo { MemberValue[] elements = new MemberValue[num]; for (int i = 0; i < num; ++i) { pos = memberValue(pos); - elements[i] = memberValue; + elements[i] = currentMember; } amv.setValue(elements); - memberValue = amv; + currentMember = amv; return pos; } } -- cgit v1.2.3