]> source.dussan.org Git - aspectj.git/commitdiff
Allows for MarkerAnnotations - doh! (i.e. ones with no values) and unpacks invis...
authoraclement <aclement>
Thu, 9 Dec 2004 15:19:39 +0000 (15:19 +0000)
committeraclement <aclement>
Thu, 9 Dec 2004 15:19:39 +0000 (15:19 +0000)
bcel-builder/src/org/aspectj/apache/bcel/classfile/annotation/Annotation.java
bcel-builder/src/org/aspectj/apache/bcel/generic/ClassGen.java
bcel-builder/testdata/MarkedType.java [new file with mode: 0644]
bcel-builder/testdata/MarkerAnnotation.java [new file with mode: 0644]
bcel-builder/testdata/MarkerAnnotationInvisible.java [new file with mode: 0644]
bcel-builder/testdata/testcode.jar
bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/AllTests.java
bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/MethodAnnotationsTest.java
bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/TypeAnnotationsTest.java [new file with mode: 0644]
lib/bcel/bcel-src.zip
lib/bcel/bcel.jar

index f5c28001806feb1393c3cf7da2c96cecc3f65ea0..ca7a8ec8d22f39a1d73cc4f946323158c0a6853d 100644 (file)
@@ -30,7 +30,7 @@ import org.aspectj.apache.bcel.classfile.Utility;
  */
 public class Annotation {
        private int typeIndex;
-       private List /* ElementNameValuePair */ evs;
+       private List /* ElementNameValuePair */ evs = new ArrayList();
        private ConstantPool cpool;
        private boolean isRuntimeVisible;
        
@@ -74,7 +74,6 @@ public class Annotation {
        }
        
        public void addElementNameValuePair(ElementNameValuePair evp) {
-               if (evs == null) evs = new ArrayList();
                evs.add(evp);
        }
        
index 93e5ca8fb233841d9b10d030d71acc8be72907a1..a4fd19d13552cba098c28f4566e6a76ff7dbe1e3 100644 (file)
@@ -68,6 +68,7 @@ import org.aspectj.apache.bcel.classfile.Method;
 import org.aspectj.apache.bcel.classfile.SourceFile;
 import org.aspectj.apache.bcel.classfile.Utility;
 import org.aspectj.apache.bcel.classfile.annotation.Annotation;
+import org.aspectj.apache.bcel.classfile.annotation.RuntimeInvisibleAnnotations;
 import org.aspectj.apache.bcel.classfile.annotation.RuntimeVisibleAnnotations;
 import org.aspectj.apache.bcel.generic.annotation.AnnotationGen;
 
@@ -76,7 +77,7 @@ import org.aspectj.apache.bcel.generic.annotation.AnnotationGen;
  * existing java class (file).
  *
  * @see JavaClass
- * @version $Id: ClassGen.java,v 1.3 2004/11/22 08:31:27 aclement Exp $
+ * @version $Id: ClassGen.java,v 1.4 2004/12/09 15:19:39 aclement Exp $
  * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
  */
 public class ClassGen extends AccessFlags implements Cloneable {
@@ -200,6 +201,13 @@ public class ClassGen extends AccessFlags implements Cloneable {
                                Annotation a = (Annotation) iter.next();
                                annotationGenObjs.add(new AnnotationGen(a,getConstantPool()));
                        }
+               } else if (attr instanceof RuntimeInvisibleAnnotations) {
+                       RuntimeInvisibleAnnotations ria = (RuntimeInvisibleAnnotations)attr;
+                       List annos = ria.getAnnotations();
+                       for (Iterator iter = annos.iterator(); iter.hasNext();) {
+                               Annotation a = (Annotation) iter.next();
+                               annotationGenObjs.add(new AnnotationGen(a,getConstantPool()));
+                       }
                }
        }
        return (AnnotationGen[])annotationGenObjs.toArray(new AnnotationGen[]{});
diff --git a/bcel-builder/testdata/MarkedType.java b/bcel-builder/testdata/MarkedType.java
new file mode 100644 (file)
index 0000000..2b09484
--- /dev/null
@@ -0,0 +1,4 @@
+@MarkerAnnotationInvisible
+@MarkerAnnotation
+public class MarkedType {
+}
diff --git a/bcel-builder/testdata/MarkerAnnotation.java b/bcel-builder/testdata/MarkerAnnotation.java
new file mode 100644 (file)
index 0000000..f314a94
--- /dev/null
@@ -0,0 +1,4 @@
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface MarkerAnnotation { }
diff --git a/bcel-builder/testdata/MarkerAnnotationInvisible.java b/bcel-builder/testdata/MarkerAnnotationInvisible.java
new file mode 100644 (file)
index 0000000..9b41a59
--- /dev/null
@@ -0,0 +1,4 @@
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.CLASS)
+public @interface MarkerAnnotationInvisible { }
index cbfaa1a2d13df055c0a8e6a7f05a003eac49caf0..3324bf3403293c76bc448284314368564c2f2e36 100644 (file)
Binary files a/bcel-builder/testdata/testcode.jar and b/bcel-builder/testdata/testcode.jar differ
index 69d41d6b84da7547e31c451c1710825ba314d31b..c2a087166151a3c8ecb0dd3f1e927294c2ed8f95 100644 (file)
@@ -48,6 +48,7 @@ public class AllTests {
                suite.addTestSuite(AnnotationGenTest.class);
                suite.addTestSuite(ParameterAnnotationsTest.class);
                suite.addTestSuite(GeneratingAnnotatedClassesTest.class);
+               suite.addTestSuite(TypeAnnotationsTest.class);
                //$JUnit-END$
                return suite;
        }
index 5740add02520ea618d81de3808108a4a83218fa1..dab8e7cf35184a9531a5b46a18d87ec73cb2e380 100644 (file)
@@ -30,7 +30,6 @@ public class MethodAnnotationsTest extends BcelTestCase {
                super.setUp();
        }
        
-       
        public void testMethodAnnotations() throws ClassNotFoundException {
                JavaClass clazz = getClassFromJar("AnnotatedMethods");
                
diff --git a/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/TypeAnnotationsTest.java b/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/TypeAnnotationsTest.java
new file mode 100644 (file)
index 0000000..88313fa
--- /dev/null
@@ -0,0 +1,35 @@
+/* *******************************************************************
+ * Copyright (c) 2004 IBM
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Common Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://www.eclipse.org/legal/cpl-v10.html 
+ *  
+ * Contributors: 
+ *     Andy Clement -     initial implementation 
+ * ******************************************************************/
+
+package org.aspectj.apache.bcel.classfile.tests;
+
+import org.aspectj.apache.bcel.classfile.JavaClass;
+import org.aspectj.apache.bcel.generic.ClassGen;
+import org.aspectj.apache.bcel.generic.annotation.AnnotationGen;
+
+
+public class TypeAnnotationsTest extends BcelTestCase {
+       
+
+       protected void setUp() throws Exception {
+               super.setUp();
+       }
+       
+       public void testMarkerAnnotationsOnTypes() throws ClassNotFoundException {
+               JavaClass clazz = getClassFromJar("MarkedType");
+               ClassGen cg = new ClassGen(clazz);
+               AnnotationGen[] annotations = cg.getAnnotations();
+               assertTrue("Should be a MarkerAnnotation and a MarkerAnnotationInvisible - but found: "+annotations.length,annotations.length==2);
+       }
+       
+       
+}
index 75442a25a4c42c7e865e7f2b5cf2fc41dff7277b..14d4fd61071dda7d22025ec0fdc24aa8b4e08f7e 100644 (file)
Binary files a/lib/bcel/bcel-src.zip and b/lib/bcel/bcel-src.zip differ
index 864a40e16059ea3250029518f5de9f81b72558f3..3d5db140e9874495cee103da36326624ce79c9f9 100644 (file)
Binary files a/lib/bcel/bcel.jar and b/lib/bcel/bcel.jar differ