aboutsummaryrefslogtreecommitdiffstats
path: root/tests/new/PR519.java
blob: 7f585ae9d8383e91f2c9993e369d5cc98591a097 (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
99
100
101
102
103
104
105
106
107
108
109
110
111
import org.aspectj.testing.Tester; 

/** @testcase PR#519 Exception thrown when planning advice */
public class PR519 {
    private static final boolean DO_OUTPUT;
    private static final String[] EXPECTED;
    public static void main(String[] args) {
        try {
            A.main(args);
            Tester.checkAllEvents();
        } catch (MyException e) {
            // expecting this
            log("caught expected exception " + e);
        } catch (Exception e) {
            e.printStackTrace(System.err);
        }
    }
    public static void log(String s) {
        if (DO_OUTPUT) System.err.println(s);
        Tester.event(s);
    }

    static {
        DO_OUTPUT = false;
        EXPECTED = new String[]
        { "*** class A.foo()"
          , "*** class B.foo()"
          , "*** class A.bar()"
          , "after():  call(void A.bar(..)) : call(void A.bar())"
          , "*** class A.bar()"
          , "after():  call(void A.bar(..)) : call(void A.bar())"
          , "*** class B.bar()"
          , "*** class A.bar(String s)"
          , "after():  call(void A.bar(..)) : call(void A.bar(String))"
          , "*** class A.bar(String s1, String s2)"
          , "after():  call(void A.bar(..)) : call(void A.bar(String, String))"
          , "*** class A.bar(int i)"
          , "*** class A.bar()"
          , "after():  call(void A.bar(..)) : call(void A.bar())"
          , "after():  call(void A.bar(..)) : call(void A.bar(int))"
          , "after():  call(void A.bar(..))  && args(problem): call(void A.bar(int))"
          , "caught expected exception MyException" };
        Tester.expectEvent(EXPECTED);
    } // static init
}

class A extends B {
    private int a = 0;
    private int lala;

    public void bar(int i){
        PR519.log("*** " + this.getClass() + ".bar(int i)");
        bar();
    }

    public void bar(){
        PR519.log("*** " + this.getClass() + ".bar()");
    }

    public void bar(String s){
        PR519.log("*** " + this.getClass() + ".bar(String s)");
    }
    public void bar(String s1, String s2){
        PR519.log("*** " + this.getClass() + ".bar(String s1, String s2)");
    }

    public static void main(String[] argv) throws Exception {
        B b = new B();
        A a = new A();

        a.foo();
        b.foo();

        a.bar();
        a.bar();
        b.bar();

        a.bar("lala");
        a.bar("lala", "poo");

        a.bar(9);
        throw new MyException();
    }
}
class MyException extends Exception { }
 
class B {
    private int b = 0;

    public void foo(){
        PR519.log("*** " + this.getClass() + ".foo()");
    }

    public void bar(){
        PR519.log("*** " + this.getClass() + ".bar()");
    }
}


aspect InstanceOfProblemAspect {
    public static final String PREFIX = "after():  call(void A.bar(..)) ";
    after(): !within(PR519) && call(void A.bar(..)){
        PR519.log(PREFIX + ": " + thisJoinPoint);
    }

    after(int problem): !within(PR519) && call(void A.bar(..)) && args(problem){
        PR519.log(PREFIX + " && args(problem): " + thisJoinPoint);
    }

}