summaryrefslogtreecommitdiffstats
path: root/tests/design/intro/Within.java
blob: 49021c1f0785bb44e3e407194885254e77f81a8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import org.aspectj.testing.Tester;

public class Within {
    public static void main(String[] args) {
	C c = new C();
	c.mi();

	Tester.check("I.mi within A1");
	Tester.check("I.mi instanceof C");
	Tester.check("I.mi instanceof I");

	c.mc();
    }
}


class C {
    void mc() {}
}

interface I {}

aspect A1 {
    void I.mi() {}
}

aspect A2 {
    declare parents: C implements I;
}



aspect Test {
    before (): execution(* I.*(..)) && within(C) {
	Tester.checkFailed(thisJoinPoint + " I.* within C");
    }
    before (): execution(* I.*(..)) && within(I) {
	Tester.checkFailed(thisJoinPoint + " I.* within I");
    }
    before (): execution(* I.*(..)) && within(A1) {
	Tester.checkEqual(thisJoinPoint.getSignature().getName(), "mi",
			   thisJoinPoint + " I.* within A1");
	Tester.note("I.mi within A1");
    }
    before (): execution(* I.*(..)) && within(A2) {
    }

    before (): execution(* I.*(..)) && this(C) {
	Tester.checkEqual(thisJoinPoint.getSignature().getName(), "mi",
			   thisJoinPoint + " I.* instanceof C");
	Tester.note("I.mi instanceof C");
    }
    before (): execution(* I.*(..)) && this(I) {
	Tester.checkEqual(thisJoinPoint.getSignature().getName(), "mi",
			   thisJoinPoint + " I.* instanceof I");
	Tester.note("I.mi instanceof I");
    }
    before (): execution(* I.*(..)) && this(A1) {
	Tester.checkFailed(thisJoinPoint + " I.* instanceof A1");
    }
    before (): execution(* I.*(..)) && this(A2) {
	Tester.checkFailed(thisJoinPoint + " I.* instanceof A2");
    }
}