OpenJDK / valhalla / valhalla10-old / langtools
changeset 4328:bd7d251a4bb5 nestmates tip
Merge
author | dholmes |
---|---|
date | Wed, 27 Sep 2017 01:20:57 -0400 |
parents | 814d50024bd7 19293ea3999f |
children | |
files | |
diffstat | 19 files changed, 369 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgtags Thu Sep 21 01:21:54 2017 -0400 +++ b/.hgtags Wed Sep 27 01:20:57 2017 -0400 @@ -445,3 +445,6 @@ e2096f634fb46d469c9f8cada7dc5e27d1409b1f jdk-9+180 5ecbed31312536cc2f3c454425c7607385ff8834 jdk-9+181 d78323fc3fd5fc443e3be8f88bf874ca3744c2a1 jdk-10+20 +fd3ce6210d0c53489ba231ee83ff61f9a3cd3288 jdk-10+21 +9fa96500eb1538b9cfd70099f8c47dc59a31e208 jdk-10+22 +214ffa12262b10c3ae6f89ca5d11380723f6a5b9 jdk-10+23
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java Thu Sep 21 01:21:54 2017 -0400 +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlDocletWriter.java Wed Sep 27 01:20:57 2017 -0400 @@ -624,12 +624,12 @@ ulAllClasses.addAttr(HtmlAttr.ID, allClassesId); subDiv.addContent(ulAllClasses); if (header && configuration.createindex) { - HtmlTree inputText = HtmlTree.INPUT("text", "search"); - HtmlTree inputReset = HtmlTree.INPUT("reset", "reset"); - Content searchTxt = new ContentBuilder(); - searchTxt.addContent(configuration.getContent("doclet.search")); - searchTxt.addContent(Contents.SPACE); - HtmlTree liInput = HtmlTree.LI(HtmlTree.SPAN(searchTxt)); + String searchValueId = "search"; + String reset = "reset"; + HtmlTree inputText = HtmlTree.INPUT("text", searchValueId, searchValueId); + HtmlTree inputReset = HtmlTree.INPUT(reset, reset, reset); + Content searchTxt = configuration.getContent("doclet.search"); + HtmlTree liInput = HtmlTree.LI(HtmlTree.LABEL(searchValueId, searchTxt)); liInput.addContent(inputText); liInput.addContent(inputReset); HtmlTree ulSearch = HtmlTree.UL(HtmlStyle.navListSearch, liInput);
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlAttr.java Thu Sep 21 01:21:54 2017 -0400 +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlAttr.java Wed Sep 27 01:20:57 2017 -0400 @@ -44,6 +44,7 @@ COLS, CONTENT, DISABLED, + FOR, HREF, HTTP_EQUIV("http-equiv"), ID,
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlTag.java Thu Sep 21 01:21:54 2017 -0400 +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlTag.java Wed Sep 27 01:20:57 2017 -0400 @@ -67,6 +67,7 @@ IFRAME(BlockType.OTHER, EndTag.END), IMG(BlockType.INLINE, EndTag.NOEND), INPUT(BlockType.BLOCK, EndTag.NOEND), + LABEL(BlockType.INLINE, EndTag.END), LI, LISTING, LINK(BlockType.OTHER, EndTag.NOEND),
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlTree.java Thu Sep 21 01:21:54 2017 -0400 +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/HtmlTree.java Wed Sep 27 01:20:57 2017 -0400 @@ -474,18 +474,32 @@ * * @param type the type of input * @param id id for the tag + * @param value value for the tag * @return an HtmlTree object for the INPUT tag */ - public static HtmlTree INPUT(String type, String id) { + public static HtmlTree INPUT(String type, String id, String value) { HtmlTree htmltree = new HtmlTree(HtmlTag.INPUT); htmltree.addAttr(HtmlAttr.TYPE, nullCheck(type)); htmltree.addAttr(HtmlAttr.ID, nullCheck(id)); - htmltree.addAttr(HtmlAttr.VALUE, " "); + htmltree.addAttr(HtmlAttr.VALUE, nullCheck(value)); htmltree.addAttr(HtmlAttr.DISABLED, "disabled"); return htmltree; } /** + * Generates a LABEL tag with some content. + * + * @param forLabel value of "for" attribute of the LABEL tag + * @param body content for the tag + * @return an HtmlTree object for the LABEL tag + */ + public static HtmlTree LABEL(String forLabel, Content body) { + HtmlTree htmltree = new HtmlTree(HtmlTag.LABEL, nullCheck(body)); + htmltree.addAttr(HtmlAttr.FOR, nullCheck(forLabel)); + return htmltree; + } + + /** * Generates a LI tag with some content. * * @param body content for the tag
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/search.js Thu Sep 21 01:21:54 2017 -0400 +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/search.js Wed Sep 27 01:20:57 2017 -0400 @@ -78,6 +78,7 @@ } var watermark = 'Search'; $(function() { + $("#search").val(''); $("#search").prop("disabled", false); $("#reset").prop("disabled", false); $("#search").val(watermark).addClass('watermark');
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/stylesheet.css Thu Sep 21 01:21:54 2017 -0400 +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/stylesheet.css Wed Sep 27 01:20:57 2017 -0400 @@ -203,7 +203,7 @@ padding: 5px 6px; text-transform:uppercase; } -ul.navListSearch li span { +ul.navListSearch li label { position:relative; right:-16px; } @@ -756,18 +756,20 @@ } #reset { background-color: rgb(255,255,255); + background-image:url('resources/x.png'); + background-position:center; + background-repeat:no-repeat; + background-size:12px; border:0 none; width:16px; height:17px; position:relative; - left:-2px; - background-image:url('resources/x.png'); - background-repeat:no-repeat; - background-size:12px; - background-position:center; + left:-4px; + top:-4px; + font-size:0px; } .watermark { - color:#888; + color:#545454; } .searchTagDescResult { font-style:italic; @@ -854,6 +856,8 @@ } table.striped > thead { background-color: #DDD; +} +table.striped > thead > tr > th, table.striped > thead > tr > td { border: 1px solid black; } table.striped > tbody > tr:nth-child(even) { @@ -862,12 +866,10 @@ table.striped > tbody > tr:nth-child(odd) { background-color: #FFF } -table.striped > thead > tr > th, table.striped > tbody > tr > th, -table.striped > tbody > tr > td, table.striped > tbody > tr > td { +table.striped > tbody > tr > th, table.striped > tbody > tr > td { border-left: 1px solid black; border-right: 1px solid black; } table.striped > tbody > tr > th { font-weight: normal; } -
--- a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/ConsoleIOContext.java Thu Sep 21 01:21:54 2017 -0400 +++ b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/ConsoleIOContext.java Wed Sep 27 01:20:57 2017 -0400 @@ -55,7 +55,6 @@ import jdk.internal.jline.WindowsTerminal; import jdk.internal.jline.console.ConsoleReader; import jdk.internal.jline.console.KeyMap; -import jdk.internal.jline.console.Operation; import jdk.internal.jline.console.UserInterruptException; import jdk.internal.jline.console.history.History; import jdk.internal.jline.console.history.MemoryHistory; @@ -94,14 +93,14 @@ term = new JShellUnixTerminal(input); } term.init(); - List<CompletionTask> completionTODO = new ArrayList<>(); + CompletionState completionState = new CompletionState(); in = new ConsoleReader(cmdin, cmdout, term) { @Override public KeyMap getKeys() { - return new CheckCompletionKeyMap(super.getKeys(), completionTODO); + return new CheckCompletionKeyMap(super.getKeys(), completionState); } @Override protected boolean complete() throws IOException { - return ConsoleIOContext.this.complete(completionTODO); + return ConsoleIOContext.this.complete(completionState); } }; in.setExpandEvents(false); @@ -201,15 +200,19 @@ private static final String LINE_SEPARATORS2 = LINE_SEPARATOR + LINE_SEPARATOR; @SuppressWarnings("fallthrough") - private boolean complete(List<CompletionTask> todo) { + private boolean complete(CompletionState completionState) { //The completion has multiple states (invoked by subsequent presses of <tab>). //On the first invocation in a given sequence, all steps are precomputed - //and placed into the todo list. The todo list is then followed on both the first - //and subsequent <tab> presses: + //and placed into the todo list (completionState.todo). The todo list is + //then followed on both the first and subsequent completion invocations: try { String text = in.getCursorBuffer().toString(); int cursor = in.getCursorBuffer().cursor; - if (todo.isEmpty()) { + + List<CompletionTask> todo = completionState.todo; + + if (todo.isEmpty() || completionState.actionCount != 1) { + ConsoleIOContextTestSupport.willComputeCompletion(); int[] anchor = new int[] {-1}; List<Suggestion> suggestions; List<String> doc; @@ -237,6 +240,8 @@ CompletionTask ordinaryCompletion = new OrdinaryCompletionTask(suggestions, anchor[0], !command && !doc.isEmpty(), hasSmart); CompletionTask allCompletion = new AllSuggestionsCompletionTask(suggestions, anchor[0]); + todo = new ArrayList<>(); + //the main decission tree: if (command) { CompletionTask shortDocumentation = new CommandSynopsisTask(doc); @@ -310,6 +315,9 @@ } } + completionState.actionCount = 0; + completionState.todo = todo; + if (repaint) { in.redrawLine(); in.flush(); @@ -1167,7 +1175,7 @@ public TestTerminal(StopDetectingInputStream input) throws Exception { super(true); - setAnsiSupported(false); + setAnsiSupported(Boolean.getBoolean("test.terminal.ansi.supported")); setEchoEnabled(false); this.input = input; int h = DEFAULT_HEIGHT; @@ -1203,12 +1211,12 @@ private static final class CheckCompletionKeyMap extends KeyMap { private final KeyMap del; - private final List<CompletionTask> completionTODO; + private final CompletionState completionState; - public CheckCompletionKeyMap(KeyMap del, List<CompletionTask> completionTODO) { + public CheckCompletionKeyMap(KeyMap del, CompletionState completionState) { super(del.getName(), del.isViKeyMap()); this.del = del; - this.completionTODO = completionTODO; + this.completionState = completionState; } @Override @@ -1233,13 +1241,9 @@ @Override public Object getBound(CharSequence keySeq) { - Object res = del.getBound(keySeq); + this.completionState.actionCount++; - if (res != Operation.COMPLETE) { - completionTODO.clear(); - } - - return res; + return del.getBound(keySeq); } @Override @@ -1252,4 +1256,12 @@ return "check: " + del.toString(); } } + + private static final class CompletionState { + /**The number of actions since the last completion invocation. Will be 1 when completion is + * invoked immediately after the last completion invocation.*/ + public int actionCount; + /**Precomputed completion actions. Should only be reused if actionCount == 1.*/ + public List<CompletionTask> todo = Collections.emptyList(); } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/ConsoleIOContextTestSupport.java Wed Sep 27 01:20:57 2017 -0400 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jdk.internal.jshell.tool; + +/**A support class to the ConsoleIOContext, containing callbacks called + * on important points in ConsoleIOContext. + */ +public abstract class ConsoleIOContextTestSupport { + + public static ConsoleIOContextTestSupport IMPL; + + public static void willComputeCompletion() { + if (IMPL != null) + IMPL.willComputeCompletionCallback(); + } + + protected abstract void willComputeCompletionCallback(); + +}
--- a/src/jdk.jshell/share/classes/jdk/jshell/Eval.java Thu Sep 21 01:21:54 2017 -0400 +++ b/src/jdk.jshell/share/classes/jdk/jshell/Eval.java Wed Sep 27 01:20:57 2017 -0400 @@ -574,7 +574,7 @@ DeclarationSnippet sn = (DeclarationSnippet) state.maps.getSnippetDeadOrAlive(ex.id()); exception = new UnresolvedReferenceException(sn, translateExceptionStack(ex)); } catch (UserException ex) { - exception = new EvalException(translateExceptionMessage(ex), + exception = new EvalException(ex.getMessage(), ex.causeExceptionClass(), translateExceptionStack(ex)); } catch (RunException ex) { @@ -782,13 +782,6 @@ return elems; } - private String translateExceptionMessage(Exception ex) { - String msg = ex.getMessage(); - return msg.equals("<none>") - ? null - : msg; - } - private boolean isWrap(StackTraceElement ste) { return PREFIX_PATTERN.matcher(ste.getClassName()).find(); }
--- a/src/jdk.jshell/share/classes/jdk/jshell/execution/ExecutionControlForwarder.java Thu Sep 21 01:21:54 2017 -0400 +++ b/src/jdk.jshell/share/classes/jdk/jshell/execution/ExecutionControlForwarder.java Wed Sep 27 01:20:57 2017 -0400 @@ -45,6 +45,12 @@ class ExecutionControlForwarder { /** + * Represent null in a streamed UTF string. Vanishingly improbable string to + * occur in a user string. + */ + static final String NULL_MARKER = "\u0002*\u03C0*NULL*\u03C0*\u0003"; + + /** * Maximum number of characters for writeUTF(). Byte maximum is 65535, at * maximum three bytes per character that is 65535 / 3 == 21845. Minus one * for safety. @@ -93,6 +99,10 @@ out.writeInt(i); } + private void writeNullOrUTF(String s) throws IOException { + writeUTF(s == null ? NULL_MARKER : s); + } + private void writeUTF(String s) throws IOException { if (s == null) { s = ""; @@ -197,7 +207,7 @@ return true; } catch (UserException ex) { writeStatus(RESULT_USER_EXCEPTION); - writeUTF(ex.getMessage()); + writeNullOrUTF(ex.getMessage()); writeUTF(ex.causeExceptionClass()); writeObject(ex.getStackTrace()); flush(); @@ -213,8 +223,10 @@ flush(); return true; } catch (Throwable ex) { + // Unexpected exception, have something in the message writeStatus(RESULT_TERMINATED); - writeUTF(ex.getMessage()); + String msg = ex.getMessage(); + writeUTF(msg == null? ex.toString() : msg); flush(); return false; }
--- a/src/jdk.jshell/share/classes/jdk/jshell/execution/StreamingExecutionControl.java Thu Sep 21 01:21:54 2017 -0400 +++ b/src/jdk.jshell/share/classes/jdk/jshell/execution/StreamingExecutionControl.java Wed Sep 27 01:20:57 2017 -0400 @@ -29,6 +29,7 @@ import java.io.ObjectOutput; import jdk.jshell.JShellException; import jdk.jshell.spi.ExecutionControl; +import static jdk.jshell.execution.ExecutionControlForwarder.NULL_MARKER; import static jdk.jshell.execution.RemoteCodes.*; /** @@ -185,6 +186,16 @@ } /** + * Read a UTF or a null encoded as a null marker. + * @return a string or null + * @throws IOException passed through from readUTF() + */ + private String readNullOrUTF() throws IOException { + String s = in.readUTF(); + return s.equals(NULL_MARKER) ? null : s; + } + + /** * Reports results from a remote agent command that does not expect * exceptions. */ @@ -273,7 +284,7 @@ } case RESULT_USER_EXCEPTION: { // A user exception was encountered. - String message = in.readUTF(); + String message = readNullOrUTF(); String exceptionClassName = in.readUTF(); StackTraceElement[] elems = (StackTraceElement[]) in.readObject(); throw new UserException(message, exceptionClassName, elems);
--- a/test/jdk/javadoc/doclet/testSearch/TestSearch.java Thu Sep 21 01:21:54 2017 -0400 +++ b/test/jdk/javadoc/doclet/testSearch/TestSearch.java Wed Sep 27 01:20:57 2017 -0400 @@ -23,7 +23,7 @@ /* * @test - * @bug 8141492 8071982 8141636 8147890 8166175 8168965 8176794 8175218 8147881 8181622 + * @bug 8141492 8071982 8141636 8147890 8166175 8168965 8176794 8175218 8147881 8181622 8182263 * @summary Test the search feature of javadoc. * @author bpatel * @library ../lib @@ -273,9 +273,9 @@ "<script type=\"text/javascript\" src=\"jquery/jquery-ui.js\"></script>", "var pathtoroot = \"./\";loadScripts(document, 'script');", "<ul class=\"navListSearch\">\n", - "<li><span>SEARCH: </span>\n", - "<input type=\"text\" id=\"search\" value=\" \" disabled=\"disabled\">\n", - "<input type=\"reset\" id=\"reset\" value=\" \" disabled=\"disabled\">\n"); + "<li><label for=\"search\">SEARCH:</label>\n" + + "<input type=\"text\" id=\"search\" value=\"search\" disabled=\"disabled\">\n" + + "<input type=\"reset\" id=\"reset\" value=\"reset\" disabled=\"disabled\">\n"); checkOutput(fileName, true, "<div class=\"fixedNav\">"); }
--- a/test/jdk/javadoc/doclet/testStylesheet/TestStylesheet.java Thu Sep 21 01:21:54 2017 -0400 +++ b/test/jdk/javadoc/doclet/testStylesheet/TestStylesheet.java Wed Sep 27 01:20:57 2017 -0400 @@ -24,7 +24,7 @@ /* * @test * @bug 4494033 7028815 7052425 8007338 8023608 8008164 8016549 8072461 8154261 8162363 8160196 8151743 8177417 - * 8175218 8176452 8181215 + * 8175218 8176452 8181215 8182263 * @summary Run tests on doclet stylesheet. * @author jamieh * @library ../lib @@ -185,6 +185,23 @@ + "th.colConstructorName a:link, th.colConstructorName a:visited,\n" + ".constantValuesContainer td a:link, .constantValuesContainer td a:visited {\n" + " font-weight:bold;\n" + + "}", + "#reset {\n" + + " background-color: rgb(255,255,255);\n" + + " background-image:url('resources/x.png');\n" + + " background-position:center;\n" + + " background-repeat:no-repeat;\n" + + " background-size:12px;\n" + + " border:0 none;\n" + + " width:16px;\n" + + " height:17px;\n" + + " position:relative;\n" + + " left:-4px;\n" + + " top:-4px;\n" + + " font-size:0px;\n" + + "}", + ".watermark {\n" + + " color:#545454;\n" + "}"); checkOutput("pkg/A.html", true,
--- a/test/jdk/jshell/ComputeFQNsTest.java Thu Sep 21 01:21:54 2017 -0400 +++ b/test/jdk/jshell/ComputeFQNsTest.java Wed Sep 27 01:20:57 2017 -0400 @@ -51,14 +51,14 @@ private final Path outDir = Paths.get("ComputeFQNsTest"); public void testAddImport() throws Exception { - compiler.compile(outDir, "package test1; public class TestClass { }", "package test2; public class TestClass { }"); + compiler.compile(outDir, "package test1; public class FQNTestClass { }", "package test2; public class FQNTestClass { }"); String jarName = "test.jar"; - compiler.jar(outDir, jarName, "test1/TestClass.class", "test2/TestClass.class"); + compiler.jar(outDir, jarName, "test1/FQNTestClass.class", "test2/FQNTestClass.class"); addToClasspath(compiler.getPath(outDir).resolve(jarName)); assertInferredFQNs("LinkedList", "java.util.LinkedList"); assertInferredFQNs("ArrayList", "java.util.ArrayList"); - assertInferredFQNs("TestClass", "test1.TestClass", "test2.TestClass"); + assertInferredFQNs("FQNTestClass", "test1.FQNTestClass", "test2.FQNTestClass"); assertInferredFQNs("CharSequence", "CharSequence".length(), true, "java.lang.CharSequence"); assertInferredFQNs("unresolvable"); assertInferredFQNs("void test(ArrayList", "ArrayList".length(), false, "java.util.ArrayList");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/jshell/ExceptionMessageTest.java Wed Sep 27 01:20:57 2017 -0400 @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8185108 + * @summary Test exception().getMessage() in events returned by eval() + * @run testng ExceptionMessageTest + */ + +import java.util.HashMap; +import java.util.Map; +import java.util.List; + +import jdk.jshell.JShell; +import jdk.jshell.SnippetEvent; +import jdk.jshell.execution.DirectExecutionControl; +import jdk.jshell.execution.JdiExecutionControlProvider; +import jdk.jshell.execution.LocalExecutionControlProvider; +import jdk.jshell.spi.ExecutionControl; +import jdk.jshell.spi.ExecutionControlProvider; +import jdk.jshell.spi.ExecutionEnv; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +@Test +public class ExceptionMessageTest { + + public void testDefaultEC() { + doTestCases(new JdiExecutionControlProvider(), "default"); + } + + public void testLocalEC() { + doTestCases(new LocalExecutionControlProvider(), "local"); + } + + public void testDirectEC() { + doTestCases(new ExecutionControlProvider() { + public ExecutionControl generate(ExecutionEnv env, Map<String, String> param) throws Throwable { + return new DirectExecutionControl(); + } + + public String name() { + return "direct"; + } + + }, "direct"); + } + + private JShell shell(ExecutionControlProvider ec) { + return JShell.builder().executionEngine(ec, new HashMap<>()).build(); + } + + private void doTestCases(ExecutionControlProvider ec, String label) { + JShell jshell = shell(ec); + doTest(jshell, label, "throw new java.io.IOException();", null); + doTest(jshell, label, "throw new java.io.IOException((String)null);", null); + doTest(jshell, label, "throw new java.io.IOException(\"\");", ""); + doTest(jshell, label, "throw new java.io.IOException(\"test\");", "test"); + } + + private void doTest(JShell jshell, String label, String code, String expected) { + List<SnippetEvent> result = jshell.eval(code); + assertEquals(result.size(), 1, "Expected only one event"); + SnippetEvent evt = result.get(0); + Exception exc = evt.exception(); + String out = exc.getMessage(); + assertEquals(out, expected, "Exception message not as expected: " + + label + " -- " + code); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/jdk/jshell/PasteAndMeasurementsUITest.java Wed Sep 27 01:20:57 2017 -0400 @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 8182297 + * @summary Verify that pasting multi-line snippets works properly. + * @library /tools/lib + * @modules + * java.base/java.lang:open + * java.base/java.io:open + * jdk.compiler/com.sun.tools.javac.api + * jdk.compiler/com.sun.tools.javac.main + * jdk.jshell/jdk.internal.jshell.tool.resources:open + * jdk.jshell/jdk.jshell:open + * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask + * @build Compiler UITesting + * @build PasteAndMeasurementsUITest + * @run testng/othervm PasteAndMeasurementsUITest + */ + +import java.io.Console; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; + +import org.testng.annotations.Test; + +@Test +public class PasteAndMeasurementsUITest extends UITesting { + + public void testPrevNextSnippet() throws Exception { + System.setProperty(ANSI_SUPPORTED_PROPERTY, "true"); + Field cons = System.class.getDeclaredField("cons"); + cons.setAccessible(true); + Constructor console = Console.class.getDeclaredConstructor(); + console.setAccessible(true); + cons.set(null, console.newInstance()); + doRunTest((inputSink, out) -> { + inputSink.write("void test1() {\nSystem.err.println(1);\n}\n" + LOC + + "void test2() {\nSystem.err.println(1);\n}\n" + LOC + LOC + LOC + LOC + LOC); + waitOutput(out, "\u001b\\[6nvoid test1\\(\\) \\{\n" + + "\u0006\u001b\\[6nSystem.err.println\\(1\\);\n" + + "\u0006\u001b\\[6n\\}\n" + + "\\| created method test1\\(\\)\n" + + "\u0005\u001b\\[6nvoid test2\\(\\) \\{\n" + + "\u0006\u001b\\[6nSystem.err.println\\(1\\);\n" + + "\u0006\u001b\\[6n\\}\n" + + "\\| created method test2\\(\\)\n" + + "\u0005\u001b\\[6n"); + }); + } + private static final String ANSI_SUPPORTED_PROPERTY = "test.terminal.ansi.supported"; + private static final String LOC = "\033[12;1R"; +}
--- a/test/jdk/jshell/ToolTabSnippetTest.java Thu Sep 21 01:21:54 2017 -0400 +++ b/test/jdk/jshell/ToolTabSnippetTest.java Wed Sep 27 01:20:57 2017 -0400 @@ -23,10 +23,11 @@ /** * @test - * @bug 8177076 + * @bug 8177076 8185426 * @modules * jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.main + * jdk.jshell/jdk.internal.jshell.tool * jdk.jshell/jdk.internal.jshell.tool.resources:open * jdk.jshell/jdk.jshell:open * @library /tools/lib @@ -42,10 +43,12 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; +import java.util.concurrent.CountDownLatch; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; import java.util.regex.Pattern; +import jdk.internal.jshell.tool.ConsoleIOContextTestSupport; import org.testng.annotations.Test; @Test @@ -191,6 +194,39 @@ }); } + public void testCleaningCompletionTODO() throws Exception { + doRunTest((inputSink, out) -> { + CountDownLatch testCompleteComputationStarted = new CountDownLatch(1); + CountDownLatch testCompleteComputationContinue = new CountDownLatch(1); + ConsoleIOContextTestSupport.IMPL = new ConsoleIOContextTestSupport() { + @Override + protected void willComputeCompletionCallback() { + if (testCompleteComputationStarted != null) { + testCompleteComputationStarted.countDown(); + } + if (testCompleteComputationContinue != null) { + try { + testCompleteComputationContinue.await(); + } catch (InterruptedException ex) { + throw new IllegalStateException(ex); + } + } + } + }; + //-> <tab> + inputSink.write("\011"); + testCompleteComputationStarted.await(); + //-> <tab><tab> + inputSink.write("\011\011"); + testCompleteComputationContinue.countDown(); + waitOutput(out, "\u0005"); + //-> <tab> + inputSink.write("\011"); + waitOutput(out, "\u0005"); + ConsoleIOContextTestSupport.IMPL = null; + }); + } + private Path prepareZip() { String clazz1 = "package jshelltest;\n" +
--- a/test/jdk/jshell/UITesting.java Thu Sep 21 01:21:54 2017 -0400 +++ b/test/jdk/jshell/UITesting.java Wed Sep 27 01:20:57 2017 -0400 @@ -138,7 +138,7 @@ while (true) { Matcher m = expectedPattern.matcher(out); if (m.find()) { - out.delete(0, m.end() + 1); + out.delete(0, m.end()); return ; } long e = System.currentTimeMillis();