aboutsummaryrefslogtreecommitdiffstats
path: root/tests/new/PR355.java
blob: 5c9d4fa0e4cfe9706c672dc9c8ca4ad83ba11c5e (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
import org.aspectj.testing.*;
import java.io.*;

public class PR355 {
    public static void main(String[] args) {
        new PR355().go();
    }

    static {
        String[] types  = { "static", "non", "instance" };
        String[] advice = { "before", "after", "around" };
        for (int i = 0; i < types.length; i++) {
            for (int j = 0; j < advice.length; j++) {
                Tester.expectEvent(types[i] + "-" + advice[j]);
            }
        }
        Tester.expectEventsInString("C.f,C.e");
    }

    void go() {
        new C().f();
        Tester.checkAllEvents();
    }
}


class C {
    void f() { Tester.event("C.f"); e(); }
    void e() { Tester.event("C.e"); }
}

abstract aspect Cuts {
    pointcut p(): within(C) && call(* C.*(..));
    static void a(String s) { Tester.event(s); }
}

/* Static aspects have no problem */
aspect StaticAspect extends Cuts {
    before():      p() { a("static-before"); }
    void around(): p() { a("static-around"); proceed();  }
    after ():      p() { a("static-after");  }
}

/* Non-static aspects have a problem */
aspect NonStaticAspect extends Cuts issingleton() {
    before():      p() { a("non-before"); }
    void around(): p() { a("non-around"); proceed();  }
    after ():      p() { a("non-after");  }
}

/* No problem here */
aspect InstanceOfAspect extends Cuts perthis(this(C)) { 
    before():      p() { a("instance-before"); }
    void around(): p() { a("instance-around"); proceed(); }
    after ():      p() { a("instance-after");  }
}