]> source.dussan.org Git - aspectj.git/commitdiff
declare annotation on type XML support
authorAndy Clement <andrew.clement@gmail.com>
Thu, 12 Apr 2012 00:33:59 +0000 (17:33 -0700)
committerAndy Clement <andrew.clement@gmail.com>
Thu, 12 Apr 2012 00:33:59 +0000 (17:33 -0700)
loadtime/src/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java
tests/bugs170/xmldefs/Anno7.java [new file with mode: 0644]
tests/bugs170/xmldefs/Hello7.java [new file with mode: 0644]
tests/bugs170/xmldefs/aop7.xml [new file with mode: 0644]

index bc6695e3ed7b3c3ba949b255c4b5601cfa228239..620b84874a22332a08a9ee09a541f5643678e34a 100644 (file)
@@ -63,6 +63,7 @@ import org.aspectj.weaver.patterns.NamePattern;
 import org.aspectj.weaver.patterns.PatternParser;
 import org.aspectj.weaver.patterns.PerClause;
 import org.aspectj.weaver.patterns.PerSingleton;
+import org.aspectj.weaver.patterns.TypePattern;
 
 /**
  * Generates bytecode for concrete-aspect.
@@ -551,23 +552,31 @@ public class ConcreteAspectCodeGen {
                if (constructedAnnotation==null) {
                        return; // error occurred (and was reported), do not continue
                }
+
+               String nameComponent = da.declareAnnotationKind.name().toLowerCase();           
+               String declareName = new StringBuilder("ajc$declare_at_").append(nameComponent).append("_").append(decCounter).toString();                      
+               LazyMethodGen declareMethod = new LazyMethodGen(Modifier.PUBLIC, Type.VOID, declareName, Type.NO_ARGS, EMPTY_STRINGS, cg);
+               InstructionList declareMethodBody = declareMethod.getBody();
+               declareMethodBody.append(InstructionFactory.RETURN);
+               declareMethod.addAnnotation(constructedAnnotation);
+
+               DeclareAnnotation deca = null;
+               ITokenSource tokenSource = BasicTokenSource.makeTokenSource(da.pattern,null);
+               PatternParser pp = new PatternParser(tokenSource);
+
                if (da.declareAnnotationKind==DeclareAnnotationKind.Method || da.declareAnnotationKind==DeclareAnnotationKind.Field) {  
-                       String declareName = new StringBuilder("ajc$declare_at_").append(da.declareAnnotationKind==DeclareAnnotationKind.Method?"method":"field").append("_").append(decCounter).toString();                    
-                       LazyMethodGen declareMethod = new LazyMethodGen(Modifier.PUBLIC, Type.VOID, declareName, Type.NO_ARGS, EMPTY_STRINGS, cg);
-                       InstructionList declareMethodBody = declareMethod.getBody();
-                       declareMethodBody.append(InstructionFactory.RETURN);
-                       declareMethod.addAnnotation(constructedAnnotation);
-
-                       ITokenSource tokenSource = BasicTokenSource.makeTokenSource(da.pattern,null);
-                       PatternParser pp = new PatternParser(tokenSource);
                        ISignaturePattern isp = (da.declareAnnotationKind==DeclareAnnotationKind.Method?pp.parseCompoundMethodOrConstructorSignaturePattern(true):pp.parseCompoundFieldSignaturePattern());
-                       DeclareAnnotation deca = new DeclareAnnotation(da.declareAnnotationKind==DeclareAnnotationKind.Method?DeclareAnnotation.AT_METHOD:DeclareAnnotation.AT_FIELD, isp);
-                       deca.setAnnotationMethod(declareName);
-                       deca.setAnnotationString(da.annotation);
-                       AjAttribute attribute = new AjAttribute.DeclareAttribute(deca);
-                       cg.addAttribute(attribute);
-                       cg.addMethodGen(declareMethod);
+                       deca = new DeclareAnnotation(da.declareAnnotationKind==DeclareAnnotationKind.Method?DeclareAnnotation.AT_METHOD:DeclareAnnotation.AT_FIELD, isp);
+               } else if (da.declareAnnotationKind==DeclareAnnotationKind.Type) {                      
+                       TypePattern tp = pp.parseTypePattern();
+                       deca = new DeclareAnnotation(DeclareAnnotation.AT_TYPE,tp);
                }
+               
+               deca.setAnnotationMethod(declareName);
+               deca.setAnnotationString(da.annotation);
+               AjAttribute attribute = new AjAttribute.DeclareAttribute(deca);
+               cg.addAttribute(attribute);
+               cg.addMethodGen(declareMethod);
        }
 
        /**
diff --git a/tests/bugs170/xmldefs/Anno7.java b/tests/bugs170/xmldefs/Anno7.java
new file mode 100644 (file)
index 0000000..36fdeb3
--- /dev/null
@@ -0,0 +1,5 @@
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Anno7 {
+}
diff --git a/tests/bugs170/xmldefs/Hello7.java b/tests/bugs170/xmldefs/Hello7.java
new file mode 100644 (file)
index 0000000..ed43f01
--- /dev/null
@@ -0,0 +1,39 @@
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.util.Collections;
+import java.util.*;
+
+public class Hello7 {
+
+
+        public static void main(String[] args) {
+                printAnnos(Hello7.class);
+        } 
+
+        public static void printAnnos(Class clazz) {
+               try {
+                       Annotation[] annos = clazz.getAnnotations();
+                       System.out.println("Annotations on "+clazz.getName()+"? "+(annos!=null && annos.length!=0));
+                       if (annos!=null && annos.length>0) {
+                               List<Annotation> la = new ArrayList<Annotation>();
+                               for (Annotation anno: annos) {
+                                       la.add(anno);
+                               }
+                               Collections.<Annotation>sort(la,new AnnoComparator());
+                               
+                               System.out.println("Annotation count is "+annos.length);
+                               for (Annotation anno: la) {
+                                       System.out.println(anno);
+                               }
+                       }
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+        }
+        
+        static class AnnoComparator implements Comparator<Annotation> {
+               public int compare(Annotation a, Annotation b) {
+                       return a.toString().compareTo(b.toString());
+               }
+        }
+}
diff --git a/tests/bugs170/xmldefs/aop7.xml b/tests/bugs170/xmldefs/aop7.xml
new file mode 100644 (file)
index 0000000..048163f
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<aspectj>
+  <aspects>
+    <concrete-aspect name="ConjuredUp">
+      <declare-annotation type="H*" annotation="@Anno7"/>
+    </concrete-aspect>
+  </aspects>
+
+  <weaver options="-Xreweavable -verbose -XlazyTjp -showWeaveInfo">
+    <include within="Hello7"/>
+  </weaver> 
+</aspectj>
+