aboutsummaryrefslogtreecommitdiffstats
path: root/tests/new/NewSiteAdvice.java
blob: 1534c2454dbd469519624ce08b803ce37492827d (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
import org.aspectj.testing.Tester;

import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;

public class NewSiteAdvice {

    public static void main(String[] args) { test(); }

    NewSiteAdvice() throws RemoteException { }

    /* here's another comment */
    public static void test() {
        Tester.checkEqual(new NewSiteAdvice().go(), "ran", "rmi exception intercepted");
        Tester.check(new Integer(42) == A.cached42, "caching new 42");
        Tester.check("around NewSiteAdvice");
    }

    /** this is the way to make things go **/
    String go() {
        return "ran"; // and an eol commment
    }
}
aspect A {
    pointcut makeNewSiteAdvice():
        within(NewSiteAdvice) && call(NewSiteAdvice.new());
        
    declare soft: RemoteException: makeNewSiteAdvice();

    NewSiteAdvice around(): makeNewSiteAdvice() {
        NewSiteAdvice result = null;
        try {
            result = proceed();
        } catch (RemoteException e){
        }

        Tester.note("around NewSiteAdvice");
        return result;
    }

    Integer around(int i):
        args(i) && call(Integer.new(int)) && !within(A) {
        if (i == 42) return cached42;
        return proceed(i);
    }


    static Integer cached42 = new Integer(42);
}