aboutsummaryrefslogtreecommitdiffstats
path: root/tests/errors/protectedAccess/Main.java
blob: 39ba8307c9d9fef3709d7260475579c9bfef7e48 (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
package protectedAccess;

import org.aspectj.testing.Tester;
import protectedAccess.p1.C1;

public class Main {
    public static void main(String[] args) {
        SubC1 subc1 = new SubC1();
        subc1.m(subc1, subc1);
    }
}

class SubC1 extends C1 {
    public void m(SubC1 subc1, C1 c1) {
        Tester.checkEqual(this.s, "protected");
        Tester.checkEqual(this.m(), "protected");

        Tester.checkEqual(s, "protected");
        Tester.checkEqual(m(), "protected");

        Tester.checkEqual(subc1.s, "protected");
        Tester.checkEqual(subc1.m(), "protected");

        C1 c1a = new C1() { };

        C1 c1b = new C1(); //ERROR: illegal protected access

        Tester.checkEqual(c1.s, "protected"); //ERROR: illegal protected access
        Tester.checkEqual(c1.m(), "protected"); //ERROR: illegal protected access

        Tester.checkEqual(c1.m(), "protected"); //ERROR: illegal protected access
    }

    class SubI1 extends I1 {
        public void m(SubC1 subc1, C1 c1, I1 i1) {
            Tester.checkEqual(s, "protected");
            Tester.checkEqual(m(), "protected"); //ERROR: method not found
            
            Tester.checkEqual(SubC1.this.s, "protected");
            Tester.checkEqual(SubC1.this.m(), "protected");

            Tester.checkEqual(subc1.s, "protected");
            Tester.checkEqual(subc1.m(), "protected");
            
            Tester.checkEqual(c1.s, "protected"); //ERROR: illegal protected access
            Tester.checkEqual(c1.m(), "protected"); //ERROR: illegal protected access

            Tester.checkEqual(si, "ip");
            Tester.checkEqual(mi(), "ip");

            Tester.checkEqual(this.si, "ip");
            Tester.checkEqual(this.mi(), "ip");

            Tester.checkEqual(i1.si, "ip"); //ERROR: illegal protected access
            Tester.checkEqual(i1.mi(), "ip"); //ERROR: illegal protected access
        }
    }

    protected String mString(Object o) {
        return o.toString();
    }
}