langtools/test/jdk/jshell/CompletionSuggestionTest.java
author jlahoda
Mon, 15 Aug 2016 08:28:26 +0200
changeset 40318 3f7eb1205cee
parent 37939 3eb8c2a89b77
child 40770 dfccc36b61b6
permissions -rw-r--r--
8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion 8129422: JShell: methods and fields of uncompleted expressions should be suggested Summary: Fixing several completion bugs Reviewed-by: rfield
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
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
    26
 * @bug 8141092 8153761
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    27
 * @summary Test Completion
35359
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 33715
diff changeset
    28
 * @modules jdk.compiler/com.sun.tools.javac.api
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 33715
diff changeset
    29
 *          jdk.compiler/com.sun.tools.javac.main
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35359
diff changeset
    30
 *          jdk.jdeps/com.sun.tools.javap
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    31
 * @library /tools/lib
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    32
 * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    33
 * @build KullaTesting TestingInputStream Compiler
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    34
 * @run testng CompletionSuggestionTest
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    35
 */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    36
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
    37
import java.io.IOException;
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
    38
import java.lang.reflect.Field;
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
    39
import java.nio.file.Files;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    40
import java.nio.file.Path;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    41
import java.nio.file.Paths;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    42
import java.util.Arrays;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    43
import java.util.Collections;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    44
import java.util.Set;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    45
import java.util.HashSet;
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
    46
import java.util.jar.JarEntry;
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
    47
import java.util.jar.JarOutputStream;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    48
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    49
import jdk.jshell.Snippet;
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
    50
import org.testng.annotations.BeforeMethod;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    51
import org.testng.annotations.Test;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    52
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    53
import static jdk.jshell.Snippet.Status.VALID;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    54
import static jdk.jshell.Snippet.Status.OVERWRITTEN;
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
@Test
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    57
public class CompletionSuggestionTest extends KullaTesting {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    58
33715
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
    59
    private final Compiler compiler = new Compiler();
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
    60
    private final Path outDir = Paths.get("completion_suggestion_test");
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
    61
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    62
    public void testMemberExpr() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    63
        assertEval("class Test { static void test() { } }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    64
        assertCompletion("Test.t|", "test()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    65
        assertEval("Test ccTestInstance = new Test();");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    66
        assertCompletion("ccTestInstance.t|", "toString()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    67
        assertCompletion(" ccTe|", "ccTestInstance");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    68
        assertCompletion("String value = ccTestInstance.to|", "toString()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    69
        assertCompletion("java.util.Coll|", "Collection", "Collections");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    70
        assertCompletion("String.cla|", "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    71
        assertCompletion("boolean.cla|", "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    72
        assertCompletion("byte.cla|", "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    73
        assertCompletion("short.cla|", "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    74
        assertCompletion("char.cla|", "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    75
        assertCompletion("int.cla|", "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    76
        assertCompletion("float.cla|", "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    77
        assertCompletion("long.cla|", "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    78
        assertCompletion("double.cla|", "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    79
        assertCompletion("void.cla|", "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    80
        assertCompletion("Object[].|", "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    81
        assertCompletion("int[].|", "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    82
        assertEval("Object[] ao = null;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    83
        assertCompletion("int i = ao.|", "length");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    84
        assertEval("int[] ai = null;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    85
        assertCompletion("int i = ai.|", "length");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    86
        assertCompletionIncludesExcludes("\"\".|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    87
                new HashSet<>(Collections.emptyList()),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    88
                new HashSet<>(Arrays.asList("String(")));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    89
        assertEval("double d = 0;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    90
        assertEval("void m() {}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    91
        assertCompletionIncludesExcludes("d.|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    92
                new HashSet<>(Collections.emptyList()),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    93
                new HashSet<>(Arrays.asList("class")));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    94
        assertCompletionIncludesExcludes("m().|",
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
        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
    98
        assertCompletionIncludesExcludes("C.|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    99
                new HashSet<>(Arrays.asList("D", "E", "F", "H", "class")),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   100
                new HashSet<>(Arrays.asList("method()", "number")));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   101
        assertCompletionIncludesExcludes("new C().|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   102
                new HashSet<>(Arrays.asList("method()", "number")),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   103
                new HashSet<>(Arrays.asList("D", "E", "F", "H", "class")));
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
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   108
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   109
    public void testStartOfExpression() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   110
        assertEval("int ccTest = 0;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   111
        assertCompletion("System.err.println(cc|", "ccTest");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   112
        assertCompletion("for (int i = cc|", "ccTest");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   113
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   114
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   115
    public void testParameter() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   116
        assertCompletion("class C{void method(int num){num|", "num");
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
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   119
    public void testPrimitive() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   120
        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
   121
        Set<String> onlyVoid = new HashSet<>(Collections.singletonList("void"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   122
        Set<String> primitivesOrVoid = new HashSet<>(primitives);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   123
        primitivesOrVoid.addAll(onlyVoid);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   124
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   125
        assertCompletionIncludesExcludes("|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   126
                primitivesOrVoid,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   127
                new HashSet<>(Collections.emptyList()));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   128
        assertCompletionIncludesExcludes("int num = |",
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("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("class C{void m() {|",
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("void method(|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   138
                primitives,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   139
                onlyVoid);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   140
        assertCompletionIncludesExcludes("void method(int num, |",
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
        assertCompletion("new java.util.ArrayList<doub|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   144
        assertCompletion("class A extends doubl|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   145
        assertCompletion("class A implements doubl|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   146
        assertCompletion("interface A extends doubl|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   147
        assertCompletion("enum A implements doubl|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   148
        assertCompletion("class A<T extends doubl|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   149
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   150
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   151
    public void testEmpty() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   152
        assertCompletionIncludesExcludes("|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   153
                new HashSet<>(Arrays.asList("Object", "Void")),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   154
                new HashSet<>(Arrays.asList("$REPL00DOESNOTMATTER")));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   155
        assertCompletionIncludesExcludes("V|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   156
                new HashSet<>(Collections.singletonList("Void")),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   157
                new HashSet<>(Collections.singletonList("Object")));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   158
        assertCompletionIncludesExcludes("{ |",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   159
                new HashSet<>(Arrays.asList("Object", "Void")),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   160
                new HashSet<>(Arrays.asList("$REPL00DOESNOTMATTER")));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   161
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   162
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   163
    public void testSmartCompletion() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   164
        assertEval("int ccTest1 = 0;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   165
        assertEval("int ccTest2 = 0;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   166
        assertEval("String ccTest3 = null;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   167
        assertEval("void method(int i, String str) { }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   168
        assertEval("void method(String str, int i) { }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   169
        assertEval("java.util.List<String> list = null;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   170
        assertCompletion("int ccTest4 = |", true, "ccTest1", "ccTest2");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   171
        assertCompletion("ccTest2 = |", true, "ccTest1", "ccTest2");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   172
        assertCompletion("int ccTest4 = ccTe|", "ccTest1", "ccTest2", "ccTest3");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   173
        assertCompletion("int ccTest4 = ccTest3.len|", true, "length()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   174
        assertCompletion("method(|", true, "ccTest1", "ccTest2", "ccTest3");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   175
        assertCompletion("method(0, |", true, "ccTest3");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   176
        assertCompletion("list.add(|", true, "ccTest1", "ccTest2", "ccTest3");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   177
        assertCompletion("list.add(0, |", true, "ccTest3");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   178
        assertCompletion("new String(|", true, "ccTest3");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   179
        assertCompletion("new String(new char[0], |", true, "ccTest1", "ccTest2");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   180
        assertCompletionIncludesExcludes("new jav|", new HashSet<>(Arrays.asList("java", "javax")), Collections.emptySet());
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   181
        assertCompletion("Class<String> clazz = String.c|", true, "class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   182
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   183
        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
   184
        assertCompletion("new Klass().method(|", true, "ccTest1", "ccTest2");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   185
        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
   186
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   187
                ste(klass, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   188
        assertCompletion("Klass.method(|", true, "ccTest1", "ccTest2");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   189
        assertEval("class Klass {Klass(int n) {} private Klass(String str) {}}",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   190
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   191
                ste(klass2, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   192
        assertCompletion("new Klass(|", true, "ccTest1", "ccTest2");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   193
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   194
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   195
    public void testSmartCompletionInOverriddenMethodInvocation() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   196
        assertEval("int ccTest1 = 0;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   197
        assertEval("int ccTest2 = 0;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   198
        assertEval("String ccTest3 = null;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   199
        assertCompletion("\"\".wait(|", true, "ccTest1", "ccTest2");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   200
        assertEval("class Base {void method(int n) {}}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   201
        assertEval("class Extend extends Base {}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   202
        assertCompletion("new Extend().method(|", true, "ccTest1", "ccTest2");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   203
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   204
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   205
    public void testSmartCompletionForBoxedType() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   206
        assertEval("int ccTest1 = 0;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   207
        assertEval("Integer ccTest2 = 0;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   208
        assertEval("Object ccTest3 = null;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   209
        assertEval("int method1(int n) {return n;}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   210
        assertEval("Integer method2(Integer n) {return n;}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   211
        assertEval("Object method3(Object o) {return o;}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   212
        assertCompletion("int ccTest4 = |", true, "ccTest1", "ccTest2", "method1(", "method2(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   213
        assertCompletion("Integer ccTest4 = |", true, "ccTest1", "ccTest2", "method1(", "method2(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   214
        assertCompletion("Object ccTest4 = |", true, "ccTest1", "ccTest2", "ccTest3", "method1(", "method2(", "method3(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   215
        assertCompletion("method1(|", true, "ccTest1", "ccTest2", "method1(", "method2(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   216
        assertCompletion("method2(|", true, "ccTest1", "ccTest2", "method1(", "method2(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   217
        assertCompletion("method3(|", true, "ccTest1", "ccTest2", "ccTest3", "method1(", "method2(", "method3(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   218
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   219
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   220
    public void testNewClass() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   221
        assertCompletion("String str = new Strin|", "String(", "StringBuffer(", "StringBuilder(", "StringIndexOutOfBoundsException(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   222
        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
   223
        assertCompletion("String str = new |", true, "String(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   224
        assertCompletion("String str = new java.lang.|", true, "String(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   225
        assertCompletion("throw new Strin|", true, "StringIndexOutOfBoundsException(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   226
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   227
        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
   228
        assertEval("A a;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   229
        assertCompletion("new A().new |", "B()", "C(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   230
        assertCompletion("a.new |", "B()", "C(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   231
        assertCompletion("new A.|", "D()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   232
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   233
        assertEval("enum E{; class A {}}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   234
        assertEval("interface I{; class A {}}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   235
        assertCompletion("new E.|", "A()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   236
        assertCompletion("new I.|", "A()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   237
        assertCompletion("new String(I.A|", "A");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   238
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   239
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   240
    public void testFullyQualified() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   241
        assertCompletion("Optional<String> opt = java.u|", "util");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   242
        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
   243
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   244
        assertEval("void method(java.util.Optional<String> opt) {}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   245
        assertCompletion("method(java.u|", "util");
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
        assertCompletion("Object.notElement.|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   248
        assertCompletion("Object o = com.su|", "sun");
33715
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   249
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   250
        Path p1 = outDir.resolve("dir1");
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   251
        compiler.compile(p1,
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   252
                "package p1.p2;\n" +
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   253
                "public class Test {\n" +
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   254
                "}",
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   255
                "package p1.p3;\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
        String jarName = "test.jar";
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   259
        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
   260
        addToClasspath(compiler.getPath(p1.resolve(jarName)));
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   261
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   262
        assertCompletionIncludesExcludes("|", new HashSet<>(Collections.singletonList("p1")), Collections.emptySet());
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   263
        assertCompletion("p1.|", "p2", "p3");
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   264
        assertCompletion("p1.p2.|", "Test");
74b1bed86932 8141092: JShell: Completion hangs on identifier completion
jlahoda
parents: 33362
diff changeset
   265
        assertCompletion("p1.p3.|", "Test");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   266
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   267
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   268
    public void testCheckAccessibility() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   269
        assertCompletion("java.util.regex.Pattern.co|", "compile(");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   270
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   271
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   272
    public void testCompletePackages() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   273
        assertCompletion("java.u|", "util");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   274
        assertCompletionIncludesExcludes("jav|", new HashSet<>(Arrays.asList("java", "javax")), Collections.emptySet());
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   275
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   276
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   277
    public void testImports() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   278
        assertCompletion("import java.u|", "util");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   279
        assertCompletionIncludesExcludes("import jav|", new HashSet<>(Arrays.asList("java", "javax")), Collections.emptySet());
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   280
        assertCompletion("import static java.u|", "util");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   281
        assertCompletionIncludesExcludes("import static jav|", new HashSet<>(Arrays.asList("java", "javax")), Collections.emptySet());
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   282
        assertCompletion("import static java.lang.Boolean.g|", "getBoolean");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   283
        assertCompletion("import java.util.*|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   284
        assertCompletionIncludesExcludes("import java.lang.String.|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   285
                Collections.emptySet(),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   286
                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
   287
        assertCompletionIncludesExcludes("import static java.lang.String.|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   288
                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
   289
                new HashSet<>(Arrays.asList("class", "length")));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   290
        assertCompletionIncludesExcludes("import java.util.Map.|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   291
                new HashSet<>(Arrays.asList("Entry")),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   292
                new HashSet<>(Arrays.asList("class")));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   293
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   294
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   295
    public void testBrokenClassFile() throws Exception {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   296
        Compiler compiler = new Compiler();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   297
        Path testOutDir = Paths.get("CompletionTestBrokenClassFile");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   298
        String input = "package test.inner; public class Test {}";
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   299
        compiler.compile(testOutDir, input);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   300
        addToClasspath(compiler.getPath(testOutDir).resolve("test"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   301
        assertCompletion("import inner.|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   302
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   303
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   304
    public void testDocumentation() throws Exception {
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   305
        dontReadParameterNamesFromClassFile();
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   306
        assertDocumentation("System.getProperty(|",
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   307
                "java.lang.System.getProperty(java.lang.String key)",
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   308
                "java.lang.System.getProperty(java.lang.String key, java.lang.String def)");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   309
        assertEval("char[] chars = null;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   310
        assertDocumentation("new String(chars, |",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   311
                "java.lang.String(char[] arg0, int arg1, int arg2)");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   312
        assertDocumentation("String.format(|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   313
                "java.lang.String.format(java.lang.String arg0, java.lang.Object... arg1)",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   314
                "java.lang.String.format(java.util.Locale arg0, java.lang.String arg1, java.lang.Object... arg2)");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   315
        assertDocumentation("\"\".getBytes(\"\"|", "java.lang.String.getBytes(int arg0, int arg1, byte[] arg2, int arg3)",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   316
                                                    "java.lang.String.getBytes(java.lang.String arg0)",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   317
                                                    "java.lang.String.getBytes(java.nio.charset.Charset arg0)");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   318
        assertDocumentation("\"\".getBytes(\"\" |", "java.lang.String.getBytes(int arg0, int arg1, byte[] arg2, int arg3)",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   319
                                                     "java.lang.String.getBytes(java.lang.String arg0)",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   320
                                                     "java.lang.String.getBytes(java.nio.charset.Charset arg0)");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   321
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   322
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   323
    public void testMethodsWithNoArguments() throws Exception {
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   324
        dontReadParameterNamesFromClassFile();
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   325
        assertDocumentation("System.out.println(|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   326
                "java.io.PrintStream.println()",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   327
                "java.io.PrintStream.println(boolean arg0)",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   328
                "java.io.PrintStream.println(char arg0)",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   329
                "java.io.PrintStream.println(int arg0)",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   330
                "java.io.PrintStream.println(long arg0)",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   331
                "java.io.PrintStream.println(float arg0)",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   332
                "java.io.PrintStream.println(double arg0)",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   333
                "java.io.PrintStream.println(char[] arg0)",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   334
                "java.io.PrintStream.println(java.lang.String arg0)",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   335
                "java.io.PrintStream.println(java.lang.Object arg0)");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   336
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   337
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   338
    public void testErroneous() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   339
        assertCompletion("Undefined.|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   340
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   341
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   342
    public void testClinit() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   343
        assertEval("enum E{;}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   344
        assertEval("class C{static{}}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   345
        assertCompletionIncludesExcludes("E.|", Collections.emptySet(), new HashSet<>(Collections.singletonList("<clinit>")));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   346
        assertCompletionIncludesExcludes("C.|", Collections.emptySet(), new HashSet<>(Collections.singletonList("<clinit>")));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   347
    }
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
    public void testMethodHeaderContext() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   350
        assertCompletion("private void f(Runn|", "Runnable");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   351
        assertCompletion("void f(Runn|", "Runnable");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   352
        assertCompletion("void f(Object o1, Runn|", "Runnable");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   353
        assertCompletion("void f(Object o1) throws Num|", true, "NumberFormatException");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   354
        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
   355
        assertEval("class HogeHoge {static class HogeHogeException extends Exception {}}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   356
        assertCompletion("void f(Object o1) throws Hoge|", "HogeHoge");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   357
        assertCompletion("void f(Object o1) throws HogeHoge.|", true, "HogeHogeException");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   358
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   359
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   360
    public void testTypeVariables() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   361
        assertCompletion("class A<TYPE> { public void test() { TY|", "TYPE");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   362
        assertCompletion("class A<TYPE> { public static void test() { TY|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   363
        assertCompletion("class A<TYPE> { public <TYPE> void test() { TY|", "TYPE");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   364
        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
   365
    }
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
    public void testGeneric() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   368
        assertEval("import java.util.concurrent.*;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   369
        assertCompletion("java.util.List<Integ|", "Integer");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   370
        assertCompletion("class A<TYPE extends Call|", "Callable");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   371
        assertCompletion("class A<TYPE extends Callable<TY|", "TYPE");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   372
        assertCompletion("<TYPE> void f(TY|", "TYPE");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   373
        assertCompletion("class A<TYPE extends Callable<? sup|", "super");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   374
        assertCompletion("class A<TYPE extends Callable<? super TY|", "TYPE");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   375
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   376
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   377
    public void testFields() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   378
        assertEval("interface Interface { int field = 0; }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   379
        Snippet clazz = classKey(assertEval("class Clazz {" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   380
                "static int staticField = 0;" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   381
                "int field = 0;" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   382
                " }"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   383
        assertCompletion("Interface.fiel|", "field");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   384
        assertCompletion("Clazz.staticFiel|", "staticField");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   385
        assertCompletion("new Interface() {}.fiel|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   386
        assertCompletion("new Clazz().staticFiel|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   387
        assertCompletion("new Clazz().fiel|", "field");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   388
        assertCompletion("new Clazz() {}.fiel|", "field");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   389
        assertEval("class Clazz implements Interface {}",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   390
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   391
                ste(clazz, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   392
        assertCompletion("Clazz.fiel|", "field");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   393
        assertCompletion("new Clazz().fiel|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   394
        assertCompletion("new Clazz() {}.fiel|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   395
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   396
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   397
    public void testMethods() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   398
        assertEval("interface Interface {" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   399
                "default int defaultMethod() { return 0; }" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   400
                "static int staticMethod() { return 0; }" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   401
                "}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   402
        Snippet clazz = classKey(assertEval("class Clazz {" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   403
                "static int staticMethod() { return 0; }" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   404
                "int method() { return 0; }" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   405
                "}"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   406
        assertCompletion("Interface.staticMeth|", "staticMethod()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   407
        assertCompletion("Clazz.staticMeth|", "staticMethod()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   408
        assertCompletion("new Interface() {}.defaultMe||", "defaultMethod()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   409
        assertCompletion("new Clazz().staticMeth|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   410
        assertCompletion("new Clazz().meth|", "method()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   411
        assertEval("class Clazz implements Interface {}",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   412
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   413
                ste(clazz, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   414
        assertCompletion("Clazz.staticMeth|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   415
        assertCompletion("new Clazz() {}.defaultM|", "defaultMethod()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   416
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   417
40318
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   418
    @Test
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   419
    public void testUncompletedDeclaration() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   420
        assertCompletion("class Clazz { Claz|", "Clazz");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   421
        assertCompletion("class Clazz { class A extends Claz|", "Clazz");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   422
        assertCompletion("class Clazz { Clazz clazz; Object o = cla|", "clazz");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   423
        assertCompletion("class Clazz { static Clazz clazz; Object o = cla|", "clazz");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   424
        assertCompletion("class Clazz { Clazz clazz; static Object o = cla|", true);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   425
        assertCompletion("class Clazz { void method(Claz|", "Clazz");
40318
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   426
        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
   427
        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
   428
        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
   429
        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
   430
        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
   431
        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
   432
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   433
40318
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   434
    @Test
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   435
    public void testClassDeclaration() {
40318
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   436
        assertEval("void ClazzM() {}");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   437
        assertEval("void InterfaceM() {}");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   438
        assertEval("interface Interface {}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   439
        assertCompletion("interface A extends Interf|", "Interface");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   440
        assertCompletion("class A implements Interf|", "Interface");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   441
        assertEval("class Clazz {}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   442
        assertCompletion("class A extends Claz|", "Clazz");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   443
        assertCompletion("class A extends Clazz implements Interf|", "Interface");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   444
        assertEval("interface Interface1 {}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   445
        assertCompletion("class A extends Clazz implements Interface, Interf|", "Interface", "Interface1");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   446
        assertCompletion("interface A implements Claz|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   447
        assertCompletion("interface A implements Inter|");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   448
        assertCompletion("class A implements Claz|", true);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   449
        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
   450
        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
   451
        assertEval("class InterfaceClazz {}");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   452
        assertCompletion("class A <T extends Claz|", "Clazz");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   453
        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
   454
        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
   455
        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
   456
        assertCompletion("class A <T extends Claz|", true, "Clazz");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   457
        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
   458
        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
   459
        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
   460
    }
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   461
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   462
    public void testMethodDeclaration() {
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   463
        assertEval("void ClazzM() {}");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   464
        assertEval("void InterfaceM() {}");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   465
        assertEval("interface Interface {}");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   466
        assertCompletion("void m(Interf|", "Interface");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   467
        assertCompletion("void m(Interface i1, Interf|", "Interface");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   468
        assertEval("class InterfaceException extends Exception {}");
3f7eb1205cee 8129421: JShell: unacceptable suggestions in 'extends', 'implements' in smart completion
jlahoda
parents: 37939
diff changeset
   469
        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
   470
        assertCompletion("void m(Interface i1) throws Interf|", true, "InterfaceException");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   471
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   472
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   473
    public void testDocumentationOfUserDefinedMethods() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   474
        assertEval("void f() {}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   475
        assertDocumentation("f(|", "f()");
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   476
        assertEval("void f(int i) {}");
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   477
        assertDocumentation("f(|", "f()", "f(int i)");
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   478
        assertEval("<T> void f(T... ts) {}", DiagCheck.DIAG_WARNING, DiagCheck.DIAG_OK);
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   479
        assertDocumentation("f(|", "f()", "f(int i)", "f(T... ts)");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   480
        assertEval("class A {}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   481
        assertEval("void f(A a) {}");
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   482
        assertDocumentation("f(|", "f()", "f(int i)", "f(T... ts)", "f(A a)");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   483
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   484
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   485
    public void testDocumentationOfUserDefinedConstructors() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   486
        Snippet a = classKey(assertEval("class A {}"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   487
        assertDocumentation("new A(|", "A()");
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   488
        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
   489
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   490
                ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET)));
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   491
        assertDocumentation("new A(|", "A()", "A(int i)");
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   492
        assertEval("class A<T> { A(T t) {} A(int i) {}}",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   493
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   494
                ste(a2, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   495
        assertDocumentation("new A(|", "A(T t)", "A(int i)");
33362
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
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   498
    public void testDocumentationOfOverriddenMethods() throws Exception {
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   499
        dontReadParameterNamesFromClassFile();
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   500
        assertDocumentation("\"\".wait(|",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   501
            "java.lang.Object.wait(long arg0)",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   502
            "java.lang.Object.wait(long arg0, int arg1)",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   503
            "java.lang.Object.wait()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   504
        assertEval("class Base {void method() {}}");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   505
        Snippet e = classKey(assertEval("class Extend extends Base {}"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   506
        assertDocumentation("new Extend().method(|", "Base.method()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   507
        assertEval("class Extend extends Base {void method() {}}",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   508
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   509
                ste(e, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   510
        assertDocumentation("new Extend().method(|", "Extend.method()");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   511
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   512
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   513
    public void testDocumentationOfInvisibleMethods() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   514
        assertDocumentation("Object.wait(|", "");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   515
        assertDocumentation("\"\".indexOfSupplementary(|", "");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   516
        Snippet a = classKey(assertEval("class A {void method() {}}"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   517
        assertDocumentation("A.method(|", "");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   518
        assertEval("class A {private void method() {}}",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   519
                ste(MAIN_SNIPPET, VALID, VALID, true, null),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   520
                ste(a, VALID, OVERWRITTEN, false, MAIN_SNIPPET));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   521
        assertDocumentation("new A().method(|", "");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   522
    }
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
    public void testDocumentationOfInvisibleConstructors() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   525
        assertDocumentation("new Compiler(|", "");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   526
        assertEval("class A { private A() {} }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   527
        assertDocumentation("new A(|", "");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   528
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   529
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   530
    public void testDocumentationWithBoxing() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   531
        assertEval("int primitive = 0;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   532
        assertEval("Integer boxed = 0;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   533
        assertEval("Object object = null;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   534
        assertEval("void method(int n, Object o) { }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   535
        assertEval("void method(Object n, int o) { }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   536
        assertDocumentation("method(primitive,|",
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   537
                "method(int n, java.lang.Object o)",
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   538
                "method(java.lang.Object n, int o)");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   539
        assertDocumentation("method(boxed,|",
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   540
                "method(int n, java.lang.Object o)",
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   541
                "method(java.lang.Object n, int o)");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   542
        assertDocumentation("method(object,|",
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   543
                "method(java.lang.Object n, int o)");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   544
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   545
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   546
    public void testVarArgs() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   547
        assertEval("int i = 0;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   548
        assertEval("class Foo1 { static void m(int... i) { } } ");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   549
        assertCompletion("Foo1.m(|", true, "i");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   550
        assertCompletion("Foo1.m(i, |", true, "i");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   551
        assertCompletion("Foo1.m(i, i, |", true, "i");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   552
        assertEval("class Foo2 { static void m(String s, int... i) { } } ");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   553
        assertCompletion("Foo2.m(|", true);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   554
        assertCompletion("Foo2.m(i, |", true);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   555
        assertCompletion("Foo2.m(\"\", |", true, "i");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   556
        assertCompletion("Foo2.m(\"\", i, |", true, "i");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   557
        assertCompletion("Foo2.m(\"\", i, i, |", true, "i");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   558
        assertEval("class Foo3 { Foo3(String s, int... i) { } } ");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   559
        assertCompletion("new Foo3(|", true);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   560
        assertCompletion("new Foo3(i, |", true);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   561
        assertCompletion("new Foo3(\"\", |", true, "i");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   562
        assertCompletion("new Foo3(\"\", i, |", true, "i");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   563
        assertCompletion("new Foo3(\"\", i, i, |", true, "i");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   564
        assertEval("int[] ia = null;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   565
        assertCompletion("Foo1.m(ia, |", true);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   566
        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
   567
        assertEval("String str = null;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   568
        assertCompletion("Foo4.m(ia, |", true, "str");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   569
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   570
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   571
    public void testConstructorAsMemberOf() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   572
        assertEval("class Baz<X> { Baz(X x) { } } ");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   573
        assertEval("String str = null;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   574
        assertEval("Integer i = null;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   575
        assertCompletion("new Baz(|", true, "i", "str");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   576
        assertCompletion("new Baz<String>(|", true, "str");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   577
        assertCompletion("Baz<String> bz = new Baz<>(|", true, "str");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   578
        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
   579
        assertCompletion("Foo.m(new Baz<>(|", true, "str");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   580
    }
37939
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   581
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   582
    @BeforeMethod
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   583
    public void setUp() {
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   584
        super.setUp();
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   585
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   586
        Path srcZip = Paths.get("src.zip");
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   587
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   588
        try (JarOutputStream out = new JarOutputStream(Files.newOutputStream(srcZip))) {
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   589
            out.putNextEntry(new JarEntry("java/lang/System.java"));
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   590
            out.write(("package java.lang;\n" +
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   591
                       "public class System {\n" +
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   592
                       "    public String getProperty(String key) { return null; }\n" +
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   593
                       "    public String getProperty(String key, String def) { return def; }\n" +
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   594
                       "}\n").getBytes());
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   595
        } catch (IOException ex) {
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   596
            throw new IllegalStateException(ex);
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   597
        }
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   598
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   599
        try {
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   600
            Field availableSources = getAnalysis().getClass().getDeclaredField("availableSources");
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   601
            availableSources.setAccessible(true);
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   602
            availableSources.set(getAnalysis(), Arrays.asList(srcZip));
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   603
        } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException ex) {
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   604
            throw new IllegalStateException(ex);
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   605
        }
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   606
    }
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   607
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   608
    private void dontReadParameterNamesFromClassFile() throws Exception {
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   609
        Field keepParameterNames = getAnalysis().getClass().getDeclaredField("keepParameterNames");
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   610
        keepParameterNames.setAccessible(true);
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   611
        keepParameterNames.set(getAnalysis(), new String[0]);
3eb8c2a89b77 8153761: JShell: Completion -- Show parameter names if possible
jlahoda
parents: 36778
diff changeset
   612
    }
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   613
}