summaryrefslogtreecommitdiffstats
path: root/tests/new/badCast/Driver.java
blob: 1a6c04674ad0d7d7028c1d367b602ab45eafc14b (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
import org.aspectj.testing.Tester;

// PR#275 & 276 cast error generated by ajc when type not in signature

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

    public static void test() {
        Tester.checkEqual(new SourcePane().go(), -10);
    }
}

class SourcePane {
    public int go() {
        Location location = new Location();
        return location.lineNumber();
    }
}

class Location {
    public int lineNumber() {
        return 10;
    }
}

aspect DriverAspect {

    pointcut locationLineNumber(Location loc):
        //XXX Fails with a star
        //calls(int *.lineNumber()) && within(SourcePane);
        //calls(int loc.lineNumber()) && within(SourcePane);
        target(loc) && call(int Location.lineNumber()) && within(SourcePane);
    int around(Location loc): locationLineNumber(loc) {
        int result = proceed(loc);
        return result * -1;
    }
// The following code won't report the cast error and will work:
/*
    pointcut locationLineNumber(SourcePane s, Location loc):
        calls(loc, int lineNumber()) & within(s);
    static around(SourcePane s, Location loc) returns int: locationLineNumber(s, loc) {
        int result = proceed(s, loc);
        return result * -1;
    }
*/
}