diff options
author | avasseur <avasseur> | 2005-05-17 08:59:54 +0000 |
---|---|---|
committer | avasseur <avasseur> | 2005-05-17 08:59:54 +0000 |
commit | 8804ab51509ace3479735013356edc571de282cf (patch) | |
tree | 6cfe6190fbdbd163475311b09cbb317615f6422c /tests/java5 | |
parent | 33c5c59a9e5ef8378f8695b905ceddf03f685c2b (diff) | |
download | aspectj-8804ab51509ace3479735013356edc571de282cf.tar.gz aspectj-8804ab51509ace3479735013356edc571de282cf.zip |
LTW and around inling test for code style
Diffstat (limited to 'tests/java5')
4 files changed, 143 insertions, 0 deletions
diff --git a/tests/java5/ataspectj/ajc-ant.xml b/tests/java5/ataspectj/ajc-ant.xml index d6034f2a7..ab0e52437 100644 --- a/tests/java5/ataspectj/ajc-ant.xml +++ b/tests/java5/ataspectj/ajc-ant.xml @@ -38,5 +38,13 @@ </java> </target> + <target name="ltw.AroundInlineMungerTest2"> + <java fork="yes" classname="ataspectj.AroundInlineMungerTest2" failonerror="yes"> + <classpath refid="aj.path"/> + <jvmarg value="-javaagent:${aj.root}/lib/test/loadtime5.jar"/> + <jvmarg value="-Daj5.def=ataspectj/aop-aroundinlinemungertest2.xml"/> + </java> + </target> + <target name="javac.ltw" depends="compile:javac, ltw"/> </project>
\ No newline at end of file diff --git a/tests/java5/ataspectj/ataspectj/AroundInlineMungerTest2.aj b/tests/java5/ataspectj/ataspectj/AroundInlineMungerTest2.aj new file mode 100644 index 000000000..eeec49f9f --- /dev/null +++ b/tests/java5/ataspectj/ataspectj/AroundInlineMungerTest2.aj @@ -0,0 +1,41 @@ +/******************************************************************************* + * 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 AroundInlineMungerTest2 extends TestCase { + + public static void main(String[] args) { + TestHelper.runAndThrowOnFailure(suite()); + } + + public static junit.framework.Test suite() { + return new junit.framework.TestSuite(AroundInlineMungerTest2.class); + } + + public void testAccessNonPublicFromAroundAdvice() { + target(); + assertEquals(3, AroundInlineMungerTestAspects2.Open.aroundCount); + assertEquals(6, AroundInlineMungerTestAspects2.Open.beforeCount); + } + + public void target() {} + +} diff --git a/tests/java5/ataspectj/ataspectj/AroundInlineMungerTestAspects2.aj b/tests/java5/ataspectj/ataspectj/AroundInlineMungerTestAspects2.aj new file mode 100644 index 000000000..28d7f05af --- /dev/null +++ b/tests/java5/ataspectj/ataspectj/AroundInlineMungerTestAspects2.aj @@ -0,0 +1,87 @@ +/******************************************************************************* + * 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 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 AroundInlineMungerTestAspects2 { + + public static abstract aspect OpenBase { + protected void superMethod() {} + } + + public static abstract aspect OpenSubBase extends OpenBase {} + + // aspect will be prepared for inlining + public static aspect Open extends OpenSubBase { + + public static int aroundCount = 0; + public static int beforeCount = 0; + + private int i; + private static int I; + + Object around() : execution(* ataspectj.AroundInlineMungerTest2.target()) { + 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 proceed(); + } + + // this advice to test around advice body call/get/set advising + before() : (call(* ataspectj.AroundInlineMungerTestAspects2.Open.priv(..)) + || get(int ataspectj.AroundInlineMungerTestAspects2.Open.i) + || set(int ataspectj.AroundInlineMungerTestAspects2.Open.i) + || get(int ataspectj.AroundInlineMungerTestAspects2.Open.I) + || set(int ataspectj.AroundInlineMungerTestAspects2.Open.I) + )&& this(ataspectj.AroundInlineMungerTestAspects2.Open) { + beforeCount++; + } + + Object around() : execution(* ataspectj.AroundInlineMungerTest2.target()) { + 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 proceed(); + } + + Object around() : execution(* ataspectj.AroundInlineMungerTest2.target()) { + aroundCount++; + // all those field access will be wrapped + int li = i; + i = li; + int lI = I; + I = lI; + return 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/java5/ataspectj/ataspectj/aop-aroundinlinemungertest2.xml b/tests/java5/ataspectj/ataspectj/aop-aroundinlinemungertest2.xml new file mode 100644 index 000000000..3f7de3cd3 --- /dev/null +++ b/tests/java5/ataspectj/ataspectj/aop-aroundinlinemungertest2.xml @@ -0,0 +1,7 @@ +<?xml version="1.0"?> +<aspectj> + <weaver options="-XmessageHolderClass:ataspectj.TestHelper"/> + <aspects> + <aspect name="ataspectj.AroundInlineMungerTestAspects2.Open"/> + </aspects> +</aspectj> |