]> source.dussan.org Git - aspectj.git/commitdiff
tests and fix for pr108903 - MUST process from super aspect to sub aspect when findin...
authoracolyer <acolyer>
Mon, 12 Sep 2005 10:04:51 +0000 (10:04 +0000)
committeracolyer <acolyer>
Mon, 12 Sep 2005 10:04:51 +0000 (10:04 +0000)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java
tests/bugs150/pr108903/com/designpattern/decorator/HeaderDecorator.aj [new file with mode: 0644]
tests/bugs150/pr108903/com/designpattern/decorator/Main.java [new file with mode: 0644]
tests/bugs150/pr108903/com/designpattern/decorator/Order.java [new file with mode: 0644]
tests/bugs150/pr108903/com/designpattern/decorator/OrderDecorator.aj [new file with mode: 0644]
tests/bugs150/pr108903/com/designpattern/decorator/SalesOrder.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java
tests/src/org/aspectj/systemtest/ajc150/ajc150.xml

index f157dbbda78840aa34793f09a6f2face20589764..4b4ada030b7d2448eaa67f1a2f750797746d7f47 100644 (file)
@@ -122,14 +122,22 @@ public class AjLookupEnvironment extends LookupEnvironment implements AnonymousC
                AnonymousClassPublisher.aspectOf().setAnonymousClassCreationListener(this);
                
                // need to build inter-type declarations for all AspectDeclarations at this point
-        for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
-            SourceTypeBinding[] b = units[i].scope.topLevelTypes;
-            for (int j = 0; j < b.length; j++) {
-                buildInterTypeAndPerClause(b[j].scope);
-                addCrosscuttingStructures(b[j].scope);
-            }
-        }        
+               // this MUST be done in order from super-types to subtypes
+               List typesToProcess = new ArrayList();
+               for (int i=lastCompletedUnitIndex+1; i<=lastUnitIndex; i++) {
+                       CompilationUnitScope cus = units[i].scope;
+                       SourceTypeBinding[] stbs = cus.topLevelTypes;
+                       for (int j=0; j<stbs.length; j++) {
+                               SourceTypeBinding stb = stbs[j];
+                               typesToProcess.add(stb);
+                       }
+               }
 
+               while (typesToProcess.size()>0) {
+                       // removes types from the list as they are processed...
+                       collectAllITDsAndDeclares((SourceTypeBinding)typesToProcess.get(0),typesToProcess);
+               }               
+                               
                factory.finishTypeMungers();
        
                // now do weaving
@@ -156,7 +164,7 @@ public class AjLookupEnvironment extends LookupEnvironment implements AnonymousC
                boolean typeProcessingOrderIsImportant = declareParents.size()>0 || declareAnnotationOnTypes.size()>0; //DECAT
                
                if (typeProcessingOrderIsImportant) {
-                       List typesToProcess = new ArrayList();
+                       typesToProcess = new ArrayList();
                        for (int i=lastCompletedUnitIndex+1; i<=lastUnitIndex; i++) {
                                CompilationUnitScope cus = units[i].scope;
                                SourceTypeBinding[] stbs = cus.topLevelTypes;
@@ -201,6 +209,24 @@ public class AjLookupEnvironment extends LookupEnvironment implements AnonymousC
                lastCompletedUnitIndex = lastUnitIndex;
        }
        
+       
+       /**
+        * Find all the ITDs and Declares, but it is important we do this from the supertypes
+        * down to the subtypes.
+        * @param sourceType
+        * @param yetToProcess
+        */
+       private void collectAllITDsAndDeclares(SourceTypeBinding sourceType, Collection yetToProcess) {
+               // Look at the supertype first
+           ReferenceBinding superType = sourceType.superclass();
+           if (yetToProcess.contains(superType) && superType instanceof SourceTypeBinding) {
+               collectAllITDsAndDeclares((SourceTypeBinding)superType, yetToProcess);
+           }
+        buildInterTypeAndPerClause(sourceType.scope);
+        addCrosscuttingStructures(sourceType.scope);
+        yetToProcess.remove(sourceType);
+       }
+       
        /**
         * Weave the parents and intertype decls into a given type.  This method looks at the
         * supertype and superinterfaces for the specified type and recurses to weave those first
index 406542ec13f8db499c3bd3c6f2c3e0a98471ee22..e95c782330ea1f4288a3b02c1f6aab8ecf32b3a3 100644 (file)
@@ -27,7 +27,6 @@ import org.aspectj.ajdt.internal.core.builder.AjBuildManager;
 import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.bridge.IMessage.Kind;
 import org.aspectj.org.eclipse.jdt.core.compiler.CharOperation;
-import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
diff --git a/tests/bugs150/pr108903/com/designpattern/decorator/HeaderDecorator.aj b/tests/bugs150/pr108903/com/designpattern/decorator/HeaderDecorator.aj
new file mode 100644 (file)
index 0000000..fe9f12b
--- /dev/null
@@ -0,0 +1,19 @@
+/**
+ * 
+ */
+package com.designpattern.decorator;
+
+public aspect HeaderDecorator extends OrderDecorator 
+{
+       
+       void around(Order order) : print(order)
+       {
+               printHeader(order);
+               proceed(order);
+       }
+
+       private void printHeader(Order order)
+       {
+               System.out.println("XYZ Incorporated\nDate of Sale:");
+       }
+}
diff --git a/tests/bugs150/pr108903/com/designpattern/decorator/Main.java b/tests/bugs150/pr108903/com/designpattern/decorator/Main.java
new file mode 100644 (file)
index 0000000..580150e
--- /dev/null
@@ -0,0 +1,11 @@
+package com.designpattern.decorator;
+
+public class Main {
+       private static Order order;
+
+       public static void main(String[] args) {
+               order = new SalesOrder();
+               order.print();
+
+       }
+}
diff --git a/tests/bugs150/pr108903/com/designpattern/decorator/Order.java b/tests/bugs150/pr108903/com/designpattern/decorator/Order.java
new file mode 100644 (file)
index 0000000..8ab3a8e
--- /dev/null
@@ -0,0 +1,9 @@
+package com.designpattern.decorator;
+
+public abstract class Order {
+
+       public void print() {
+        System.out.print("Order.print()") ;
+       }
+
+}
diff --git a/tests/bugs150/pr108903/com/designpattern/decorator/OrderDecorator.aj b/tests/bugs150/pr108903/com/designpattern/decorator/OrderDecorator.aj
new file mode 100644 (file)
index 0000000..0c4926b
--- /dev/null
@@ -0,0 +1,17 @@
+/**
+ * 
+ */
+package com.designpattern.decorator;
+
+public abstract aspect OrderDecorator
+{
+    protected pointcut print(Order order) : target(order) && call(public void print());
+
+    declare parents : SalesOrder extends Order ;
+
+    public void SalesOrder.print()
+    {
+        super.print();
+    }
+
+}
diff --git a/tests/bugs150/pr108903/com/designpattern/decorator/SalesOrder.java b/tests/bugs150/pr108903/com/designpattern/decorator/SalesOrder.java
new file mode 100644 (file)
index 0000000..2dd0add
--- /dev/null
@@ -0,0 +1,5 @@
+package com.designpattern.decorator;
+
+public class SalesOrder {
+
+}
index 29d58d31f99fea6d3d87c33d650fe300e1a223f0..41105f06d94946f74bfb81778d598954e29f98cb 100644 (file)
@@ -405,7 +405,11 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
   public void testSuperCallInITD() {
          runTest("super call in ITD");
   }
-  
+
+  public void testSuperCallInITDPart2() {
+         runTest("super call in ITD - part 2");
+  }
+
   public void testNoUnusedParameterWarningsForSyntheticAdviceArgs() {
          runTest("no unused parameter warnings for synthetic advice args");
   }
@@ -417,6 +421,8 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
   public void testCantFindTypeErrorWithGenericReturnTypeOrParameter() {
          runTest("cant find type error with generic return type or parameter");
   }
+
   
 // currently failing...
 //  public void testNoVerifyErrorOnGenericCollectionMemberAccess() {
index 3e44ba7f15fa4f1a05ed55b1d686cf8c5b3891e6..cbd07c2819df6e1e9415762efc50ceb9e31e112d 100644 (file)
         </compile>
         <run class="pr105181"/>
     </ajc-test> 
-       
+
+    <ajc-test dir="bugs150/pr108903" pr="108903" title="super call in ITD - part 2">
+        <compile files="com/designpattern/decorator/HeaderDecorator.aj,com/designpattern/decorator/Main.java,com/designpattern/decorator/Order.java,com/designpattern/decorator/OrderDecorator.aj,com/designpattern/decorator/SalesOrder.java" options="-1.5" >
+        </compile>
+    </ajc-test> 
+        
     <!-- ============================================================================ -->
     <!-- ============================================================================ -->