aboutsummaryrefslogtreecommitdiffstats
path: root/tests/design/intro/Interfaces.java
blob: 67ca0f684c9a8e08750d1ebf4e02476c4a84d17a (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import org.aspectj.testing.Tester;

import java.util.*;

import org.aspectj.lang.reflect.*;

public class Interfaces {
    public static void main(String[] args) {
	String v = I.staticField;
	Tester.checkEqual(notes, "I.staticField", "static init of I");
	Tester.checkEqual(v, "I.staticField");
	clearNotes();

	I i = (I)new C();
	Tester.checkEqual(notes, 
	    "initialize-I instanceField-A* I.instanceField privateField-A* I.privateField-from-A privateField-A* I.privateField-from-B",
	    "inst init of I");
	Tester.checkEqual(i.instanceField, "I.instanceField");
	clearNotes();

	v = SubI.staticField;
	Tester.checkEqual(notes, "SubI.staticField", "static init of SubI");
	Tester.checkEqual(v, "SubI.staticField");
	clearNotes();

	SubI si = (SubI)new SubC();
	Tester.checkEqual(notes, 
	    "initialize-I instanceField-A* I.instanceField privateField-A* I.privateField-from-A privateField-A* I.privateField-from-B SubI.instanceField",
	    "inst init of SubI");
	Tester.checkEqual(si.instanceField, "SubI.instanceField");
	clearNotes();


        i.instanceField += "-XXX";
        Tester.checkEqual(notes, "I.instanceField-!I||A*", "I.instanceField set");
        Tester.checkEqual(i.instanceField, "I.instanceField-XXX");
    }

    private static List notes = new LinkedList();

    public static void clearNotes() {
	notes = new LinkedList();
	//System.out.println("***********************************************");
    }

    public static String note(String note) {
	notes.add(note);
	//System.out.println(note);
	return note;
    }
}

class C implements I {
    String instanceField = "C.instanceField";
}

class SubC extends C implements SubI {
    String instanceField = "SubC.instanceField";
}

interface I {
    // must follow standard Java rules
    String staticField = Interfaces.note("I.staticField");
}

interface SubI extends I {
    String staticField = Interfaces.note("SubI.staticField");
}
    


aspect A1 {
    public String SubI.instanceField = Interfaces.note("SubI.instanceField");

    public String I.instanceField = Interfaces.note("I.instanceField");
    private String I.privateField = Interfaces.note("I.privateField-from-A");
}

aspect A2 {
    private String I.privateField = Interfaces.note("I.privateField-from-B");
}    

aspect A3 {
    before(I i): !within(I||A*) && set(String I.*) && target(i) {
        Interfaces.note(thisJoinPoint.getSignature().toShortString()+"-!I||A*"); // +"::" + thisJoinPoint.getSourceLocation().getWithinType());
    }

    before(I i): within(I) && set(String I.*) && target(i) {
	Interfaces.note(thisJoinPoint.getSignature().getName()+"-I"); //toShortString());
    }
    before(I i): within(A*) && set(String I.*) && target(i) {
	Interfaces.note(thisJoinPoint.getSignature().getName()+"-A*"); //toShortString());
    }

    before(I i): initialization(I.new(..)) && target(i) {
        Interfaces.note("initialize-I");
    }
}