diff options
author | avasseur <avasseur> | 2005-05-03 14:43:43 +0000 |
---|---|---|
committer | avasseur <avasseur> | 2005-05-03 14:43:43 +0000 |
commit | 9e2ef17dadcfb72eb462e59d996282e0ff0da76b (patch) | |
tree | f6e29a4b3a0d1985f30acffa5a54d16abc23a527 /tests | |
parent | a89568a77f2d3e74b0d23f3f7b0e112d7ca92d74 (diff) | |
download | aspectj-9e2ef17dadcfb72eb462e59d996282e0ff0da76b.tar.gz aspectj-9e2ef17dadcfb72eb462e59d996282e0ff0da76b.zip |
@AJ around inline + test, fix a bug in BcelClassWeaver on my way
Diffstat (limited to 'tests')
4 files changed, 169 insertions, 56 deletions
diff --git a/tests/java5/ataspectj/ataspectj/AroundInlineMungerTest.java b/tests/java5/ataspectj/ataspectj/AroundInlineMungerTest.java new file mode 100644 index 000000000..8be6217b4 --- /dev/null +++ b/tests/java5/ataspectj/ataspectj/AroundInlineMungerTest.java @@ -0,0 +1,108 @@ +/******************************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexandre Vasseur initial implementation + *******************************************************************************/ +package ataspectj; + +import junit.framework.TestCase; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Before; +import org.aspectj.lang.ProceedingJoinPoint; + +/** + * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a> + */ +public class AroundInlineMungerTest extends TestCase { + + public static void main(String[] args) { + TestHelper.runAndThrowOnFailure(suite()); + } + + public static junit.framework.Test suite() { + return new junit.framework.TestSuite(AroundInlineMungerTest.class); + } + + public void testAccessNonPublicFromAroundAdvice() { + target(); + assertEquals(3, Open.aroundCount); + assertEquals(6, Open.beforeCount); + } + + public void target() {} + + public static class OpenBase { + protected void superMethod() {} + } + + public static class OpenSubBase extends OpenBase {} + + // aspect will be prepared for inlining + @Aspect + public static class Open extends OpenSubBase { + + public static int aroundCount = 0; + public static int beforeCount = 0; + + private int i; + private static int I; + + @Around("execution(* ataspectj.AroundInlineMungerTest.target())") + public Object around1(ProceedingJoinPoint jp) throws Throwable { + aroundCount++; + priv(1, 2L, 3); + super.superMethod(); + new Inner().priv();//fails to be wrapped so this advice will not be inlined but previous call were still prepared + return jp.proceed(); + } + + // this advice to test around advice body call/get/set advising + @Before("(call(* ataspectj.AroundInlineMungerTest.Open.priv(..))" + + " || get(int ataspectj.AroundInlineMungerTest.Open.i)" + + " || set(int ataspectj.AroundInlineMungerTest.Open.i)" + + " || get(int ataspectj.AroundInlineMungerTest.Open.I)" + + " || set(int ataspectj.AroundInlineMungerTest.Open.I)" + + " )&& this(ataspectj.AroundInlineMungerTest.Open)") + public void before1() { + beforeCount++; + } + + @Around("execution(* ataspectj.AroundInlineMungerTest.target())") + public Object around2(ProceedingJoinPoint jp) throws Throwable { + aroundCount++; + super.superMethod(); + new Inner().priv();//fails to be wrapped so next calls won't be prepared but previous was + priv(1, 2L, 3); + return jp.proceed(); + } + + @Around("execution(* ataspectj.AroundInlineMungerTest.target())") + public Object around3(ProceedingJoinPoint jp) throws Throwable { + aroundCount++; + // all those field access will be wrapped + int li = i; + i = li; + int lI = I; + I = lI; + return jp.proceed(); + } + + // -- some private member for which access will be wrapped so that around advice can be inlined + + private void priv(int i, long j, int k) { + long l = i + j + k; + } + + private static class Inner { + private Inner() {} + private void priv() {}; + } + } +} diff --git a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/AtAjSyntaxTests.java b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/AtAjSyntaxTests.java index 0ff079345..7927a2675 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/AtAjSyntaxTests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/AtAjSyntaxTests.java @@ -18,7 +18,7 @@ import junit.framework.Test; import org.aspectj.testing.XMLBasedAjcTestCase; import org.aspectj.testing.AutowiredXMLBasedAjcTestCase; -/** +/** * A suite for @AspectJ aspects located in java5/ataspectj * * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a> diff --git a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/misuse.xml b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/misuse.xml index d56357c80..d9c0ba75c 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/misuse.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/misuse.xml @@ -4,20 +4,20 @@ <suite> -<!-- <comment>this one is ok - too simple - could be removed..</comment>--> -<!-- <ajc-test dir="java5/ataspectj"--> -<!-- pr="" title="@Aspect class extending @Aspect class">--> -<!-- <compile files="ataspectj/misuse/Test005.java" options="-1.5 -Xdev:NoAtAspectJProcessing">--> -<!-- </compile>--> -<!-- </ajc-test>--> -<!----> -<!-- <comment>just a warning - might be skept if further optimized in Aj5Attributes..</comment>--> -<!-- <ajc-test dir="java5/ataspectj"--> -<!-- pr="" title="class with @Before extending @Aspect class">--> -<!-- <compile files="ataspectj/misuse/Test006.java" options="-1.5 -Xdev:NoAtAspectJProcessing">--> -<!-- <message kind="warning" line="11" text="Found @AspectJ annotations in a non @Aspect type 'ataspectj.misuse.Test006B'"/>--> -<!-- </compile>--> -<!-- </ajc-test>--> + <comment>this one is ok - too simple - could be removed..</comment> + <ajc-test dir="java5/ataspectj" + pr="" title="@Aspect class extending @Aspect class"> + <compile files="ataspectj/misuse/Test005.java" options="-1.5 -Xdev:NoAtAspectJProcessing"> + </compile> + </ajc-test> + + <comment>just a warning - might be skept if further optimized in Aj5Attributes..</comment> + <ajc-test dir="java5/ataspectj" + pr="" title="class with @Before extending @Aspect class"> + <compile files="ataspectj/misuse/Test006.java" options="-1.5 -Xdev:NoAtAspectJProcessing"> + <message kind="warning" line="11" text="Found @AspectJ annotations in a non @Aspect type 'ataspectj.misuse.Test006B'"/> + </compile> + </ajc-test> <comment>a warning. We ignore the pointcut (TBD) - line is enclosing class (TBD Andy do better ?)</comment> <ajc-test dir="java5/ataspectj" @@ -27,7 +27,6 @@ </compile> </ajc-test> - <!-- <ajc-test dir="java5/ataspectj"--> <!-- pr="" title="@Aspect on interface">--> <!-- <compile files="ataspectj/misuse/Test010.java" options="-1.5 -Xdev:NoAtAspectJProcessing">--> @@ -35,46 +34,46 @@ <!-- </compile>--> <!-- </ajc-test>--> -<!-- <comment>line is enclosing class - TBD</comment>--> -<!-- <ajc-test dir="java5/ataspectj"--> -<!-- pr="" title="@Pointcut with garbage string">--> -<!-- <compile files="ataspectj/misuse/Test014.java" options="-1.5 -Xdev:NoAtAspectJProcessing">--> -<!-- <message kind="error" line="7" text="Cannot parse @Pointcut 'call%dddd"/>--> -<!-- </compile>--> -<!-- </ajc-test>--> -<!----> -<!-- <comment>line is enclosing class - TBD</comment>--> -<!-- <ajc-test dir="java5/ataspectj"--> -<!-- pr="" title="@Pointcut with throws clause">--> -<!-- <compile files="ataspectj/misuse/Test016.java" options="-1.5 -Xdev:NoAtAspectJProcessing">--> -<!-- <message kind="warning" line="7" text="Found @Pointcut on a method throwing exception 'someCall()V'"/>--> -<!-- </compile>--> -<!-- </ajc-test>--> -<!----> -<!-- <comment>very dirty hack - can't get this location to work properly so added match all error..</comment>--> -<!-- <ajc-test dir="java5/ataspectj"--> -<!-- pr="" title="@AfterReturning with wrong number of args">--> -<!-- <compile files="ataspectj/misuse/Test019.java" options="-1.5 -Xdev:NoAtAspectJProcessing -Xlint:ignore">--> -<!-- <message kind="error" line="1" text="the parameter x is not bound"/>--> -<!-- <message kind="error"/>--> -<!-- </compile>--> -<!-- </ajc-test>--> -<!----> -<!-- <comment>line number is enclosing type</comment>--> -<!-- <ajc-test dir="java5/ataspectj"--> -<!-- pr="" title="@Before on non-public method">--> -<!-- <compile files="ataspectj/misuse/Test020.java" options="-1.5 -Xdev:NoAtAspectJProcessing -Xlint:ignore">--> -<!-- <message kind="error" line="7" text="Found @AspectJ annotation on a non public advice 'someCall()V'"/>--> -<!-- </compile>--> -<!-- </ajc-test>--> -<!----> -<!-- <comment>line number is enclosing type</comment>--> -<!-- <ajc-test dir="java5/ataspectj"--> -<!-- pr="" title="@Before on method not returning void">--> -<!-- <compile files="ataspectj/misuse/Test021.java" options="-1.5 -Xdev:NoAtAspectJProcessing -Xlint:ignore">--> -<!-- <message kind="error" line="7" text="Found @AspectJ annotation on a non around advice not returning void 'someCall()I'"/>--> -<!-- </compile>--> -<!-- </ajc-test>--> + <comment>line is enclosing class - TBD</comment> + <ajc-test dir="java5/ataspectj" + pr="" title="@Pointcut with garbage string"> + <compile files="ataspectj/misuse/Test014.java" options="-1.5 -Xdev:NoAtAspectJProcessing"> + <message kind="error" line="7" text="Cannot parse @Pointcut 'call%dddd"/> + </compile> + </ajc-test> + + <comment>line is enclosing class - TBD</comment> + <ajc-test dir="java5/ataspectj" + pr="" title="@Pointcut with throws clause"> + <compile files="ataspectj/misuse/Test016.java" options="-1.5 -Xdev:NoAtAspectJProcessing"> + <message kind="warning" line="7" text="Found @Pointcut on a method throwing exception 'someCall()V'"/> + </compile> + </ajc-test> + + <comment>very dirty hack - can't get this location to work properly so added match all error..</comment> + <ajc-test dir="java5/ataspectj" + pr="" title="@AfterReturning with wrong number of args"> + <compile files="ataspectj/misuse/Test019.java" options="-1.5 -Xdev:NoAtAspectJProcessing -Xlint:ignore"> + <message kind="error" line="1" text="the parameter x is not bound"/> + <message kind="error"/> + </compile> + </ajc-test> + + <comment>line number is enclosing type</comment> + <ajc-test dir="java5/ataspectj" + pr="" title="@Before on non-public method"> + <compile files="ataspectj/misuse/Test020.java" options="-1.5 -Xdev:NoAtAspectJProcessing -Xlint:ignore"> + <message kind="error" line="7" text="Found @AspectJ annotation on a non public advice 'someCall()V'"/> + </compile> + </ajc-test> + + <comment>line number is enclosing type</comment> + <ajc-test dir="java5/ataspectj" + pr="" title="@Before on method not returning void"> + <compile files="ataspectj/misuse/Test021.java" options="-1.5 -Xdev:NoAtAspectJProcessing -Xlint:ignore"> + <message kind="error" line="7" text="Found @AspectJ annotation on a non around advice not returning void 'someCall()I'"/> + </compile> + </ajc-test> <!-- ALEX: todo diff --git a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/syntax.xml b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/syntax.xml index daeb4da84..eab2949e5 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/syntax.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/syntax.xml @@ -87,4 +87,10 @@ <run class="ataspectj.PerClauseTest"/> </ajc-test> + <ajc-test dir="java5/ataspectj" title="AroundInlineMunger"> + <compile files="ataspectj/AroundInlineMungerTest.java,ataspectj/TestHelper.java" options="-1.5 -XnoInline -Xdev:NoAtAspectJProcessing -Xlint:ignore"/> + <run class="ataspectj.AroundInlineMungerTest"/> + <compile files="ataspectj/AroundInlineMungerTest.java,ataspectj/TestHelper.java" options="-1.5 -Xdev:NoAtAspectJProcessing -Xlint:ignore"/> + <run class="ataspectj.AroundInlineMungerTest"/> + </ajc-test> </suite>
\ No newline at end of file |