From: aclement Date: Thu, 19 Jan 2006 09:40:04 +0000 (+0000) Subject: 77166 - newarray joinpoint - testcode X-Git-Tag: POST_MEMORY_CHANGES~172 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7e6cfb2bbb19a01ba9043a3e791d9128dd162e75;p=aspectj.git 77166 - newarray joinpoint - testcode --- 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file