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

import org.aspectj.lang.*;

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

    public static void test() {
        SuperC sc = new SubC();
        Tester.checkEqual(sc.doIt(":foo"), 
                           ":foo:beforeDoIt:inSubC:foo:beforeDoIt1:inSubC:doIt1",
                           "SubC.doIt");
         Tester.checkEqual(new SuperC().doIt(":foo"), 
                            ":foo:beforeDoIt1:inSuperC:doIt1",
                            "SuperC.doIt");
         Tester.checkEqual(new SubC().packageDoIt(":foo"), 
                            ":foo:beforePackageDoIt:inSubC:foo",
                            "SubC.packageDoIt");
    }
 
    String getTargetName(JoinPoint thisJoinPoint) {
        return thisJoinPoint.getTarget().getClass().getName();
    }

    String around(String a): 
        target(*) && call(String packageDoIt(String)) && args(a)
    {
	return a+
            ":beforePackageDoIt:in"+getTargetName(thisJoinPoint)
            + proceed(a);
    }
    String around(String a):
        target(SubC) && call(String doIt(String)) && args(a) {
	return a+
            ":beforeDoIt:in"+getTargetName(thisJoinPoint)
            + proceed(a);
    }
    String around(String a):
        target(SuperC) && call(String doIt1(String)) && args(a) {
	return a+
            ":beforeDoIt1:in"+getTargetName(thisJoinPoint)
            + proceed(a);
    }
}

class SuperC {
    public String doIt(String arg) {
        return doIt1(arg);
    }
    protected String doIt1(String arg) {
        return ":doIt1";
    }
    String packageDoIt(String arg) {
        return arg;
    }
}

class SubC extends SuperC {
    public String doIt(String arg) {
        return super.doIt(arg);
    }
}