langtools/test/jdk/jshell/ReplaceTest.java
author rfield
Mon, 10 Oct 2016 18:41:12 -0700
changeset 41514 a75c2b869d8d
parent 40304 0318f4e75c6d
child 43366 9e917e04f53c
permissions -rw-r--r--
8167128: JShell: /drop of statement gives confusing output Reviewed-by: jlahoda
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
/*
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
     2
 * Copyright (c) 2015, 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
/*
36780
6bf2bef08a91 8152925: JShell: enable corralling of any type declaration, including enum
rfield
parents: 36499
diff changeset
    25
 * @test 8080069 8152925
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    26
 * @summary Test of Snippet redefinition and replacement.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    27
 * @build KullaTesting TestingInputStream
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    28
 * @run testng ReplaceTest
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
40304
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 37644
diff changeset
    31
import java.util.Iterator;
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
    32
import java.util.List;
40304
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 37644
diff changeset
    33
import java.util.stream.Stream;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    34
import jdk.jshell.Snippet;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    35
import jdk.jshell.MethodSnippet;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    36
import jdk.jshell.TypeDeclSnippet;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    37
import jdk.jshell.VarSnippet;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    38
import jdk.jshell.DeclarationSnippet;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    39
import org.testng.annotations.Test;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    40
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
    41
import jdk.jshell.SnippetEvent;
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
    42
import jdk.jshell.UnresolvedReferenceException;
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
    43
import static org.testng.Assert.assertEquals;
40304
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 37644
diff changeset
    44
import static org.testng.Assert.assertFalse;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    45
import static jdk.jshell.Snippet.Status.*;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    46
import static jdk.jshell.Snippet.SubKind.*;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    47
import static org.testng.Assert.assertTrue;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    48
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    49
@Test
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    50
public class ReplaceTest extends KullaTesting {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    51
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    52
    public void testRedefine() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    53
        Snippet vx = varKey(assertEval("int x;"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    54
        Snippet mu = methodKey(assertEval("int mu() { return x * 4; }"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    55
        Snippet c = classKey(assertEval("class C { String v() { return \"#\" + mu(); } }"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    56
        assertEval("C c0  = new C();");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    57
        assertEval("c0.v();", "\"#0\"");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    58
        assertEval("int x = 10;", "10",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    59
                ste(MAIN_SNIPPET, VALID, VALID, false, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    60
                ste(vx, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    61
        assertEval("c0.v();", "\"#40\"");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    62
        assertEval("C c = new C();");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    63
        assertEval("c.v();", "\"#40\"");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    64
        assertEval("int mu() { return x * 3; }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    65
                ste(MAIN_SNIPPET, VALID, VALID, false, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    66
                ste(mu, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    67
        assertEval("c.v();", "\"#30\"");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    68
        assertEval("class C { String v() { return \"@\" + mu(); } }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    69
                ste(MAIN_SNIPPET, VALID, VALID, false, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    70
                ste(c, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    71
        assertEval("c0.v();", "\"@30\"");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    72
        assertEval("c = new C();");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    73
        assertEval("c.v();", "\"@30\"");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    74
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    75
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    76
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    77
    public void testReplaceClassToVar() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    78
        Snippet oldA = classKey(assertEval("class A { public String toString() { return \"old\"; } }"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    79
        Snippet v = varKey(assertEval("A a = new A();", "old"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    80
        assertEval("a;", "old");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    81
        Snippet midA = classKey(assertEval("class A { public String toString() { return \"middle\"; } }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    82
                ste(MAIN_SNIPPET, VALID, VALID, false, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    83
                ste(oldA, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    84
        assertEval("a;", "middle");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    85
        assertEval("class A { int x; public String toString() { return \"new\"; } }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    86
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    87
                ste(midA, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    88
                ste(v, VALID, VALID, true, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    89
        assertEval("a;", "null");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    90
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    91
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    92
40304
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 37644
diff changeset
    93
    private <T extends Snippet> void identityMatch(Stream<T> got, T expected) {
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 37644
diff changeset
    94
        Iterator<T> it = got.iterator();
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 37644
diff changeset
    95
        assertTrue(it.hasNext(), "expected exactly one");
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 37644
diff changeset
    96
        assertTrue(expected == it.next(), "Identity must not change");
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 37644
diff changeset
    97
        assertFalse(it.hasNext(), "expected exactly one");
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 37644
diff changeset
    98
    }
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 37644
diff changeset
    99
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   100
    public void testReplaceVarToMethod() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   101
        Snippet x = varKey(assertEval("int x;"));
40304
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 37644
diff changeset
   102
        MethodSnippet musn = methodKey(assertEval("double mu() { return x * 4; }"));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   103
        assertEval("x == 0;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   104
        assertEval("mu() == 0.0;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   105
        assertEval("double x = 2.5;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   106
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 36780
diff changeset
   107
                ste(x, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
40304
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 37644
diff changeset
   108
        identityMatch(getState().methods(), musn);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   109
        assertEval("x == 2.5;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   110
        assertEval("mu() == 10.0;", "true");  // Auto redefine
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   111
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   112
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   113
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   114
    public void testReplaceMethodToMethod() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   115
        Snippet a = methodKey(assertEval("double a() { return 2; }"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   116
        Snippet b = methodKey(assertEval("double b() { return a() * 10; }"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   117
        assertEval("double c() { return b() * 3; }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   118
        assertEval("double d() { return c() + 1000; }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   119
        assertEval("d();", "1060.0");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   120
        assertEval("int a() { return 5; }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   121
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 36780
diff changeset
   122
                ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   123
        assertEval("d();", "1150.0");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   124
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   125
    }
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
    public void testReplaceClassToMethod() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   128
        Snippet c = classKey(assertEval("class C { int f() { return 7; } }"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   129
        Snippet m = methodKey(assertEval("int m() { return new C().f(); }"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   130
        assertEval("m();", "7");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   131
        assertEval("class C { int x = 99; int f() { return x; } }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   132
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 36780
diff changeset
   133
                ste(c, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   134
        assertEval("m();", "99");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   135
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   136
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   137
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   138
    public void testReplaceVarToClass() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   139
        Snippet x = varKey(assertEval("int x;"));
40304
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 37644
diff changeset
   140
        TypeDeclSnippet c = classKey(assertEval("class A { double a = 4 * x; }"));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   141
        assertEval("x == 0;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   142
        assertEval("new A().a == 0.0;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   143
        assertEval("double x = 2.5;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   144
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 36780
diff changeset
   145
                ste(x, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
40304
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 37644
diff changeset
   146
        identityMatch(getState().types(), c);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   147
        assertEval("x == 2.5;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   148
        assertEval("new A().a == 10.0;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   149
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   150
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   151
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   152
    public void testReplaceMethodToClass() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   153
        Snippet x = methodKey(assertEval("int x() { return 0; }"));
40304
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 37644
diff changeset
   154
        TypeDeclSnippet c = classKey(assertEval("class A { double a = 4 * x(); }"));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   155
        assertEval("x() == 0;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   156
        assertEval("new A().a == 0.0;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   157
        assertEval("double x() { return 2.5; }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   158
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 36780
diff changeset
   159
                ste(x, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   160
        assertEval("x();", "2.5");
40304
0318f4e75c6d 8143964: JShell API: convert query responses to Stream instead of List
rfield
parents: 37644
diff changeset
   161
        identityMatch(getState().types(), c);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   162
        assertEval("x() == 2.5;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   163
        assertEval("new A().a == 10.0;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   164
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   165
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   166
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   167
    public void testReplaceClassToClass() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   168
        TypeDeclSnippet a = classKey(assertEval("class A {}"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   169
        assertTypeDeclSnippet(a, "A", VALID, CLASS_SUBKIND, 0, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   170
        TypeDeclSnippet b = classKey(assertEval("class B extends A {}"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   171
        TypeDeclSnippet c = classKey(assertEval("class C extends B {}"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   172
        TypeDeclSnippet d = classKey(assertEval("class D extends C {}"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   173
        assertEval("class A { int x; public String toString() { return \"NEW\"; } }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   174
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   175
                ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   176
                ste(b, VALID, VALID, true, MAIN_SNIPPET),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   177
                ste(c, VALID, VALID, true, b),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   178
                ste(d, VALID, VALID, true, c));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   179
        assertTypeDeclSnippet(b, "B", VALID, CLASS_SUBKIND, 0, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   180
        assertTypeDeclSnippet(c, "C", VALID, CLASS_SUBKIND, 0, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   181
        assertTypeDeclSnippet(d, "D", VALID, CLASS_SUBKIND, 0, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   182
        assertEval("new D();", "NEW");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   183
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   184
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   185
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   186
    public void testOverwriteReplaceMethod() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   187
        MethodSnippet k1 = methodKey(assertEval("String m(Integer i) { return i.toString(); }"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   188
        MethodSnippet k2 = methodKey(assertEval("String m(java.lang.Integer i) { return \"java.lang.\" + i.toString(); }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   189
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   190
                ste(k1, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   191
        assertMethodDeclSnippet(k1, "m", "(Integer)String", OVERWRITTEN, 0, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   192
        assertEval("m(6);", "\"java.lang.6\"");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   193
        assertEval("String m(Integer i) { return i.toString(); }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   194
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   195
                ste(k2, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   196
        assertMethodDeclSnippet(k2, "m", "(java.lang.Integer)String", OVERWRITTEN, 0, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   197
        assertEval("m(6);", "\"6\"");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   198
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   199
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   200
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   201
    public void testOverwriteMethodForwardReferenceClass() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   202
        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
   203
                added(RECOVERABLE_NOT_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   204
        assertUnresolvedDependencies1((MethodSnippet) k1, RECOVERABLE_NOT_DEFINED, "class Boo");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   205
        assertEval("class Boo { int x = 55; }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   206
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   207
                ste(k1, RECOVERABLE_NOT_DEFINED, VALID, true, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   208
        assertMethodDeclSnippet((MethodSnippet) k1, "q", "(Boo)int", VALID, 0, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   209
        assertEval("q(new Boo());", "55");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   210
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   211
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   212
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   213
    public void testOverwriteMethodForwardReferenceClassImport() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   214
        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
   215
                added(RECOVERABLE_NOT_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   216
        assertUnresolvedDependencies1(k1, RECOVERABLE_NOT_DEFINED, "class List");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   217
        assertEval("import java.util.*;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   218
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   219
                ste(k1, RECOVERABLE_NOT_DEFINED, VALID, true, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   220
        assertMethodDeclSnippet(k1, "ff", "(List)int", VALID, 0, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   221
        assertEval("ff(new ArrayList());", "0");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   222
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   223
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   224
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   225
    public void testForwardVarToMethod() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   226
        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
   227
        assertUnresolvedDependencies1(t, RECOVERABLE_DEFINED, "variable x");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   228
        assertEvalUnresolvedException("t();", "t", 1, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   229
        Snippet x = varKey(assertEval("int x = 33;", "33",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   230
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   231
                ste(t, RECOVERABLE_DEFINED, VALID, false, null)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   232
        assertEval("t();", "33");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   233
        assertEval("double x = 0.88;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   234
                "0.88", null,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   235
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   236
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   237
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   238
                ste(x, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   239
                ste(t, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   240
        assertEvalUnresolvedException("t();", "t", 0, 1);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   241
        assertActiveKeys();
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 testForwardMethodToMethod() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   245
        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
   246
        Snippet f = methodKey(assertEval("int f() { return g(); }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   247
                added(RECOVERABLE_DEFINED),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   248
                ste(t, RECOVERABLE_DEFINED, VALID, false, null)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   249
        assertUnresolvedDependencies1((DeclarationSnippet) f, RECOVERABLE_DEFINED, "method g()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   250
        assertEvalUnresolvedException("t();", "f", 1, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   251
        Snippet g = methodKey(assertEval("int g() { return 55; }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   252
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   253
                ste(f, RECOVERABLE_DEFINED, VALID, false, null)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   254
        assertEval("t();", "55");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   255
        assertEval("double g() { return 3.14159; }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   256
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   257
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   258
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   259
                ste(g, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   260
                ste(f, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   261
        DeclarationSnippet exsn = assertEvalUnresolvedException("t();", "f", 0, 1);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   262
        assertTrue(exsn == f, "Identity must not change");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   263
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   264
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   265
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   266
    public void testForwardClassToMethod() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   267
        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
   268
        assertUnresolvedDependencies1(t, RECOVERABLE_DEFINED, "class A");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   269
        assertEvalUnresolvedException("t();", "t", 1, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   270
        Snippet a = classKey(assertEval(
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   271
                "class A {\n" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   272
                        "   int f() { return 10; }\n" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   273
                "}",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   274
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   275
                ste(t, RECOVERABLE_DEFINED, VALID, false, null)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   276
        assertEval("t();", "10");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   277
        assertEval(
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   278
                "class A {\n" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   279
                "   double f() { return 88.0; }\n" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   280
                "}",
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(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   285
                ste(t, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   286
        assertEvalUnresolvedException("t();", "t", 0, 1);
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 testForwardVarToClass() {
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   291
        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
   292
        assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "variable g");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   293
        Snippet g = varKey(assertEval("int g = 10;", "10",
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   294
                added(VALID),
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   295
                ste(a, RECOVERABLE_DEFINED, VALID, false, null)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   296
        assertEval("new A().f();", "10");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   297
        assertEval("double g = 10;", "10.0", null,
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   298
                DiagCheck.DIAG_OK,
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   299
                DiagCheck.DIAG_ERROR,
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   300
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   301
                ste(g, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   302
                ste(a, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   303
        assertUnresolvedDependencies(a, 0);
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   304
        assertActiveKeys();
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   305
    }
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   306
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   307
    public void testForwardVarToClassGeneric() {
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   308
        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
   309
        assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "variable g");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   310
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   311
        List<SnippetEvent> events = assertEval("A<String> as = new A<>(\"hi\");", null,
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   312
                UnresolvedReferenceException.class, DiagCheck.DIAG_OK, DiagCheck.DIAG_OK, null);
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   313
        SnippetEvent ste = events.get(0);
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   314
        Snippet assn = ste.snippet();
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   315
        DeclarationSnippet unsn = ((UnresolvedReferenceException) ste.exception()).getSnippet();
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   316
        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
   317
        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
   318
        assertEquals(getState().diagnostics(unsn).count(), 0L, "Expected no diagnostics");
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   319
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   320
        Snippet g = varKey(assertEval("int g = 10;", "10",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   321
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   322
                ste(a, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   323
        assertEval("A<String> as = new A<>(\"low\");",
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   324
                ste(MAIN_SNIPPET, VALID, VALID, false, null),
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   325
                ste(assn, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   326
        assertEval("as.get();", "\"low\"");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   327
        assertUnresolvedDependencies(a, 0);
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   328
        assertActiveKeys();
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   329
    }
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   330
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   331
   public void testForwardVarToClassExtendsImplements() {
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   332
        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
   333
        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
   334
        DeclarationSnippet ck = classKey(assertEval("class C { int cc() { return 3; } }", added(VALID)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   335
        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
   336
        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
   337
        assertUnresolvedDependencies1(dk, RECOVERABLE_DEFINED, "variable g");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   338
        assertEvalUnresolvedException("new D();", "D", 1, 0);
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   339
        assertEvalUnresolvedException("new E();", "D", 1, 0);
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   340
        VarSnippet g = varKey(assertEval("int g = 10;", "10",
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   341
                added(VALID),
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   342
                ste(dk, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   343
        assertEval("E e = new E();");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   344
        assertDrop(g,
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   345
                ste(g, VALID, DROPPED, true, null),
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   346
                ste(dk, VALID, RECOVERABLE_DEFINED, false, g));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   347
        assertEvalUnresolvedException("new D();", "D", 1, 0);
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   348
        assertEvalUnresolvedException("new E();", "D", 1, 0);
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   349
        assertEval("e.ee();", "5");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   350
        assertEvalUnresolvedException("e.dd();", "D", 1, 0);
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   351
        assertEval("e.cc();", "3");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   352
        assertEval("e.jj();", "2");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   353
        assertEval("e.ii();", "1");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   354
        assertActiveKeys();
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   355
    }
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   356
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   357
    public void testForwardVarToInterface() {
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   358
        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
   359
        assertUnresolvedDependencies1(i, RECOVERABLE_DEFINED, "variable x");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   360
        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
   361
        assertEval("C c = new C();");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   362
        assertEval("c.z();", "2");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   363
        assertEvalUnresolvedException("c.f()", "I", 1, 0);
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   364
        Snippet g = varKey(assertEval("int x = 55;", "55",
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   365
                added(VALID),
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   366
                ste(i, RECOVERABLE_DEFINED, VALID, false, null)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   367
        assertEval("c.f();", "55");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   368
        assertUnresolvedDependencies(i, 0);
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   369
        assertActiveKeys();
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   370
    }
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   371
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   372
    public void testForwardVarToEnum() {
36780
6bf2bef08a91 8152925: JShell: enable corralling of any type declaration, including enum
rfield
parents: 36499
diff changeset
   373
        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
   374
        assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "variable fff");
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   375
        Snippet g = varKey(assertEval("float fff = 4.5f;", "4.5",
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   376
                added(VALID),
36780
6bf2bef08a91 8152925: JShell: enable corralling of any type declaration, including enum
rfield
parents: 36499
diff changeset
   377
                ste(a, RECOVERABLE_DEFINED, VALID, false, null)));
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   378
        assertEval("E.Q.ff();", "4.5");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   379
        assertEval("double fff = 3.3;", "3.3", null,
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   380
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   381
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   382
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   383
                ste(g, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
36780
6bf2bef08a91 8152925: JShell: enable corralling of any type declaration, including enum
rfield
parents: 36499
diff changeset
   384
                ste(a, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   385
        assertUnresolvedDependencies(a, 0);
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
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   388
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   389
    public void testForwardMethodToClass() {
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   390
        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
   391
        assertUnresolvedDependencies1(a, RECOVERABLE_DEFINED, "method g()");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   392
        assertEval("A foo() { return null; }");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   393
        assertEvalUnresolvedException("new A();", "A", 1, 0);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   394
        Snippet g = methodKey(assertEval("int g() { return 10; }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   395
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   396
                ste(a, RECOVERABLE_DEFINED, VALID, false, null)));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   397
        assertEval("new A().f();", "10");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   398
        assertEval("double g() { return 10; }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   399
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   400
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   401
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   402
                ste(g, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   403
                ste(a, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   404
        assertUnresolvedDependencies(a, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   405
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   406
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   407
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   408
    public void testForwardClassToClass1() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   409
        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
   410
        assertDeclareFail("new A().b;", "compiler.err.cant.resolve.location");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   411
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   412
        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
   413
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   414
                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   415
        assertEval("new A().b;", "B");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   416
        assertEval("interface B { }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   417
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   418
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   419
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   420
                ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   421
                ste(a, VALID, RECOVERABLE_DEFINED, true, MAIN_SNIPPET));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   422
        assertEvalUnresolvedException("new A().b;", "A", 0, 1);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   423
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   424
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   425
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   426
    public void testForwardClassToClass2() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   427
        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
   428
        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   429
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   430
        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
   431
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   432
                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   433
        assertEval("new A();", "B");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   434
        assertEval("interface B { }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   435
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   436
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   437
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   438
                ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   439
                ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   440
        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   441
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   442
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   443
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   444
    public void testForwardClassToClass3() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   445
        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
   446
        assertDeclareFail("A.f();", "compiler.err.cant.resolve.location");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   447
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   448
        Snippet b = classKey(assertEval("interface B { }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   449
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   450
                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   451
        assertEval("A.f();", "10");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   452
        assertEval("class B { }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   453
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   454
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   455
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   456
                ste(b, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   457
                ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   458
        assertDeclareFail("A.f();", "compiler.err.cant.resolve.location");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   459
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   460
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   461
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   462
    public void testImportDeclare() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   463
        Snippet singleImport = importKey(assertEval("import java.util.List;", added(VALID)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   464
        Snippet importOnDemand = importKey(assertEval("import java.util.*;", added(VALID)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   465
        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
   466
        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
   467
        assertEval("import java.util.List; //again",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   468
                ste(MAIN_SNIPPET, VALID, VALID, false, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   469
                ste(singleImport, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   470
        assertEval("import java.util.*; //again",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   471
                ste(MAIN_SNIPPET, VALID, VALID, false, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   472
                ste(importOnDemand, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   473
        assertEval("import static java.lang.Math.abs; //again",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   474
                ste(MAIN_SNIPPET, VALID, VALID, false, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   475
                ste(singleStaticImport, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   476
        assertEval("import static java.lang.Math.*; //again",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   477
                ste(MAIN_SNIPPET, VALID, VALID, false, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   478
                ste(staticImportOnDemand, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   479
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   480
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   481
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   482
    public void testForwardVariable() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   483
        assertEval("int f() { return x; }", added(RECOVERABLE_DEFINED));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   484
        assertEvalUnresolvedException("f();", "f", 1, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   485
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   486
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   487
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   488
    public void testLocalClassInUnresolved() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   489
        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
   490
        assertEval("void g() {}",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   491
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   492
                ste(f, RECOVERABLE_DEFINED, VALID, false, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   493
        assertEval("f();", "");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   494
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   495
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   496
    @Test(enabled = false) // TODO 8129420
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   497
    public void testLocalClassEvolve() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   498
        Snippet j = methodKey(assertEval("Object j() { return null; }", added(VALID)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   499
        assertEval("Object j() { class B {}; return null; }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   500
                ste(MAIN_SNIPPET, VALID, VALID, false, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   501
        assertEval("Object j() { class B {}; return new B(); }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   502
                ste(MAIN_SNIPPET, VALID, VALID, false, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   503
        assertEval("j().getClass().getSimpleName();", "\"B\"");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   504
        assertEval("Object j() { class B { int p; public String toString() { return \"Yep\";} }; return new B(); }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   505
                ste(MAIN_SNIPPET, VALID, VALID, false, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   506
        assertEval("j().getClass().getSimpleName();", "\"B\"");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   507
        assertEval("j();", "Yep");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   508
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   509
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   510
    public void testForwardSingleImportMethodToMethod() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   511
        DeclarationSnippet string = methodKey(assertEval("String string() { return format(\"string\"); }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   512
                added(RECOVERABLE_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   513
        assertUnresolvedDependencies1(string, RECOVERABLE_DEFINED, "method format(java.lang.String)");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   514
        assertEvalUnresolvedException("string();", "string", 1, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   515
        assertEval("import static java.lang.String.format;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   516
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   517
                ste(string, RECOVERABLE_DEFINED, VALID, false, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   518
        assertEval("string();", "\"string\"");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   519
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   520
        assertEval("double format(String s) { return 0; }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   521
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   522
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   523
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   524
                ste(string, VALID, RECOVERABLE_DEFINED, false, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   525
        assertEvalUnresolvedException("string();", "string", 0, 1);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   526
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   527
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   528
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   529
    public void testForwardImportMethodOnDemandToMethod() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   530
        DeclarationSnippet string = methodKey(assertEval("String string() { return format(\"string\"); }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   531
                added(RECOVERABLE_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   532
        assertUnresolvedDependencies1(string, RECOVERABLE_DEFINED, "method format(java.lang.String)");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   533
        assertEvalUnresolvedException("string();", "string", 1, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   534
        assertEval("import static java.lang.String.*;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   535
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   536
                ste(string, RECOVERABLE_DEFINED, VALID, false, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   537
        assertEval("string();", "\"string\"");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   538
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   539
        assertEval("double format(String s) { return 0; }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   540
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   541
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   542
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   543
                ste(string, VALID, RECOVERABLE_DEFINED, false, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   544
        assertEvalUnresolvedException("string();", "string", 0, 1);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   545
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   546
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   547
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   548
    public void testForwardSingleImportFieldToMethod() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   549
        DeclarationSnippet pi = methodKey(assertEval("double pi() { return PI; }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   550
                added(RECOVERABLE_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   551
        assertUnresolvedDependencies1(pi, RECOVERABLE_DEFINED, "variable PI");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   552
        assertEvalUnresolvedException("pi();", "pi", 1, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   553
        assertEval("import static java.lang.Math.PI;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   554
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   555
                ste(pi, RECOVERABLE_DEFINED, VALID, false, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   556
        assertEval("Math.abs(pi() - 3.1415) < 0.001;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   557
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   558
        assertEval("String PI;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   559
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   560
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   561
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   562
                ste(pi, VALID, RECOVERABLE_DEFINED, false, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   563
        assertEvalUnresolvedException("pi();", "pi", 0, 1);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   564
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   565
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   566
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   567
    public void testForwardImportFieldOnDemandToMethod() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   568
        DeclarationSnippet pi = methodKey(assertEval("double pi() { return PI; }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   569
                added(RECOVERABLE_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   570
        assertUnresolvedDependencies1(pi, RECOVERABLE_DEFINED, "variable PI");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   571
        assertEvalUnresolvedException("pi();", "pi", 1, 0);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   572
        assertEval("import static java.lang.Math.*;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   573
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   574
                ste(pi, RECOVERABLE_DEFINED, VALID, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   575
        assertEval("Math.abs(pi() - 3.1415) < 0.001;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   576
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   577
        assertEval("String PI;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   578
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   579
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   580
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   581
                ste(pi, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   582
        assertEvalUnresolvedException("pi();", "pi", 0, 1);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   583
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   584
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   585
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   586
    public void testForwardSingleImportMethodToClass1() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   587
        Snippet a = classKey(assertEval("class A { String s = format(\"%d\", 10); }",
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   588
                added(RECOVERABLE_DEFINED)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   589
        assertEvalUnresolvedException("new A();", "A", 1, 0);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   590
        assertEval("import static java.lang.String.format;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   591
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   592
                ste(a, RECOVERABLE_DEFINED, VALID, false, null));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   593
        assertEval("new A().s;", "\"10\"");
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   594
        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
   595
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   596
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   597
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   598
                ste(a, VALID, RECOVERABLE_DEFINED, false, MAIN_SNIPPET)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   599
        assertEvalUnresolvedException("new A();", "A", 0, 1);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   600
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   601
        assertDrop(format,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   602
                ste(format, VALID, DROPPED, true, null),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   603
                ste(a, RECOVERABLE_DEFINED, VALID, false, format));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   604
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   605
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   606
    public void testForwardSingleImportMethodToClass2() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   607
        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
   608
                added(RECOVERABLE_DEFINED)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   609
        assertEvalUnresolvedException("new A();", "A", 1, 0);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   610
        assertEval("import static java.lang.String.format;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   611
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   612
                ste(a, RECOVERABLE_DEFINED, VALID, false, null));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   613
        assertEval("new A().s();", "\"10\"");
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   614
        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
   615
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   616
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   617
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   618
                ste(a, VALID, RECOVERABLE_DEFINED, false, null)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   619
        assertEvalUnresolvedException("new A();", "A", 0, 1);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   620
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   621
        assertDrop(format,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   622
                ste(format, VALID, DROPPED, true, null),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   623
                ste(a, RECOVERABLE_DEFINED, VALID, false, format));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   624
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   625
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   626
    public void testForwardSingleImportClassToClass1() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   627
        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
   628
                added(RECOVERABLE_NOT_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   629
        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   630
        assertEval("import java.util.List;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   631
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   632
                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   633
        assertEval("import java.util.Arrays;", added(VALID));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   634
        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
   635
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   636
        Snippet list = classKey(assertEval("class List {}",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   637
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   638
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   639
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   640
                ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, null)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   641
        assertDeclareFail("A.list = Arrays.asList(1, 2, 3);", "compiler.err.already.defined.static.single.import");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   642
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   643
        assertDrop(list,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   644
                ste(list, VALID, DROPPED, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   645
                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, list));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   646
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   647
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   648
    public void testForwardSingleImportClassToClass2() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   649
        Snippet clsA = classKey(assertEval("class A extends ArrayList<Integer> { }",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   650
                added(RECOVERABLE_NOT_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   651
        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   652
        assertEval("import java.util.ArrayList;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   653
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   654
                ste(clsA, RECOVERABLE_NOT_DEFINED, VALID, true, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   655
        Snippet vara = varKey(assertEval("A a = new A();", "[]"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   656
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   657
        Snippet arraylist = classKey(assertEval("class ArrayList {}",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   658
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   659
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   660
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   661
                ste(clsA, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   662
                ste(vara, VALID, RECOVERABLE_NOT_DEFINED, true, clsA)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   663
        assertDeclareFail("A a = new A();", "compiler.err.cant.resolve.location",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   664
                ste(MAIN_SNIPPET, RECOVERABLE_NOT_DEFINED, REJECTED, false, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   665
                ste(vara, RECOVERABLE_NOT_DEFINED, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   666
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   667
        assertDrop(arraylist,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   668
                ste(arraylist, VALID, DROPPED, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   669
                ste(clsA, RECOVERABLE_NOT_DEFINED, VALID, true, arraylist));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   670
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   671
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   672
    public void testForwardImportOnDemandMethodToClass1() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   673
        Snippet a = classKey(assertEval("class A { String s = format(\"%d\", 10); }",
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   674
                added(RECOVERABLE_DEFINED)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   675
        assertEvalUnresolvedException("new A();", "A", 1, 0);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   676
        assertEval("import static java.lang.String.*;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   677
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   678
                ste(a, RECOVERABLE_DEFINED, VALID, false, null));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   679
        assertEval("A x = new A();");
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   680
        assertEval("x.s;", "\"10\"");
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   681
        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
   682
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   683
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   684
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   685
                ste(a, VALID, RECOVERABLE_DEFINED, false, null)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   686
        assertEvalUnresolvedException("new A();", "A", 0, 1);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   687
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   688
        assertDrop(format,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   689
                ste(format, VALID, DROPPED, true, null),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   690
                ste(a, RECOVERABLE_DEFINED, VALID, false, format));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   691
        assertEval("x.s;", "\"10\"");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   692
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   693
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   694
    public void testForwardImportOnDemandMethodToClass2() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   695
        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
   696
                added(RECOVERABLE_DEFINED)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   697
        assertEvalUnresolvedException("new A();", "A", 1, 0);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   698
        assertEval("import static java.lang.String.*;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   699
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   700
                ste(a, RECOVERABLE_DEFINED, VALID, false, null));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   701
        assertEval("new A().s();", "\"10\"");
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   702
        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
   703
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   704
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   705
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   706
                ste(a, VALID, RECOVERABLE_DEFINED, false, null)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   707
        assertEvalUnresolvedException("new A();", "A", 0, 1);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   708
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   709
        assertDrop(format,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   710
                ste(format, VALID, DROPPED, true, null),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   711
                ste(a, RECOVERABLE_DEFINED, VALID, false, format));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   712
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   713
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   714
    public void testForwardImportOnDemandClassToClass1() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   715
        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
   716
                added(RECOVERABLE_NOT_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   717
        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   718
        assertEval("import java.util.*;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   719
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   720
                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   721
        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
   722
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   723
        Snippet list = classKey(assertEval("class List {}",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   724
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   725
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   726
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   727
                ste(a, VALID, RECOVERABLE_NOT_DEFINED, true, null)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   728
        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
   729
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   730
        assertDrop(list,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   731
                ste(list, VALID, DROPPED, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   732
                ste(a, RECOVERABLE_NOT_DEFINED, VALID, true, list));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   733
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   734
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   735
    public void testForwardImportOnDemandClassToClass2() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   736
        Snippet clsA = classKey(assertEval("class A extends ArrayList<Integer> { }",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   737
                added(RECOVERABLE_NOT_DEFINED)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   738
        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   739
        assertEval("import java.util.*;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   740
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   741
                ste(clsA, RECOVERABLE_NOT_DEFINED, VALID, true, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   742
        Snippet vara = varKey(assertEval("A a = new A();", "[]"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   743
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   744
        Snippet arraylist = classKey(assertEval("class ArrayList {}",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   745
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   746
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   747
                added(VALID),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   748
                ste(clsA, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   749
                ste(vara, VALID, RECOVERABLE_NOT_DEFINED, true, clsA)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   750
        assertDeclareFail("new A();", "compiler.err.cant.resolve.location");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   751
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   752
        assertDrop(arraylist,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   753
                ste(arraylist, VALID, DROPPED, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   754
                ste(clsA, RECOVERABLE_NOT_DEFINED, VALID, true, arraylist),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   755
                ste(vara, RECOVERABLE_NOT_DEFINED, VALID, true, clsA));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   756
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   757
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   758
    public void testForwardSingleImportFieldToClass1() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   759
        Snippet a = classKey(assertEval("class A { static double pi() { return PI; } }",
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   760
                added(RECOVERABLE_DEFINED)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   761
        assertEvalUnresolvedException("new A();", "A", 1, 0);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   762
        assertEval("import static java.lang.Math.PI;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   763
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   764
                ste(a, RECOVERABLE_DEFINED, VALID, false, null));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   765
        assertEval("Math.abs(A.pi() - 3.1415) < 0.001;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   766
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   767
        Snippet list = varKey(assertEval("String PI;",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   768
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   769
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   770
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   771
                ste(a, VALID, RECOVERABLE_DEFINED, false, null)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   772
        assertEvalUnresolvedException("new A();", "A", 0, 1);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   773
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   774
        assertDrop(list,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   775
                ste(list, VALID, DROPPED, true, null),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   776
                ste(a, RECOVERABLE_DEFINED, VALID, false, list));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   777
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   778
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   779
    public void testForwardSingleImportFieldToClass2() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   780
        Snippet a = classKey(assertEval("class A { static double pi = PI; }",
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   781
                added(RECOVERABLE_DEFINED)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   782
        assertEvalUnresolvedException("new A();", "A", 1, 0);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   783
        assertEval("import static java.lang.Math.PI;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   784
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   785
                ste(a, RECOVERABLE_DEFINED, VALID, true, null));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   786
        assertEval("Math.abs(A.pi - 3.1415) < 0.001;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   787
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   788
        Snippet list = varKey(assertEval("String PI;",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   789
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   790
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   791
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   792
                ste(a, VALID, RECOVERABLE_DEFINED, true, null)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   793
        assertEvalUnresolvedException("new A();", "A", 0, 1);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   794
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   795
        assertDrop(list,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   796
                ste(list, VALID, DROPPED, true, null),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   797
                ste(a, RECOVERABLE_DEFINED, VALID, true, list));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   798
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   799
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   800
    public void testForwardImportOnDemandFieldToClass1() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   801
        Snippet a = classKey(assertEval("class A { static double pi() { return PI; } }",
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   802
                added(RECOVERABLE_DEFINED)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   803
        assertEvalUnresolvedException("new A();", "A", 1, 0);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   804
        assertEval("import static java.lang.Math.*;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   805
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   806
                ste(a, RECOVERABLE_DEFINED, VALID, false, null));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   807
        assertEval("Math.abs(A.pi() - 3.1415) < 0.001;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   808
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   809
        Snippet list = varKey(assertEval("String PI;",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   810
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   811
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   812
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   813
                ste(a, VALID, RECOVERABLE_DEFINED, false, null)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   814
        assertEvalUnresolvedException("new A();", "A", 0, 1);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   815
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   816
        assertDrop(list,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   817
                ste(list, VALID, DROPPED, true, null),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   818
                ste(a, RECOVERABLE_DEFINED, VALID, false, list));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   819
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   820
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   821
    public void testForwardImportOnDemandFieldToClass2() {
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   822
        Snippet a = classKey(assertEval("class A { static double pi = PI; }",
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   823
                added(RECOVERABLE_DEFINED)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   824
        assertEvalUnresolvedException("new A();", "A", 1, 0);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   825
        assertEval("import static java.lang.Math.*;",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   826
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   827
                ste(a, RECOVERABLE_DEFINED, VALID, true, null));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   828
        assertEval("Math.abs(A.pi - 3.1415) < 0.001;", "true");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   829
41514
a75c2b869d8d 8167128: JShell: /drop of statement gives confusing output
rfield
parents: 40304
diff changeset
   830
        Snippet list = varKey(assertEval("String PI;",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   831
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   832
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   833
                added(VALID),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   834
                ste(a, VALID, RECOVERABLE_DEFINED, true, null)));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   835
        assertEvalUnresolvedException("new A();", "A", 0, 1);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   836
        assertActiveKeys();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   837
        assertDrop(list,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   838
                ste(list, VALID, DROPPED, true, null),
36499
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   839
                ste(a, RECOVERABLE_DEFINED, VALID, true, list));
9d823cc0fe98 8080069: JShell: Support for corralled classes
rfield
parents: 33362
diff changeset
   840
        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
   841
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   842
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   843
    public void testReplaceCausesMethodReferenceError() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   844
        Snippet l = classKey(assertEval("interface Logger { public void log(String message); }", added(VALID)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   845
        Snippet v = varKey(assertEval("Logger l = System.out::println;", added(VALID)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   846
        assertEval("interface Logger { public boolean accept(String message);  }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   847
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   848
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   849
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   850
                ste(l, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   851
                ste(v, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   852
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   853
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   854
    public void testReplaceCausesClassCompilationError() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   855
        Snippet l = classKey(assertEval("interface L { }", added(VALID)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   856
        Snippet c = classKey(assertEval("class C implements L { }", added(VALID)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   857
        assertEval("interface L { void m(); }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   858
                DiagCheck.DIAG_OK,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   859
                DiagCheck.DIAG_ERROR,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   860
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   861
                ste(l, VALID, OVERWRITTEN, false, MAIN_SNIPPET),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   862
                ste(c, VALID, RECOVERABLE_NOT_DEFINED, true, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   863
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   864
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   865
    public void testOverwriteNoUpdate() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   866
        String xsi = "int x = 5;";
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   867
        String xsd = "double x = 3.14159;";
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   868
        VarSnippet xi = varKey(assertEval(xsi, added(VALID)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   869
        String ms1 = "double m(Integer i) { return i + x; }";
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   870
        String ms2 = "double m(java.lang.Integer i) { return i + x; }";
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   871
        MethodSnippet k1 = methodKey(assertEval(ms1, added(VALID)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   872
        VarSnippet xd = varKey(assertEval(xsd,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   873
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 36780
diff changeset
   874
                ste(xi, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   875
        MethodSnippet k2 = methodKey(assertEval(ms2,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   876
                ste(MAIN_SNIPPET, VALID, VALID, true, null), //TODO: technically, should be false
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   877
                ste(k1, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   878
        VarSnippet xi2 = varKey(assertEval(xsi,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   879
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 36780
diff changeset
   880
                ste(xd, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   881
        varKey(assertEval(xsd,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   882
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
37644
33cf53901cac 8154485: JShell: infrastructure for multi-Snippet class wrappers
rfield
parents: 36780
diff changeset
   883
                ste(xi2, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   884
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   885
}