]> source.dussan.org Git - aspectj.git/commitdiff
fix and test for Bugzilla Bug 42993
authorjhugunin <jhugunin>
Fri, 12 Sep 2003 16:49:58 +0000 (16:49 +0000)
committerjhugunin <jhugunin>
Fri, 12 Sep 2003 16:49:58 +0000 (16:49 +0000)
   Language regression, or possible language improvement?

The problem was caused by moving name binding in pointcut declarations to
happen before declare parents are evaluated.  Because of this, the
compiler doesn't know that ContainerDescriptor isa Key when resolving
the ContainerLoader.containerLoads reference.

The change in ordering was made to fix a bug reported in declare error
and declare soft whose pcds where being evaluated before name binding
had happened in the pointcut declarations.  Unfortunately, declare error
and declare soft are concretized at the same time as declare parents
(and all other declares ;-), so this move also led to the regression
noted above.

org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java
tests/ajcTests.xml
tests/bugs/ParentsAndPointcuts.java [new file with mode: 0644]
weaver/src/org/aspectj/weaver/CrosscuttingMembersSet.java
weaver/src/org/aspectj/weaver/ResolvedTypeX.java

index 4f9badc839fbcde5272a28a89be917c2fcba31ef..711eb25fcb7d05127b500722cb651274baea9214 100644 (file)
@@ -92,21 +92,10 @@ public class AjLookupEnvironment extends LookupEnvironment {
             SourceTypeBinding[] b = units[i].scope.topLevelTypes;
             for (int j = 0; j < b.length; j++) {
                 buildInterTypeAndPerClause(b[j].scope);
-            }
-        }
-        for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
-            SourceTypeBinding[] b = units[i].scope.topLevelTypes;
-            for (int j = 0; j < b.length; j++) {
-                resolvePointcutDeclarations(b[j].scope);
-            }
-        }
-        
-        for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
-            SourceTypeBinding[] b = units[i].scope.topLevelTypes;
-            for (int j = 0; j < b.length; j++) {
                 addCrosscuttingStructures(b[j].scope);
             }
-        }
+        }        
+
                factory.finishTypeMungers();
        
                // now do weaving
@@ -118,8 +107,25 @@ public class AjLookupEnvironment extends LookupEnvironment {
 
                for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
                        weaveInterTypeDeclarations(units[i].scope, typeMungers, declareParents);
-            units[i] = null; // release unnecessary reference to the parsed unit
                }
+        
+        for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
+            SourceTypeBinding[] b = units[i].scope.topLevelTypes;
+            for (int j = 0; j < b.length; j++) {
+                resolvePointcutDeclarations(b[j].scope);
+            }
+        }
+        
+        for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
+            SourceTypeBinding[] b = units[i].scope.topLevelTypes;
+            for (int j = 0; j < b.length; j++) {
+                addAdviceLikeDeclares(b[j].scope);
+            }
+        }
+        
+        for (int i = lastCompletedUnitIndex + 1; i <= lastUnitIndex; i++) {
+            units[i] = null; // release unnecessary reference to the parsed unit
+        }
                 
                stepCompleted = BUILD_FIELDS_AND_METHODS;
                lastCompletedUnitIndex = lastUnitIndex;
@@ -132,6 +138,21 @@ public class AjLookupEnvironment extends LookupEnvironment {
                }
                pendingTypesToWeave.clear();
        }
+    
+    private void addAdviceLikeDeclares(ClassScope s) {
+        TypeDeclaration dec = s.referenceContext;
+        
+        if (dec instanceof AspectDeclaration) {
+            ResolvedTypeX typeX = factory.fromEclipse(dec.binding);
+            factory.getWorld().getCrosscuttingMembersSet().addAdviceLikeDeclares(typeX);
+        }
+        
+        SourceTypeBinding sourceType = s.referenceContext.binding;
+        ReferenceBinding[] memberTypes = sourceType.memberTypes;
+        for (int i = 0, length = memberTypes.length; i < length; i++) {
+            addCrosscuttingStructures(((SourceTypeBinding) memberTypes[i]).scope);
+        }
+    }
 
     private void addCrosscuttingStructures(ClassScope s) {
         TypeDeclaration dec = s.referenceContext;
index a50e6940db09fc66591c10ec58cabef00ada6b43..39dd3b14693bc0448d8e88a0900475872c730b7d 100644 (file)
                <compile files="aspects/Softener.aj,test/NoSoftener.java"/>
                <run class="test.NoSoftener"/>
        </ajc-test>
+       
+    <ajc-test dir="bugs" pr="42993"
+           title="Interaction between pointcut binding and declare parents">
+        <compile files="ParentsAndPointcuts.java"/>
+        <run class="ParentsAndPointcuts"/>
+    </ajc-test>
 </suite>
diff --git a/tests/bugs/ParentsAndPointcuts.java b/tests/bugs/ParentsAndPointcuts.java
new file mode 100644 (file)
index 0000000..522c29e
--- /dev/null
@@ -0,0 +1,44 @@
+import org.aspectj.testing.Tester;
+
+public class ParentsAndPointcuts {
+    public static void main(String[] args) {
+        ContainerDescriptor d = new ContainerDescriptor();
+        Tester.check(d instanceof AbstractCaching.Key, "instanceof");
+    }
+}
+
+aspect AspectBug extends AbstractCaching
+perthis(execution(ContainerLoader+.new(..)))
+{
+    declare parents: ContainerDescriptor implements AbstractCaching.Key;
+
+    protected pointcut loadExecutions( Key key ):
+        ContainerLoader.containerLoads( *, key );
+}
+
+abstract aspect AbstractCaching  {
+    interface Key {}
+    protected abstract pointcut loadExecutions(Key key);
+}
+
+class Key {
+}
+
+class ContainerDescriptor {
+}
+
+class ActiveContainer {
+}
+
+class ContainerLoader {
+    public ActiveContainer createContainer(ContainerDescriptor c) {
+        return null;
+    }
+
+    public pointcut containerLoads(ContainerLoader loader,
+                                   
+ContainerDescriptor containerDesc ):
+        this(loader) && args(containerDesc)
+        && execution(ActiveContainer ContainerLoader.createContainer
+(ContainerDescriptor));
+}
\ No newline at end of file
index ec81a0cf2979851ac3c4c0f06975be6eb29b4041..2dcae923c141d7ef373f8a0459797f99d84391a4 100644 (file)
@@ -59,6 +59,11 @@ public class CrosscuttingMembersSet {
                        }
                }
        }
+    
+    public void addAdviceLikeDeclares(ResolvedTypeX aspectType) {
+        CrosscuttingMembers xcut = (CrosscuttingMembers)members.get(aspectType);
+        xcut.addDeclares(aspectType.collectDeclares(true));
+    }
        
        public boolean deleteAspect(TypeX aspectType) {
                boolean isAspect = members.remove(aspectType) != null;
@@ -69,7 +74,7 @@ public class CrosscuttingMembersSet {
        public boolean containsAspect(TypeX aspectType) {
                return members.containsKey(aspectType);
        }
-       
+    
        //XXX only for testing
        public void addFixedCrosscuttingMembers(ResolvedTypeX aspectType) {
                members.put(aspectType, aspectType.crosscuttingMembers);
@@ -139,8 +144,5 @@ public class CrosscuttingMembersSet {
                        declareDominates = ret;
                }
                return declareDominates;
-       }
-       
-       
-       
+       }       
 }
index e3504fcbe7bd53030e09fc2ef9daba8bdb59231d..d4526ec9dd56efe8f6645e87801085b5b26618be 100644 (file)
@@ -329,14 +329,14 @@ public abstract class ResolvedTypeX extends TypeX {
                crosscuttingMembers.setPerClause(getPerClause());
                crosscuttingMembers.addShadowMungers(collectShadowMungers());
                crosscuttingMembers.addTypeMungers(getTypeMungers());
-               crosscuttingMembers.addDeclares(collectDeclares());
+               crosscuttingMembers.addDeclares(collectDeclares(!this.doesNotExposeShadowMungers()));
                crosscuttingMembers.addPrivilegedAccesses(getPrivilegedAccesses());
                
                //System.err.println("collected cc members: " + this + ", " + collectDeclares());
                return crosscuttingMembers;
        }
        
-       private final Collection collectDeclares() {
+       public final Collection collectDeclares(boolean includeAdviceLike) {
                if (! this.isAspect() ) return Collections.EMPTY_LIST;
                
                ArrayList ret = new ArrayList();
@@ -345,6 +345,9 @@ public abstract class ResolvedTypeX extends TypeX {
                        Declare dec = (Declare) i.next();
                        if (!dec.isAdviceLike()) ret.add(dec);
                }
+        
+        if (!includeAdviceLike) return ret;
+        
                if (!this.isAbstract()) {
                        //ret.addAll(getDeclares());
                        final Iterators.Filter dupFilter = Iterators.dupFilter();