aboutsummaryrefslogtreecommitdiffstats
path: root/tests/java5/ataspectj
diff options
context:
space:
mode:
authoravasseur <avasseur>2005-07-04 12:58:41 +0000
committeravasseur <avasseur>2005-07-04 12:58:41 +0000
commit44dc6e9700b0e9a013d53c8444971e4ba47f9699 (patch)
tree2133ba50eff90f6c5b38b65175faedaee8c35e68 /tests/java5/ataspectj
parentc3b7d70b101defcc0b0284895ceb56bfca6a1548 (diff)
downloadaspectj-44dc6e9700b0e9a013d53c8444971e4ba47f9699.tar.gz
aspectj-44dc6e9700b0e9a013d53c8444971e4ba47f9699.zip
fix source location for @AJ + fix the AsmManager behavior for @AJ (still no luck in AJDT though)
Diffstat (limited to 'tests/java5/ataspectj')
-rw-r--r--tests/java5/ataspectj/ajc-ant.xml2
-rw-r--r--tests/java5/ataspectj/ataspectj/SingletonAspectBindingsTest.java19
-rw-r--r--tests/java5/ataspectj/ataspectj/SingletonAspectBindingsTest2.aj150
3 files changed, 170 insertions, 1 deletions
diff --git a/tests/java5/ataspectj/ajc-ant.xml b/tests/java5/ataspectj/ajc-ant.xml
index e4d4008eb..bd5f98a2b 100644
--- a/tests/java5/ataspectj/ajc-ant.xml
+++ b/tests/java5/ataspectj/ajc-ant.xml
@@ -21,7 +21,7 @@
<!-- use META-INF/aop.xml style -->
<classpath path="ataspectj/pathentry"/>
<jvmarg value="-javaagent:${aj.root}/lib/test/loadtime5.jar"/>
- <!--<jvmarg line="${jdwp}"/>-->
+<!-- <jvmarg line="${jdwp}"/>-->
</java>
</target>
diff --git a/tests/java5/ataspectj/ataspectj/SingletonAspectBindingsTest.java b/tests/java5/ataspectj/ataspectj/SingletonAspectBindingsTest.java
index 27ce636b4..e59821cb8 100644
--- a/tests/java5/ataspectj/ataspectj/SingletonAspectBindingsTest.java
+++ b/tests/java5/ataspectj/ataspectj/SingletonAspectBindingsTest.java
@@ -19,6 +19,9 @@ import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import junit.framework.TestCase;
+import java.io.File;
+import java.io.FileReader;
+
/**
* Test various advice and JoinPoint + binding, without pc ref
*
@@ -129,4 +132,20 @@ public class SingletonAspectBindingsTest extends TestCase {
}
}
+
+// public void testHe() throws Throwable {
+// //Allow to look inn file based on advises/advised-by offset numbers
+// File f = new File("../tests/java5/ataspectj/ataspectj/SingletonAspectBindingsTest2.aj");
+// FileReader r = new FileReader(f);
+// int i = 0;
+// for (i = 0; i < 2800; i++) {
+// r.read();
+// }
+// for (;i < 2900; i++) {
+// if (i == 2817) System.out.print("X");
+// System.out.print((char)r.read());
+// }
+// System.out.print("|DONE");
+// r.close();
+// }
}
diff --git a/tests/java5/ataspectj/ataspectj/SingletonAspectBindingsTest2.aj b/tests/java5/ataspectj/ataspectj/SingletonAspectBindingsTest2.aj
new file mode 100644
index 000000000..5083375bb
--- /dev/null
+++ b/tests/java5/ataspectj/ataspectj/SingletonAspectBindingsTest2.aj
@@ -0,0 +1,150 @@
+/*******************************************************************************
+ * 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:
+ * initial implementation Alexandre Vasseur
+ *******************************************************************************/
+package ataspectj;
+
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.After;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.ProceedingJoinPoint;
+import junit.framework.TestCase;
+
+import java.io.File;
+import java.io.FileReader;
+
+/**
+ * Test various advice and JoinPoint + binding, without pc ref
+ *
+ * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
+ */
+public class SingletonAspectBindingsTest2 extends TestCase {
+
+ static StringBuffer s_log = new StringBuffer();
+ static void log(String s) {
+ s_log.append(s).append(" ");
+ }
+
+ public static void main(String[] args) {
+ TestHelper.runAndThrowOnFailure(suite());
+ }
+
+ public static junit.framework.Test suite() {
+ return new junit.framework.TestSuite(SingletonAspectBindingsTest2.class);
+ }
+
+ public void hello() {
+ log("hello");
+ }
+
+ public void hello(String s) {
+ log("hello-");
+ log(s);
+ }
+
+ public void testExecutionWithThisBinding() {
+ s_log = new StringBuffer();
+ SingletonAspectBindingsTest2 me = new SingletonAspectBindingsTest2();
+ me.hello();
+ // see here advice precedence as in source code order
+ //TODO check around relative order
+ // see fix in BcelWeaver sorting shadowMungerList
+ //assertEquals("around2_ around_ before hello after _around _around2 ", s_log.toString());
+ assertEquals("around_ around2_ before hello _around2 _around after ", s_log.toString());
+ }
+
+ public void testExecutionWithArgBinding() {
+ s_log = new StringBuffer();
+ SingletonAspectBindingsTest2 me = new SingletonAspectBindingsTest2();
+ me.hello("x");
+ assertEquals("before- x hello- x ", s_log.toString());
+ }
+
+
+ //@Aspect
+ static aspect TestAspect {
+
+ static int s = 0;
+
+ static {
+ s++;
+ }
+
+ public TestAspect() {
+ // assert clinit has run when singleton aspectOf reaches that
+ assertTrue(s>0);
+ }
+
+ //public static TestAspect aspectOf() {return null;}
+
+ void around() : execution(* ataspectj.SingletonAspectBindingsTest2.hello()) {
+ //public void aaround(ProceedingJoinPoint jp) {
+ log("around_");
+ try {
+ proceed();
+ } catch (Throwable throwable) {
+ throwable.printStackTrace();
+ }
+ log("_around");
+ }
+
+ void around(Object t) : execution(* ataspectj.SingletonAspectBindingsTest2.hello()) && this(t) {
+ //public void around2(ProceedingJoinPoint jp, Object t) {
+ log("around2_");
+ assertEquals(SingletonAspectBindingsTest2.class.getName(), t.getClass().getName());
+ try {
+ proceed(t);
+ } catch (Throwable throwable) {
+ throwable.printStackTrace();
+ }
+ log("_around2");
+ }
+
+ before() : execution(* ataspectj.SingletonAspectBindingsTest2.hello()) {
+ //public void before(JoinPoint.StaticPart sjp) {
+ log("before");
+ assertEquals("hello", thisJoinPointStaticPart.getSignature().getName());
+ }
+
+ after() : execution(* ataspectj.SingletonAspectBindingsTest2.hello()) {
+ //public void after(JoinPoint.StaticPart sjp) {
+ log("after");
+ assertEquals("execution(public void ataspectj.SingletonAspectBindingsTest2.hello())", thisJoinPointStaticPart.toLongString());
+ }
+
+ //TODO see String alias, see before advice name clash - all that works
+ // 1/ String is in java.lang.* - see SimpleScope.javalangPrefix array
+ // 2/ the advice is register thru its Bcel Method mirror
+ before(String s) : execution(* ataspectj.SingletonAspectBindingsTest2.hello(String)) && args(s) {
+ //public void before(String s, JoinPoint.StaticPart sjp) {
+ log("before-");
+ log(s);
+ assertEquals("hello", thisJoinPointStaticPart.getSignature().getName());
+ }
+
+ }
+
+// public void testHe() throws Throwable {
+// File f = new File("../tests/java5/ataspectj/ataspectj/SingletonAspectBindingsTest2.aj");
+// FileReader r = new FileReader(f);
+// int i = 0;
+// for (i = 0; i < 3950; i++) {
+// r.read();
+// }
+// for (;i < 4000; i++) {
+// if (i == 3983) System.out.print("X");
+// System.out.print((char)r.read());
+// }
+// System.out.print("|DONE");
+// r.close();
+// }
+}