aboutsummaryrefslogtreecommitdiffstats
path: root/tests/new/SuperDisambiguatingType.java
blob: b94223f41ba9b8204618780e0b21c3431d56c715 (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
import org.aspectj.testing.*;


/** @testcase PUREJAVA super reference used to disambiguate names of different but compatible types */
public class SuperDisambiguatingType {
    public static void main (String[] args) {
        new Sub().test();
        Tester.checkAllEvents();
    } 
    static {
        Tester.expectEvent("test");
    }
}


interface I { }
class C { }
class IClass implements I { }
class CClass extends C { }

class Super {
    protected C fieldC;
    protected I fieldI;
}

class Sub extends Super {
    // hiding super
    protected CClass fieldC;
    protected IClass fieldI;
    protected Integer intField;
    public void test() {
        testC();
        testI();
        Tester.event("test");
    }
    public void testC() {
        super.fieldC = (C) (fieldC = new CClass());
        checkC("super.fieldC = (C) (fieldC = new CClass())");
        super.fieldC = (C) fieldC;
        checkC("super.fieldC = (C) fieldC");
        super.fieldC = fieldC;
        checkC("super.fieldC = fieldC");
    }
    private final void checkC(String label) {
        Tester.check(null != fieldC, label + "null != fieldC");
        Tester.check(super.fieldC == fieldC, label + "super.fieldC == fieldC");
    }
    public void testI() {
        super.fieldI = (I) (fieldI = new IClass());
        checkI("super.fieldI = (I) (fieldI = new IClass())");
        super.fieldI = (I) fieldI;
        checkI("super.fieldI = (I) fieldI");
        super.fieldI = fieldI;
        checkI("super.fieldI = fieldI");
    }
    private final void checkI(String label) {
        Tester.check(null != fieldI, label + "null != fieldI");
        Tester.check(super.fieldI == fieldI, label + "super.fieldI == fieldI");
    }
}