]> source.dussan.org Git - aspectj.git/commitdiff
253067: fix
authoraclement <aclement>
Tue, 2 Dec 2008 18:04:07 +0000 (18:04 +0000)
committeraclement <aclement>
Tue, 2 Dec 2008 18:04:07 +0000 (18:04 +0000)
weaver/src/org/aspectj/weaver/bcel/BcelShadow.java
weaver/src/org/aspectj/weaver/model/AsmRelationshipProvider.java

index c22ae880e84fc64867d1a9ef5e41fd2128cdec7c..f3dfb361521869b8f5ba4e0ffc339e1a9a5d4dd1 100644 (file)
@@ -1144,6 +1144,28 @@ public class BcelShadow extends Shadow {
                }
        }
 
+        public Member getRealEnclosingCodeSignature() {
+                       return enclosingMethod.getMemberView();
+        }
+
+       // public Member getEnclosingCodeSignatureForModel() {
+       // if (getKind().isEnclosingKind()) {
+       // return getSignature();
+       // } else if (getKind() == Shadow.PreInitialization) {
+       // // PreInit doesn't enclose code but its signature
+       // // is correctly the signature of the ctor.
+       // return getSignature();
+       // } else if (enclosingShadow == null) {
+       // return getEnclosingMethod().getMemberView();
+       // } else {
+       // if (enclosingShadow.getKind() == Shadow.MethodExecution && enclosingMethod.getEffectiveSignature() != null) {
+       //
+       // } else {
+       // return enclosingShadow.getSignature();
+       // }
+       // }
+       // }
+
        private InstructionList makeArgsObjectArray() {
                InstructionFactory fact = getFactory();
                BcelVar arrayVar = genTempVar(UnresolvedType.OBJECTARRAY);
index 2f9db1d699407520d7a9b94710f608686de771e5..94e881671b573b7d8b855646e447262bb41865ab 100644 (file)
@@ -38,6 +38,7 @@ import org.aspectj.weaver.Shadow;
 import org.aspectj.weaver.ShadowMunger;
 import org.aspectj.weaver.UnresolvedType;
 import org.aspectj.weaver.World;
+import org.aspectj.weaver.bcel.BcelShadow;
 import org.aspectj.weaver.patterns.DeclareErrorOrWarning;
 import org.aspectj.weaver.patterns.Pointcut;
 
@@ -419,8 +420,32 @@ public class AsmRelationshipProvider {
 
        protected static IProgramElement getNode(AsmManager model, Shadow shadow) {
                Member enclosingMember = shadow.getEnclosingCodeSignature();
+               // This variant will not be tricked by ITDs that would report they are in the target type already.
+               // This enables us to discover the ITD declaration (in the aspect) and advise it appropriately.
+
+               // Have to be smart here, for a code node within an ITD we want to lookup the declaration of the
+               // ITD in the aspect in order to add the code node at the right place - and not lookup the
+               // ITD as it applies in some target type. Due to the use of effectiveSignature we will find
+               // that shadow.getEnclosingCodeSignature() will return a member representing the ITD as it will
+               // appear in the target type. So here, we do an extra bit of analysis to make sure we
+               // do the right thing in the ITD case.
+               IProgramElement enclosingNode = null;
+               if (shadow instanceof BcelShadow) {
+                       Member actualEnclosingMember = ((BcelShadow) shadow).getRealEnclosingCodeSignature();
+
+                       UnresolvedType type = enclosingMember.getDeclaringType();
+                       UnresolvedType actualType = actualEnclosingMember.getDeclaringType();
+
+                       // if these are not the same, it is an ITD and we need to use the latter to lookup
+                       if (type.equals(actualType)) {
+                               enclosingNode = lookupMember(model.getHierarchy(), shadow.getEnclosingType(), enclosingMember);
+                       } else {
+                               enclosingNode = lookupMember(model.getHierarchy(), shadow.getEnclosingType(), actualEnclosingMember);
+                       }
+               } else {
+                       enclosingNode = lookupMember(model.getHierarchy(), shadow.getEnclosingType(), enclosingMember);
+               }
 
-               IProgramElement enclosingNode = lookupMember(model.getHierarchy(), enclosingMember);
                if (enclosingNode == null) {
                        Lint.Kind err = shadow.getIWorld().getLint().shadowNotInStructure;
                        if (err.isEnabled()) {
@@ -501,6 +526,11 @@ public class AsmRelationshipProvider {
                return findMemberInClass(classNode, member);
        }
 
+       protected static IProgramElement lookupMember(IHierarchy model, UnresolvedType declaringType, Member member) {
+               IProgramElement classNode = model.findElementForType(declaringType.getPackageName(), declaringType.getClassName());
+               return findMemberInClass(classNode, member);
+       }
+
        protected static IProgramElement findMemberInClass(IProgramElement classNode, Member member) {
                if (classNode == null)
                        return null; // XXX remove this check