test/langtools/jdk/jshell/ForwardReferenceImportTest.java
author jlahoda
Mon, 27 Nov 2017 19:29:00 +0100
changeset 47948 8b11e4b32db3
parent 47216 71c04702a3d5
permissions -rw-r--r--
8133616: compiler error messages for dup single type, single static import switched Summary: When reporting clashing imports, use the (non-)staticness of the original import to generate the error message. Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     1
/*
43366
9e917e04f53c 8173232: JShell tests: ReplaceTest takes too long
rfield
parents: 41514
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     4
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     8
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    13
 * accompanied this code).
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    14
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    18
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    21
 * questions.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    22
 */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    23
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    24
/*
43366
9e917e04f53c 8173232: JShell tests: ReplaceTest takes too long
rfield
parents: 41514
diff changeset
    25
 * @test 8173232
9e917e04f53c 8173232: JShell tests: ReplaceTest takes too long
rfield
parents: 41514
diff changeset
    26
 * @summary Test of forward referencing of snippets (related to import).
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    27
 * @build KullaTesting TestingInputStream
43366
9e917e04f53c 8173232: JShell tests: ReplaceTest takes too long
rfield
parents: 41514
diff changeset
    28
 * @run testng ForwardReferenceImportTest
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    29
 */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    30
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    31
import jdk.jshell.Snippet;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    32
import jdk.jshell.DeclarationSnippet;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    33
import org.testng.annotations.Test;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    34
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    35
import static jdk.jshell.Snippet.Status.*;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    36
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    37
@Test
43366
9e917e04f53c 8173232: JShell tests: ReplaceTest takes too long
rfield
parents: 41514
diff changeset
    38
public class ForwardReferenceImportTest extends KullaTesting {
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    39
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    40
    public void testImportDeclare() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    41
        Snippet singleImport = importKey(assertEval("import java.util.List;", added(VALID)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    42
        Snippet importOnDemand = importKey(assertEval("import java.util.*;", added(VALID)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    43
        Snippet singleStaticImport = importKey(assertEval("import static java.lang.Math.abs;", added(VALID)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    44
        Snippet staticImportOnDemand = importKey(assertEval("import static java.lang.Math.*;", added(VALID)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    45
        assertEval("import java.util.List; //again",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    46
                ste(MAIN_SNIPPET, VALID, VALID, false, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    47
                ste(singleImport, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    48
        assertEval("import java.util.*; //again",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    49
                ste(MAIN_SNIPPET, VALID, VALID, false, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    50
                ste(importOnDemand, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    51
        assertEval("import static java.lang.Math.abs; //again",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    52
                ste(MAIN_SNIPPET, VALID, VALID, false, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    53
                ste(singleStaticImport, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    54
        assertEval("import static java.lang.Math.*; //again",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    55
                ste(MAIN_SNIPPET, VALID, VALID, false, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    56
                ste(staticImportOnDemand, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    57
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    58
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    59
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    60
    public void testForwardSingleImportMethodToMethod() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    61
        DeclarationSnippet string = methodKey(assertEval("String string() { return format(\"string\"); }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    62
                added(RECOVERABLE_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    63
        assertUnresolvedDependencies1(string, RECOVERABLE_DEFINED, "method format(java.lang.String)");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    64
        assertEvalUnresolvedException("string();", "string", 1, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    65
        assertEval("import static java.lang.String.format;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    66
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    67
                ste(string, RECOVERABLE_DEFINED, VALID, false, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    68
        assertEval("string();", "\"string\"");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    69
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    70
        assertEval("double format(String s) { return 0; }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    71
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    72
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    73
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    74
                ste(string, VALID, RECOVERABLE_DEFINED, false, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    75
        assertEvalUnresolvedException("string();", "string", 0, 1);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    76
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    77
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    78
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    79
    public void testForwardImportMethodOnDemandToMethod() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    80
        DeclarationSnippet string = methodKey(assertEval("String string() { return format(\"string\"); }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    81
                added(RECOVERABLE_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    82
        assertUnresolvedDependencies1(string, RECOVERABLE_DEFINED, "method format(java.lang.String)");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    83
        assertEvalUnresolvedException("string();", "string", 1, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    84
        assertEval("import static java.lang.String.*;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    85
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    86
                ste(string, RECOVERABLE_DEFINED, VALID, false, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    87
        assertEval("string();", "\"string\"");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    88
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    89
        assertEval("double format(String s) { return 0; }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    90
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    91
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    92
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    93
                ste(string, VALID, RECOVERABLE_DEFINED, false, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    94
        assertEvalUnresolvedException("string();", "string", 0, 1);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    95
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    96
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    97
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    98
    public void testForwardSingleImportFieldToMethod() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    99
        DeclarationSnippet pi = methodKey(assertEval("double pi() { return PI; }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   100
                added(RECOVERABLE_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   101
        assertUnresolvedDependencies1(pi, RECOVERABLE_DEFINED, "variable PI");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   102
        assertEvalUnresolvedException("pi();", "pi", 1, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   103
        assertEval("import static java.lang.Math.PI;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   104
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   105
                ste(pi, RECOVERABLE_DEFINED, VALID, false, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   106
        assertEval("Math.abs(pi() - 3.1415) < 0.001;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   107
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   108
        assertEval("String PI;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   109
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   110
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   111
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   112
                ste(pi, VALID, RECOVERABLE_DEFINED, false, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   113
        assertEvalUnresolvedException("pi();", "pi", 0, 1);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   114
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   115
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   116
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   117
    public void testForwardImportFieldOnDemandToMethod() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   118
        DeclarationSnippet pi = methodKey(assertEval("double pi() { return PI; }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   119
                added(RECOVERABLE_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   120
        assertUnresolvedDependencies1(pi, RECOVERABLE_DEFINED, "variable PI");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   121
        assertEvalUnresolvedException("pi();", "pi", 1, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   122
        assertEval("import static java.lang.Math.*;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   123
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   124
                ste(pi, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   125
        assertEval("Math.abs(pi() - 3.1415) < 0.001;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   126
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   127
        assertEval("String PI;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   128
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   129
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   130
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   131
                ste(pi, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   132
        assertEvalUnresolvedException("pi();", "pi", 0, 1);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   133
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   134
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   135
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   136
    public void testForwardSingleImportMethodToClass1() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   137
        Snippet a = classKey(assertEval("class A { String s = format(\"%d\", 10); }",
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   138
                added(RECOVERABLE_DEFINED)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   139
        assertEvalUnresolvedException("new A();", "A", 1, 0);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   140
        assertEval("import static java.lang.String.format;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   141
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   142
                ste(a, RECOVERABLE_DEFINED, VALID, false, null));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   143
        assertEval("new A().s;", "\"10\"");
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   144
        Snippet format = methodKey(assertEval("void format(String s, int d) { }",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   145
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   146
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   147
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   148
                ste(a, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   149
        assertEvalUnresolvedException("new A();", "A", 0, 1);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   150
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   151
        assertDrop(format,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   152
                ste(format, VALID, DROPPED, true, null),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   153
                ste(a, RECOVERABLE_DEFINED, VALID, false, format));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   154
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   155
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   156
    public void testForwardSingleImportMethodToClass2() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   157
        Snippet a = classKey(assertEval("class A { String s() { return format(\"%d\", 10); } }",
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   158
                added(RECOVERABLE_DEFINED)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   159
        assertEvalUnresolvedException("new A();", "A", 1, 0);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   160
        assertEval("import static java.lang.String.format;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   161
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   162
                ste(a, RECOVERABLE_DEFINED, VALID, false, null));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   163
        assertEval("new A().s();", "\"10\"");
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   164
        Snippet format = methodKey(assertEval("void format(String s, int d) { }",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   165
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   166
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   167
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   168
                ste(a, VALID, RECOVERABLE_DEFINED, false, null)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   169
        assertEvalUnresolvedException("new A();", "A", 0, 1);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   170
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   171
        assertDrop(format,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   172
                ste(format, VALID, DROPPED, true, null),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   173
                ste(a, RECOVERABLE_DEFINED, VALID, false, format));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   174
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   175
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   176
    public void testForwardSingleImportClassToClass1() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   177
        Snippet a = classKey(assertEval("class A { static List<Integer> list; }",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   178
                added(RECOVERABLE_NOT_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   179
        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   180
        assertEval("import java.util.List;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   181
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   182
                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   183
        assertEval("import java.util.Arrays;", added(VALID));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   184
        assertEval("A.list = Arrays.asList(1, 2, 3);", "[1, 2, 3]");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   185
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   186
        Snippet list = classKey(assertEval("class List {}",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   187
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   188
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   189
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   190
                ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, null)));
47948
8b11e4b32db3 8133616: compiler error messages for dup single type, single static import switched
jlahoda
parents: 47216
diff changeset
   191
        assertDeclareFail("A.list = Arrays.asList(1, 2, 3);", "compiler.err.already.defined.single.import");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   192
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   193
        assertDrop(list,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   194
                ste(list, VALID, DROPPED, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   195
                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, list));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   196
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   197
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   198
    public void testForwardSingleImportClassToClass2() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   199
        Snippet clsA = classKey(assertEval("class A extends ArrayList<Integer> { }",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   200
                added(RECOVERABLE_NOT_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   201
        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   202
        assertEval("import java.util.ArrayList;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   203
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   204
                ste(clsA, RECOVERABLE_NOT_DEFINED, VALID, true, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   205
        Snippet vara = varKey(assertEval("A a = new A();", "[]"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   206
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   207
        Snippet arraylist = classKey(assertEval("class ArrayList {}",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   208
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   209
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   210
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   211
                ste(clsA, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   212
                ste(vara, VALID, RECOVERABLE_NOT_DEFINED, true, clsA)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   213
        assertDeclareFail("A a = new A();", "compiler.err.cant.resolve.location",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   214
                ste(MAIN_SNIPPET, RECOVERABLE_NOT_DEFINED, REJECTED, false, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   215
                ste(vara, RECOVERABLE_NOT_DEFINED, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   216
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   217
        assertDrop(arraylist,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   218
                ste(arraylist, VALID, DROPPED, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   219
                ste(clsA, RECOVERABLE_NOT_DEFINED, VALID, true, arraylist));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   220
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   221
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   222
    public void testForwardImportOnDemandMethodToClass1() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   223
        Snippet a = classKey(assertEval("class A { String s = format(\"%d\", 10); }",
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   224
                added(RECOVERABLE_DEFINED)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   225
        assertEvalUnresolvedException("new A();", "A", 1, 0);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   226
        assertEval("import static java.lang.String.*;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   227
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   228
                ste(a, RECOVERABLE_DEFINED, VALID, false, null));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   229
        assertEval("A x = new A();");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   230
        assertEval("x.s;", "\"10\"");
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   231
        Snippet format = methodKey(assertEval("void format(String s, int d) { }",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   232
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   233
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   234
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   235
                ste(a, VALID, RECOVERABLE_DEFINED, false, null)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   236
        assertEvalUnresolvedException("new A();", "A", 0, 1);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   237
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   238
        assertDrop(format,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   239
                ste(format, VALID, DROPPED, true, null),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   240
                ste(a, RECOVERABLE_DEFINED, VALID, false, format));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   241
        assertEval("x.s;", "\"10\"");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   242
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   243
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   244
    public void testForwardImportOnDemandMethodToClass2() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   245
        Snippet a = classKey(assertEval("class A { String s() { return format(\"%d\", 10); } }",
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   246
                added(RECOVERABLE_DEFINED)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   247
        assertEvalUnresolvedException("new A();", "A", 1, 0);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   248
        assertEval("import static java.lang.String.*;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   249
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   250
                ste(a, RECOVERABLE_DEFINED, VALID, false, null));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   251
        assertEval("new A().s();", "\"10\"");
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   252
        Snippet format = methodKey(assertEval("void format(String s, int d) { }",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   253
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   254
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   255
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   256
                ste(a, VALID, RECOVERABLE_DEFINED, false, null)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   257
        assertEvalUnresolvedException("new A();", "A", 0, 1);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   258
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   259
        assertDrop(format,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   260
                ste(format, VALID, DROPPED, true, null),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   261
                ste(a, RECOVERABLE_DEFINED, VALID, false, format));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   262
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   263
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   264
    public void testForwardImportOnDemandClassToClass1() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   265
        Snippet a = classKey(assertEval("class A { static List<Integer> list; }",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   266
                added(RECOVERABLE_NOT_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   267
        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   268
        assertEval("import java.util.*;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   269
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   270
                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   271
        assertEval("A.list = Arrays.asList(1, 2, 3);", "[1, 2, 3]");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   272
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   273
        Snippet list = classKey(assertEval("class List {}",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   274
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   275
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   276
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   277
                ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, null)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   278
        assertDeclareFail("A.list = Arrays.asList(1, 2, 3);", "compiler.err.cant.resolve.location");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   279
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   280
        assertDrop(list,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   281
                ste(list, VALID, DROPPED, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   282
                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, list));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   283
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   284
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   285
    public void testForwardImportOnDemandClassToClass2() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   286
        Snippet clsA = classKey(assertEval("class A extends ArrayList<Integer> { }",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   287
                added(RECOVERABLE_NOT_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   288
        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   289
        assertEval("import java.util.*;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   290
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   291
                ste(clsA, RECOVERABLE_NOT_DEFINED, VALID, true, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   292
        Snippet vara = varKey(assertEval("A a = new A();", "[]"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   293
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   294
        Snippet arraylist = classKey(assertEval("class ArrayList {}",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   295
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   296
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   297
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   298
                ste(clsA, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   299
                ste(vara, VALID, RECOVERABLE_NOT_DEFINED, true, clsA)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   300
        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   301
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   302
        assertDrop(arraylist,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   303
                ste(arraylist, VALID, DROPPED, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   304
                ste(clsA, RECOVERABLE_NOT_DEFINED, VALID, true, arraylist),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   305
                ste(vara, RECOVERABLE_NOT_DEFINED, VALID, true, clsA));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   306
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   307
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   308
    public void testForwardSingleImportFieldToClass1() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   309
        Snippet a = classKey(assertEval("class A { static double pi() { return PI; } }",
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   310
                added(RECOVERABLE_DEFINED)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   311
        assertEvalUnresolvedException("new A();", "A", 1, 0);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   312
        assertEval("import static java.lang.Math.PI;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   313
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   314
                ste(a, RECOVERABLE_DEFINED, VALID, false, null));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   315
        assertEval("Math.abs(A.pi() - 3.1415) < 0.001;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   316
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   317
        Snippet list = varKey(assertEval("String PI;",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   318
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   319
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   320
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   321
                ste(a, VALID, RECOVERABLE_DEFINED, false, null)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   322
        assertEvalUnresolvedException("new A();", "A", 0, 1);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   323
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   324
        assertDrop(list,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   325
                ste(list, VALID, DROPPED, true, null),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   326
                ste(a, RECOVERABLE_DEFINED, VALID, false, list));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   327
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   328
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   329
    public void testForwardSingleImportFieldToClass2() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   330
        Snippet a = classKey(assertEval("class A { static double pi = PI; }",
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   331
                added(RECOVERABLE_DEFINED)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   332
        assertEvalUnresolvedException("new A();", "A", 1, 0);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   333
        assertEval("import static java.lang.Math.PI;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   334
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   335
                ste(a, RECOVERABLE_DEFINED, VALID, true, null));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   336
        assertEval("Math.abs(A.pi - 3.1415) < 0.001;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   337
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   338
        Snippet list = varKey(assertEval("String PI;",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   339
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   340
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   341
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   342
                ste(a, VALID, RECOVERABLE_DEFINED, true, null)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   343
        assertEvalUnresolvedException("new A();", "A", 0, 1);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   344
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   345
        assertDrop(list,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   346
                ste(list, VALID, DROPPED, true, null),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   347
                ste(a, RECOVERABLE_DEFINED, VALID, true, list));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   348
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   349
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   350
    public void testForwardImportOnDemandFieldToClass1() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   351
        Snippet a = classKey(assertEval("class A { static double pi() { return PI; } }",
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   352
                added(RECOVERABLE_DEFINED)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   353
        assertEvalUnresolvedException("new A();", "A", 1, 0);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   354
        assertEval("import static java.lang.Math.*;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   355
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   356
                ste(a, RECOVERABLE_DEFINED, VALID, false, null));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   357
        assertEval("Math.abs(A.pi() - 3.1415) < 0.001;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   358
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   359
        Snippet list = varKey(assertEval("String PI;",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   360
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   361
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   362
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   363
                ste(a, VALID, RECOVERABLE_DEFINED, false, null)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   364
        assertEvalUnresolvedException("new A();", "A", 0, 1);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   365
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   366
        assertDrop(list,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   367
                ste(list, VALID, DROPPED, true, null),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   368
                ste(a, RECOVERABLE_DEFINED, VALID, false, list));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   369
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   370
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   371
    public void testForwardImportOnDemandFieldToClass2() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   372
        Snippet a = classKey(assertEval("class A { static double pi = PI; }",
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   373
                added(RECOVERABLE_DEFINED)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   374
        assertEvalUnresolvedException("new A();", "A", 1, 0);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   375
        assertEval("import static java.lang.Math.*;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   376
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   377
                ste(a, RECOVERABLE_DEFINED, VALID, true, null));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   378
        assertEval("Math.abs(A.pi - 3.1415) < 0.001;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   379
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   380
        Snippet list = varKey(assertEval("String PI;",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   381
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   382
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   383
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   384
                ste(a, VALID, RECOVERABLE_DEFINED, true, null)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   385
        assertEvalUnresolvedException("new A();", "A", 0, 1);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   386
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   387
        assertDrop(list,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   388
                ste(list, VALID, DROPPED, true, null),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   389
                ste(a, RECOVERABLE_DEFINED, VALID, true, list));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   390
        assertEval("Math.abs(A.pi - 3.1415) < 0.001;", "true");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   391
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   392
}