aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraclement <aclement>2006-01-19 09:40:04 +0000
committeraclement <aclement>2006-01-19 09:40:04 +0000
commit7e6cfb2bbb19a01ba9043a3e791d9128dd162e75 (patch)
tree08b891aad76177c7a22fa36fd2b28a60d90c04b8
parent04067a6017182b42f520e450240dc90a2ed86bb4 (diff)
downloadaspectj-7e6cfb2bbb19a01ba9043a3e791d9128dd162e75.tar.gz
aspectj-7e6cfb2bbb19a01ba9043a3e791d9128dd162e75.zip
77166 - newarray joinpoint - testcode
-rw-r--r--tests/features151/newarrayjoinpoint/Eight.java11
-rw-r--r--tests/features151/newarrayjoinpoint/Eleven.java24
-rw-r--r--tests/features151/newarrayjoinpoint/Five.java17
-rw-r--r--tests/features151/newarrayjoinpoint/Four.java21
-rw-r--r--tests/features151/newarrayjoinpoint/Nine.java11
-rw-r--r--tests/features151/newarrayjoinpoint/One.java12
-rw-r--r--tests/features151/newarrayjoinpoint/Seven.java9
-rw-r--r--tests/features151/newarrayjoinpoint/Six.java10
-rw-r--r--tests/features151/newarrayjoinpoint/Ten.java25
-rw-r--r--tests/features151/newarrayjoinpoint/Three.java13
-rw-r--r--tests/features151/newarrayjoinpoint/Twelve.java25
-rw-r--r--tests/features151/newarrayjoinpoint/Two.java12
-rw-r--r--tests/src/org/aspectj/systemtest/ajc151/NewarrayJoinpointTests.java75
-rw-r--r--tests/src/org/aspectj/systemtest/ajc151/newarray_joinpoint.xml153
14 files changed, 418 insertions, 0 deletions
diff --git a/tests/features151/newarrayjoinpoint/Eight.java b/tests/features151/newarrayjoinpoint/Eight.java
new file mode 100644
index 000000000..7a93808d5
--- /dev/null
+++ b/tests/features151/newarrayjoinpoint/Eight.java
@@ -0,0 +1,11 @@
+public class Eight {
+ public static void main(String []argv) {
+ Integer[][] Is = new Integer[5][6];
+ int[][] is = new int[2][4];
+ }
+}
+
+aspect X {
+ before(): call(int[][].new(int,int)) { System.err.println("advice running 1");}
+ before(): call(Integer[][].new(int,int)) { System.err.println("advice running 2");}
+}
diff --git a/tests/features151/newarrayjoinpoint/Eleven.java b/tests/features151/newarrayjoinpoint/Eleven.java
new file mode 100644
index 000000000..da8964fdb
--- /dev/null
+++ b/tests/features151/newarrayjoinpoint/Eleven.java
@@ -0,0 +1,24 @@
+// let's look at using it for real...
+
+public class Eleven {
+
+ static int[] is1,is2;
+
+ public static void main(String []argv) {
+ is1 = new int[5];
+ is2 = new int[8];
+ }
+}
+
+aspect X {
+
+ Object interestingArray = null;
+
+ after(int size) returning(Object o): call(*.new(..)) && within(Eleven) && args(size) {
+ if (size==8) {
+ System.err.println("Found the interesting array");
+ interestingArray = o;
+ }
+ }
+
+} \ No newline at end of file
diff --git a/tests/features151/newarrayjoinpoint/Five.java b/tests/features151/newarrayjoinpoint/Five.java
new file mode 100644
index 000000000..c87e12248
--- /dev/null
+++ b/tests/features151/newarrayjoinpoint/Five.java
@@ -0,0 +1,17 @@
+// different advice kinds on the newarray jp
+public class Five {
+ public static void main(String []argv) {
+ Integer[] Is = new Integer[5];
+ }
+}
+
+aspect X {
+ before(): call(new(..)) && within(Five) { System.err.println("before");}
+}
+aspect Y {
+ after(): call(new(..)) && within(Five){System.err.println("after");}
+ after() returning: call(new(..)) && within(Five){System.err.println("after returning");}
+}
+aspect Z {
+ Integer[] around(): call(new(..)) && within(Five){System.err.println("around!"); return new Integer[500]; }
+}
diff --git a/tests/features151/newarrayjoinpoint/Four.java b/tests/features151/newarrayjoinpoint/Four.java
new file mode 100644
index 000000000..8381f0c42
--- /dev/null
+++ b/tests/features151/newarrayjoinpoint/Four.java
@@ -0,0 +1,21 @@
+// what about printing the join point?
+public class Four {
+ public static void main(String []argv) {
+ Integer[] Is = new Integer[5];
+ Foo f = new Foo(6);
+ }
+}
+
+aspect X {
+ before(): call(Integer[].new(int)) {
+ System.err.println("tjp1=>"+thisJoinPoint);
+ }
+ before(): call(Foo.new(int)) {
+ System.err.println("tjp2=>"+thisJoinPoint);
+ }
+}
+class Foo {
+ Foo(int i) {
+
+ }
+}
diff --git a/tests/features151/newarrayjoinpoint/Nine.java b/tests/features151/newarrayjoinpoint/Nine.java
new file mode 100644
index 000000000..0e9f5fde6
--- /dev/null
+++ b/tests/features151/newarrayjoinpoint/Nine.java
@@ -0,0 +1,11 @@
+public class Nine {
+ public static void main(String []argv) {
+ Integer[][] Is = new Integer[5][6];
+ int[][] is = new int[2][4];
+ }
+}
+
+aspect X {
+ before(int a,int b): call(int[][].new(int,int)) && args(a,b) { System.err.println("advice running 1 ("+a+","+b+")");}
+ before(int a,int b): call(Integer[][].new(int,int)) && args(a,b) { System.err.println("advice running 2 ("+a+","+b+")");}
+}
diff --git a/tests/features151/newarrayjoinpoint/One.java b/tests/features151/newarrayjoinpoint/One.java
new file mode 100644
index 000000000..965746cbb
--- /dev/null
+++ b/tests/features151/newarrayjoinpoint/One.java
@@ -0,0 +1,12 @@
+// basics
+public class One {
+ public static void main(String []argv) {
+ Integer[] is = new Integer[5];
+ }
+}
+
+aspect X {
+ before(): call(Integer[].new(..)) {
+ System.err.println("advice running");
+ }
+}
diff --git a/tests/features151/newarrayjoinpoint/Seven.java b/tests/features151/newarrayjoinpoint/Seven.java
new file mode 100644
index 000000000..da4bb7543
--- /dev/null
+++ b/tests/features151/newarrayjoinpoint/Seven.java
@@ -0,0 +1,9 @@
+public class Seven {
+ public static void main(String []argv) {
+ int[] is = new int[5];
+ }
+}
+
+aspect X {
+ before(): call(int[].new(int)) { System.err.println("advice running");}
+}
diff --git a/tests/features151/newarrayjoinpoint/Six.java b/tests/features151/newarrayjoinpoint/Six.java
new file mode 100644
index 000000000..1087d1c72
--- /dev/null
+++ b/tests/features151/newarrayjoinpoint/Six.java
@@ -0,0 +1,10 @@
+// accessing the size of the array
+public class Six {
+ public static void main(String []argv) {
+ Integer[] Is = new Integer[5];
+ }
+}
+
+aspect X {
+ before(int n): call(Integer[].new(int)) && args(n) { System.err.println("Array size = "+n);}
+} \ No newline at end of file
diff --git a/tests/features151/newarrayjoinpoint/Ten.java b/tests/features151/newarrayjoinpoint/Ten.java
new file mode 100644
index 000000000..b9313f04e
--- /dev/null
+++ b/tests/features151/newarrayjoinpoint/Ten.java
@@ -0,0 +1,25 @@
+public class Ten {
+
+ public static void main(String []argv) {
+ Ten a = new Ten();
+ int [] is = new int[5];
+ }
+}
+
+aspect X {
+
+ pointcut p(Object o): call(new(..)) && target(o) && within(Ten);
+
+ before(Object o): p(o) {
+ System.err.println("before "+o);
+ }
+
+ after(Object o): p(o) {
+ System.err.println("after "+o);
+ }
+
+ after() returning(Object o): call(*.new(..)) && within(Ten) {
+ System.err.println("afterReturning "+o.getClass());
+ }
+
+} \ No newline at end of file
diff --git a/tests/features151/newarrayjoinpoint/Three.java b/tests/features151/newarrayjoinpoint/Three.java
new file mode 100644
index 000000000..93c96b88c
--- /dev/null
+++ b/tests/features151/newarrayjoinpoint/Three.java
@@ -0,0 +1,13 @@
+// incorrect signature
+public class Three {
+ public static void main(String []argv) {
+ Integer[] Is = new Integer[5];
+ }
+}
+
+aspect X {
+ before(): execution(Integer.new(..)) { } // no match, it's execution
+ before(): call(Integer.new(..)) { } // no match, it's an integer array
+ before(): execution(Integer[].new(..)) { } // no match, no execution jp
+ before(): call(Integer[].new()) { } // no match, the call takes an int
+}
diff --git a/tests/features151/newarrayjoinpoint/Twelve.java b/tests/features151/newarrayjoinpoint/Twelve.java
new file mode 100644
index 000000000..f4f802db5
--- /dev/null
+++ b/tests/features151/newarrayjoinpoint/Twelve.java
@@ -0,0 +1,25 @@
+// writing general advice for multiple array types
+
+public class Twelve {
+
+ static int[] is1;
+ static Integer[] is2;
+ static String[][] strs;
+
+ public static void main(String []argv) {
+ is1 = new int[5];
+ is2 = new Integer[8];
+ strs = new String[4][8];
+ }
+}
+
+aspect X {
+
+ after() returning(Object o): call(*.new(..)) && within(Twelve) {
+ System.err.println("It is "+o.getClass());
+ System.err.println("Is it an array? "+o.getClass().isArray());
+ System.err.println("Component type is "+o.getClass().getComponentType());
+ System.err.println("--");
+ }
+
+} \ No newline at end of file
diff --git a/tests/features151/newarrayjoinpoint/Two.java b/tests/features151/newarrayjoinpoint/Two.java
new file mode 100644
index 000000000..008ece774
--- /dev/null
+++ b/tests/features151/newarrayjoinpoint/Two.java
@@ -0,0 +1,12 @@
+// Using wildcard for type
+public class Two {
+ public static void main(String []argv) {
+ Integer[] Is = new Integer[5];
+ }
+}
+
+aspect X {
+ before(): call(*.new(..)) {
+ System.err.println("advice running");
+ }
+}
diff --git a/tests/src/org/aspectj/systemtest/ajc151/NewarrayJoinpointTests.java b/tests/src/org/aspectj/systemtest/ajc151/NewarrayJoinpointTests.java
new file mode 100644
index 000000000..fb46d3b8f
--- /dev/null
+++ b/tests/src/org/aspectj/systemtest/ajc151/NewarrayJoinpointTests.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andy Clement - initial implementation
+ *******************************************************************************/
+package org.aspectj.systemtest.ajc151;
+
+import java.io.File;
+
+import junit.framework.Test;
+
+import org.aspectj.testing.XMLBasedAjcTestCase;
+
+/*
+ * The design:
+ *
+ * There are 3 instructions that create arrays:
+ *
+ * - NEWARRAY for primitive arrays
+ * - ANEWARRAY for object arrays
+ * - MULTIANEWARRAY for multidimensional arrays
+ *
+ * The changes to expose the new joinpoint are in:
+ * BcelClassWeaver.match(LazyMethodGen mg,InstructionHandle ih,BcelShadow enclosingShadow,List shadowAccumulator)
+ *
+ * Determining the type of the array is easy. Determining the size of the array is not easily statically, it is on the stack.
+ *
+ *
+ * to think about:
+ *
+ * args
+ * thisJoinPoint - does anything need to manifest in it?
+ * wildcards in declaringtype 'Integer*' matches 'Integer[]' ?
+ * what is the signature of the joinpoint - are its modifiers simply 'public' ?
+ */
+
+
+public class NewarrayJoinpointTests extends XMLBasedAjcTestCase {
+
+ // when its the creation of a new 'object' (not a primitive) single dimension array
+ public void testTheBasics_1() { runTest("basics"); }
+ public void testTheBasics_2() { runTest("basics - 2"); }
+ public void testWhatShouldntMatch() { runTest("shouldnt match"); }
+ public void testThisJoinPoint() { runTest("thisjoinpoint"); }
+ public void testDifferentAdviceKinds() { runTest("different advice kinds");}
+ public void testArgs() { runTest("args");}
+
+ // when it is the creation of a new array of primitives
+ public void testBasicWithAPrimitiveArray() { runTest("basic primitive array creation");}
+
+
+ // when it is the creation of a new multi-dimensional array
+ public void testBasicWithAMultiDimensionalArray() { runTest("multi dimensional array creation"); }
+ public void testArgsWithAMultiDimensionalArray() { runTest("multi dimensional array args");}
+
+ // complicated
+ public void testUsingTargetAndAfterReturningAdvice() { runTest("using target and after returning");}
+ public void testUsingItForReal() { runTest("using it for real");}
+ public void testDifferentiatingArrayTypes() { runTest("differentiating array types");}
+
+ //
+ public static Test suite() {
+ return XMLBasedAjcTestCase.loadSuite(NewarrayJoinpointTests.class);
+ }
+
+ protected File getSpecFile() {
+ return new File("../tests/src/org/aspectj/systemtest/ajc151/newarray_joinpoint.xml");
+ }
+
+}
diff --git a/tests/src/org/aspectj/systemtest/ajc151/newarray_joinpoint.xml b/tests/src/org/aspectj/systemtest/ajc151/newarray_joinpoint.xml
new file mode 100644
index 000000000..39fa37225
--- /dev/null
+++ b/tests/src/org/aspectj/systemtest/ajc151/newarray_joinpoint.xml
@@ -0,0 +1,153 @@
+<!DOCTYPE suite SYSTEM "../tests/ajcTestSuite.dtd"[]>
+
+<!-- AspectJ v1.5.1 Tests -->
+<suite>
+
+ <ajc-test dir="features151/newarrayjoinpoint" title="basics">
+ <compile files="One.java" options="-1.5 -showWeaveInfo">
+ <message kind="weave" text="Join point 'constructor-call(void java.lang.Integer[].&lt;init&gt;(int))' in Type 'One' (One.java:4) advised by before advice from 'X' (One.java:9)"/>
+ </compile>
+ <run class="One">
+ <stderr>
+ <line text="advice running"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+
+ <ajc-test dir="features151/newarrayjoinpoint" title="basics - 2">
+ <compile files="Two.java" options="-1.5 -showWeaveInfo">
+ <message kind="weave" text="Join point 'constructor-call(void java.lang.Integer[].&lt;init&gt;(int))' in Type 'Two' (Two.java:4) advised by before advice from 'X' (Two.java:9)"/>
+ </compile>
+ <run class="Two">
+ <stderr>
+ <line text="advice running"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="features151/newarrayjoinpoint" title="shouldnt match">
+ <compile files="Three.java" options="-1.5 -showWeaveInfo">
+ <message kind="warning" line="9" text="advice defined in X has not been applied [Xlint:adviceDidNotMatch]"/>
+ <message kind="warning" line="10" text="advice defined in X has not been applied [Xlint:adviceDidNotMatch]"/>
+ <message kind="warning" line="11" text="advice defined in X has not been applied [Xlint:adviceDidNotMatch]"/>
+ <message kind="warning" line="12" text="advice defined in X has not been applied [Xlint:adviceDidNotMatch]"/>
+ </compile>
+ </ajc-test>
+
+ <ajc-test dir="features151/newarrayjoinpoint" title="thisjoinpoint">
+ <compile files="Four.java" options="-1.5 -showWeaveInfo">
+ <message kind="weave" text="Join point 'constructor-call(void java.lang.Integer[].&lt;init&gt;(int))' in Type 'Four' (Four.java:4) advised by before advice from 'X' (Four.java:10)"/>
+ <message kind="weave" text="Join point 'constructor-call(void Foo.&lt;init&gt;(int))' in Type 'Four' (Four.java:5) advised by before advice from 'X' (Four.java:13)"/>
+ </compile>
+ <run class="Four">
+ <stderr>
+ <line text="tjp1=>call(java.lang.Integer[](int))"/>
+ <line text="tjp2=>call(Foo(int))"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="features151/newarrayjoinpoint" title="different advice kinds">
+ <compile files="Five.java" options="-1.5 -showWeaveInfo">
+ <message kind="weave" text="Join point 'constructor-call(void java.lang.Integer[].&lt;init&gt;(int))' in Type 'Five' (Five.java:4) advised by around advice from 'Z' (Five.java:16)"/>
+ <message kind="weave" text="Join point 'constructor-call(void java.lang.Integer[].&lt;init&gt;(int))' in Type 'Five' (Five.java:4) advised by after advice from 'Y' (Five.java:12)"/>
+ <message kind="weave" text="Join point 'constructor-call(void java.lang.Integer[].&lt;init&gt;(int))' in Type 'Five' (Five.java:4) advised by afterReturning advice from 'Y' (Five.java:13)"/>
+ <message kind="weave" text="Join point 'constructor-call(void java.lang.Integer[].&lt;init&gt;(int))' in Type 'Five' (Five.java:4) advised by before advice from 'X' (Five.java:9)"/>
+ </compile>
+ <run class="Five">
+ <stderr>
+ <line text="before"/>
+ <line text="around!"/>
+ <line text="after"/>
+ <line text="after returning"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="features151/newarrayjoinpoint" title="args">
+ <compile files="Six.java" options="-1.5"/>
+ <run class="Six">
+ <stderr>
+ <line text="Array size = 5"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="features151/newarrayjoinpoint" title="basic primitive array creation">
+ <compile files="Seven.java" options="-1.5"/>
+ <run class="Seven">
+ <stderr>
+ <line text="advice running"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="features151/newarrayjoinpoint" title="multi dimensional array creation">
+ <compile files="Eight.java" options="-1.5"/>
+ <run class="Eight">
+ <stderr>
+ <line text="advice running 2"/>
+ <line text="advice running 1"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="features151/newarrayjoinpoint" title="multi dimensional array args">
+ <compile files="Nine.java" options="-1.5"/>
+ <run class="Nine">
+ <stderr>
+ <line text="advice running 2 (5,6)"/>
+ <line text="advice running 1 (2,4)"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="features151/newarrayjoinpoint" title="using target and after returning">
+ <compile files="Ten.java" options="-1.5 -showWeaveInfo">
+ <message kind="warning" line="13" text="advice defined in X has not been applied [Xlint:adviceDidNotMatch]"/>
+ <message kind="warning" line="17" text="advice defined in X has not been applied [Xlint:adviceDidNotMatch]"/>
+ <message kind="weave" text="Join point 'constructor-call(void Ten.&lt;init&gt;())' in Type 'Ten' (Ten.java:4) advised by afterReturning advice from 'X' (Ten.java:21)"/>
+ <message kind="weave" text="Join point 'constructor-call(void int[].&lt;init&gt;(int))' in Type 'Ten' (Ten.java:5) advised by afterReturning advice from 'X' (Ten.java:21)"/>
+ </compile>
+ <run class="Ten">
+ <stderr>
+ <line text="afterReturning class Ten"/>
+ <line text="afterReturning class [I"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="features151/newarrayjoinpoint" title="using it for real">
+ <compile files="Eleven.java" options="-1.5">
+ <!--message kind="weave" text="Join point 'constructor-call(void Ten.&lt;init&gt;())' in Type 'Ten' (Ten.java:4) advised by afterReturning advice from 'X' (Ten.java:21)"/>
+ <message kind="weave" text="Join point 'constructor-call(void int[].&lt;init&gt;(int))' in Type 'Ten' (Ten.java:5) advised by afterReturning advice from 'X' (Ten.java:21)"/-->
+ </compile>
+ <run class="Eleven">
+ <stderr>
+ <line text="Found the interesting array"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="features151/newarrayjoinpoint" title="differentiating array types">
+ <compile files="Twelve.java" options="-1.5"/>
+ <run class="Twelve">
+ <stderr>
+ <line text="It is class [I"/>
+ <line text="Is it an array? true"/>
+ <line text="Component type is int"/>
+ <line text="--"/>
+ <line text="It is class [Ljava.lang.Integer;"/>
+ <line text="Is it an array? true"/>
+ <line text="Component type is class java.lang.Integer"/>
+ <line text="--"/>
+ <line text="It is class [[Ljava.lang.String;"/>
+ <line text="Is it an array? true"/>
+ <line text="Component type is class [Ljava.lang.String;"/>
+ <line text="--"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+</suite> \ No newline at end of file