]> source.dussan.org Git - aspectj.git/commitdiff
test and fix for 86903
authoraclement <aclement>
Thu, 3 Nov 2005 15:24:48 +0000 (15:24 +0000)
committeraclement <aclement>
Thu, 3 Nov 2005 15:24:48 +0000 (15:24 +0000)
tests/bugs150/pr86903/BadWormhole.java [new file with mode: 0644]
tests/bugs150/pr86903/GenericService.java [new file with mode: 0644]
tests/bugs150/pr86903/Main.java [new file with mode: 0644]
tests/bugs150/pr86903/Service.java [new file with mode: 0644]
weaver/src/org/aspectj/weaver/IntMap.java
weaver/src/org/aspectj/weaver/patterns/CflowPointcut.java
weaver/src/org/aspectj/weaver/patterns/IfPointcut.java

diff --git a/tests/bugs150/pr86903/BadWormhole.java b/tests/bugs150/pr86903/BadWormhole.java
new file mode 100644 (file)
index 0000000..6d14b49
--- /dev/null
@@ -0,0 +1,11 @@
+
+aspect BadWormhole {
+
+  pointcut isDynamicService(Main mm,Service s):
+    cflowbelow(this(mm)) && 
+    if(true==true) && 
+    this(s);
+
+  //before(Main mm,Service s): isDynamicService(mm,s) {}
+  before(Service s): isDynamicService(*,s) {}
+}
diff --git a/tests/bugs150/pr86903/GenericService.java b/tests/bugs150/pr86903/GenericService.java
new file mode 100644 (file)
index 0000000..3c69508
--- /dev/null
@@ -0,0 +1,4 @@
+
+public interface GenericService {
+    public abstract void setContext(String localCtx);
+}
diff --git a/tests/bugs150/pr86903/Main.java b/tests/bugs150/pr86903/Main.java
new file mode 100644 (file)
index 0000000..7122a29
--- /dev/null
@@ -0,0 +1,6 @@
+
+public class Main {
+  public static void main(String []argv) {
+    new Service().setContext("foo");
+  }
+}
diff --git a/tests/bugs150/pr86903/Service.java b/tests/bugs150/pr86903/Service.java
new file mode 100644 (file)
index 0000000..635172b
--- /dev/null
@@ -0,0 +1,8 @@
+
+public class Service implements GenericService {
+    String srvContext = "none";
+
+    public void setContext(String localCtx) {
+        this.srvContext=localCtx;
+    }
+}
index e5ab6bfd4225d495d7cfaf76c28f3aaf8a0b783a..e61cbf4b4114075ee435d57bce7d749f5358c953 100644 (file)
@@ -37,12 +37,9 @@ public class IntMap {
        }
        
        
-       public ResolvedPointcutDefinition peekEnclosingDefinitition() {
-        try {
-                   return (ResolvedPointcutDefinition)enclosingDefinition.get(enclosingDefinition.size()-1);
-        } catch (IndexOutOfBoundsException e) {
-            return null;
-        }
+       public ResolvedPointcutDefinition peekEnclosingDefinition() {
+               if (enclosingDefinition.size()==0) return null;
+           return (ResolvedPointcutDefinition)enclosingDefinition.get(enclosingDefinition.size()-1);
        }
        
        
index 1c7af01c711f79c5ac397403a2c593ded31b07a6..9934b723787524c388ab83cd09b371084d8d1046 100644 (file)
@@ -243,8 +243,22 @@ public class CflowPointcut extends Pointcut {
                                if (!bindings.hasKey(freeVar)) continue; 
                                
                                int formalIndex = bindings.get(freeVar);
-                               ResolvedType formalType =
-                                       bindings.getAdviceSignature().getParameterTypes()[formalIndex].resolve(world);
+                               
+                               // We need to look in the right place for the type of the formal.  Suppose the advice looks like this:
+                               //  before(String s):  somePointcut(*,s) 
+                               // where the first argument in somePointcut is of type Number
+                               // for free variable 0 we want to ask the pointcut for the type of its first argument, if we only
+                               // ask the advice for the type of its first argument then we'll get the wrong type (pr86903)
+                               
+                               ResolvedPointcutDefinition enclosingDef = bindings.peekEnclosingDefinition();
+                               ResolvedType formalType = null;
+                               
+                               // Is there a useful enclosing pointcut?
+                               if (enclosingDef!=null && enclosingDef.getParameterTypes().length>0) {
+                                       formalType = enclosingDef.getParameterTypes()[freeVar].resolve(world);
+                               } else {
+                                       formalType = bindings.getAdviceSignature().getParameterTypes()[formalIndex].resolve(world);
+                               }
                                
                                ConcreteCflowPointcut.Slot slot = 
                                        new ConcreteCflowPointcut.Slot(formalIndex, formalType, i);
index 3afb4350eeef9b4837b4bd3852f10513ce608020..25fa8edcb79c827089182b6a5b5ee13af43ce370 100644 (file)
@@ -263,7 +263,7 @@ public class IfPointcut extends Pointcut {
         final IfPointcut ret;
         if (extraParameterFlags < 0 && testMethod == null) {
             // @AJ style, we need to find the testMethod in the aspect defining the "if()" enclosing pointcut
-            ResolvedPointcutDefinition def = bindings.peekEnclosingDefinitition();
+            ResolvedPointcutDefinition def = bindings.peekEnclosingDefinition();
             if (def != null) {
                 ResolvedType aspect = inAspect.getWorld().resolve(def.getDeclaringType());
                 for (Iterator memberIter = aspect.getMethods(); memberIter.hasNext();) {
@@ -327,7 +327,7 @@ public class IfPointcut extends Pointcut {
                        }
                        ret.residueSource = advice.getPointcut().concretize(inAspect, inAspect, ret.baseArgsCount, advice);
                } else {
-                       ResolvedPointcutDefinition def = bindings.peekEnclosingDefinitition();
+                       ResolvedPointcutDefinition def = bindings.peekEnclosingDefinition();
                        if (def == CflowPointcut.CFLOW_MARKER) {
                                inAspect.getWorld().showMessage(IMessage.ERROR,
                                                WeaverMessages.format(WeaverMessages.IF_LEXICALLY_IN_CFLOW),