diff options
author | avasseur <avasseur> | 2005-10-17 10:49:11 +0000 |
---|---|---|
committer | avasseur <avasseur> | 2005-10-17 10:49:11 +0000 |
commit | bb2d44016148994e99f8a2389754b69f18b710b2 (patch) | |
tree | af8d62f1f9df15f44b915be60b221a908cfc9d49 /tests | |
parent | 0b5a5420704f7e32509fffaef66d8c94dcedcf17 (diff) | |
download | aspectj-bb2d44016148994e99f8a2389754b69f18b710b2.tar.gz aspectj-bb2d44016148994e99f8a2389754b69f18b710b2.zip |
implement @AspectJ ITD @DeclareParents and @DeclareImplements
changed AjType as ITD field is meaningless (as @AJ ITD is interface driven)
Diffstat (limited to 'tests')
5 files changed, 174 insertions, 3 deletions
diff --git a/tests/java5/ataspectj/annotationGen/ITDTest.aj b/tests/java5/ataspectj/annotationGen/ITDTest.aj index 841af326b..bfa2e58bd 100644 --- a/tests/java5/ataspectj/annotationGen/ITDTest.aj +++ b/tests/java5/ataspectj/annotationGen/ITDTest.aj @@ -145,9 +145,9 @@ public aspect ITDTest { } catch (ClassNotFoundException cnf) { throw new RuntimeException(cnf); } - assertEquals("1: ",1,x.getDeclaredITDFields().length); - assertEquals("i: ","i",x.getDeclaredITDFields()[0].getName()); - assertEquals("1: ",1,x.getITDMethods().length); + //assertEquals("ITD field 1: ",1,x.getDeclaredITDFields().length); + //assertEquals("ITD filed name i: ","i",x.getDeclaredITDFields()[0].getName()); + assertEquals("ITD method 1: ",1,x.getITDMethods().length); assertEquals("getNumber: ","getNumber",x.getITDMethods()[0].getName()); } @@ -163,6 +163,9 @@ class A {} class X { @org.aspectj.lang.annotation.DeclareParents("org.xyz..*") + public static I myMixin = new Mixin(); + + public static class Mixin implements I { private int i = 0; diff --git a/tests/java5/ataspectj/ataspectj/DeclareParentsImplementsTest.java b/tests/java5/ataspectj/ataspectj/DeclareParentsImplementsTest.java new file mode 100644 index 000000000..aee12280e --- /dev/null +++ b/tests/java5/ataspectj/ataspectj/DeclareParentsImplementsTest.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * 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.DeclareParents; +import org.aspectj.lang.annotation.Before; + +import java.util.Arrays; + +/** + * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a> + */ +public class DeclareParentsImplementsTest extends TestCase { + + static class Target { + void target() { + log("hello"); + } + } + + static interface Introduced { + final static int field1 = 1; + void intro(); + } + + static class Implementation implements Introduced { + public void intro() { + log("intro-"+field1); + // we cannot copy the raw bytecode as there might be super.* calls, and other OO stuff + } + } + + @Aspect + static class TestAspect { + + @DeclareParents("ataspectj.DeclareParentsImplementsTest.Target") + public static Introduced i = new Implementation();//see here control of instantiation + // will lead to: class Target implements Introduced { + // void intro(args) { TestAspect.i.intro(args); } + // } + + @Before("execution(* ataspectj.DeclareParentsImplementsTest.Introduced.intro())") + public void before() { + log("aop"); + } + } + + static StringBuffer s_log = new StringBuffer(); + static void log(String s) { + s_log.append(s).append(" "); + } + + public void testDecPInt() { + Class[] intfs = Target.class.getInterfaces(); + assertTrue("Was not introduced", Arrays.asList(intfs).contains(Introduced.class)); + } + + public void testDecPIntAdvised() { + s_log = new StringBuffer(); + ((Introduced)new Target()).intro(); + assertEquals("aop intro-1 ", s_log.toString()); + } + + public static void main(String[] args) { + TestHelper.runAndThrowOnFailure(suite()); + } + + public static junit.framework.Test suite() { + return new junit.framework.TestSuite(DeclareParentsImplementsTest.class); + } +} diff --git a/tests/java5/ataspectj/ataspectj/DeclareParentsInterfaceTest.java b/tests/java5/ataspectj/ataspectj/DeclareParentsInterfaceTest.java new file mode 100644 index 000000000..ffac0e4a2 --- /dev/null +++ b/tests/java5/ataspectj/ataspectj/DeclareParentsInterfaceTest.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * 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.Before; +import org.aspectj.lang.annotation.DeclareImplements; + +import java.util.Arrays; + +/** + * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a> + */ +public class DeclareParentsInterfaceTest extends TestCase { + + static class Target { + void target() { + log("hello"); + } + } + + static interface Marker {} + + @Aspect + static class TestAspect { + + @DeclareImplements("ataspectj.DeclareParentsInterfaceTest.Target") + Marker introduce; + + @Before("execution(* ataspectj.DeclareParentsInterfaceTest.Marker+.target())") + public void before() { + log("aop"); + } + } + + static StringBuffer s_log = new StringBuffer(); + static void log(String s) { + s_log.append(s).append(" "); + } + + public void testDecPInt() { + Class[] intfs = Target.class.getInterfaces(); + assertTrue("Was not introduced", Arrays.asList(intfs).contains(Marker.class)); + } + + public void testDecPIntAdvised() { + s_log = new StringBuffer(); + new Target().target(); + assertEquals("aop hello ", s_log.toString()); + } + + public static void main(String[] args) { + TestHelper.runAndThrowOnFailure(suite()); + } + + public static junit.framework.Test suite() { + return new junit.framework.TestSuite(DeclareParentsInterfaceTest.class); + } +} diff --git a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/AtAjSyntaxTests.java b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/AtAjSyntaxTests.java index e4f883c66..5e802c4a7 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/AtAjSyntaxTests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/AtAjSyntaxTests.java @@ -120,4 +120,12 @@ public class AtAjSyntaxTests extends XMLBasedAjcTestCase { public void testBug104212() { runTest("Bug104212"); } + + public void testDeclareParentsInterface() { + runTest("DeclareParentsInterface"); + } + + public void testDeclareParentsImplements() { + runTest("DeclareParentsImplements"); + } }
\ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/syntax.xml b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/syntax.xml index 04667476b..89f2e0f08 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/syntax.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/syntax.xml @@ -149,5 +149,14 @@ <run class="ataspectj.Bug104212"/> </ajc-test> + <ajc-test dir="java5/ataspectj" title="DeclareParentsInterface"> + <compile files="ataspectj/DeclareParentsInterfaceTest.java,ataspectj/TestHelper.java" options="-1.5 -Xdev:NoAtAspectJProcessing -Xlint:ignore"/> + <run class="ataspectj.DeclareParentsInterfaceTest"/> + </ajc-test> + + <ajc-test dir="java5/ataspectj" title="DeclareParentsImplements"> + <compile files="ataspectj/DeclareParentsImplementsTest.java,ataspectj/TestHelper.java" options="-1.5 -Xdev:NoAtAspectJProcessing -Xlint:ignore"/> + <run class="ataspectj.DeclareParentsImplementsTest"/> + </ajc-test> </suite>
\ No newline at end of file |