aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AnnotationGenTest.java67
1 files changed, 66 insertions, 1 deletions
diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AnnotationGenTest.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AnnotationGenTest.java
index a98fcecff..0f6c1e981 100644
--- a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AnnotationGenTest.java
+++ b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AnnotationGenTest.java
@@ -16,8 +16,14 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Vector;
import org.aspectj.apache.bcel.Constants;
+import org.aspectj.apache.bcel.classfile.Utility;
+import org.aspectj.apache.bcel.classfile.Attribute;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleAnnotations;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations;
import org.aspectj.apache.bcel.generic.ClassGen;
import org.aspectj.apache.bcel.generic.ConstantPoolGen;
import org.aspectj.apache.bcel.generic.ObjectType;
@@ -69,7 +75,66 @@ public class AnnotationGenTest extends BcelTestCase {
// Check we can save and load it ok
checkSerialize(a,cp);
}
-
+
+
+ public void testVisibleInvisibleAnnotationGen() {
+
+ // Create the containing class
+ ClassGen cg = createClassGen("HelloWorld");
+ ConstantPoolGen cp = cg.getConstantPool();
+
+ // Create the simple primitive value '4' of type 'int'
+ SimpleElementValueGen evg =
+ new SimpleElementValueGen(ElementValueGen.PRIMITIVE_INT,cp,4);
+
+ // Give it a name, call it 'id'
+ ElementNameValuePairGen nvGen = new ElementNameValuePairGen("id",evg,cp);
+
+ // Check it looks right
+ assertTrue("Should include string 'id=4' but says: "+nvGen.toString(),
+ nvGen.toString().indexOf("id=4")!=-1);
+
+
+ ObjectType t = new ObjectType("SimpleAnnotation");
+
+ List elements = new ArrayList();
+ elements.add(nvGen);
+
+ // Build a RV annotation of type 'SimpleAnnotation' with 'id=4' as the only value :)
+ AnnotationGen a = new AnnotationGen(t,elements,true,cp);
+
+ Vector v = new Vector();
+ v.add(a);
+ Attribute[] attributes = Utility.getAnnotationAttributes(cp, v);
+ boolean foundRV = false;
+ for (int i = 0; i < attributes.length; i++) {
+ Attribute attribute = attributes[i];
+ if (attribute instanceof RuntimeVisibleAnnotations) {
+ assertTrue(((RuntimeAnnotations)attribute).areVisible());
+ foundRV = true;
+
+ }
+ }
+ assertTrue("Should have seen a RuntimeVisibleAnnotation", foundRV);
+
+
+ // Build a RIV annotation of type 'SimpleAnnotation' with 'id=4' as the only value :)
+ AnnotationGen a2 = new AnnotationGen(t,elements,false,cp);
+
+ Vector v2 = new Vector();
+ v2.add(a2);
+ Attribute[] attributes2 = Utility.getAnnotationAttributes(cp, v2);
+ boolean foundRIV = false;
+ for (int i = 0; i < attributes2.length; i++) {
+ Attribute attribute = attributes2[i];
+ if (attribute instanceof RuntimeInvisibleAnnotations) {
+ assertFalse(((RuntimeAnnotations)attribute).areVisible());
+ foundRIV = true;
+ }
+ }
+ assertTrue("Should have seen a RuntimeInvisibleAnnotation", foundRIV);
+ }
+
////
// Helper methods