test/langtools/jdk/jshell/ToolTabSnippetTest.java
author jlahoda
Thu, 09 May 2019 11:58:26 +0200
changeset 54778 d1d6e939803f
parent 52938 5ff7480c9e28
permissions -rw-r--r--
8221759: Crash when completing \"java.io.File.path\" Summary: Do not provide documentation for inaccessible elements. Reviewed-by: rfield
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     1
/*
50868
addda6247cb0 8205913: Inconsistent source code model
jlahoda
parents: 50338
diff changeset
     2
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     4
 *
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     8
 *
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    13
 * accompanied this code).
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    14
 *
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    18
 *
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    21
 * questions.
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    22
 */
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    23
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    24
/**
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    25
 * @test
54778
d1d6e939803f 8221759: Crash when completing \"java.io.File.path\"
jlahoda
parents: 52938
diff changeset
    26
 * @bug 8177076 8185426 8189595 8188072 8221759
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    27
 * @modules
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    28
 *     jdk.compiler/com.sun.tools.javac.api
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    29
 *     jdk.compiler/com.sun.tools.javac.main
47050
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
    30
 *     jdk.jshell/jdk.internal.jshell.tool
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    31
 *     jdk.jshell/jdk.internal.jshell.tool.resources:open
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    32
 *     jdk.jshell/jdk.jshell:open
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    33
 * @library /tools/lib
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    34
 * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask
44570
7fec4e13a5cf 8178077: jshell tool: crash on ctrl-up or ctrl-down
jlahoda
parents: 44459
diff changeset
    35
 * @build Compiler UITesting
46185
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 44811
diff changeset
    36
 * @build ToolTabSnippetTest
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 44811
diff changeset
    37
 * @run testng/timeout=300 ToolTabSnippetTest
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    38
 */
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    39
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    40
import java.io.IOException;
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    41
import java.lang.reflect.Field;
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    42
import java.nio.file.Files;
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    43
import java.nio.file.Path;
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    44
import java.nio.file.Paths;
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    45
import java.util.Arrays;
47050
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
    46
import java.util.concurrent.CountDownLatch;
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    47
import java.util.jar.JarEntry;
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    48
import java.util.jar.JarOutputStream;
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    49
47050
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
    50
import jdk.internal.jshell.tool.ConsoleIOContextTestSupport;
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    51
import org.testng.annotations.Test;
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    52
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    53
@Test
46185
f4c981fc7818 8182270: JShell API: Tools need snippet information without evaluating snippet
rfield
parents: 44811
diff changeset
    54
public class ToolTabSnippetTest extends UITesting {
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    55
52938
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents: 50868
diff changeset
    56
    public ToolTabSnippetTest() {
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents: 50868
diff changeset
    57
        super(true);
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents: 50868
diff changeset
    58
    }
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents: 50868
diff changeset
    59
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    60
    public void testExpression() throws Exception {
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    61
        Path classes = prepareZip();
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    62
        doRunTest((inputSink, out) -> {
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    63
            inputSink.write("/env -class-path " + classes.toString() + "\n");
52938
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents: 50868
diff changeset
    64
            waitOutput(out, resource("jshell.msg.set.restore") + "\n\\u001B\\[\\?2004h" + PROMPT);
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    65
            inputSink.write("import jshelltest.*;\n");
52938
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents: 50868
diff changeset
    66
            waitOutput(out, "\n\\u001B\\[\\?2004l\\u001B\\[\\?2004h" + PROMPT);
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    67
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    68
            //-> <tab>
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
    69
            inputSink.write(TAB);
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    70
            waitOutput(out, getMessage("jshell.console.completion.all.completions.number", "[0-9]+"));
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
    71
            inputSink.write(TAB);
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
    72
            waitOutput(out, ".*String.*StringBuilder.*" +
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
    73
                            REDRAW_PROMPT + "");
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    74
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    75
            //new JShellTes<tab>
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
    76
            inputSink.write("new JShellTes" + TAB);
52938
5ff7480c9e28 8214491: Upgrade to JLine 3.9.0
jlahoda
parents: 50868
diff changeset
    77
            waitOutput(out, "\nJShellTest\\(      JShellTestAux\\(   " +
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
    78
                            REDRAW_PROMPT + "new JShellTest");
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    79
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    80
            //new JShellTest<tab>
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
    81
            inputSink.write(TAB);
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    82
            waitOutput(out, "JShellTest\\(      JShellTestAux\\(   \n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    83
                            "\n" +
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
    84
                            resource("jshell.console.completion.current.signatures") + "\n" +
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    85
                            "jshelltest.JShellTest\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    86
                            "\n" +
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
    87
                            resource("jshell.console.see.documentation") +
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
    88
                            REDRAW_PROMPT + "new JShellTest");
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
    89
            inputSink.write(TAB);
50338
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 48275
diff changeset
    90
            waitOutput(out, "\\u001B\\[1mjshelltest.JShellTest\\u001B\\[0m\n" +
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
    91
                            "JShellTest 0" +
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
    92
                            REDRAW_PROMPT + "new JShellTest");
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
    93
            inputSink.write(TAB);
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    94
            waitOutput(out, "JShellTest\\(      JShellTestAux\\(   \n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    95
                            "\n" +
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
    96
                            resource("jshell.console.completion.current.signatures") + "\n" +
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    97
                            "jshelltest.JShellTest\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
    98
                            "\n" +
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
    99
                            resource("jshell.console.see.documentation") +
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   100
                            REDRAW_PROMPT + "new JShellTest");
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   101
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   102
            //new JShellTest(<tab>
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   103
            inputSink.write("(" + TAB);
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   104
            waitOutput(out, "\\(\n" +
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   105
                            resource("jshell.console.completion.current.signatures") + "\n" +
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   106
                            "JShellTest\\(String str\\)\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   107
                            "JShellTest\\(String str, int i\\)\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   108
                            "\n" +
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   109
                            resource("jshell.console.see.documentation") +
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   110
                            REDRAW_PROMPT + "new JShellTest\\(");
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   111
            inputSink.write(TAB);
50338
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 48275
diff changeset
   112
            waitOutput(out, "\\u001B\\[1mJShellTest\\(String str\\)\\u001B\\[0m\n" +
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   113
                            "JShellTest 1\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   114
                            "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   115
                            "\n" +
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   116
                            resource("jshell.console.see.next.page") +
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   117
                            REDRAW_PROMPT + "new JShellTest\\(");
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   118
            inputSink.write(TAB);
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   119
            waitOutput(out, "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   120
                            "\n" +
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   121
                            resource("jshell.console.see.next.javadoc") +
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   122
                            REDRAW_PROMPT + "new JShellTest\\(");
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   123
            inputSink.write(TAB);
50338
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 48275
diff changeset
   124
            waitOutput(out, "\\u001B\\[1mJShellTest\\(String str, int i\\)\\u001B\\[0m\n" +
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   125
                            "JShellTest 2\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   126
                            "\n" +
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   127
                            getMessage("jshell.console.completion.all.completions.number", "[0-9]+") +
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   128
                            REDRAW_PROMPT + "new JShellTest\\(");
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   129
            inputSink.write(TAB);
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   130
            waitOutput(out, ".*String.*StringBuilder.*" +
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   131
                            REDRAW_PROMPT + "new JShellTest\\(");
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   132
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   133
            inputSink.write(INTERRUPT + "String str = \"\";\nnew JShellTest(");
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   134
            waitOutput(out, PROMPT + "new JShellTest\\(");
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   135
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   136
            inputSink.write(TAB);
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   137
            waitOutput(out, "\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   138
                            "str   \n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   139
                            "\n" +
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   140
                            resource("jshell.console.completion.current.signatures") + "\n" +
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   141
                            "JShellTest\\(String str\\)\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   142
                            "JShellTest\\(String str, int i\\)\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   143
                            "\n" +
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   144
                            resource("jshell.console.see.documentation") +
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   145
                            REDRAW_PROMPT + "new JShellTest\\(");
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   146
            inputSink.write(TAB);
50338
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 48275
diff changeset
   147
            waitOutput(out, "\\u001B\\[1mJShellTest\\(String str\\)\\u001B\\[0m\n" +
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   148
                            "JShellTest 1\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   149
                            "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   150
                            "\n" +
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   151
                            resource("jshell.console.see.next.page") +
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   152
                            REDRAW_PROMPT + "new JShellTest\\(");
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   153
            inputSink.write(TAB);
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   154
            waitOutput(out, "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   155
                            "\n" +
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   156
                            resource("jshell.console.see.next.javadoc") +
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   157
                            REDRAW_PROMPT + "new JShellTest\\(");
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   158
            inputSink.write(TAB);
50338
1d5694c1aa03 8203827: Upgrade JLine to 2.14.6
jlahoda
parents: 48275
diff changeset
   159
            waitOutput(out, "\\u001B\\[1mJShellTest\\(String str, int i\\)\\u001B\\[0m\n" +
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   160
                            "JShellTest 2\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   161
                            "\n" +
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   162
                            getMessage("jshell.console.completion.all.completions.number", "[0-9]+") +
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   163
                            REDRAW_PROMPT + "new JShellTest\\(");
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   164
            inputSink.write(TAB);
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   165
            waitOutput(out, ".*String.*StringBuilder.*" +
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   166
                            REDRAW_PROMPT + "new JShellTest\\(");
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   167
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   168
            inputSink.write(INTERRUPT + "JShellTest t = new JShellTest" + TAB);
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   169
            waitOutput(out, PROMPT + "JShellTest t = new JShellTest\n" +
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   170
                            "JShellTest\\(   \n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   171
                            "\n" +
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   172
                            resource("jshell.console.completion.current.signatures") + "\n" +
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   173
                            "jshelltest.JShellTest\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   174
                            "\n" +
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   175
                            resource("jshell.console.completion.all.completions") +
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   176
                            REDRAW_PROMPT + "JShellTest t = new JShellTest");
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   177
            inputSink.write(TAB);
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   178
            waitOutput(out, "JShellTest\\(      JShellTestAux\\(   \n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   179
                            "\n" +
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   180
                            resource("jshell.console.see.documentation") +
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   181
                            REDRAW_PROMPT + "JShellTest t = new JShellTest");
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   182
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   183
            inputSink.write(INTERRUPT + "JShellTest t = new " + TAB);
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   184
            waitOutput(out, PROMPT + "JShellTest t = new \n" +
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   185
                            "JShellTest\\(   \n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   186
                            "\n" +
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   187
                            getMessage("jshell.console.completion.all.completions.number", "[0-9]+") +
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   188
                            REDRAW_PROMPT + "JShellTest t = new ");
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   189
            inputSink.write(TAB);
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   190
            waitOutput(out, ".*String.*StringBuilder.*" +
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   191
                            REDRAW_PROMPT + "JShellTest t = new ");
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   192
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   193
            inputSink.write(INTERRUPT + "class JShelX{}\n");
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   194
            inputSink.write("new JShel" + TAB);
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   195
            waitOutput(out, PROMPT + "new JShel\n" +
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   196
                            "JShelX\\(\\)         JShellTest\\(      JShellTestAux\\(   " +
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   197
                            REDRAW_PROMPT + "new JShel");
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   198
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   199
            //no crash:
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   200
            inputSink.write(INTERRUPT + "new Stringbuil" + TAB);
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   201
            waitOutput(out, PROMPT + "new Stringbuil" + BELL);
47517
b5ad886110b3 8188072: JShell: NPE in SourceCodeAnalysis.completionSuggestions()
rfield
parents: 47216
diff changeset
   202
b5ad886110b3 8188072: JShell: NPE in SourceCodeAnalysis.completionSuggestions()
rfield
parents: 47216
diff changeset
   203
            //no crash: 8188072
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   204
            inputSink.write(INTERRUPT + "for (int:" + TAB);
50868
addda6247cb0 8205913: Inconsistent source code model
jlahoda
parents: 50338
diff changeset
   205
            waitOutput(out, PROMPT + "for \\(int:\n" +
addda6247cb0 8205913: Inconsistent source code model
jlahoda
parents: 50338
diff changeset
   206
                            getMessage("jshell.console.completion.all.completions.number", "[0-9]+") +
addda6247cb0 8205913: Inconsistent source code model
jlahoda
parents: 50338
diff changeset
   207
                            REDRAW_PROMPT + "for \\(int:");
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   208
        });
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   209
    }
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   210
47050
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   211
    public void testCleaningCompletionTODO() throws Exception {
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   212
        doRunTest((inputSink, out) -> {
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   213
            CountDownLatch testCompleteComputationStarted = new CountDownLatch(1);
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   214
            CountDownLatch testCompleteComputationContinue = new CountDownLatch(1);
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   215
            ConsoleIOContextTestSupport.IMPL = new ConsoleIOContextTestSupport() {
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   216
                @Override
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   217
                protected void willComputeCompletionCallback() {
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   218
                    if (testCompleteComputationStarted != null) {
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   219
                        testCompleteComputationStarted.countDown();
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   220
                    }
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   221
                    if (testCompleteComputationContinue != null) {
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   222
                        try {
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   223
                            testCompleteComputationContinue.await();
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   224
                        } catch (InterruptedException ex) {
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   225
                            throw new IllegalStateException(ex);
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   226
                        }
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   227
                    }
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   228
                }
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   229
            };
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   230
            //-> <tab>
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   231
            inputSink.write(TAB);
47050
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   232
            testCompleteComputationStarted.await();
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   233
            //-> <tab><tab>
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   234
            inputSink.write(TAB + TAB);
47050
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   235
            testCompleteComputationContinue.countDown();
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   236
            waitOutput(out, PROMPT);
47050
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   237
            //-> <tab>
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   238
            inputSink.write(TAB);
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   239
            waitOutput(out, PROMPT);
47050
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   240
            ConsoleIOContextTestSupport.IMPL = null;
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   241
        });
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   242
    }
72ec64aeaa57 8185426: Jshell crashing on autocompletion
jlahoda
parents: 46185
diff changeset
   243
47484
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   244
    public void testNoRepeat() throws Exception {
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   245
        doRunTest((inputSink, out) -> {
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   246
            inputSink.write("String xyzAA;\n");
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   247
            waitOutput(out, PROMPT);
47484
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   248
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   249
            //xyz<tab>
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   250
            inputSink.write("String s = xyz" + TAB);
47484
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   251
            waitOutput(out, "^String s = xyzAA");
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   252
            inputSink.write(".");
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   253
            waitOutput(out, "^\\.");
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   254
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   255
            inputSink.write(INTERRUPT);
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   256
            waitOutput(out, PROMPT);
47484
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   257
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   258
            inputSink.write("double xyzAB;\n");
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   259
            waitOutput(out, PROMPT);
47484
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   260
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   261
            //xyz<tab>
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   262
            inputSink.write("String s = xyz" + TAB);
47484
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   263
            String allCompletions =
48275
b2190c70a1ac 8192863: jshell tool: /<id><tab> gives "No such command"
rfield
parents: 47518
diff changeset
   264
                    resource("jshell.console.completion.all.completions");
47484
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   265
            waitOutput(out, ".*xyzAA.*" + allCompletions + ".*\u0005String s = xyzA");
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   266
        });
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   267
    }
d0cb66d8cbf1 8189595: jshell tool: line redrawn on each completion
jlahoda
parents: 47216
diff changeset
   268
54778
d1d6e939803f 8221759: Crash when completing \"java.io.File.path\"
jlahoda
parents: 52938
diff changeset
   269
    public void testCrash8221759() throws Exception {
d1d6e939803f 8221759: Crash when completing \"java.io.File.path\"
jlahoda
parents: 52938
diff changeset
   270
        doRunTest((inputSink, out) -> {
d1d6e939803f 8221759: Crash when completing \"java.io.File.path\"
jlahoda
parents: 52938
diff changeset
   271
            inputSink.write("java.io.File.path" + TAB);
d1d6e939803f 8221759: Crash when completing \"java.io.File.path\"
jlahoda
parents: 52938
diff changeset
   272
            waitOutput(out, "java.io.File.path\n" +
d1d6e939803f 8221759: Crash when completing \"java.io.File.path\"
jlahoda
parents: 52938
diff changeset
   273
                            "pathSeparator       pathSeparatorChar   " +
d1d6e939803f 8221759: Crash when completing \"java.io.File.path\"
jlahoda
parents: 52938
diff changeset
   274
                            REDRAW_PROMPT + "java.io.File.pathSeparator");
d1d6e939803f 8221759: Crash when completing \"java.io.File.path\"
jlahoda
parents: 52938
diff changeset
   275
        });
d1d6e939803f 8221759: Crash when completing \"java.io.File.path\"
jlahoda
parents: 52938
diff changeset
   276
    }
d1d6e939803f 8221759: Crash when completing \"java.io.File.path\"
jlahoda
parents: 52938
diff changeset
   277
44459
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   278
    private Path prepareZip() {
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   279
        String clazz1 =
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   280
                "package jshelltest;\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   281
                "/**JShellTest 0" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   282
                " */\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   283
                "public class JShellTest {\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   284
                "    /**JShellTest 1\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   285
                "     * <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   286
                "     * <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   287
                "     * <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1 <p>1\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   288
                "     */\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   289
                "    public JShellTest(String str) {}\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   290
                "    /**JShellTest 2" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   291
                "     */\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   292
                "    public JShellTest(String str, int i) {}\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   293
                "}\n";
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   294
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   295
        String clazz2 =
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   296
                "package jshelltest;\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   297
                "/**JShellTestAux 0" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   298
                " */\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   299
                "public class JShellTestAux {\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   300
                "    /**JShellTest 1" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   301
                "     */\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   302
                "    public JShellTestAux(String str) { }\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   303
                "    /**JShellTest 2" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   304
                "     */\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   305
                "    public JShellTestAux(String str, int i) { }\n" +
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   306
                "}\n";
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   307
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   308
        Path srcZip = Paths.get("src.zip");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   309
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   310
        try (JarOutputStream out = new JarOutputStream(Files.newOutputStream(srcZip))) {
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   311
            out.putNextEntry(new JarEntry("jshelltest/JShellTest.java"));
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   312
            out.write(clazz1.getBytes());
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   313
            out.putNextEntry(new JarEntry("jshelltest/JShellTestAux.java"));
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   314
            out.write(clazz2.getBytes());
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   315
        } catch (IOException ex) {
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   316
            throw new IllegalStateException(ex);
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   317
        }
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   318
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   319
        compiler.compile(clazz1, clazz2);
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   320
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   321
        try {
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   322
            Field availableSources = Class.forName("jdk.jshell.SourceCodeAnalysisImpl").getDeclaredField("availableSourcesOverride");
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   323
            availableSources.setAccessible(true);
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   324
            availableSources.set(null, Arrays.asList(srcZip));
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   325
        } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException | ClassNotFoundException ex) {
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   326
            throw new IllegalStateException(ex);
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   327
        }
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   328
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   329
        return compiler.getClassDir();
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   330
    }
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   331
    //where:
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   332
        private final Compiler compiler = new Compiler();
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   333
5224425af378 8177076: jshell tool: usability of completion
jlahoda
parents:
diff changeset
   334
}