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

/** @testcase PR#536 expecting compile failures with subclass narrowing scope of superclass methods or accessing private superclass variables */
public class RestrictingVisibilityCF {
    public static void main(String[] args) {
        Tester.check(false, "compile should fail");
    }
}

class Parent {
    public int publicAccess;
    protected int protectedAccess;
    int defaultAccess;
    private int privateAccess;

    public void publicAccess() {}
    protected void protectedAccess() {}
    void defaultAccess() {}
    private void privateAccess() {}
    void drivePrivateAccess() {
        privateAccess();
    }
}

class InValidChild extends Parent {
    /** @testcase subclass private implementation of public method */
    private void publicAccess() { }           // errLine 27
    /** @testcase subclass private implementation of method with default access */
    private void defaultAccess() { }          // errLine 29
    /** @testcase subclass private implementation of protected method */
    private void protectedAccess() { }        // errLine 31

    // todo: sep package, attempt package acces
    int defaultAccessSub = defaultAccess;
}

class InValidChild2 extends Parent {
    /** @testcase subclass private implementation of method with default access */
    private void defaultAccess() { }        // errLine 39 
    /** @testcase subclass protected implementation of public method */
    protected void publicAccess() { }         // errLine 41 
}

class InValidChild3 extends Parent {
    /** @testcase subclass default implementation of method with protected access */
    void protectedAccess() { }        // errLine 46 
    /** @testcase subclass default implementation of public method */
    void publicAccess() { }                   // errLine 48 
}

class InValidChild4 extends Parent {
    /** @testcase private access members unavailable in subclass */
    private int foo = new Parent().privateAccess; // errLine 53
}

//  /** todo: separate package test */
//  class Invalid {
//      /** @testcase default access members unavailable from separate package */
//      private int bar = new Parent().defaultAccess;
//      /** @testcase protected access members unavailable from separate package */
//      private int foo = new Parent().protectedAccess;
//  }