File: QualifiedAccess_1.java

package info (click to toggle)
libnb-javaparser-java 9%2B2018-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 65,320 kB
  • sloc: java: 440,096; xml: 6,359; sh: 865; makefile: 314
file content (77 lines) | stat: -rw-r--r-- 2,410 bytes parent folder | download | duplicates (20)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
 * @test  /nodynamiccopyright/
 * @bug 4094658 4277296 4785453
 * @summary Test enforcement of JLS 6.6.1 and 6.6.2 rules requiring that
 * the type to which a component member belongs be accessible in qualified
 * names.
 *
 * @compile pack1/P1.java
 * @compile pack1/P2.java
 * @compile/fail/ref=QualifiedAccess_1.out -XDrawDiagnostics QualifiedAccess_1.java
 */

import pack1.P1;

public class QualifiedAccess_1 {

    // Inaccessible types in member declarations.
    // These exercise 'Env.resolve'.
    // Errors are localized poorly.
    //
    // Fields 'P3' and 'P5' are inaccessible.

    P1 foo;
    P1.P3 bar;                                  // ERROR
    P1.P3.P4 baz;                               // ERROR
    P1.P3.P4.P5 quux;                           // ERROR

    P1 m11() {return null;}
    P1.P3 m12() {return null;}                  // ERROR
    P1.P3.P4 m13() {return null;}               // ERROR
    P1.P3.P4.P5 m14() {return null;}            // ERROR

    void m21(P1 x) {}
    void m22(P1.P3 x) {}                        // ERROR
    void m23(P1.P3.P4 x) {}                     // ERROR
    void m24(P1.P3.P4.P5 x) {}                  // ERROR

    void test1() {

        // Inaccessible types in local variable declarations.
        // These exercise 'FieldExpression.checkCommon'.
        //
        // Fields 'P3' and 'P5' are inaccessible.

        P1 foo = null;
        P1.P3 bar = null;                       // ERROR
        P1.P3.P4 baz = null;                    // ERROR
        P1.P3.P4.P5 quux = null;                // ERROR
    }

    void test2() {

        // Inaccessible types in casts.
        // These exercise 'FieldExpression.checkCommon'.
        //
        // Fields 'P3' and 'P5' are inaccessible.

        Object foo = (P1)null;
        Object bar = (P1.P3)null;               // ERROR
        Object baz = (P1.P3.P4)null;            // ERROR
        Object quux = (P1.P3.P4.P5)null;        // ERROR
    }

    void test3() {

        // Inaccessible types in 'instanceof' expressions.
        // These exercise 'FieldExpression.checkCommon'.
        //
        // Fields 'P3' and 'P5' are inaccessible.

        boolean foo = null instanceof P1;
        boolean bar = null instanceof P1.P3;            // ERROR
        boolean baz = null instanceof P1.P3.P4;         // ERROR
        boolean quux = null instanceof P1.P3.P4.P5;     // ERROR
    }

}