summaryrefslogtreecommitdiffstats
path: root/tests/new/Binkley2.java
blob: fe0d27d02a30283827460ed6dbd47ef1b0ffdddd (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
import java.util.*;
import org.aspectj.lang.*;
import org.aspectj.lang.reflect.*;
import org.aspectj.testing.*;

public class Binkley2 {
    public static void main(String[] args) {
        // catch the static init early
        C c = new C();
        
        Art.enable = true;
        Ar.enable  = false;
        new C().foo();
        
        Art.enable = false;
        Ar.enable  = true;
        new C().foo();
        Post.checkAll();    
    }
}

class C {
    public int x = 0;
    public void foo() 
    {
        x = 1;
        x = 2;
    }
    
}

class Post {
    static List haves = new Vector();
    static String[] wants = new String[] {
        "preinitialization(C())-Ar-0", 
        "initialization(C())-Ar-0", 
        "execution(C())-Ar-0", 
        "set(C.x)-Ar-0",
        "execution(C.foo())-Ar-0", 
        "set(C.x)-Ar-0",
        "set(C.x)-Ar-0",
        
        "preinitialization(C())-Art-0", 
        "initialization(C())-Art-0", 
        "execution(C())-Art-1",
        "set(C.x)-Art-2",
        "execution(C.foo())-Art-0",
        "set(C.x)-Art-1",
        "set(C.x)-Art-2",
        };

    static void post(JoinPoint jp, String name, int num) {
    	//System.out.println("have: " + jp.toShortString() + "-" + name + "-" + num);
	haves.add(jp.toShortString() + "-" + name + "-" + num);
    }
    static void checkAll() {
	Tester.checkEqual(haves, wants, "haves != wants");
    }
}

aspect Ar percflow(pc()){
    pointcut pc() : within(C) ;
    int count = 0;
    static boolean enable = false;
    before(): pc() {
        if ( enable ) {
            Post.post(thisJoinPoint, "Ar", count++);
        }
    }
}

/*
 * I'm trying to simulate eachcflowrootop.
 */
aspect Art percflow(Art.pc() && !cflowbelow(Art.pc()))
{
    pointcut pc() : within(C) ;
    //pointcut pctop(): pc() && !cflow(pc());                  (see above)
    int count = 0;
    static boolean enable = false;
    
    before(): pc() {
        if ( enable ) {
            Post.post(thisJoinPoint, "Art", count++);
        }
    }
}