]> source.dussan.org Git - aspectj.git/commitdiff
Declare annotation: support for new declare collections.
authoraclement <aclement>
Thu, 10 Mar 2005 17:37:46 +0000 (17:37 +0000)
committeraclement <aclement>
Thu, 10 Mar 2005 17:37:46 +0000 (17:37 +0000)
weaver/src/org/aspectj/weaver/CrosscuttingMembers.java
weaver/src/org/aspectj/weaver/CrosscuttingMembersSet.java
weaver/src/org/aspectj/weaver/World.java

index e02b8a2141ae442a3dda16066e3c399f6c9e6a25..5787f39c61466908fbbe8306badd9627fc386d61 100644 (file)
@@ -53,6 +53,10 @@ public class CrosscuttingMembers {
        private List declareSofts = new ArrayList(0);
        private List declareDominates = new ArrayList(4);
        
+       // These are like declare parents type mungers
+       private List declareAnnotationsOnType    = new ArrayList();
+       private List declareAnnotationsOnField   = new ArrayList();
+       private List declareAnnotationsOnMethods = new ArrayList(); // includes ctors
        
        public CrosscuttingMembers(ResolvedTypeX inAspect) {
                this.inAspect = inAspect;
@@ -116,7 +120,16 @@ public class CrosscuttingMembers {
                        declareSofts.add(new DeclareSoft(d.getException(), concretePointcut));
                        addConcreteShadowMunger(m);
                } else if (declare instanceof DeclareAnnotation) {
-                       System.err.println("Need to implement CrosscuttingMembers.addDeclare for annotations");
+                   // FIXME asc perf Possible Improvement. Investigate why this is called twice in a weave ?
+                       DeclareAnnotation da = (DeclareAnnotation)declare;
+                       da.setAspect(this.inAspect);
+                       if (da.isDeclareAtType()) {
+                               declareAnnotationsOnType.add(da);       
+                       } else if (da.isDeclareAtField()) {
+                               declareAnnotationsOnField.add(da);
+                       } else if (da.isDeclareAtMethod() || da.isDeclareAtConstuctor()) {
+                               declareAnnotationsOnMethods.add(da);
+                       }
                } else {
                        throw new RuntimeException("unimplemented");
                }
@@ -199,6 +212,22 @@ public class CrosscuttingMembers {
                        declareSofts = other.declareSofts;
                }
                
+               // DECAT for when attempting to replace an aspect
+               if (!declareAnnotationsOnType.equals(other.declareAnnotationsOnType)) {
+                       changed = true;
+                       declareAnnotationsOnType = other.declareAnnotationsOnType;
+               }
+               
+               if (!declareAnnotationsOnField.equals(other.declareAnnotationsOnField)) {
+                       changed = true;
+                       declareAnnotationsOnField = other.declareAnnotationsOnField;
+               }
+               
+               if (!declareAnnotationsOnMethods.equals(other.declareAnnotationsOnMethods)) {
+                       changed = true;
+                       declareAnnotationsOnMethods = other.declareAnnotationsOnMethods;
+               }
+               
                return changed;
        }
 
@@ -229,5 +258,20 @@ public class CrosscuttingMembers {
        public List getTypeMungers() {
                return typeMungers;
        }
+       
+       public List getDeclareAnnotationOnTypes() {
+               return declareAnnotationsOnType;
+       }
+       
+       public List getDeclareAnnotationOnFields() {
+               return declareAnnotationsOnField;
+       }
+       
+    /**
+     * includes declare @method and @constructor
+     */
+       public List getDeclareAnnotationOnMethods() {
+               return declareAnnotationsOnMethods;
+       }
 
 }
index f8db5c29a22d6bd5be559f7d1de6538dd323238b..44f050d11a439a408095962f34b73025f8d3ebe5 100644 (file)
@@ -37,6 +37,9 @@ public class CrosscuttingMembersSet {
        private List typeMungers = null;
        private List declareSofts = null;
        private List declareParents = null;
+       private List declareAnnotationOnTypes   = null;
+       private List declareAnnotationOnFields = null; 
+       private List declareAnnotationOnMethods= null; // includes ctors
        private List declareDominates = null;
        
        public CrosscuttingMembersSet(World world) {
@@ -138,6 +141,43 @@ public class CrosscuttingMembersSet {
                return declareParents;
        }
        
+       // DECAT Merge multiple together
+       public List getDeclareAnnotationOnTypes() {
+               if (declareAnnotationOnTypes == null) {
+                       ArrayList ret = new ArrayList();
+                       for (Iterator i = members.values().iterator(); i.hasNext(); ) {
+                               ret.addAll(((CrosscuttingMembers)i.next()).getDeclareAnnotationOnTypes());
+                       }
+                       declareAnnotationOnTypes = ret;
+               }
+               return declareAnnotationOnTypes;
+       }
+       
+       public List getDeclareAnnotationOnFields() {
+               if (declareAnnotationOnFields == null) {
+                       ArrayList ret = new ArrayList();
+                       for (Iterator i = members.values().iterator(); i.hasNext(); ) {
+                               ret.addAll(((CrosscuttingMembers)i.next()).getDeclareAnnotationOnFields());
+                       }
+                       declareAnnotationOnFields = ret;
+               }
+               return declareAnnotationOnFields;
+       }
+       
+       /**
+        * Return an amalgamation of the declare @method/@constructor statements.
+        */
+       public List getDeclareAnnotationOnMethods() {
+               if (declareAnnotationOnMethods == null) {
+                       ArrayList ret = new ArrayList();
+                       for (Iterator i = members.values().iterator(); i.hasNext(); ) {
+                               ret.addAll(((CrosscuttingMembers)i.next()).getDeclareAnnotationOnMethods());
+                       }
+                       declareAnnotationOnMethods = ret;
+               }
+               return declareAnnotationOnMethods;
+       }
+       
        public List getDeclareDominates() {
                if (declareDominates == null) {
                        ArrayList ret = new ArrayList();
index 228eeb3f1e36d59911a5ad0e2a18f400e566a768..a21414538a5542dfc6ffab6965b03cb006b66a0b 100644 (file)
@@ -400,6 +400,18 @@ public abstract class World implements Dump.INode {
        public List getDeclareParents() {
                return crosscuttingMembersSet.getDeclareParents();
        }
+       
+       public List getDeclareAnnotationOnTypes() {
+               return crosscuttingMembersSet.getDeclareAnnotationOnTypes();
+       }
+       
+       public List getDeclareAnnotationOnFields() {
+               return crosscuttingMembersSet.getDeclareAnnotationOnFields();
+       }
+       
+       public List getDeclareAnnotationOnMethods() {
+               return crosscuttingMembersSet.getDeclareAnnotationOnMethods();
+       }
 
        public List getDeclareSoft() {
                return crosscuttingMembersSet.getDeclareSofts();