test/langtools/jdk/jshell/ForwardReferenceTest.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 43366 langtools/test/jdk/jshell/ForwardReferenceTest.java@9e917e04f53c
child 50735 2f2af62dfac7
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
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.
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 ForwardReferenceTest
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
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
    31
import java.util.List;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    32
import jdk.jshell.Snippet;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    33
import jdk.jshell.MethodSnippet;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    34
import jdk.jshell.VarSnippet;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    35
import jdk.jshell.DeclarationSnippet;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    36
import org.testng.annotations.Test;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    37
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
    38
import jdk.jshell.SnippetEvent;
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
    39
import jdk.jshell.UnresolvedReferenceException;
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
    40
import static org.testng.Assert.assertEquals;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    41
import static jdk.jshell.Snippet.Status.*;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    42
import static org.testng.Assert.assertTrue;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    43
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    44
@Test
43366
9e917e04f53c 8173232: JShell tests: ReplaceTest takes too long
rfield
parents: 41514
diff changeset
    45
public class ForwardReferenceTest extends KullaTesting {
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    46
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    47
    public void testOverwriteMethodForwardReferenceClass() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    48
        Snippet k1 = methodKey(assertEval("int q(Boo b) { return b.x; }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    49
                added(RECOVERABLE_NOT_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    50
        assertUnresolvedDependencies1((MethodSnippet) k1, RECOVERABLE_NOT_DEFINED, "class Boo");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    51
        assertEval("class Boo { int x = 55; }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    52
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    53
                ste(k1, RECOVERABLE_NOT_DEFINED, VALID, true, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    54
        assertMethodDeclSnippet((MethodSnippet) k1, "q", "(Boo)int", VALID, 0, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    55
        assertEval("q(new Boo());", "55");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    56
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    57
    }
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
    public void testOverwriteMethodForwardReferenceClassImport() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    60
        MethodSnippet k1 = methodKey(assertEval("int ff(List lis) { return lis.size(); }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    61
                added(RECOVERABLE_NOT_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    62
        assertUnresolvedDependencies1(k1, RECOVERABLE_NOT_DEFINED, "class List");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    63
        assertEval("import java.util.*;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    64
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    65
                ste(k1, RECOVERABLE_NOT_DEFINED, VALID, true, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    66
        assertMethodDeclSnippet(k1, "ff", "(List)int", VALID, 0, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    67
        assertEval("ff(new ArrayList());", "0");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    68
        assertActiveKeys();
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
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    71
    public void testForwardVarToMethod() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    72
        DeclarationSnippet t = methodKey(assertEval("int t() { return x; }", added(RECOVERABLE_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    73
        assertUnresolvedDependencies1(t, RECOVERABLE_DEFINED, "variable x");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    74
        assertEvalUnresolvedException("t();", "t", 1, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    75
        Snippet x = varKey(assertEval("int x = 33;", "33",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    76
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    77
                ste(t, RECOVERABLE_DEFINED, VALID, false, null)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    78
        assertEval("t();", "33");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    79
        assertEval("double x = 0.88;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    80
                "0.88", null,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    81
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    82
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    83
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    84
                ste(x, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    85
                ste(t, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    86
        assertEvalUnresolvedException("t();", "t", 0, 1);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    87
        assertActiveKeys();
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
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    90
    public void testForwardMethodToMethod() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    91
        Snippet t = methodKey(assertEval("int t() { return f(); }", added(RECOVERABLE_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    92
        Snippet f = methodKey(assertEval("int f() { return g(); }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    93
                added(RECOVERABLE_DEFINED),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    94
                ste(t, RECOVERABLE_DEFINED, VALID, false, null)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    95
        assertUnresolvedDependencies1((DeclarationSnippet) f, RECOVERABLE_DEFINED, "method g()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    96
        assertEvalUnresolvedException("t();", "f", 1, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    97
        Snippet g = methodKey(assertEval("int g() { return 55; }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    98
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    99
                ste(f, RECOVERABLE_DEFINED, VALID, false, null)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   100
        assertEval("t();", "55");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   101
        assertEval("double g() { return 3.14159; }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   102
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   103
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   104
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   105
                ste(g, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   106
                ste(f, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   107
        DeclarationSnippet exsn = assertEvalUnresolvedException("t();", "f", 0, 1);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   108
        assertTrue(exsn == f, "Identity must not change");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   109
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   110
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   111
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   112
    public void testForwardClassToMethod() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   113
        DeclarationSnippet t = methodKey(assertEval("int t() { return new A().f(); }", added(RECOVERABLE_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   114
        assertUnresolvedDependencies1(t, RECOVERABLE_DEFINED, "class A");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   115
        assertEvalUnresolvedException("t();", "t", 1, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   116
        Snippet a = classKey(assertEval(
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   117
                "class A {\n" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   118
                        "   int f() { return 10; }\n" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   119
                "}",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   120
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   121
                ste(t, RECOVERABLE_DEFINED, VALID, false, null)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   122
        assertEval("t();", "10");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   123
        assertEval(
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   124
                "class A {\n" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   125
                "   double f() { return 88.0; }\n" +
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
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   128
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   129
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   130
                ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   131
                ste(t, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   132
        assertEvalUnresolvedException("t();", "t", 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 testForwardVarToClass() {
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   137
        DeclarationSnippet a = classKey(assertEval("class A { int f() { return g; } }", added(RECOVERABLE_DEFINED)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   138
        assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "variable g");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   139
        Snippet g = varKey(assertEval("int g = 10;", "10",
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   140
                added(VALID),
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   141
                ste(a, RECOVERABLE_DEFINED, VALID, false, null)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   142
        assertEval("new A().f();", "10");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   143
        assertEval("double g = 10;", "10.0", null,
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   144
                DiagCheck.DIAG_OK,
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   145
                DiagCheck.DIAG_ERROR,
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   146
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   147
                ste(g, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
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
        assertUnresolvedDependencies(a, 0);
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   150
        assertActiveKeys();
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   151
    }
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   152
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   153
    public void testForwardVarToClassGeneric() {
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   154
        DeclarationSnippet a = classKey(assertEval("class A<T> { final T x; A(T v) { this.x = v; } ; T get() { return x; } int core() { return g; } }", added(RECOVERABLE_DEFINED)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   155
        assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "variable g");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   156
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   157
        List<SnippetEvent> events = assertEval("A<String> as = new A<>(\"hi\");", null,
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   158
                UnresolvedReferenceException.class, DiagCheck.DIAG_OK, DiagCheck.DIAG_OK, null);
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   159
        SnippetEvent ste = events.get(0);
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   160
        Snippet assn = ste.snippet();
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   161
        DeclarationSnippet unsn = ((UnresolvedReferenceException) ste.exception()).getSnippet();
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   162
        assertEquals(unsn.name(), "A", "Wrong with unresolved");
40304
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 37644
diff changeset
   163
        assertEquals(getState().unresolvedDependencies(unsn).count(), 1, "Wrong size unresolved");
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 37644
diff changeset
   164
        assertEquals(getState().diagnostics(unsn).count(), 0L, "Expected no diagnostics");
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   165
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   166
        Snippet g = varKey(assertEval("int g = 10;", "10",
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, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   169
        assertEval("A<String> as = new A<>(\"low\");",
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   170
                ste(MAIN_SNIPPET, VALID, VALID, false, null),
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   171
                ste(assn, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   172
        assertEval("as.get();", "\"low\"");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   173
        assertUnresolvedDependencies(a, 0);
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   174
        assertActiveKeys();
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   175
    }
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   176
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   177
   public void testForwardVarToClassExtendsImplements() {
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   178
        DeclarationSnippet ik = classKey(assertEval("interface I { default int ii() { return 1; } }", added(VALID)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   179
        DeclarationSnippet jk = classKey(assertEval("interface J { default int jj() { return 2; } }", added(VALID)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   180
        DeclarationSnippet ck = classKey(assertEval("class C { int cc() { return 3; } }", added(VALID)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   181
        DeclarationSnippet dk = classKey(assertEval("class D extends C implements I,J { int dd() { return g; } }", added(RECOVERABLE_DEFINED)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   182
        DeclarationSnippet ek = classKey(assertEval("class E extends D { int ee() { return 5; } }", added(VALID)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   183
        assertUnresolvedDependencies1(dk, RECOVERABLE_DEFINED, "variable g");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   184
        assertEvalUnresolvedException("new D();", "D", 1, 0);
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   185
        assertEvalUnresolvedException("new E();", "D", 1, 0);
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   186
        VarSnippet g = varKey(assertEval("int g = 10;", "10",
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   187
                added(VALID),
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   188
                ste(dk, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   189
        assertEval("E e = new E();");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   190
        assertDrop(g,
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   191
                ste(g, VALID, DROPPED, true, null),
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   192
                ste(dk, VALID, RECOVERABLE_DEFINED, false, g));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   193
        assertEvalUnresolvedException("new D();", "D", 1, 0);
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   194
        assertEvalUnresolvedException("new E();", "D", 1, 0);
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   195
        assertEval("e.ee();", "5");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   196
        assertEvalUnresolvedException("e.dd();", "D", 1, 0);
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   197
        assertEval("e.cc();", "3");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   198
        assertEval("e.jj();", "2");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   199
        assertEval("e.ii();", "1");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   200
        assertActiveKeys();
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   201
    }
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   202
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   203
    public void testForwardVarToInterface() {
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   204
        DeclarationSnippet i = classKey(assertEval("interface I { default int f() { return x; } }", added(RECOVERABLE_DEFINED)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   205
        assertUnresolvedDependencies1(i, RECOVERABLE_DEFINED, "variable x");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   206
        DeclarationSnippet c = classKey(assertEval("class C implements I { int z() { return 2; } }", added(VALID)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   207
        assertEval("C c = new C();");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   208
        assertEval("c.z();", "2");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   209
        assertEvalUnresolvedException("c.f()", "I", 1, 0);
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   210
        Snippet g = varKey(assertEval("int x = 55;", "55",
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   211
                added(VALID),
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   212
                ste(i, RECOVERABLE_DEFINED, VALID, false, null)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   213
        assertEval("c.f();", "55");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   214
        assertUnresolvedDependencies(i, 0);
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   215
        assertActiveKeys();
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   216
    }
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   217
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   218
    public void testForwardVarToEnum() {
36780
6bf2bef08a91 8152925: JShell: enable corralling of any type declaration, including enum
rfield
parents: 36499
diff changeset
   219
        DeclarationSnippet a = classKey(assertEval("enum E { Q, W, E; float ff() { return fff; } }", added(RECOVERABLE_DEFINED)));
6bf2bef08a91 8152925: JShell: enable corralling of any type declaration, including enum
rfield
parents: 36499
diff changeset
   220
        assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "variable fff");
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   221
        Snippet g = varKey(assertEval("float fff = 4.5f;", "4.5",
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   222
                added(VALID),
36780
6bf2bef08a91 8152925: JShell: enable corralling of any type declaration, including enum
rfield
parents: 36499
diff changeset
   223
                ste(a, RECOVERABLE_DEFINED, VALID, false, null)));
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   224
        assertEval("E.Q.ff();", "4.5");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   225
        assertEval("double fff = 3.3;", "3.3", null,
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   226
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   227
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   228
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   229
                ste(g, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
36780
6bf2bef08a91 8152925: JShell: enable corralling of any type declaration, including enum
rfield
parents: 36499
diff changeset
   230
                ste(a, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   231
        assertUnresolvedDependencies(a, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   232
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   233
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   234
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   235
    public void testForwardMethodToClass() {
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   236
        DeclarationSnippet a = classKey(assertEval("class A { int f() { return g(); } }", added(RECOVERABLE_DEFINED)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   237
        assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "method g()");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   238
        assertEval("A foo() { return null; }");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   239
        assertEvalUnresolvedException("new A();", "A", 1, 0);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   240
        Snippet g = methodKey(assertEval("int g() { return 10; }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   241
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   242
                ste(a, RECOVERABLE_DEFINED, VALID, false, null)));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   243
        assertEval("new A().f();", "10");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   244
        assertEval("double g() { return 10; }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   245
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   246
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   247
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   248
                ste(g, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   249
                ste(a, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   250
        assertUnresolvedDependencies(a, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   251
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   252
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   253
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   254
    public void testForwardClassToClass1() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   255
        Snippet a = classKey(assertEval("class A { B b = new B(); }", added(RECOVERABLE_NOT_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   256
        assertDeclareFail("new A().b;", "compiler.err.cant.resolve.location");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   257
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   258
        Snippet b = classKey(assertEval("class B { public String toString() { return \"B\"; } }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   259
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   260
                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   261
        assertEval("new A().b;", "B");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   262
        assertEval("interface B { }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   263
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   264
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   265
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   266
                ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   267
                ste(a, VALID, RECOVERABLE_DEFINED, true, MAIN_SNIPPET));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   268
        assertEvalUnresolvedException("new A().b;", "A", 0, 1);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   269
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   270
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   271
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   272
    public void testForwardClassToClass2() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   273
        Snippet a = classKey(assertEval("class A extends B { }", added(RECOVERABLE_NOT_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   274
        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   275
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   276
        Snippet b = classKey(assertEval("class B { public String toString() { return \"B\"; } }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   277
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   278
                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   279
        assertEval("new A();", "B");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   280
        assertEval("interface B { }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   281
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   282
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   283
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   284
                ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   285
                ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   286
        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   287
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   288
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   289
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   290
    public void testForwardClassToClass3() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   291
        Snippet a = classKey(assertEval("interface A extends B { static int f() { return 10; } }", added(RECOVERABLE_NOT_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   292
        assertDeclareFail("A.f();", "compiler.err.cant.resolve.location");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   293
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   294
        Snippet b = classKey(assertEval("interface B { }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   295
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   296
                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   297
        assertEval("A.f();", "10");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   298
        assertEval("class B { }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   299
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   300
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   301
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   302
                ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   303
                ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   304
        assertDeclareFail("A.f();", "compiler.err.cant.resolve.location");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   305
        assertActiveKeys();
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 testForwardVariable() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   309
        assertEval("int f() { return x; }", added(RECOVERABLE_DEFINED));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   310
        assertEvalUnresolvedException("f();", "f", 1, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   311
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   312
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   313
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   314
    public void testLocalClassInUnresolved() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   315
        Snippet f = methodKey(assertEval("void f() { class A {} g(); }", added(RECOVERABLE_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   316
        assertEval("void g() {}",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   317
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   318
                ste(f, RECOVERABLE_DEFINED, VALID, false, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   319
        assertEval("f();", "");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   320
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   321
}