@@ -0,0 +1,7 @@ | |||
public class A { | |||
S s = new S(); | |||
public void method() { | |||
System.out.println("A.method() running"); | |||
s.m1(); | |||
} | |||
} |
@@ -0,0 +1,7 @@ | |||
public class B { | |||
T t = new T(); | |||
public void method() { | |||
System.out.println("B.method() running"); | |||
t.m2(); | |||
} | |||
} |
@@ -0,0 +1,21 @@ | |||
import java.lang.reflect.Method; | |||
public class Main { | |||
public static void main(String []argv) { | |||
try { | |||
System.out.println("into:main"); | |||
Class clazzA = Class.forName("A"); | |||
Method clazzAMethod = clazzA.getMethod("method",null); | |||
clazzAMethod.invoke(clazzA.newInstance(),null); | |||
Class clazzB= Class.forName("B"); | |||
Method clazzBMethod = clazzB.getMethod("method",null); | |||
clazzBMethod.invoke(clazzB.newInstance(),null); | |||
System.out.println("leave:main"); | |||
} catch (Throwable t) { | |||
t.printStackTrace(); | |||
} | |||
} | |||
} |
@@ -0,0 +1,6 @@ | |||
public class T { | |||
public void m1() {System.out.println("T.m1() running");} | |||
public void m2() {System.out.println("T.m2() running");} | |||
} |
@@ -0,0 +1,9 @@ | |||
import java.io.Serializable; | |||
public aspect X { | |||
declare parents: T implements Serializable; | |||
before(): call(* Serializable+.m*(..)) { | |||
System.out.println("advice running"); | |||
} | |||
} |
@@ -0,0 +1,7 @@ | |||
<aspectj> | |||
<weaver options="-showWeaveInfo -verbose"/> | |||
<aspects> | |||
<aspect name="X"/> | |||
</aspects> | |||
</aspectj> | |||
@@ -0,0 +1,7 @@ | |||
public class A { | |||
T t = new T(); | |||
public void method() { | |||
System.out.println("A.method() running"); | |||
t.m1(); | |||
} | |||
} |
@@ -0,0 +1,17 @@ | |||
import java.lang.reflect.Method; | |||
public class Main { | |||
public static void main(String []argv) { | |||
try { | |||
System.out.println("into:main"); | |||
Class clazzA = Class.forName("A"); | |||
Method clazzAMethod = clazzA.getMethod("method",null); | |||
clazzAMethod.invoke(clazzA.newInstance(),null); | |||
System.out.println("leave:main"); | |||
} catch (Throwable t) { | |||
t.printStackTrace(); | |||
} | |||
} | |||
} |
@@ -0,0 +1,3 @@ | |||
public class T { | |||
public void m1() {System.out.println("T.m1() running");} | |||
} |
@@ -0,0 +1,9 @@ | |||
import java.io.Serializable; | |||
public aspect X { | |||
declare parents: T implements Serializable; | |||
before(): call(* Serializable+.m*(..)) { | |||
System.out.println("advice running"); | |||
} | |||
} |
@@ -0,0 +1,7 @@ | |||
<aspectj> | |||
<weaver options="-showWeaveInfo -verbose"/> | |||
<aspects> | |||
<aspect name="X"/> | |||
</aspects> | |||
</aspectj> | |||
@@ -0,0 +1 @@ | |||
Basic case, where type T needs munging with a declare parents before the join point in A.method() are matched. |
@@ -0,0 +1,7 @@ | |||
public class A { | |||
T t = new T(); | |||
public void method() { | |||
System.out.println("A.method() running"); | |||
t.m1(); | |||
} | |||
} |
@@ -0,0 +1,17 @@ | |||
import java.lang.reflect.Method; | |||
public class Main { | |||
public static void main(String []argv) { | |||
try { | |||
System.out.println("into:main"); | |||
Class clazzA = Class.forName("A"); | |||
Method clazzAMethod = clazzA.getMethod("method",null); | |||
clazzAMethod.invoke(clazzA.newInstance(),null); | |||
System.out.println("leave:main"); | |||
} catch (Throwable t) { | |||
t.printStackTrace(); | |||
} | |||
} | |||
} |
@@ -0,0 +1,3 @@ | |||
import java.lang.annotation.*; | |||
public @interface MarkerAnnotation {} |
@@ -0,0 +1,3 @@ | |||
public class T { | |||
public void m1() {System.out.println("T.m1() running");} | |||
} |
@@ -0,0 +1,9 @@ | |||
import java.io.Serializable; | |||
public aspect X { | |||
declare @type: T: @MarkerAnnotation; | |||
before(): call(* (@MarkerAnnotation *).m*(..)) { | |||
System.out.println("advice running"); | |||
} | |||
} |
@@ -0,0 +1,7 @@ | |||
<aspectj> | |||
<weaver options="-showWeaveInfo -verbose"/> | |||
<aspects> | |||
<aspect name="X"/> | |||
</aspects> | |||
</aspectj> | |||
@@ -0,0 +1 @@ | |||
Now type T needs munging with a declare annotation |
@@ -0,0 +1,7 @@ | |||
public class A { | |||
S s = new S(); | |||
public void method() { | |||
System.out.println("A.method() running"); | |||
s.m1(); | |||
} | |||
} |
@@ -0,0 +1,17 @@ | |||
import java.lang.reflect.Method; | |||
public class Main { | |||
public static void main(String []argv) { | |||
try { | |||
System.out.println("into:main"); | |||
Class clazzA = Class.forName("A"); | |||
Method clazzAMethod = clazzA.getMethod("method",null); | |||
clazzAMethod.invoke(clazzA.newInstance(),null); | |||
System.out.println("leave:main"); | |||
} catch (Throwable t) { | |||
t.printStackTrace(); | |||
} | |||
} | |||
} |
@@ -0,0 +1,2 @@ | |||
public class S extends T { | |||
} |
@@ -0,0 +1,3 @@ | |||
public class T { | |||
public void m1() {System.out.println("T.m1() running");} | |||
} |
@@ -0,0 +1,9 @@ | |||
import java.io.Serializable; | |||
public aspect X { | |||
declare parents: T implements Serializable; | |||
before(): call(* Serializable+.m*(..)) { | |||
System.out.println("advice running"); | |||
} | |||
} |
@@ -0,0 +1,7 @@ | |||
<aspectj> | |||
<weaver options="-showWeaveInfo -verbose"/> | |||
<aspects> | |||
<aspect name="X"/> | |||
</aspects> | |||
</aspectj> | |||
@@ -0,0 +1 @@ | |||
declare parents, but this time there is an extra layer in the hierarchy, A calls S but S extends T and T is decp targeted |
@@ -0,0 +1,7 @@ | |||
<aspectj> | |||
<weaver options="-showWeaveInfo"/> | |||
<aspects> | |||
<aspect name="child.Advisor"/> | |||
</aspects> | |||
</aspectj> | |||
@@ -0,0 +1,23 @@ | |||
/******************************************************************************* | |||
* Copyright (c) 2006 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: | |||
* Ron Bodkin | |||
*/ | |||
package child; | |||
import util.A; | |||
import util.T; | |||
aspect Advisor { | |||
declare parents: A* implements T; | |||
before() : call(* T+.*(..)) { | |||
System.out.println("T call"); | |||
} | |||
} |
@@ -0,0 +1,20 @@ | |||
/******************************************************************************* | |||
* Copyright (c) 2006 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: | |||
* Ron Bodkin | |||
*/ | |||
package child; | |||
import util.A; | |||
public class Executor implements Runnable { | |||
public void run() { | |||
new A().foo(); | |||
} | |||
} |
@@ -0,0 +1,2 @@ | |||
<!-- empty aop.xml file. Used to turn on load-time weaving with no aspects defined at top-level --> | |||
<aspectj/> |
@@ -0,0 +1,18 @@ | |||
/******************************************************************************* | |||
* Copyright (c) 2006 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: | |||
* Ron Bodkin | |||
*/ | |||
package top; | |||
public class SimpleMain { | |||
public static void main(String args[]) throws Exception { | |||
new child.Executor().run(); | |||
} | |||
} |
@@ -0,0 +1,16 @@ | |||
/******************************************************************************* | |||
* Copyright (c) 2006 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: | |||
* Ron Bodkin | |||
*/ | |||
package util; | |||
public class A { | |||
public void foo() {} | |||
} |
@@ -0,0 +1,14 @@ | |||
/******************************************************************************* | |||
* Copyright (c) 2006 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: | |||
* Ron Bodkin | |||
*/ | |||
package util; | |||
public interface T {} |