test/langtools/jdk/jshell/CompletionSuggestionTest.java
author jlahoda
Wed, 21 Feb 2018 17:07:12 +0100
changeset 48931 b25eb74ec283
parent 47268 48ec75306997
child 54778 d1d6e939803f
permissions -rw-r--r--
8197439: Crash with -XDfind=lambda for anonymous class in anonymous class. Summary: Ensuring unresolvable anonymous classes are attributed. Reviewed-by: mcimadamore, sadayapalam
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
/*
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35359
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
/*
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    25
 * @test
48931
b25eb74ec283 8197439: Crash with -XDfind=lambda for anonymous class in anonymous class.
jlahoda
parents: 47268
diff changeset
    26
 * @bug 8131025 8141092 8153761 8145263 8131019 8175886 8176184 8176241 8176110 8177466 8197439
41527
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
    27
 * @summary Test Completion and Documentation
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
    28
 * @library /tools/lib
35359
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 33715
diff changeset
    29
 * @modules jdk.compiler/com.sun.tools.javac.api
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 33715
diff changeset
    30
 *          jdk.compiler/com.sun.tools.javac.main
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35359
diff changeset
    31
 *          jdk.jdeps/com.sun.tools.javap
42407
f3702cff2933 8169069: Module system implementation refresh (11/2016)
alanb
parents: 41865
diff changeset
    32
 *          jdk.jshell/jdk.jshell:open
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    33
 * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    34
 * @build KullaTesting TestingInputStream Compiler
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    35
 * @run testng CompletionSuggestionTest
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    36
 */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    37
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
    38
import java.io.IOException;
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
    39
import java.lang.reflect.Field;
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
    40
import java.nio.file.Files;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    41
import java.nio.file.Path;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    42
import java.nio.file.Paths;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    43
import java.util.Arrays;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    44
import java.util.Collections;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    45
import java.util.Set;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    46
import java.util.HashSet;
41527
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
    47
import java.util.function.BiFunction;
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
    48
import java.util.function.Function;
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
    49
import java.util.jar.JarEntry;
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
    50
import java.util.jar.JarOutputStream;
33362
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
import jdk.jshell.Snippet;
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
    53
import org.testng.annotations.BeforeMethod;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    54
import org.testng.annotations.Test;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    55
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    56
import static jdk.jshell.Snippet.Status.VALID;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    57
import static jdk.jshell.Snippet.Status.OVERWRITTEN;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    58
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    59
@Test
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    60
public class CompletionSuggestionTest extends KullaTesting {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    61
33715
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
    62
    private final Compiler compiler = new Compiler();
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
    63
    private final Path outDir = Paths.get("completion_suggestion_test");
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
    64
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    65
    public void testMemberExpr() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    66
        assertEval("class Test { static void test() { } }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    67
        assertCompletion("Test.t|", "test()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    68
        assertEval("Test ccTestInstance = new Test();");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    69
        assertCompletion("ccTestInstance.t|", "toString()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    70
        assertCompletion(" ccTe|", "ccTestInstance");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    71
        assertCompletion("String value = ccTestInstance.to|", "toString()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    72
        assertCompletion("java.util.Coll|", "Collection", "Collections");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    73
        assertCompletion("String.cla|", "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    74
        assertCompletion("boolean.cla|", "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    75
        assertCompletion("byte.cla|", "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    76
        assertCompletion("short.cla|", "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    77
        assertCompletion("char.cla|", "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    78
        assertCompletion("int.cla|", "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    79
        assertCompletion("float.cla|", "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    80
        assertCompletion("long.cla|", "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    81
        assertCompletion("double.cla|", "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    82
        assertCompletion("void.cla|", "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    83
        assertCompletion("Object[].|", "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    84
        assertCompletion("int[].|", "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    85
        assertEval("Object[] ao = null;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    86
        assertCompletion("int i = ao.|", "length");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    87
        assertEval("int[] ai = null;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    88
        assertCompletion("int i = ai.|", "length");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    89
        assertCompletionIncludesExcludes("\"\".|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    90
                new HashSet<>(Collections.emptyList()),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    91
                new HashSet<>(Arrays.asList("String(")));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    92
        assertEval("double d = 0;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    93
        assertEval("void m() {}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    94
        assertCompletionIncludesExcludes("d.|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    95
                new HashSet<>(Collections.emptyList()),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    96
                new HashSet<>(Arrays.asList("class")));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    97
        assertCompletionIncludesExcludes("m().|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    98
                new HashSet<>(Collections.emptyList()),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    99
                new HashSet<>(Arrays.asList("class")));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   100
        assertEval("class C {class D {} static class E {} enum F {} interface H {} void method() {} int number;}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   101
        assertCompletionIncludesExcludes("C.|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   102
                new HashSet<>(Arrays.asList("D", "E", "F", "H", "class")),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   103
                new HashSet<>(Arrays.asList("method()", "number")));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   104
        assertCompletionIncludesExcludes("new C().|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   105
                new HashSet<>(Arrays.asList("method()", "number")),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   106
                new HashSet<>(Arrays.asList("D", "E", "F", "H", "class")));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   107
        assertCompletionIncludesExcludes("new C() {}.|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   108
                new HashSet<>(Arrays.asList("method()", "number")),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   109
                new HashSet<>(Arrays.asList("D", "E", "F", "H", "class")));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   110
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   111
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   112
    public void testStartOfExpression() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   113
        assertEval("int ccTest = 0;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   114
        assertCompletion("System.err.println(cc|", "ccTest");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   115
        assertCompletion("for (int i = cc|", "ccTest");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   116
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   117
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   118
    public void testParameter() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   119
        assertCompletion("class C{void method(int num){num|", "num");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   120
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   121
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   122
    public void testPrimitive() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   123
        Set<String> primitives = new HashSet<>(Arrays.asList("boolean", "char", "byte", "short", "int", "long", "float", "double"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   124
        Set<String> onlyVoid = new HashSet<>(Collections.singletonList("void"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   125
        Set<String> primitivesOrVoid = new HashSet<>(primitives);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   126
        primitivesOrVoid.addAll(onlyVoid);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   127
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   128
        assertCompletionIncludesExcludes("|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   129
                primitivesOrVoid,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   130
                new HashSet<>(Collections.emptyList()));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   131
        assertCompletionIncludesExcludes("int num = |",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   132
                primitivesOrVoid,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   133
                new HashSet<>(Collections.emptyList()));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   134
        assertCompletionIncludesExcludes("num = |",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   135
                primitivesOrVoid,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   136
                new HashSet<>(Collections.emptyList()));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   137
        assertCompletionIncludesExcludes("class C{void m() {|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   138
                primitivesOrVoid,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   139
                new HashSet<>(Collections.emptyList()));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   140
        assertCompletionIncludesExcludes("void method(|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   141
                primitives,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   142
                onlyVoid);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   143
        assertCompletionIncludesExcludes("void method(int num, |",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   144
                primitives,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   145
                onlyVoid);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   146
        assertCompletion("new java.util.ArrayList<doub|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   147
        assertCompletion("class A extends doubl|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   148
        assertCompletion("class A implements doubl|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   149
        assertCompletion("interface A extends doubl|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   150
        assertCompletion("enum A implements doubl|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   151
        assertCompletion("class A<T extends doubl|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   152
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   153
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   154
    public void testEmpty() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   155
        assertCompletionIncludesExcludes("|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   156
                new HashSet<>(Arrays.asList("Object", "Void")),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   157
                new HashSet<>(Arrays.asList("$REPL00DOESNOTMATTER")));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   158
        assertCompletionIncludesExcludes("V|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   159
                new HashSet<>(Collections.singletonList("Void")),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   160
                new HashSet<>(Collections.singletonList("Object")));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   161
        assertCompletionIncludesExcludes("{ |",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   162
                new HashSet<>(Arrays.asList("Object", "Void")),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   163
                new HashSet<>(Arrays.asList("$REPL00DOESNOTMATTER")));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   164
    }
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
    public void testSmartCompletion() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   167
        assertEval("int ccTest1 = 0;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   168
        assertEval("int ccTest2 = 0;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   169
        assertEval("String ccTest3 = null;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   170
        assertEval("void method(int i, String str) { }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   171
        assertEval("void method(String str, int i) { }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   172
        assertEval("java.util.List<String> list = null;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   173
        assertCompletion("int ccTest4 = |", true, "ccTest1", "ccTest2");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   174
        assertCompletion("ccTest2 = |", true, "ccTest1", "ccTest2");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   175
        assertCompletion("int ccTest4 = ccTe|", "ccTest1", "ccTest2", "ccTest3");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   176
        assertCompletion("int ccTest4 = ccTest3.len|", true, "length()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   177
        assertCompletion("method(|", true, "ccTest1", "ccTest2", "ccTest3");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   178
        assertCompletion("method(0, |", true, "ccTest3");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   179
        assertCompletion("list.add(|", true, "ccTest1", "ccTest2", "ccTest3");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   180
        assertCompletion("list.add(0, |", true, "ccTest3");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   181
        assertCompletion("new String(|", true, "ccTest3");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   182
        assertCompletion("new String(new char[0], |", true, "ccTest1", "ccTest2");
45747
bdf4b1b26697 8176110: JShell: completions with package results should, in most cases, be dot terminated
rfield
parents: 44814
diff changeset
   183
        assertCompletionIncludesExcludes("new jav|", new HashSet<>(Arrays.asList("java.", "javax.")), Collections.emptySet());
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   184
        assertCompletion("Class<String> clazz = String.c|", true, "class");
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
        Snippet klass = classKey(assertEval("class Klass {void method(int n) {} private void method(String str) {}}"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   187
        assertCompletion("new Klass().method(|", true, "ccTest1", "ccTest2");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   188
        Snippet klass2 = classKey(assertEval("class Klass {static void method(int n) {} void method(String str) {}}",
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(klass, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   191
        assertCompletion("Klass.method(|", true, "ccTest1", "ccTest2");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   192
        assertEval("class Klass {Klass(int n) {} private Klass(String str) {}}",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   193
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   194
                ste(klass2, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   195
        assertCompletion("new Klass(|", true, "ccTest1", "ccTest2");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   196
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   197
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   198
    public void testSmartCompletionInOverriddenMethodInvocation() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   199
        assertEval("int ccTest1 = 0;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   200
        assertEval("int ccTest2 = 0;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   201
        assertEval("String ccTest3 = null;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   202
        assertCompletion("\"\".wait(|", true, "ccTest1", "ccTest2");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   203
        assertEval("class Base {void method(int n) {}}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   204
        assertEval("class Extend extends Base {}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   205
        assertCompletion("new Extend().method(|", true, "ccTest1", "ccTest2");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   206
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   207
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   208
    public void testSmartCompletionForBoxedType() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   209
        assertEval("int ccTest1 = 0;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   210
        assertEval("Integer ccTest2 = 0;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   211
        assertEval("Object ccTest3 = null;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   212
        assertEval("int method1(int n) {return n;}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   213
        assertEval("Integer method2(Integer n) {return n;}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   214
        assertEval("Object method3(Object o) {return o;}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   215
        assertCompletion("int ccTest4 = |", true, "ccTest1", "ccTest2", "method1(", "method2(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   216
        assertCompletion("Integer ccTest4 = |", true, "ccTest1", "ccTest2", "method1(", "method2(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   217
        assertCompletion("Object ccTest4 = |", true, "ccTest1", "ccTest2", "ccTest3", "method1(", "method2(", "method3(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   218
        assertCompletion("method1(|", true, "ccTest1", "ccTest2", "method1(", "method2(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   219
        assertCompletion("method2(|", true, "ccTest1", "ccTest2", "method1(", "method2(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   220
        assertCompletion("method3(|", true, "ccTest1", "ccTest2", "ccTest3", "method1(", "method2(", "method3(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   221
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   222
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   223
    public void testNewClass() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   224
        assertCompletion("String str = new Strin|", "String(", "StringBuffer(", "StringBuilder(", "StringIndexOutOfBoundsException(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   225
        assertCompletion("String str = new java.lang.Strin|", "String(", "StringBuffer(", "StringBuilder(", "StringIndexOutOfBoundsException(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   226
        assertCompletion("String str = new |", true, "String(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   227
        assertCompletion("String str = new java.lang.|", true, "String(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   228
        assertCompletion("throw new Strin|", true, "StringIndexOutOfBoundsException(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   229
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   230
        assertEval("class A{class B{} class C {C(int n) {}} static class D {} interface I {}}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   231
        assertEval("A a;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   232
        assertCompletion("new A().new |", "B()", "C(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   233
        assertCompletion("a.new |", "B()", "C(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   234
        assertCompletion("new A.|", "D()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   235
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   236
        assertEval("enum E{; class A {}}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   237
        assertEval("interface I{; class A {}}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   238
        assertCompletion("new E.|", "A()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   239
        assertCompletion("new I.|", "A()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   240
        assertCompletion("new String(I.A|", "A");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   241
    }
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
    public void testFullyQualified() {
45747
bdf4b1b26697 8176110: JShell: completions with package results should, in most cases, be dot terminated
rfield
parents: 44814
diff changeset
   244
        assertCompletion("Optional<String> opt = java.u|", "util.");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   245
        assertCompletionIncludesExcludes("Optional<Strings> opt = java.util.O|", new HashSet<>(Collections.singletonList("Optional")), Collections.emptySet());
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   246
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   247
        assertEval("void method(java.util.Optional<String> opt) {}");
45747
bdf4b1b26697 8176110: JShell: completions with package results should, in most cases, be dot terminated
rfield
parents: 44814
diff changeset
   248
        assertCompletion("method(java.u|", "util.");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   249
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   250
        assertCompletion("Object.notElement.|");
45747
bdf4b1b26697 8176110: JShell: completions with package results should, in most cases, be dot terminated
rfield
parents: 44814
diff changeset
   251
        assertCompletion("Object o = com.su|", "sun.");
33715
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   252
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   253
        Path p1 = outDir.resolve("dir1");
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   254
        compiler.compile(p1,
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   255
                "package p1.p2;\n" +
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   256
                "public class Test {\n" +
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   257
                "}",
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   258
                "package p1.p3;\n" +
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   259
                "public class Test {\n" +
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   260
                "}");
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   261
        String jarName = "test.jar";
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   262
        compiler.jar(p1, jarName, "p1/p2/Test.class", "p1/p3/Test.class");
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   263
        addToClasspath(compiler.getPath(p1.resolve(jarName)));
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   264
45747
bdf4b1b26697 8176110: JShell: completions with package results should, in most cases, be dot terminated
rfield
parents: 44814
diff changeset
   265
        assertCompletionIncludesExcludes("|", new HashSet<>(Collections.singletonList("p1.")), Collections.emptySet());
bdf4b1b26697 8176110: JShell: completions with package results should, in most cases, be dot terminated
rfield
parents: 44814
diff changeset
   266
        assertCompletion("p1.|", "p2.", "p3.");
33715
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   267
        assertCompletion("p1.p2.|", "Test");
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   268
        assertCompletion("p1.p3.|", "Test");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   269
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   270
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   271
    public void testCheckAccessibility() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   272
        assertCompletion("java.util.regex.Pattern.co|", "compile(");
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
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   275
    public void testCompletePackages() {
45747
bdf4b1b26697 8176110: JShell: completions with package results should, in most cases, be dot terminated
rfield
parents: 44814
diff changeset
   276
        assertCompletion("java.u|", "util.");
bdf4b1b26697 8176110: JShell: completions with package results should, in most cases, be dot terminated
rfield
parents: 44814
diff changeset
   277
        assertCompletionIncludesExcludes("jav|", new HashSet<>(Arrays.asList("java.", "javax.")), Collections.emptySet());
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   278
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   279
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   280
    public void testImports() {
45747
bdf4b1b26697 8176110: JShell: completions with package results should, in most cases, be dot terminated
rfield
parents: 44814
diff changeset
   281
        assertCompletion("import java.u|", "util.");
bdf4b1b26697 8176110: JShell: completions with package results should, in most cases, be dot terminated
rfield
parents: 44814
diff changeset
   282
        assertCompletionIncludesExcludes("import jav|", new HashSet<>(Arrays.asList("java.", "javax.")), Collections.emptySet());
bdf4b1b26697 8176110: JShell: completions with package results should, in most cases, be dot terminated
rfield
parents: 44814
diff changeset
   283
        assertCompletion("import static java.u|", "util.");
bdf4b1b26697 8176110: JShell: completions with package results should, in most cases, be dot terminated
rfield
parents: 44814
diff changeset
   284
        assertCompletionIncludesExcludes("import static jav|", new HashSet<>(Arrays.asList("java.", "javax.")), Collections.emptySet());
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   285
        assertCompletion("import static java.lang.Boolean.g|", "getBoolean");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   286
        assertCompletion("import java.util.*|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   287
        assertCompletionIncludesExcludes("import java.lang.String.|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   288
                Collections.emptySet(),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   289
                new HashSet<>(Arrays.asList("CASE_INSENSITIVE_ORDER", "copyValueOf", "format", "join", "valueOf", "class", "length")));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   290
        assertCompletionIncludesExcludes("import static java.lang.String.|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   291
                new HashSet<>(Arrays.asList("CASE_INSENSITIVE_ORDER", "copyValueOf", "format", "join", "valueOf")),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   292
                new HashSet<>(Arrays.asList("class", "length")));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   293
        assertCompletionIncludesExcludes("import java.util.Map.|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   294
                new HashSet<>(Arrays.asList("Entry")),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   295
                new HashSet<>(Arrays.asList("class")));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   296
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   297
44061
d9ddf704d193 8175886: JShell: crash on tab-complete with NPE.
rfield
parents: 43146
diff changeset
   298
    public void testImportStart() {
45747
bdf4b1b26697 8176110: JShell: completions with package results should, in most cases, be dot terminated
rfield
parents: 44814
diff changeset
   299
        assertCompletionIncludesExcludes("import c|", Set.of("com."), Set.of());
44061
d9ddf704d193 8175886: JShell: crash on tab-complete with NPE.
rfield
parents: 43146
diff changeset
   300
    }
d9ddf704d193 8175886: JShell: crash on tab-complete with NPE.
rfield
parents: 43146
diff changeset
   301
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   302
    public void testBrokenClassFile() throws Exception {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   303
        Compiler compiler = new Compiler();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   304
        Path testOutDir = Paths.get("CompletionTestBrokenClassFile");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   305
        String input = "package test.inner; public class Test {}";
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   306
        compiler.compile(testOutDir, input);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   307
        addToClasspath(compiler.getPath(testOutDir).resolve("test"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   308
        assertCompletion("import inner.|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   309
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   310
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   311
    public void testDocumentation() throws Exception {
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   312
        dontReadParameterNamesFromClassFile();
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   313
        assertSignature("System.getProperty(|",
41527
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   314
                "String System.getProperty(String key)",
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   315
                "String System.getProperty(String key, String def)");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   316
        assertEval("char[] chars = null;");
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   317
        assertSignature("new String(chars, |",
41527
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   318
                "String(char[], int, int)");
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   319
        assertSignature("String.format(|",
41527
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   320
                "String String.format(String, Object...)",
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   321
                "String String.format(java.util.Locale, String, Object...)");
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   322
        assertSignature("\"\".getBytes(\"\"|", "void String.getBytes(int, int, byte[], int)",
41527
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   323
                                                    "byte[] String.getBytes(String) throws java.io.UnsupportedEncodingException",
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   324
                                                    "byte[] String.getBytes(java.nio.charset.Charset)");
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   325
        assertSignature("\"\".getBytes(\"\" |", "void String.getBytes(int, int, byte[], int)",
41527
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   326
                                                     "byte[] String.getBytes(String) throws java.io.UnsupportedEncodingException",
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   327
                                                     "byte[] String.getBytes(java.nio.charset.Charset)");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   328
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   329
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   330
    public void testMethodsWithNoArguments() throws Exception {
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   331
        dontReadParameterNamesFromClassFile();
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   332
        assertSignature("System.out.println(|",
41527
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   333
                "void java.io.PrintStream.println()",
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   334
                "void java.io.PrintStream.println(boolean)",
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   335
                "void java.io.PrintStream.println(char)",
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   336
                "void java.io.PrintStream.println(int)",
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   337
                "void java.io.PrintStream.println(long)",
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   338
                "void java.io.PrintStream.println(float)",
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   339
                "void java.io.PrintStream.println(double)",
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   340
                "void java.io.PrintStream.println(char[])",
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   341
                "void java.io.PrintStream.println(String)",
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   342
                "void java.io.PrintStream.println(Object)");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   343
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   344
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   345
    public void testErroneous() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   346
        assertCompletion("Undefined.|");
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   347
        assertSignature("does.not.exist|");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   348
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   349
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   350
    public void testClinit() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   351
        assertEval("enum E{;}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   352
        assertEval("class C{static{}}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   353
        assertCompletionIncludesExcludes("E.|", Collections.emptySet(), new HashSet<>(Collections.singletonList("<clinit>")));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   354
        assertCompletionIncludesExcludes("C.|", Collections.emptySet(), new HashSet<>(Collections.singletonList("<clinit>")));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   355
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   356
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   357
    public void testMethodHeaderContext() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   358
        assertCompletion("private void f(Runn|", "Runnable");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   359
        assertCompletion("void f(Runn|", "Runnable");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   360
        assertCompletion("void f(Object o1, Runn|", "Runnable");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   361
        assertCompletion("void f(Object o1) throws Num|", true, "NumberFormatException");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   362
        assertCompletion("void f(Object o1) throws java.lang.Num|", true, "NumberFormatException");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   363
        assertEval("class HogeHoge {static class HogeHogeException extends Exception {}}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   364
        assertCompletion("void f(Object o1) throws Hoge|", "HogeHoge");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   365
        assertCompletion("void f(Object o1) throws HogeHoge.|", true, "HogeHogeException");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   366
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   367
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   368
    public void testTypeVariables() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   369
        assertCompletion("class A<TYPE> { public void test() { TY|", "TYPE");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   370
        assertCompletion("class A<TYPE> { public static void test() { TY|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   371
        assertCompletion("class A<TYPE> { public <TYPE> void test() { TY|", "TYPE");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   372
        assertCompletion("class A<TYPE> { public static <TYPE> void test() { TY|", "TYPE");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   373
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   374
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   375
    public void testGeneric() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   376
        assertEval("import java.util.concurrent.*;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   377
        assertCompletion("java.util.List<Integ|", "Integer");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   378
        assertCompletion("class A<TYPE extends Call|", "Callable");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   379
        assertCompletion("class A<TYPE extends Callable<TY|", "TYPE");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   380
        assertCompletion("<TYPE> void f(TY|", "TYPE");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   381
        assertCompletion("class A<TYPE extends Callable<? sup|", "super");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   382
        assertCompletion("class A<TYPE extends Callable<? super TY|", "TYPE");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   383
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   384
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   385
    public void testFields() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   386
        assertEval("interface Interface { int field = 0; }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   387
        Snippet clazz = classKey(assertEval("class Clazz {" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   388
                "static int staticField = 0;" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   389
                "int field = 0;" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   390
                " }"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   391
        assertCompletion("Interface.fiel|", "field");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   392
        assertCompletion("Clazz.staticFiel|", "staticField");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   393
        assertCompletion("new Interface() {}.fiel|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   394
        assertCompletion("new Clazz().staticFiel|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   395
        assertCompletion("new Clazz().fiel|", "field");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   396
        assertCompletion("new Clazz() {}.fiel|", "field");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   397
        assertEval("class Clazz implements Interface {}",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   398
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   399
                ste(clazz, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   400
        assertCompletion("Clazz.fiel|", "field");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   401
        assertCompletion("new Clazz().fiel|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   402
        assertCompletion("new Clazz() {}.fiel|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   403
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   404
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   405
    public void testMethods() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   406
        assertEval("interface Interface {" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   407
                "default int defaultMethod() { return 0; }" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   408
                "static int staticMethod() { return 0; }" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   409
                "}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   410
        Snippet clazz = classKey(assertEval("class Clazz {" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   411
                "static int staticMethod() { return 0; }" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   412
                "int method() { return 0; }" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   413
                "}"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   414
        assertCompletion("Interface.staticMeth|", "staticMethod()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   415
        assertCompletion("Clazz.staticMeth|", "staticMethod()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   416
        assertCompletion("new Interface() {}.defaultMe||", "defaultMethod()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   417
        assertCompletion("new Clazz().staticMeth|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   418
        assertCompletion("new Clazz().meth|", "method()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   419
        assertEval("class Clazz implements Interface {}",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   420
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   421
                ste(clazz, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   422
        assertCompletion("Clazz.staticMeth|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   423
        assertCompletion("new Clazz() {}.defaultM|", "defaultMethod()");
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
40318
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   426
    @Test
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   427
    public void testUncompletedDeclaration() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   428
        assertCompletion("class Clazz { Claz|", "Clazz");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   429
        assertCompletion("class Clazz { class A extends Claz|", "Clazz");
40770
dfccc36b61b6 8164952: JShell tests: jdk/jshell/CompletionSuggestionTest.testUncompletedDeclaration(): failure
jlahoda
parents: 40318
diff changeset
   430
        assertCompletion("class Clazz { Clazz clazz; Object o = claz|", "clazz");
dfccc36b61b6 8164952: JShell tests: jdk/jshell/CompletionSuggestionTest.testUncompletedDeclaration(): failure
jlahoda
parents: 40318
diff changeset
   431
        assertCompletion("class Clazz { static Clazz clazz; Object o = claz|", "clazz");
dfccc36b61b6 8164952: JShell tests: jdk/jshell/CompletionSuggestionTest.testUncompletedDeclaration(): failure
jlahoda
parents: 40318
diff changeset
   432
        assertCompletion("class Clazz { Clazz clazz; static Object o = claz|", true);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   433
        assertCompletion("class Clazz { void method(Claz|", "Clazz");
40318
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   434
        assertCompletion("class A { int method() { return 0; } int a = meth|", "method()");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   435
        assertCompletion("class A { int field = 0; int method() { return fiel|", "field");
40318
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   436
        assertCompletion("class A { static int method() { return 0; } int a = meth|", "method()");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   437
        assertCompletion("class A { static int field = 0; int method() { return fiel|", "field");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   438
        assertCompletion("class A { int method() { return 0; } static int a = meth|", true);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   439
        assertCompletion("class A { int field = 0; static int method() { return fiel|", true);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   440
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   441
40318
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   442
    @Test
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   443
    public void testClassDeclaration() {
40318
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   444
        assertEval("void ClazzM() {}");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   445
        assertEval("void InterfaceM() {}");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   446
        assertEval("interface Interface {}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   447
        assertCompletion("interface A extends Interf|", "Interface");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   448
        assertCompletion("class A implements Interf|", "Interface");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   449
        assertEval("class Clazz {}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   450
        assertCompletion("class A extends Claz|", "Clazz");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   451
        assertCompletion("class A extends Clazz implements Interf|", "Interface");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   452
        assertEval("interface Interface1 {}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   453
        assertCompletion("class A extends Clazz implements Interface, Interf|", "Interface", "Interface1");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   454
        assertCompletion("interface A implements Claz|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   455
        assertCompletion("interface A implements Inter|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   456
        assertCompletion("class A implements Claz|", true);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   457
        assertCompletion("class A extends Clazz implements Interface, Interf|", true, "Interface1");
40318
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   458
        assertCompletion("class A extends Clazz implements Interface, Interf|", true, "Interface1");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   459
        assertEval("class InterfaceClazz {}");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   460
        assertCompletion("class A <T extends Claz|", "Clazz");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   461
        assertCompletion("class A <T extends Interf|", "Interface", "Interface1", "InterfaceClazz");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   462
        assertCompletion("class A <T extends Interface & Interf|", "Interface", "Interface1", "InterfaceClazz");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   463
        assertCompletion("class A <T extends Clazz & Interf|", "Interface", "Interface1", "InterfaceClazz");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   464
        assertCompletion("class A <T extends Claz|", true, "Clazz");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   465
        assertCompletion("class A <T extends Interf|", true, "Interface", "Interface1", "InterfaceClazz");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   466
        assertCompletion("class A <T extends Interface & Interf|", true, "Interface1");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   467
        assertCompletion("class A <T extends Clazz & Interf|", true, "Interface", "Interface1");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   468
    }
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   469
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   470
    public void testMethodDeclaration() {
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   471
        assertEval("void ClazzM() {}");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   472
        assertEval("void InterfaceM() {}");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   473
        assertEval("interface Interface {}");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   474
        assertCompletion("void m(Interf|", "Interface");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   475
        assertCompletion("void m(Interface i1, Interf|", "Interface");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   476
        assertEval("class InterfaceException extends Exception {}");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   477
        assertCompletion("void m(Interface i1) throws Interf|", "Interface", "InterfaceException");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   478
        assertCompletion("void m(Interface i1) throws Interf|", true, "InterfaceException");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   479
    }
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
    public void testDocumentationOfUserDefinedMethods() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   482
        assertEval("void f() {}");
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   483
        assertSignature("f(|", "void f()");
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   484
        assertEval("void f(int i) {}");
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   485
        assertSignature("f(|", "void f()", "void f(int i)");
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   486
        assertEval("<T> void f(T... ts) {}", DiagCheck.DIAG_WARNING, DiagCheck.DIAG_OK);
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   487
        assertSignature("f(|", "void f()", "void f(int i)", "void <T>f(T... ts)");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   488
        assertEval("class A {}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   489
        assertEval("void f(A a) {}");
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   490
        assertSignature("f(|", "void f()", "void f(int i)", "void <T>f(T... ts)", "void f(A a)");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   491
    }
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   492
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   493
    public void testClass() {
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   494
        assertSignature("String|", "java.lang.String");
33362
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
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   497
    public void testDocumentationOfUserDefinedConstructors() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   498
        Snippet a = classKey(assertEval("class A {}"));
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   499
        assertSignature("new A(|", "A()");
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   500
        Snippet a2 = classKey(assertEval("class A { A() {} A(int i) {}}",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   501
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   502
                ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   503
        assertSignature("new A(|", "A()", "A(int i)");
41527
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   504
        assertEval("class A<T> { A(T a) {} A(int i) {} <U> A(T t, U u) {}}",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   505
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   506
                ste(a2, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   507
        assertSignature("new A(|", "A<T>(T a)", "A<T>(int i)", "<U> A<T>(T t, U u)");
33362
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
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   510
    public void testDocumentationOfOverriddenMethods() throws Exception {
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   511
        dontReadParameterNamesFromClassFile();
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   512
        assertSignature("\"\".wait(|",
41527
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   513
            "void Object.wait(long) throws InterruptedException",
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   514
            "void Object.wait(long, int) throws InterruptedException",
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   515
            "void Object.wait() throws InterruptedException");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   516
        assertEval("class Base {void method() {}}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   517
        Snippet e = classKey(assertEval("class Extend extends Base {}"));
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   518
        assertSignature("new Extend().method(|", "void Base.method()");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   519
        assertEval("class Extend extends Base {void method() {}}",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   520
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   521
                ste(e, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   522
        assertSignature("new Extend().method(|", "void Extend.method()");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   523
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   524
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   525
    public void testDocumentationOfInvisibleMethods() {
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   526
        assertSignature("Object.wait(|");
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   527
        assertSignature("\"\".indexOfSupplementary(|");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   528
        Snippet a = classKey(assertEval("class A {void method() {}}"));
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   529
        assertSignature("A.method(|");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   530
        assertEval("class A {private void method() {}}",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   531
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   532
                ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   533
        assertSignature("new A().method(|");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   534
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   535
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   536
    public void testDocumentationOfInvisibleConstructors() {
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   537
        assertSignature("new Compiler(|");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   538
        assertEval("class A { private A() {} }");
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   539
        assertSignature("new A(|");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   540
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   541
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   542
    public void testDocumentationWithBoxing() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   543
        assertEval("int primitive = 0;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   544
        assertEval("Integer boxed = 0;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   545
        assertEval("Object object = null;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   546
        assertEval("void method(int n, Object o) { }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   547
        assertEval("void method(Object n, int o) { }");
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   548
        assertSignature("method(primitive,|",
41527
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   549
                "void method(int n, Object o)",
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   550
                "void method(Object n, int o)");
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   551
        assertSignature("method(boxed,|",
41527
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   552
                "void method(int n, Object o)",
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   553
                "void method(Object n, int o)");
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   554
        assertSignature("method(object,|",
41527
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   555
                "void method(Object n, int o)");
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   556
    }
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   557
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   558
    public void testDocumentationWithGenerics() {
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   559
        class TestDocumentationWithGenerics {
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   560
            private final Function<Integer, String> codeFacotry;
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   561
            private final BiFunction<String, Integer, String> evalFormatter;
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   562
            private final BiFunction<String, Integer, String> docFormatter;
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   563
            int count;
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   564
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   565
            TestDocumentationWithGenerics(
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   566
                    Function<Integer, String> codeFactory,
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   567
                    BiFunction<String, Integer, String> evalFormatter,
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   568
                    BiFunction<String, Integer, String> documentationFormatter) {
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   569
                this.codeFacotry = codeFactory;
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   570
                this.evalFormatter = evalFormatter;
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   571
                this.docFormatter = documentationFormatter;
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   572
            }
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   573
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   574
            void assertDoc(String generics) {
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   575
                assertDoc(generics, generics);
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   576
            }
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   577
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   578
            void assertDoc(String generics, String expectedGenerics) {
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   579
                assertEval(evalFormatter.apply(generics, count));
41865
3ef02797070d 8131019: jshell tool: access javadoc from tool
jlahoda
parents: 41527
diff changeset
   580
                assertSignature(codeFacotry.apply(count), docFormatter.apply(expectedGenerics, count));
41527
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   581
                count++;
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   582
            }
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   583
        }
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   584
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   585
        TestDocumentationWithGenerics[] tests = {
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   586
            new TestDocumentationWithGenerics(
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   587
                    i -> "f" + i + "(|",
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   588
                    (g, i) -> "<" + g + "> void f" + i + "() {}",
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   589
                    (g, i) -> "void <" + g + ">f" + i + "()"
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   590
            ),
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   591
            new TestDocumentationWithGenerics(
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   592
                    i -> "new C" + i + "().f(|",
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   593
                    (g, i) -> "class C" + i + "<" + g + "> { void f() {} }",
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   594
                    (g, i) -> "void C" + i + "<" + g + ">.f()"
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   595
            )
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   596
        };
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   597
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   598
        Arrays.stream(tests).forEach(t -> {
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   599
                t.assertDoc("T");
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   600
                t.assertDoc("T extends Object",
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   601
                        "T");
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   602
                t.assertDoc("T extends String");
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   603
                t.assertDoc("T extends java.lang.String",
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   604
                        "T extends String");
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   605
                t.assertDoc("T extends Number & Comparable<T>");
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   606
                t.assertDoc("T extends java.io.Serializable & CharSequence");
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   607
                t.assertDoc("K, D, M extends java.util.Map<K, D>",
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   608
                        "K, D, M extends java.util.Map<K,D>");
e8f487b79e24 8145263: JShell: Fix the format of SourceCodeAnalysis#documentation
shinyafox
parents: 40837
diff changeset
   609
        });
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   610
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   611
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   612
    public void testVarArgs() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   613
        assertEval("int i = 0;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   614
        assertEval("class Foo1 { static void m(int... i) { } } ");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   615
        assertCompletion("Foo1.m(|", true, "i");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   616
        assertCompletion("Foo1.m(i, |", true, "i");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   617
        assertCompletion("Foo1.m(i, i, |", true, "i");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   618
        assertEval("class Foo2 { static void m(String s, int... i) { } } ");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   619
        assertCompletion("Foo2.m(|", true);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   620
        assertCompletion("Foo2.m(i, |", true);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   621
        assertCompletion("Foo2.m(\"\", |", true, "i");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   622
        assertCompletion("Foo2.m(\"\", i, |", true, "i");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   623
        assertCompletion("Foo2.m(\"\", i, i, |", true, "i");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   624
        assertEval("class Foo3 { Foo3(String s, int... i) { } } ");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   625
        assertCompletion("new Foo3(|", true);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   626
        assertCompletion("new Foo3(i, |", true);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   627
        assertCompletion("new Foo3(\"\", |", true, "i");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   628
        assertCompletion("new Foo3(\"\", i, |", true, "i");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   629
        assertCompletion("new Foo3(\"\", i, i, |", true, "i");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   630
        assertEval("int[] ia = null;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   631
        assertCompletion("Foo1.m(ia, |", true);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   632
        assertEval("class Foo4 { static void m(int... i) { } static void m(int[] ia, String str) { } } ");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   633
        assertEval("String str = null;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   634
        assertCompletion("Foo4.m(ia, |", true, "str");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   635
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   636
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   637
    public void testConstructorAsMemberOf() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   638
        assertEval("class Baz<X> { Baz(X x) { } } ");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   639
        assertEval("String str = null;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   640
        assertEval("Integer i = null;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   641
        assertCompletion("new Baz(|", true, "i", "str");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   642
        assertCompletion("new Baz<String>(|", true, "str");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   643
        assertCompletion("Baz<String> bz = new Baz<>(|", true, "str");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   644
        assertEval("class Foo { static void m(String str) {} static void m(Baz<String> baz) {} }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   645
        assertCompletion("Foo.m(new Baz<>(|", true, "str");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   646
    }
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   647
47268
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   648
    public void testIntersection() {
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   649
        assertEval("<Z extends Runnable & CharSequence> Z get() { return null; }");
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   650
        assertEval("var v = get();");
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   651
        assertCompletionIncludesExcludes("v.|", true, Set.of("run()", "length()"), Set.of());
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   652
        assertCompletion("Runnable r = |", true, "get()", "v");
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   653
        assertCompletion("CharSequence r = |", true, "get()", "v");
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   654
        assertCompletion("Number r = |", true);
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   655
    }
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   656
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   657
    public void testAnonymous() {
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   658
        assertEval("var v = new Runnable() { public void run() { } public int length() { return 0; } };");
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   659
        assertCompletionIncludesExcludes("v.|", true, Set.of("run()", "length()"), Set.of());
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   660
        assertCompletion("Runnable r = |", true, "v");
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   661
        assertCompletion("CharSequence r = |", true);
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   662
    }
48ec75306997 8177466: Add compiler support for local variable type-inference
mcimadamore
parents: 47216
diff changeset
   663
48931
b25eb74ec283 8197439: Crash with -XDfind=lambda for anonymous class in anonymous class.
jlahoda
parents: 47268
diff changeset
   664
    public void testCompletionInAnonymous() {
b25eb74ec283 8197439: Crash with -XDfind=lambda for anonymous class in anonymous class.
jlahoda
parents: 47268
diff changeset
   665
        assertCompletionIncludesExcludes("new Undefined() { int i = \"\".l|", Set.of("length()"), Set.of());
b25eb74ec283 8197439: Crash with -XDfind=lambda for anonymous class in anonymous class.
jlahoda
parents: 47268
diff changeset
   666
    }
b25eb74ec283 8197439: Crash with -XDfind=lambda for anonymous class in anonymous class.
jlahoda
parents: 47268
diff changeset
   667
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   668
    @BeforeMethod
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   669
    public void setUp() {
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   670
        super.setUp();
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   671
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   672
        Path srcZip = Paths.get("src.zip");
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   673
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   674
        try (JarOutputStream out = new JarOutputStream(Files.newOutputStream(srcZip))) {
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   675
            out.putNextEntry(new JarEntry("java/lang/System.java"));
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   676
            out.write(("package java.lang;\n" +
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   677
                       "public class System {\n" +
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   678
                       "    public String getProperty(String key) { return null; }\n" +
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   679
                       "    public String getProperty(String key, String def) { return def; }\n" +
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   680
                       "}\n").getBytes());
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   681
        } catch (IOException ex) {
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   682
            throw new IllegalStateException(ex);
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   683
        }
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   684
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   685
        try {
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   686
            Field availableSources = getAnalysis().getClass().getDeclaredField("availableSources");
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   687
            availableSources.setAccessible(true);
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   688
            availableSources.set(getAnalysis(), Arrays.asList(srcZip));
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   689
        } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex) {
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   690
            throw new IllegalStateException(ex);
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   691
        }
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   692
    }
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   693
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   694
    private void dontReadParameterNamesFromClassFile() throws Exception {
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   695
        Field keepParameterNames = getAnalysis().getClass().getDeclaredField("keepParameterNames");
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   696
        keepParameterNames.setAccessible(true);
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   697
        keepParameterNames.set(getAnalysis(), new String[0]);
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   698
    }
40837
d071bcc8d32e 8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents: 40770
diff changeset
   699
43146
7c249fca6c06 8172678: JShell Tests: Disable CompletionSuggestionTest.testBrokenClassFile2()
rfield
parents: 42407
diff changeset
   700
    @Test(enabled = false) //TODO 8171829
40837
d071bcc8d32e 8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents: 40770
diff changeset
   701
    public void testBrokenClassFile2() throws IOException {
d071bcc8d32e 8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents: 40770
diff changeset
   702
        Path broken = outDir.resolve("broken");
d071bcc8d32e 8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents: 40770
diff changeset
   703
        compiler.compile(broken,
d071bcc8d32e 8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents: 40770
diff changeset
   704
                "package p;\n" +
d071bcc8d32e 8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents: 40770
diff changeset
   705
                "public class BrokenA {\n" +
d071bcc8d32e 8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents: 40770
diff changeset
   706
                "}",
d071bcc8d32e 8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents: 40770
diff changeset
   707
                "package p.q;\n" +
d071bcc8d32e 8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents: 40770
diff changeset
   708
                "public class BrokenB {\n" +
d071bcc8d32e 8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents: 40770
diff changeset
   709
                "}",
d071bcc8d32e 8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents: 40770
diff changeset
   710
                "package p;\n" +
d071bcc8d32e 8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents: 40770
diff changeset
   711
                "public class BrokenC {\n" +
d071bcc8d32e 8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents: 40770
diff changeset
   712
                "}");
d071bcc8d32e 8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents: 40770
diff changeset
   713
        Path cp = compiler.getPath(broken);
d071bcc8d32e 8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents: 40770
diff changeset
   714
        Path target = cp.resolve("p").resolve("BrokenB.class");
d071bcc8d32e 8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents: 40770
diff changeset
   715
        Files.deleteIfExists(target);
d071bcc8d32e 8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents: 40770
diff changeset
   716
        Files.move(cp.resolve("p").resolve("q").resolve("BrokenB.class"), target);
d071bcc8d32e 8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents: 40770
diff changeset
   717
        addToClasspath(cp);
d071bcc8d32e 8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents: 40770
diff changeset
   718
d071bcc8d32e 8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents: 40770
diff changeset
   719
        assertEval("import p.*;");
d071bcc8d32e 8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents: 40770
diff changeset
   720
        assertCompletion("Broke|", "BrokenA", "BrokenC");
d071bcc8d32e 8131025: JShell: crash on tab-complete reference to bad class file
jlahoda
parents: 40770
diff changeset
   721
    }
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   722
}