summaryrefslogtreecommitdiffstats
path: root/tests/design/around/ReturnCastProceed.java
blob: 4141a8e985bfc800ce14036c4c96bd77dbc26255 (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
import org.aspectj.testing.Tester;


public class ReturnCastProceed extends Helper {

    public static void main(String[] args) {
        StackChecker.setBaseDepth();

        Tester.checkEqual(mInt(), 3, "mInt is 3");
        Tester.checkAndClearEvents( new String[] { "advice" } );

        mVoid();
        Tester.checkAndClearEvents(new String[] {"advice", "void body" });

        Tester.checkEqual(mString(), "I'm a string", "mString is right");
        Tester.checkAndClearEvents(new String[] { "advice" });

        Tester.checkEqual(mInteger().intValue(), 5555, "mInteger is boxed 5555");
        Tester.checkAndClearEvents(new String[] { "advice" });

        Tester.check(mRunnable() instanceof Runnable, "mRunnable returns a Runnable");
        Tester.checkAndClearEvents(new String[] { "advice" });

        Tester.check(mObject() == f, "mObject returns f");
        Tester.checkAndClearEvents(new String[] { "advice" });

    }
}

class Helper {
    static Float f = new Float(37.8);

    static int mInt() {
        //StackChecker.checkDepth(2, "mInt");
        return 3;
    }

    static void mVoid() {
        StackChecker.checkDepth(2, "mVoid");
        Tester.event("void body");
    }

    static String mString() {
        StackChecker.checkDepth(2, "mString");
        return "I'm a string"; 
    }
    static Integer mInteger() {
        StackChecker.checkDepth(2, "mInteger");
        return new Integer(5555);
    }

    static Runnable mRunnable() {
        //StackChecker.checkDepth(2, "mRunnable");
        return new Runnable() {
                public void run() {
                    Tester.event("i'm running"); // not used yet.
                }
            };
    }

    static Object mObject() {
        StackChecker.checkDepth(2, "mObject");
        return f;
    }
}

aspect A {
     Object around(): execution(static * Helper.*(..)) { 
         Tester.event("advice");
         return (Object) proceed();
     }

//      Object around(): execution(static * ReturnCastProceed.*(..)) {  
//          Object ret = proceed();
//          System.err.println("doing stuff");
//          return ret;
//      }

//     Object around(): execution(static * ReturnCastProceed.*(..)) {
//         return proceed();
//     }

}