]> source.dussan.org Git - aspectj.git/commitdiff
77166 - newarray joinpoint - testcode
authoraclement <aclement>
Thu, 19 Jan 2006 09:40:04 +0000 (09:40 +0000)
committeraclement <aclement>
Thu, 19 Jan 2006 09:40:04 +0000 (09:40 +0000)
14 files changed:
tests/features151/newarrayjoinpoint/Eight.java [new file with mode: 0644]
tests/features151/newarrayjoinpoint/Eleven.java [new file with mode: 0644]
tests/features151/newarrayjoinpoint/Five.java [new file with mode: 0644]
tests/features151/newarrayjoinpoint/Four.java [new file with mode: 0644]
tests/features151/newarrayjoinpoint/Nine.java [new file with mode: 0644]
tests/features151/newarrayjoinpoint/One.java [new file with mode: 0644]
tests/features151/newarrayjoinpoint/Seven.java [new file with mode: 0644]
tests/features151/newarrayjoinpoint/Six.java [new file with mode: 0644]
tests/features151/newarrayjoinpoint/Ten.java [new file with mode: 0644]
tests/features151/newarrayjoinpoint/Three.java [new file with mode: 0644]
tests/features151/newarrayjoinpoint/Twelve.java [new file with mode: 0644]
tests/features151/newarrayjoinpoint/Two.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc151/NewarrayJoinpointTests.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc151/newarray_joinpoint.xml [new file with mode: 0644]

diff --git a/tests/features151/newarrayjoinpoint/Eight.java b/tests/features151/newarrayjoinpoint/Eight.java
new file mode 100644 (file)
index 0000000..7a93808
--- /dev/null
@@ -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 (file)
index 0000000..da8964f
--- /dev/null
@@ -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 (file)
index 0000000..c87e122
--- /dev/null
@@ -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 (file)
index 0000000..8381f0c
--- /dev/null
@@ -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 (file)
index 0000000..0e9f5fd
--- /dev/null
@@ -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 (file)
index 0000000..965746c
--- /dev/null
@@ -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 (file)
index 0000000..da4bb75
--- /dev/null
@@ -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 (file)
index 0000000..1087d1c
--- /dev/null
@@ -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 (file)
index 0000000..b9313f0
--- /dev/null
@@ -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 (file)
index 0000000..93c96b8
--- /dev/null
@@ -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 (file)
index 0000000..f4f802d
--- /dev/null
@@ -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 (file)
index 0000000..008ece7
--- /dev/null
@@ -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 (file)
index 0000000..fb46d3b
--- /dev/null
@@ -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 (file)
index 0000000..39fa372
--- /dev/null
@@ -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