From b5127388a3b5a2403e8d8944766bbe1895e09530 Mon Sep 17 00:00:00 2001 From: jhugunin Date: Fri, 12 Sep 2003 16:49:58 +0000 Subject: [PATCH] fix and test for Bugzilla Bug 42993 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. --- .../compiler/lookup/AjLookupEnvironment.java | 49 +++++++++++++------ tests/ajcTests.xml | 6 +++ tests/bugs/ParentsAndPointcuts.java | 44 +++++++++++++++++ .../weaver/CrosscuttingMembersSet.java | 12 +++-- .../src/org/aspectj/weaver/ResolvedTypeX.java | 7 ++- 5 files changed, 97 insertions(+), 21 deletions(-) create mode 100644 tests/bugs/ParentsAndPointcuts.java diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java index 4f9badc83..711eb25fc 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java @@ -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; diff --git a/tests/ajcTests.xml b/tests/ajcTests.xml index a50e6940d..39dd3b146 100644 --- a/tests/ajcTests.xml +++ b/tests/ajcTests.xml @@ -6751,4 +6751,10 @@ + + + + + diff --git a/tests/bugs/ParentsAndPointcuts.java b/tests/bugs/ParentsAndPointcuts.java new file mode 100644 index 000000000..522c29ea5 --- /dev/null +++ b/tests/bugs/ParentsAndPointcuts.java @@ -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 diff --git a/weaver/src/org/aspectj/weaver/CrosscuttingMembersSet.java b/weaver/src/org/aspectj/weaver/CrosscuttingMembersSet.java index ec81a0cf2..2dcae923c 100644 --- a/weaver/src/org/aspectj/weaver/CrosscuttingMembersSet.java +++ b/weaver/src/org/aspectj/weaver/CrosscuttingMembersSet.java @@ -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; - } - - - + } } diff --git a/weaver/src/org/aspectj/weaver/ResolvedTypeX.java b/weaver/src/org/aspectj/weaver/ResolvedTypeX.java index e3504fcbe..d4526ec9d 100644 --- a/weaver/src/org/aspectj/weaver/ResolvedTypeX.java +++ b/weaver/src/org/aspectj/weaver/ResolvedTypeX.java @@ -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(); -- 2.39.5