--- /dev/null
+package p;
+
+// This class does *nothing* clever, but does match the advice in X
+
+public class A {
+
+ public A() {
+ }
+
+ public static void main(String[] argv) {
+ A anA = new A();
+ anA.sayhi();
+ anA.sayhi();
+
+ System.err.println("Tests in A have passed");
+ }
+
+ public void sayhi() { System.err.println("hi from A"); }
+
+}
--- /dev/null
+package p;
+
+public class B {
+
+ public B() {
+ }
+
+ public static void main(String[] argv) {
+ B b = new B();
+ b.sayhi();
+ b.sayhi();
+ b.sayhi();
+
+ if (!a.X.hasAspect(A.class)) {
+ throw new RuntimeException("hasAspect(A.class) should return true");
+ }
+
+ if (!a.X.hasAspect(B.class)) {
+ throw new RuntimeException("hasAspect(B.class) should return true");
+ }
+
+ if (a.X.hasAspect(q.D.class)) {
+ throw new RuntimeException("hasAspect(D.class) should return false");
+ }
+
+ }
+
+ public void sayhi() { System.err.println("hi from B"); }
+
+}
--- /dev/null
+package p;
+import a.X;
+
+public class C {
+
+ public C() {
+ }
+
+ public static void main(String[] argv) {
+
+ C c = new C();
+ c.sayhi();
+ c.sayhi();
+ c.sayhi();
+ c.sayhi();
+
+ if (a.X.aspectOf(A.class)==null) {
+ throw new RuntimeException("aspectOf(A.class) should not be null");
+ }
+
+ if (a.X.aspectOf(B.class)==null) {
+ throw new RuntimeException("aspecfOf(B.class) should not be null");
+ }
+
+ try {
+ Object o = a.X.aspectOf(q.D.class);
+ throw new RuntimeException("aspectOf(D.class) should be null");
+ } catch (org.aspectj.lang.NoAspectBoundException nabe) {
+ }
+
+ a.X instanceForA = a.X.aspectOf(A.class);
+
+ a.X instanceForB = a.X.aspectOf(B.class);
+
+ if (instanceForA.equals(instanceForB)) {
+ throw new RuntimeException("Instances for A("+instanceForA+") and for B("+instanceForB+") should not be the same!");
+ }
+
+ // Now lets check the counts don't interfere
+
+ A aa = new A();
+ B b = new B();
+ c = new C();
+ X.aspectOf(A.class).setI(0);
+ X.aspectOf(B.class).setI(0);
+ X.aspectOf(C.class).setI(0);
+
+ aa.sayhi();
+ b.sayhi();
+ aa.sayhi();
+ c.sayhi();
+ b.sayhi();
+ aa.sayhi();
+ aa.sayhi();
+
+ if (a.X.aspectOf(A.class).getI()!=4) {
+ throw new RuntimeException("For A, i should be 4 but it is "+a.X.aspectOf(A.class).getI());
+ }
+ if (a.X.aspectOf(B.class).getI()!=2) {
+ throw new RuntimeException("For B, i should be 2 but it is "+a.X.aspectOf(B.class).getI());
+ }
+ if (a.X.aspectOf(C.class).getI()!=1) {
+ throw new RuntimeException("For C, i should be 1 but it is "+a.X.aspectOf(C.class).getI());
+ }
+
+ }
+
+ public void sayhi() { System.err.println("hi C"); }
+
+}
--- /dev/null
+package q;
+
+public class D {
+
+ public D() {
+ }
+
+ public static void main(String[] argv) {
+ new D().sayhi();
+ }
+
+ public void sayhi() { System.err.println("hi D"); }
+
+}
--- /dev/null
+public class G {
+
+ public static void main(String[]argv) {
+ m();
+ }
+
+ public static void m() {
+ }
+}
--- /dev/null
+public aspect H pertypewithin(G) {
+
+
+ after(): call(* *(..)) {
+ System.err.println("advice running");
+ }
+}
--- /dev/null
+import p.*;
+import q.*;
+
+public class Main {
+
+ public static void main(String[]argv) {
+ new A().sayhi();
+ new B().sayhi();
+ new C().sayhi();
+ new D().sayhi();
+ }
+}
--- /dev/null
+public class P {
+
+ public static void main(String []argv) {
+ P p = new P();
+ p.runA();
+ p.runB();
+ p.runA();
+ p.runB();
+ p.runB();
+ }
+
+ public void runA() {
+ }
+
+ public void runB() {
+ }
+
+}
--- /dev/null
+aspect Q pertypewithin(P) {
+
+ int ctr = 0;
+
+ after(): execution(* runA(..)) {
+ ctr=ctr+1;
+ }
+
+ after(): execution(* main(..)) {
+ System.err.println("Q reporting "+ctr);
+ }
+
+}
--- /dev/null
+aspect R pertypewithin(P) {
+
+ int ctr = 0;
+
+ after(): execution(* runB(..)) {
+ ctr=ctr+1;
+ }
+
+ after(): execution(* main(..)) {
+ System.err.println("R reporting "+ctr);
+ }
+
+}
--- /dev/null
+public class U {
+
+ public static int staticVar;
+ public int instanceVar;
+
+ public static void main(String[] argv) {
+ new U().m();
+ }
+
+ public void m() {
+ staticVar = 4;
+ instanceVar = 5;
+ }
+
+ static {
+ System.err.println("In static initializer");
+ }
+
+}
+
+aspect Uaspect {
+
+ before(): within(U) { }
+}
--- /dev/null
+public class V {
+
+ public static int staticVar;
+ public int instanceVar;
+
+ public static void main(String[] argv) {
+ new V().m();
+ }
+
+ public void m() {
+ staticVar = 4;
+ instanceVar = 5;
+ }
+
+ static {
+ System.err.println("In static initializer");
+ }
+
+}
+
+aspect Vaspect pertypewithin(V) {
+
+ before(): within(*) { }
+}
--- /dev/null
+package a;
+
+public aspect X pertypewithin(p..*) {
+
+ int i = 0;
+
+ public int getI() { return i; }
+
+ public void setI(int i) { this.i = i;}
+
+ after() returning: execution(* sayhi(..)) {
+ System.err.println("after() returning from a method call to sayhi()");
+ i++;
+ }
+
+ after() returning: execution(* main(..)) {
+ System.err.println("callcount = "+i);
+ }
+
+ public static void main(String []argv) {
+ System.err.println("X.main() running");
+ }
+}