]> source.dussan.org Git - aspectj.git/commitdiff
tests and fix for pr59196, args pcd not ignoring synthetic arguments at adviceexecuti...
authoracolyer <acolyer>
Thu, 1 Sep 2005 08:30:41 +0000 (08:30 +0000)
committeracolyer <acolyer>
Thu, 1 Sep 2005 08:30:41 +0000 (08:30 +0000)
tests/bugs150/pr59196.aj [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java
tests/src/org/aspectj/systemtest/ajc150/ajc150.xml
weaver/src/org/aspectj/weaver/patterns/ArgsPointcut.java

diff --git a/tests/bugs150/pr59196.aj b/tests/bugs150/pr59196.aj
new file mode 100644 (file)
index 0000000..f54d980
--- /dev/null
@@ -0,0 +1,18 @@
+aspect some_aspect {
+   pointcut call_m(int a, int b) : call(int *.m(..)) && args(a, b);
+   int m(int p, int q) { return 2; }
+   
+   void foo() {
+          m(1,4);
+   }
+   
+   int around(int x, int y) : call_m(x, y) {  return 5; }
+}
+aspect other_aspect {
+   before(int x, int y) : 
+       adviceexecution() && within(some_aspect) &&  args(x, y) {
+          
+   }
+}
\ No newline at end of file
index de828818f02f95d6a698a4a82052b651cc45234b..9d7053306cef2b455e1b996515028275d117693c 100644 (file)
@@ -346,6 +346,10 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
          runTest("visibility in signature matching with overrides - 3");
   }
   
+  public void testArgsGeneratedCorrectlyForAdviceExecution() {
+         runTest("args generated correctly for advice execution join point");
+  }
+  
   // helper methods.....
   
   public SyntheticRepository createRepos(File cpentry) {
index b1f4a2354dfb03f54aa13373964eb1123fb65b51..eaa4acef4488fc128b15e4ea2ad4d9c5601d9712 100644 (file)
             <message kind="warning" line="10" text="should match"/>
         </compile>
     </ajc-test>  
+    <ajc-test dir="bugs150" pr="59196" title="args generated correctly for advice execution join point">
+        <compile files="pr59196.aj" options="-XnoInline -1.5"/>
+    </ajc-test>  
   
     <!-- ============================================================================ -->
     <!-- ============================================================================ -->
index e3ea9f73577b2fb7fa0b1beb74f19becb83d9c98..2fd1eb7b64a507891c66f22180c3bc8b8ff7b559 100644 (file)
@@ -51,7 +51,10 @@ import org.aspectj.weaver.internal.tools.PointcutExpressionImpl;
  * @author Erik Hilsdale
  * @author Jim Hugunin
  */
-public class ArgsPointcut extends NameBindingPointcut { 
+public class ArgsPointcut extends NameBindingPointcut {
+       private static final String ASPECTJ_JP_SIGNATURE_PREFIX = "Lorg/aspectj/lang/JoinPoint";
+       private static final String ASPECTJ_SYNTHETIC_SIGNATURE_PREFIX = "Lorg/aspectj/runtime/internal/";
+       
        private TypePatternList arguments;
        
        public ArgsPointcut(TypePatternList arguments) {
@@ -76,11 +79,39 @@ public class ArgsPointcut extends NameBindingPointcut {
        }
 
        protected FuzzyBoolean matchInternal(Shadow shadow) {
+               ResolvedType[] argumentsToMatchAgainst = getArgumentsToMatchAgainst(shadow);
                FuzzyBoolean ret =
-                       arguments.matches(shadow.getIWorld().resolve(shadow.getGenericArgTypes()), TypePattern.DYNAMIC);
+                       arguments.matches(argumentsToMatchAgainst, TypePattern.DYNAMIC);
                return ret;
        }
        
+       private ResolvedType[] getArgumentsToMatchAgainst(Shadow shadow) {
+               ResolvedType[] argumentsToMatchAgainst = shadow.getIWorld().resolve(shadow.getGenericArgTypes());
+
+               // special treatment for adviceexecution which may have synthetic arguments we
+               // want to ignore.
+               if (shadow.getKind() == Shadow.AdviceExecution) {
+                       int numExtraArgs = 0;
+                       for (int i = 0; i < argumentsToMatchAgainst.length; i++) {
+                               String argumentSignature = argumentsToMatchAgainst[i].getSignature();
+                               if (argumentSignature.startsWith(ASPECTJ_JP_SIGNATURE_PREFIX) || argumentSignature.startsWith(ASPECTJ_SYNTHETIC_SIGNATURE_PREFIX)) {
+                                       numExtraArgs++;
+                               } else {
+                                       // normal arg after AJ type means earlier arg was NOT synthetic
+                                       numExtraArgs = 0;
+                               }
+                       }
+                       if (numExtraArgs > 0) {
+                               int newArgLength = argumentsToMatchAgainst.length - numExtraArgs;
+                               ResolvedType[] argsSubset = new ResolvedType[newArgLength];
+                               System.arraycopy(argumentsToMatchAgainst, 0, argsSubset, 0, newArgLength);
+                               argumentsToMatchAgainst = argsSubset;
+                       }
+               }
+               
+               return argumentsToMatchAgainst;
+       }
+       
        public FuzzyBoolean match(JoinPoint jp, JoinPoint.StaticPart jpsp) {
                FuzzyBoolean ret = arguments.matches(jp.getArgs(),TypePattern.DYNAMIC);
                // this may have given a false match (e.g. args(int) may have matched a call to doIt(Integer x)) due to boxing
@@ -234,7 +265,8 @@ public class ArgsPointcut extends NameBindingPointcut {
        }
 
        private Test findResidueNoEllipsis(Shadow shadow, ExposedState state, TypePattern[] patterns) {
-               int len = shadow.getArgCount();
+               ResolvedType[] argumentsToMatchAgainst = getArgumentsToMatchAgainst(shadow);
+               int len = argumentsToMatchAgainst.length;
                //System.err.println("boudn to : " + len + ", " + patterns.length);
                if (patterns.length != len) {
                        return Literal.FALSE;
@@ -310,7 +342,7 @@ public class ArgsPointcut extends NameBindingPointcut {
        }
        
        protected Test findResidueInternal(Shadow shadow, ExposedState state) {
-               if (arguments.matches(shadow.getIWorld().resolve(shadow.getGenericArgTypes()), TypePattern.DYNAMIC).alwaysFalse()) {
+               if (arguments.matches(getArgumentsToMatchAgainst(shadow), TypePattern.DYNAMIC).alwaysFalse()) {
                        return Literal.FALSE;
                }
                int ellipsisCount = arguments.ellipsisCount;