]> source.dussan.org Git - aspectj.git/commitdiff
test and fix for 122742 (more @AJ thisJoinPoint problems...)
authoraclement <aclement>
Tue, 21 Feb 2006 16:13:44 +0000 (16:13 +0000)
committeraclement <aclement>
Tue, 21 Feb 2006 16:13:44 +0000 (16:13 +0000)
tests/bugs151/pr122742/AfterReturningTest.java [new file with mode: 0644]
tests/bugs151/pr122742/AfterThrowingTest.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java
tests/src/org/aspectj/systemtest/ajc151/ajc151.xml
weaver/src/org/aspectj/weaver/Advice.java

diff --git a/tests/bugs151/pr122742/AfterReturningTest.java b/tests/bugs151/pr122742/AfterReturningTest.java
new file mode 100644 (file)
index 0000000..9ec10a4
--- /dev/null
@@ -0,0 +1,52 @@
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.annotation.AfterReturning;
+import org.aspectj.lang.annotation.Aspect;
+
+@Aspect
+public class AfterReturningTest {
+
+       public static void main(String[] args) {
+               new B1().start();
+       }
+       
+       // include "JoinPoint" in the argument list
+       @AfterReturning(pointcut = "execution(public B1 B1.start())", returning = "r")
+       public void afterJP(JoinPoint jp, B1 r) {
+               r.stop();
+       }
+       
+       // include "JoinPoint.StaticPart" in the argument list
+       @AfterReturning(pointcut = "execution(public B1 B1.start())", returning = "r")
+       public void afterJPSP(JoinPoint.StaticPart jp, B1 r) {
+               r.stop();
+       }
+       
+       // include "JoinPoint.EnclosingStaticPart" in the argument list
+       @AfterReturning(pointcut = "execution(public B1 B1.start())", returning = "r")
+       public void afterJPESP(JoinPoint.EnclosingStaticPart jp, B1 r) {
+               r.stop();
+       }
+       
+       // include "JoinPoint and JoinPoint.EnclosingStaticPart" in the argument list
+       @AfterReturning(pointcut = "execution(public B1 B1.start())", returning = "r")
+       public void afterJPESP2(JoinPoint jp1, JoinPoint.EnclosingStaticPart jp, B1 r) {
+               r.stop();
+       }
+       
+       // make sure it still works if "JoinPoint" is second in the argument list
+       @AfterReturning(pointcut = "execution(public B1 B1.start())", returning = "r")
+       public void afterJP2(B1 r, JoinPoint jp) {
+               r.stop();
+       }
+}
+
+class B1 {
+       
+       public B1 start() {
+               return new B1();
+       }
+       
+       public void stop() {
+       }
+       
+}
diff --git a/tests/bugs151/pr122742/AfterThrowingTest.java b/tests/bugs151/pr122742/AfterThrowingTest.java
new file mode 100644 (file)
index 0000000..449893e
--- /dev/null
@@ -0,0 +1,50 @@
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.annotation.AfterThrowing;
+import org.aspectj.lang.annotation.Aspect;
+
+@Aspect
+public class AfterThrowingTest {
+
+       public static void main(String[] args) {
+               try {
+                       new B().start();
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+       }
+       
+       // include "JoinPoint" in the argument list
+       @AfterThrowing(pointcut = "execution(public void B.start())", throwing = "ex")
+       public void handleExceptionJP(JoinPoint jp, Exception ex) {     
+       }
+
+       // include "JoinPoint.StaticPart" in the argument list
+       @AfterThrowing(pointcut = "execution(public void B.start())", throwing = "ex")
+       public void handleExceptionJPSP(JoinPoint.StaticPart jp, Exception ex) {        
+       }
+       
+       // include "JoinPoint.EnclosingStaticPart" in the argument list
+       @AfterThrowing(pointcut = "execution(public void B.start())", throwing = "ex")
+       public void handleExceptionJPESP(JoinPoint.EnclosingStaticPart jp, Exception ex) {      
+       }
+       
+       // include "JoinPoint" and "JoinPoint.EnclosingStaticPart" in the argument list
+       @AfterThrowing(pointcut = "execution(public void B.start())", throwing = "ex")
+       public void handleExceptionJPESP(JoinPoint jp1, JoinPoint.EnclosingStaticPart jp, Exception ex) {       
+       }
+       
+       // make sure it still works if "JoinPoint" is second on the argument list
+       @AfterThrowing(pointcut = "execution(public void B.start())", throwing = "ex")
+       public void handleExceptionJP2(JoinPoint jp, Exception ex) {    
+       }
+}
+
+class B implements I {
+       public void start() throws Exception {
+               throw new IllegalArgumentException();
+       }       
+}
+
+interface I {
+       public void start() throws Exception;
+}
index 2672caa3e60daea1bb8ca4bddde66f21a4dac5c1..922d278cde249cb3b184818903809096a8e86dd4 100644 (file)
@@ -87,6 +87,14 @@ public class Ajc151Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
          runTest("swallowed exceptions");
   }
   
+  public void testAtAspectVerifyErrorWithAfterThrowingAndthisJoinPoint_pr122742() {
+         runTest("@AJ VerifyError with @AfterThrowing and thisJoinPoint argument");
+  }
+  
+  public void testAtAspectVerifyErrorWithAfterReturningAndthisJoinPoint_pr122742() {
+         runTest("@AJ VerifyError with @AfterReturning and thisJoinPoint argument");
+  }
+  
   public void testSwallowedExceptionIgnored() {
          runTest("swallowed exceptions with xlint");
   }
index d340d0778949a3c946ac1f383aec56a0b5915805..9c6a85b45101b946d797086ff28a30e440f4ca02 100644 (file)
     
     <ajc-test dir="bugs151/pr127299" title="missing import gives funny message">
         <compile files="ModelErrorConversion.aj" options="-1.5"/>
-    </ajc-test>  
-    
+    </ajc-test>
+      
+    <ajc-test dir="bugs151/pr122742" title="@AJ VerifyError with @AfterThrowing and thisJoinPoint argument">
+       <compile files="AfterThrowingTest.java" options="-1.5"/>
+       <run class="AfterThrowingTest">
+       </run>
+    </ajc-test>
+
+    <ajc-test dir="bugs151/pr122742" title="@AJ VerifyError with @AfterReturning and thisJoinPoint argument">
+       <compile files="AfterReturningTest.java" options="-1.5"/>
+       <run class="AfterReturningTest">
+       </run>
+    </ajc-test>
+   
     <ajc-test dir="bugs151/pr120527" title="incorrect unused interface message">
         <compile files="Bugs.aj" options="-warn:unusedPrivate"/>
     </ajc-test>  
index f8b26a41e643f51ebd6cbd3fd0a4842ba0ee5682..4f663de6a9247f2f1d2efd880891734d8fbab8cc 100644 (file)
@@ -285,6 +285,20 @@ public abstract class Advice extends ShadowMunger {
        public UnresolvedType getExtraParameterType() {
                if (!hasExtraParameter()) return ResolvedType.MISSING;
                if (signature instanceof ResolvedMember) {
+                       if (getConcreteAspect().isAnnotationStyleAspect()) {
+                               // bug 122742 - if we're an annotation style aspect then one 
+                               // of the extra parameters could be JoinPoint which we want
+                               // to ignore
+                               int baseParmCnt = getBaseParameterCount();
+                               UnresolvedType[] genericParameterTypes = ((ResolvedMember)signature).getGenericParameterTypes();
+                               while ((baseParmCnt + 1 < genericParameterTypes.length)
+                                               && (genericParameterTypes[baseParmCnt].equals(AjcMemberMaker.TYPEX_JOINPOINT)
+                                                               || genericParameterTypes[baseParmCnt].equals(AjcMemberMaker.TYPEX_STATICJOINPOINT)
+                                                               || genericParameterTypes[baseParmCnt].equals(AjcMemberMaker.TYPEX_ENCLOSINGSTATICJOINPOINT))) {
+                                       baseParmCnt++;
+                               }
+                               return ((ResolvedMember)signature).getGenericParameterTypes()[baseParmCnt];
+                       }
                        return ((ResolvedMember)signature).getGenericParameterTypes()[getBaseParameterCount()];
                } else {
                        return signature.getParameterTypes()[getBaseParameterCount()];