langtools/test/tools/javac/QualifiedAccess/QualifiedAccess_1.java
author mikejwre
Wed, 09 Jun 2010 18:56:41 -0700
changeset 5634 895b66935810
parent 863 3113c955a388
child 6150 d055fa8ced62
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
     2
 * @test  /nodynamiccopyright/
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * @bug 4094658 4277296 4785453
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 * @summary Test enforcement of JLS 6.6.1 and 6.6.2 rules requiring that
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * the type to which a component member belongs be accessible in qualified
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * names.
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 *
863
3113c955a388 6724327: eliminate use of shell tests for simple golden file tests
jjg
parents: 10
diff changeset
     8
 * @compile pack1/P1.java
3113c955a388 6724327: eliminate use of shell tests for simple golden file tests
jjg
parents: 10
diff changeset
     9
 * @compile pack1/P2.java
3113c955a388 6724327: eliminate use of shell tests for simple golden file tests
jjg
parents: 10
diff changeset
    10
 * @compile/fail/ref=QualifiedAccess_1.out -XDrawDiagnostics -XDstdout QualifiedAccess_1.java
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
import pack1.P1;
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
public class QualifiedAccess_1 {
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
    // Inaccessible types in member declarations.
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
    // These exercise 'Env.resolve'.
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
    // Errors are localized poorly.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
    //
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
    // Fields 'P3' and 'P5' are inaccessible.
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
    P1 foo;
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
    P1.P3 bar;                                  // ERROR
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
    P1.P3.P4 baz;                               // ERROR
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
    P1.P3.P4.P5 quux;                           // ERROR
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
    P1 m11() {return null;}
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
    P1.P3 m12() {return null;}                  // ERROR
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
    P1.P3.P4 m13() {return null;}               // ERROR
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
    P1.P3.P4.P5 m14() {return null;}            // ERROR
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
    void m21(P1 x) {}
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
    void m22(P1.P3 x) {}                        // ERROR
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
    void m23(P1.P3.P4 x) {}                     // ERROR
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
    void m24(P1.P3.P4.P5 x) {}                  // ERROR
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
    void test1() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
        // Inaccessible types in local variable declarations.
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
        // These exercise 'FieldExpression.checkCommon'.
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
        //
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
        // Fields 'P3' and 'P5' are inaccessible.
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
        P1 foo = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
        P1.P3 bar = null;                       // ERROR
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
        P1.P3.P4 baz = null;                    // ERROR
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
        P1.P3.P4.P5 quux = null;                // ERROR
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
    void test2() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
        // Inaccessible types in casts.
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
        // These exercise 'FieldExpression.checkCommon'.
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
        //
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
        // Fields 'P3' and 'P5' are inaccessible.
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
        Object foo = (P1)null;
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
        Object bar = (P1.P3)null;               // ERROR
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
        Object baz = (P1.P3.P4)null;            // ERROR
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
        Object quux = (P1.P3.P4.P5)null;        // ERROR
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
    void test3() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
        // Inaccessible types in 'instanceof' expressions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
        // These exercise 'FieldExpression.checkCommon'.
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
        //
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
        // Fields 'P3' and 'P5' are inaccessible.
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
        boolean foo = null instanceof P1;
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
        boolean bar = null instanceof P1.P3;            // ERROR
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
        boolean baz = null instanceof P1.P3.P4;         // ERROR
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
        boolean quux = null instanceof P1.P3.P4.P5;     // ERROR
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
}