aboutsummaryrefslogtreecommitdiffstats
path: root/tests/new/arndAdvRet/Driver.java
blob: 73a492e6665d29b999fd54dc924bd0074711f2ab (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
import org.aspectj.testing.Tester;

// PR#140

public class Driver {
    public static void main(String[] args) { test(); }
    public static void test() {
        Tester.checkEqual(new Foo().doIt(), 5, "min of 5 and 6");
        Tester.checkEqual(new Bar().doIt(), 1, "min of 5 and 2");
    }
}

class Foo {
    public static int doIt() {
        return new Foo().bar(1, 2, 3);
    }

    int bar(int a, int b, int c) { 
        return a * b * c;
    }
}

aspect FooAspect {
    pointcut cut() : target(Foo) && call(int bar(int, int, int));
    int around(): cut() {
        int originalResult = proceed();
        return Math.max(0, Math.min(originalResult, 5));
    } 
}

class Bar {
    public static int doIt() {
        return new Bar().bar(1, 2, 1);
    }

    int bar(int a, int b, int c) { 
        return a * b * c;
    }
}

aspect BarAspect {
    pointcut cut(Bar b) : target(b) && call(int bar(int, int, int));
    int around(Bar b): cut(b) {
        int originalResult = proceed(b);
        return Math.max(0, Math.min(originalResult, 1));
    }
}