*/
public class Annotation {
private int typeIndex;
- private List /* ElementNameValuePair */ evs;
+ private List /* ElementNameValuePair */ evs = new ArrayList();
private ConstantPool cpool;
private boolean isRuntimeVisible;
}
public void addElementNameValuePair(ElementNameValuePair evp) {
- if (evs == null) evs = new ArrayList();
evs.add(evp);
}
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;
* 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 {
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[]{});
--- /dev/null
+@MarkerAnnotationInvisible
+@MarkerAnnotation
+public class MarkedType {
+}
--- /dev/null
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface MarkerAnnotation { }
--- /dev/null
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.CLASS)
+public @interface MarkerAnnotationInvisible { }
suite.addTestSuite(AnnotationGenTest.class);
suite.addTestSuite(ParameterAnnotationsTest.class);
suite.addTestSuite(GeneratingAnnotatedClassesTest.class);
+ suite.addTestSuite(TypeAnnotationsTest.class);
//$JUnit-END$
return suite;
}
super.setUp();
}
-
public void testMethodAnnotations() throws ClassNotFoundException {
JavaClass clazz = getClassFromJar("AnnotatedMethods");
--- /dev/null
+/* *******************************************************************
+ * 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);
+ }
+
+
+}