diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java index 32b21139f400c10dd55fd48e3c2cc754a4eff2cd..beb39842621267523ac56cf3dcd904e0cd1e1591 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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 @@ -418,6 +418,7 @@ public class JavacTrees extends DocTrees { private Symbol attributeDocReference(TreePath path, DCReference ref) { Env env = getAttrContext(path); + if (env == null) return null; Log.DeferredDiagnosticHandler deferredDiagnosticHandler = new Log.DeferredDiagnosticHandler(log); @@ -881,6 +882,7 @@ public class JavacTrees extends DocTrees { case INTERFACE: // System.err.println("CLASS: " + ((JCClassDecl)tree).sym.getSimpleName()); env = enter.getClassEnv(((JCClassDecl)tree).sym); + if (env == null) return null; break; case METHOD: // System.err.println("METHOD: " + ((JCMethodDecl)tree).sym.getSimpleName()); diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java index 353bb1fb7a88e14a1adafc0af1447cd928f4f67d..8e3430a271ced0252beb9df38662c07ab7fa693a 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java @@ -3994,10 +3994,16 @@ public class Attr extends JCTree.Visitor { rs.methodArguments(argtypes.map(checkDeferredMap)), kindName(sym.location()), sym.location()); - owntype = new MethodType(owntype.getParameterTypes(), - types.erasure(owntype.getReturnType()), - types.erasure(owntype.getThrownTypes()), - syms.methodClass); + if (resultInfo.pt != Infer.anyPoly || + !owntype.hasTag(METHOD) || + !owntype.isPartial()) { + //if this is not a partially inferred method type, erase return type. Otherwise, + //erasure is carried out in PartiallyInferredMethodType.check(). + owntype = new MethodType(owntype.getParameterTypes(), + types.erasure(owntype.getReturnType()), + types.erasure(owntype.getThrownTypes()), + syms.methodClass); + } } PolyKind pkind = (sym.type.hasTag(FORALL) && diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java index 63e84b91e4dbec9835219305e0e5b558b0f31b29..4869ae36bae0afcbd9024f4af7d833308109411a 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -32,6 +32,7 @@ import javax.tools.JavaFileObject; import javax.tools.JavaFileManager; import com.sun.tools.javac.code.*; +import com.sun.tools.javac.code.Kinds.KindName; import com.sun.tools.javac.code.Kinds.KindSelector; import com.sun.tools.javac.code.Scope.*; import com.sun.tools.javac.code.Symbol.*; @@ -155,6 +156,7 @@ public class Enter extends JCTree.Visitor { public Env getClassEnv(TypeSymbol sym) { Env localEnv = getEnv(sym); + if (localEnv == null) return null; Env lintEnv = localEnv; while (lintEnv.info.lint == null) lintEnv = lintEnv.next; @@ -400,8 +402,14 @@ public class Enter extends JCTree.Visitor { c = syms.enterClass(env.toplevel.modle, tree.name, packge); packge.members().enterIfAbsent(c); if ((tree.mods.flags & PUBLIC) != 0 && !classNameMatchesFileName(c, env)) { + KindName topElement = KindName.CLASS; + if ((tree.mods.flags & ENUM) != 0) { + topElement = KindName.ENUM; + } else if ((tree.mods.flags & INTERFACE) != 0) { + topElement = KindName.INTERFACE; + } log.error(tree.pos(), - "class.public.should.be.in.file", tree.name); + "class.public.should.be.in.file", topElement, tree.name); } } else { if (!tree.name.isEmpty() && diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java index 184e43863aa6753e23363df264abe7fb3e1538bf..d2d299b11075dc7fe1493d3268ad8d8033556534 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java @@ -319,7 +319,8 @@ public class Infer { * need to use it several times: with several targets. */ saved_undet = inferenceContext.save(); - if (allowGraphInference && !warn.hasNonSilentLint(Lint.LintCategory.UNCHECKED)) { + boolean unchecked = warn.hasNonSilentLint(Lint.LintCategory.UNCHECKED); + if (allowGraphInference && !unchecked) { boolean shouldPropagate = shouldPropagate(getReturnType(), resultInfo, inferenceContext); InferenceContext minContext = shouldPropagate ? @@ -338,7 +339,10 @@ public class Infer { } } inferenceContext.solve(noWarnings); - return inferenceContext.asInstType(this).getReturnType(); + Type ret = inferenceContext.asInstType(this).getReturnType(); + //inline logic from Attr.checkMethod - if unchecked conversion was required, erase + //return type _after_ resolution + return unchecked ? types.erasure(ret) : ret; } catch (InferenceException ex) { resultInfo.checkContext.report(null, ex.getDiagnostic()); Assert.error(); //cannot get here (the above should throw) diff --git a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties index 48243052b3cea3603edd953cfb6324936ff5f105..a7d479fcdbf4628a3ce971ddbe2aa7bf23a61101 100644 --- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties +++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties @@ -1246,9 +1246,9 @@ compiler.err.class.cant.write=\ # In the following string, {0} is the name of the class in the Java source. # It really should be used two times.. -# 0: name +# 0: kind name, 1: name compiler.err.class.public.should.be.in.file=\ - class {0} is public, should be declared in a file named {0}.java + {0} {1} is public, should be declared in a file named {1}.java ## All errors which do not refer to a particular line in the source code are ## preceded by this string. diff --git a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleIndexWriter.java b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleIndexWriter.java index 2d8317780a3f720dc03274f7d07b519d74d1188f..40ffe1693ddc54d67748560bb11da08f44fc5242 100644 --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleIndexWriter.java +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleIndexWriter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 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 @@ -144,6 +144,7 @@ public class ModuleIndexWriter extends AbstractModuleIndexWriter { Content div = HtmlTree.DIV(HtmlStyle.contentContainer, table); if (configuration.allowTag(HtmlTag.MAIN)) { htmlTree.addContent(div); + body.addContent(htmlTree); } else { body.addContent(div); } @@ -183,21 +184,12 @@ public class ModuleIndexWriter extends AbstractModuleIndexWriter { protected void addOverviewHeader(Content body) { addConfigurationTitle(body); if (!utils.getFullBody(configuration.overviewElement).isEmpty()) { - HtmlTree subTitleDiv = new HtmlTree(HtmlTag.DIV); - subTitleDiv.addStyle(HtmlStyle.subTitle); - addSummaryComment(configuration.overviewElement, subTitleDiv); - Content div = HtmlTree.DIV(HtmlStyle.header, subTitleDiv); - Content see = new ContentBuilder(); - see.addContent(contents.seeLabel); - see.addContent(" "); - Content descPara = HtmlTree.P(see); - Content descLink = getHyperLink(getDocLink( - SectionName.OVERVIEW_DESCRIPTION), - contents.descriptionLabel, "", ""); - descPara.addContent(descLink); - div.addContent(descPara); + HtmlTree div = new HtmlTree(HtmlTag.DIV); + div.addStyle(HtmlStyle.contentContainer); + addOverviewComment(div); if (configuration.allowTag(HtmlTag.MAIN)) { htmlTree.addContent(div); + body.addContent(htmlTree); } else { body.addContent(div); } @@ -213,29 +205,17 @@ public class ModuleIndexWriter extends AbstractModuleIndexWriter { */ protected void addOverviewComment(Content htmltree) { if (!utils.getFullBody(configuration.overviewElement).isEmpty()) { - htmltree.addContent(getMarkerAnchor(SectionName.OVERVIEW_DESCRIPTION)); addInlineComment(configuration.overviewElement, htmltree); } } /** - * Adds the tag information as provided in the file specified by the - * "-overview" option on the command line. + * Not required for this page. * * @param body the documentation tree to which the overview will be added */ @Override - protected void addOverview(Content body) { - HtmlTree div = new HtmlTree(HtmlTag.DIV); - div.addStyle(HtmlStyle.contentContainer); - addOverviewComment(div); - if (configuration.allowTag(HtmlTag.MAIN)) { - htmlTree.addContent(div); - body.addContent(htmlTree); - } else { - body.addContent(div); - } - } + protected void addOverview(Content body) {} /** * Adds the top text (from the -top option), the upper diff --git a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageIndexWriter.java b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageIndexWriter.java index cf5f1da6fbf38cbaceaec49f4688a65089c79a53..6e70ed19ce523c974d201ad932706ea162886672 100644 --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageIndexWriter.java +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/PackageIndexWriter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -134,6 +134,7 @@ public class PackageIndexWriter extends AbstractPackageIndexWriter { Content div = HtmlTree.DIV(HtmlStyle.contentContainer, table); if (configuration.allowTag(HtmlTag.MAIN)) { htmlTree.addContent(div); + body.addContent(htmlTree); } else { body.addContent(div); } @@ -176,21 +177,12 @@ public class PackageIndexWriter extends AbstractPackageIndexWriter { protected void addOverviewHeader(Content body) { addConfigurationTitle(body); if (!utils.getFullBody(configuration.overviewElement).isEmpty()) { - HtmlTree subTitleDiv = new HtmlTree(HtmlTag.DIV); - subTitleDiv.addStyle(HtmlStyle.subTitle); - addSummaryComment(configuration.overviewElement, subTitleDiv); - Content div = HtmlTree.DIV(HtmlStyle.header, subTitleDiv); - Content descBody = new ContentBuilder(); - descBody.addContent(contents.seeLabel); - descBody.addContent(" "); - Content descPara = HtmlTree.P(descBody); - Content descLink = getHyperLink(getDocLink( - SectionName.OVERVIEW_DESCRIPTION), - contents.descriptionLabel, "", ""); - descPara.addContent(descLink); - div.addContent(descPara); + HtmlTree div = new HtmlTree(HtmlTag.DIV); + div.addStyle(HtmlStyle.contentContainer); + addOverviewComment(div); if (configuration.allowTag(HtmlTag.MAIN)) { htmlTree.addContent(div); + body.addContent(htmlTree); } else { body.addContent(div); } @@ -206,29 +198,17 @@ public class PackageIndexWriter extends AbstractPackageIndexWriter { */ protected void addOverviewComment(Content htmltree) { if (!utils.getFullBody(configuration.overviewElement).isEmpty()) { - htmltree.addContent(getMarkerAnchor(SectionName.OVERVIEW_DESCRIPTION)); addInlineComment(configuration.overviewElement, htmltree); } } /** - * Adds the tag information as provided in the file specified by the - * "-overview" option on the command line. + * Not required for this page. * * @param body the documentation tree to which the overview will be added */ @Override - protected void addOverview(Content body) { - HtmlTree div = new HtmlTree(HtmlTag.DIV); - div.addStyle(HtmlStyle.contentContainer); - addOverviewComment(div); - if (configuration.allowTag(HtmlTag.MAIN)) { - htmlTree.addContent(div); - body.addContent(htmlTree); - } else { - body.addContent(div); - } - } + protected void addOverview(Content body) {} /** * Adds the top text (from the -top option), the upper diff --git a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/search.js b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/search.js index 6e4ea9bc6f9ebb6bb442f63e744480e9c0ad3107..ea8678af7198423ea8305afa05d203dcb308f1e1 100644 --- a/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/search.js +++ b/langtools/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/search.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -169,11 +169,42 @@ $(function() { var tresult = new Array(); var mresult = new Array(); var tgresult = new Array(); + var secondaryresult = new Array(); var displayCount = 0; var exactMatcher = new RegExp("^" + $.ui.autocomplete.escapeRegex(request.term) + "$", "i"); camelCaseRegexp = ($.ui.autocomplete.escapeRegex(request.term)).split(/(?=[A-Z])/).join("([a-z0-9_$]*?)"); var camelCaseMatcher = new RegExp("^" + camelCaseRegexp); secondaryMatcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i"); + + // Return the nested innermost name from the specified object + function nestedName(e) { + return e.l.substring(e.l.lastIndexOf(".") + 1); + } + + // Sort array items by short name (as opposed to fully qualified name). + // Additionally, sort by the nested type name, when present, + // as opposed to top level short name. + function sortAndConcatResults(a1, a2) { + var sortingKey; + var sortArray = function(e1, e2) { + var l = sortingKey(e1); + var m = sortingKey(e2); + if (l < m) + return -1; + if (l > m) + return 1; + return 0; + }; + sortingKey = function(e) { + return nestedName(e).toUpperCase(); + }; + a1.sort(sortArray); + a2.sort(sortArray); + a1 = a1.concat(a2); + a2.length = 0; + return a1; + } + if (moduleSearchIndex) { var mdleCount = 0; $.each(moduleSearchIndex, function(index, item) { @@ -184,10 +215,11 @@ $(function() { } else if (camelCaseMatcher.test(item.l)) { result.unshift(item); } else if (secondaryMatcher.test(item.l)) { - result.push(item); + secondaryresult.push(item); } }); displayCount = mdleCount; + result = sortAndConcatResults(result, secondaryresult); } if (packageSearchIndex) { var pCount = 0; @@ -197,48 +229,51 @@ $(function() { pkg = (item.m) ? (item.m + "/" + item.l) : item.l; - if (exactMatcher.test(item.l)) { + var s = nestedName(item); + if (exactMatcher.test(s)) { presult.unshift(item); pCount++; } else if (camelCaseMatcher.test(pkg)) { presult.unshift(item); } else if (secondaryMatcher.test(pkg)) { - presult.push(item); + secondaryresult.push(item); } }); - result = result.concat(presult); + result = result.concat(sortAndConcatResults(presult, secondaryresult)); displayCount = (pCount > displayCount) ? pCount : displayCount; } if (typeSearchIndex) { var tCount = 0; $.each(typeSearchIndex, function(index, item) { item[category] = catTypes; - if (exactMatcher.test(item.l)) { + var s = nestedName(item); + if (exactMatcher.test(s)) { tresult.unshift(item); tCount++; - } else if (camelCaseMatcher.test(item.l)) { + } else if (camelCaseMatcher.test(s)) { tresult.unshift(item); } else if (secondaryMatcher.test(item.p + "." + item.l)) { - tresult.push(item); + secondaryresult.push(item); } }); - result = result.concat(tresult); + result = result.concat(sortAndConcatResults(tresult, secondaryresult)); displayCount = (tCount > displayCount) ? tCount : displayCount; } if (memberSearchIndex) { var mCount = 0; $.each(memberSearchIndex, function(index, item) { item[category] = catMembers; - if (exactMatcher.test(item.l)) { + var s = nestedName(item); + if (exactMatcher.test(s)) { mresult.unshift(item); mCount++; - } else if (camelCaseMatcher.test(item.l)) { + } else if (camelCaseMatcher.test(s)) { mresult.unshift(item); } else if (secondaryMatcher.test(item.c + "." + item.l)) { - mresult.push(item); + secondaryresult.push(item); } }); - result = result.concat(mresult); + result = result.concat(sortAndConcatResults(mresult, secondaryresult)); displayCount = (mCount > displayCount) ? mCount : displayCount; } if (tagSearchIndex) { @@ -249,10 +284,10 @@ $(function() { tgresult.unshift(item); tgCount++; } else if (secondaryMatcher.test(item.l)) { - tgresult.push(item); + secondaryresult.push(item); } }); - result = result.concat(tgresult); + result = result.concat(sortAndConcatResults(tgresult, secondaryresult)); displayCount = (tgCount > displayCount) ? tgCount : displayCount; } displayCount = (displayCount > 500) ? displayCount : 500; @@ -312,4 +347,4 @@ $(function() { } } }); -}); \ No newline at end of file +}); diff --git a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/debug/InternalDebugControl.java b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/debug/InternalDebugControl.java index 8aa204240d06fa1388a062b7a52225320d0de313..a5854d89c0cdbe35f2f6d40b5bad933c640b23a6 100644 --- a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/debug/InternalDebugControl.java +++ b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/debug/InternalDebugControl.java @@ -89,6 +89,17 @@ public class InternalDebugControl { debugMap.put(state, flags); } + /** + * Release a JShell instance. + * + * @param state the JShell instance + */ + public static void release(JShell state) { + if (debugMap != null) { + debugMap.remove(state); + } + } + /** * Tests if any of the specified debug flags are enabled. * diff --git a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/Feedback.java b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/Feedback.java index 80641a57bdf0c8ea0c9ebbc09f859bf9f740a0bf..bbd919658ebe88be2339937f80e181d01015670e 100644 --- a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/Feedback.java +++ b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/Feedback.java @@ -116,6 +116,13 @@ class Feedback { name, type, value, unresolved, errorLines); } + public String format(String field, FormatCase fc, FormatAction fa, FormatWhen fw, + FormatResolve fr, FormatUnresolved fu, FormatErrors fe, + String name, String type, String value, String unresolved, List errorLines) { + return mode.format(field, fc, fa, fw, fr, fu, fe, + name, type, value, unresolved, errorLines); + } + public String truncateVarValue(String value) { return mode.truncateVarValue(value); } @@ -463,6 +470,14 @@ class Feedback { String format(FormatCase fc, FormatAction fa, FormatWhen fw, FormatResolve fr, FormatUnresolved fu, FormatErrors fe, String name, String type, String value, String unresolved, List errorLines) { + return format("display", fc, fa, fw, fr, fu, fe, + name, type, value, unresolved, errorLines); + } + + // Compute the display output given full context and values + String format(String field, FormatCase fc, FormatAction fa, FormatWhen fw, + FormatResolve fr, FormatUnresolved fu, FormatErrors fe, + String name, String type, String value, String unresolved, List errorLines) { // Convert the context into a bit representation used as selectors for store field formats long bits = bits(fc, fa, fw, fr, fu, fe); String fname = name==null? "" : name; @@ -476,7 +491,7 @@ class Feedback { fname, ftype, fvalue, funresolved, "*cannot-use-errors-here*", el)) .collect(joining()); return String.format( - format("display", bits), + format(field, bits), fname, ftype, fvalue, funresolved, errors, "*cannot-use-err-here*"); } diff --git a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java index 6cc516555fa52105f35314ac339e6d2cdd563f3a..95c54aad2a7c5fa6f15c61abadc26c1a073abaee 100644 --- a/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java +++ b/langtools/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java @@ -36,12 +36,9 @@ import java.io.InputStreamReader; import java.io.PrintStream; import java.io.Reader; import java.io.StringReader; -import java.net.URL; import java.nio.charset.Charset; -import java.nio.file.AccessDeniedException; import java.nio.file.FileSystems; import java.nio.file.Files; -import java.nio.file.NoSuchFileException; import java.nio.file.Path; import java.nio.file.Paths; import java.text.MessageFormat; @@ -812,6 +809,12 @@ public class JShellTool implements MessageHandler { } } + /** + * The entry point into the JShell tool. + * + * @param args the command-line arguments + * @throws Exception catastrophic fatal exception + */ public void start(String[] args) throws Exception { OptionParserCommandLine commandLineArgs = new OptionParserCommandLine(); options = commandLineArgs.parse(args); @@ -842,30 +845,33 @@ public class JShellTool implements MessageHandler { hardmsg("jshell.msg.welcome", version()); } // Be sure history is always saved so that user code isn't lost - Runtime.getRuntime().addShutdownHook(new Thread() { + Thread shutdownHook = new Thread() { @Override public void run() { replayableHistory.storeHistory(prefs); } - }); + }; + Runtime.getRuntime().addShutdownHook(shutdownHook); // execute from user input try (IOContext in = new ConsoleIOContext(this, cmdin, console)) { - start(in); - } - } - } - - private void start(IOContext in) { - try { - while (regenerateOnDeath) { - if (!live) { - resetState(); + while (regenerateOnDeath) { + if (!live) { + resetState(); + } + run(in); + } + } finally { + replayableHistory.storeHistory(prefs); + closeState(); + try { + Runtime.getRuntime().removeShutdownHook(shutdownHook); + } catch (Exception ex) { + // ignore, this probably caused by VM aready being shutdown + // and this is the last act anyhow } - run(in); } - } finally { - closeState(); } + closeState(); } private EditorSetting configEditor() { @@ -1019,6 +1025,8 @@ public class JShellTool implements MessageHandler { live = false; JShell oldState = state; if (oldState != null) { + state = null; + analysis = null; oldState.unsubscribe(shutdownSubscription); // No notification oldState.close(); } @@ -2006,7 +2014,6 @@ public class JShellTool implements MessageHandler { private boolean cmdExit() { regenerateOnDeath = false; live = false; - replayableHistory.storeHistory(prefs); fluffmsg("jshell.msg.goodbye"); return true; } @@ -2614,9 +2621,16 @@ public class JShellTool implements MessageHandler { if (stream == null) { return false; } - stream.forEachOrdered(mk - -> hard(" %s %s", mk.name(), mk.signature()) - ); + stream.forEachOrdered(meth -> { + String sig = meth.signature(); + int i = sig.lastIndexOf(")") + 1; + if (i <= 0) { + hard(" %s", meth.name()); + } else { + hard(" %s %s%s", sig.substring(i), meth.name(), sig.substring(0, i)); + } + printSnippetStatus(meth, true); + }); return true; } @@ -2648,6 +2662,7 @@ public class JShellTool implements MessageHandler { break; } hard(" %s %s", kind, ck.name()); + printSnippetStatus(ck, true); }); return true; } @@ -2837,7 +2852,8 @@ public class JShellTool implements MessageHandler { return true; } } else { - new DisplayEvent(ste, false, ste.value(), diagnostics).displayDeclarationAndValue(); + new DisplayEvent(ste, FormatWhen.PRIMARY, ste.value(), diagnostics) + .displayDeclarationAndValue(); } } else { if (diagnostics.isEmpty()) { @@ -2851,7 +2867,8 @@ public class JShellTool implements MessageHandler { List other = errorsOnly(diagnostics); // display update information - new DisplayEvent(ste, true, ste.value(), other).displayDeclarationAndValue(); + new DisplayEvent(ste, FormatWhen.UPDATE, ste.value(), other) + .displayDeclarationAndValue(); } } return false; @@ -2889,10 +2906,7 @@ public class JShellTool implements MessageHandler { } //where void printUnresolvedException(UnresolvedReferenceException ex) { - DeclarationSnippet corralled = ex.getSnippet(); - List otherErrors = errorsOnly(state.diagnostics(corralled).collect(toList())); - new DisplayEvent(corralled, state.status(corralled), FormatAction.USED, true, null, otherErrors) - .displayDeclarationAndValue(); + printSnippetStatus(ex.getSnippet(), false); } //where void printEvalException(EvalException ex) { @@ -2934,23 +2948,38 @@ public class JShellTool implements MessageHandler { return act; } + void printSnippetStatus(DeclarationSnippet sn, boolean resolve) { + List otherErrors = errorsOnly(state.diagnostics(sn).collect(toList())); + new DisplayEvent(sn, state.status(sn), resolve, otherErrors) + .displayDeclarationAndValue(); + } + class DisplayEvent { private final Snippet sn; private final FormatAction action; - private final boolean update; + private final FormatWhen update; private final String value; private final List errorLines; private final FormatResolve resolution; private final String unresolved; private final FormatUnresolved unrcnt; private final FormatErrors errcnt; + private final boolean resolve; + + DisplayEvent(SnippetEvent ste, FormatWhen update, String value, List errors) { + this(ste.snippet(), ste.status(), false, + toAction(ste.status(), ste.previousStatus(), ste.isSignatureChange()), + update, value, errors); + } - DisplayEvent(SnippetEvent ste, boolean update, String value, List errors) { - this(ste.snippet(), ste.status(), toAction(ste.status(), ste.previousStatus(), ste.isSignatureChange()), update, value, errors); + DisplayEvent(Snippet sn, Status status, boolean resolve, List errors) { + this(sn, status, resolve, FormatAction.USED, FormatWhen.UPDATE, null, errors); } - DisplayEvent(Snippet sn, Status status, FormatAction action, boolean update, String value, List errors) { + private DisplayEvent(Snippet sn, Status status, boolean resolve, + FormatAction action, FormatWhen update, String value, List errors) { this.sn = sn; + this.resolve =resolve; this.action = action; this.update = update; this.value = value; @@ -2958,6 +2987,12 @@ public class JShellTool implements MessageHandler { for (Diag d : errors) { displayDiagnostics(sn.source(), d, errorLines); } + if (resolve) { + // resolve needs error lines indented + for (int i = 0; i < errorLines.size(); ++i) { + errorLines.set(i, " " + errorLines.get(i)); + } + } long unresolvedCount; if (sn instanceof DeclarationSnippet && (status == Status.RECOVERABLE_DEFINED || status == Status.RECOVERABLE_NOT_DEFINED)) { resolution = (status == Status.RECOVERABLE_NOT_DEFINED) @@ -3012,10 +3047,17 @@ public class JShellTool implements MessageHandler { } private void custom(FormatCase fcase, String name, String type) { - String display = feedback.format(fcase, action, (update ? FormatWhen.UPDATE : FormatWhen.PRIMARY), - resolution, unrcnt, errcnt, - name, type, value, unresolved, errorLines); - if (interactive()) { + if (resolve) { + String resolutionErrors = feedback.format("resolve", fcase, action, update, + resolution, unrcnt, errcnt, + name, type, value, unresolved, errorLines); + if (!resolutionErrors.trim().isEmpty()) { + hard(" %s", resolutionErrors); + } + } else if (interactive()) { + String display = feedback.format(fcase, action, update, + resolution, unrcnt, errcnt, + name, type, value, unresolved, errorLines); cmdout.print(display); } } diff --git a/langtools/src/jdk.jshell/share/classes/jdk/jshell/JShell.java b/langtools/src/jdk.jshell/share/classes/jdk/jshell/JShell.java index f3348b11b5d3be80690a1a7fde3c0f26a11738b6..b9c7b9a34398772c239105a81b08c6cb95c3382b 100644 --- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/JShell.java +++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/JShell.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -44,8 +44,10 @@ import java.util.ResourceBundle; import java.util.function.BiFunction; import java.util.function.Consumer; +import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Stream; +import javax.tools.StandardJavaFileManager; import jdk.internal.jshell.debug.InternalDebugControl; import jdk.jshell.Snippet.Status; import jdk.jshell.spi.ExecutionControl.EngineTerminationException; @@ -92,6 +94,7 @@ public class JShell implements AutoCloseable { final BiFunction idGenerator; final List extraRemoteVMOptions; final List extraCompilerOptions; + final Function fileManagerMapping; private int nextKeyIndex = 1; @@ -115,6 +118,7 @@ public class JShell implements AutoCloseable { this.idGenerator = b.idGenerator; this.extraRemoteVMOptions = b.extraRemoteVMOptions; this.extraCompilerOptions = b.extraCompilerOptions; + this.fileManagerMapping = b.fileManagerMapping; try { if (b.executionControlProvider != null) { executionControl = b.executionControlProvider.generate(new ExecutionEnvImpl(), @@ -171,6 +175,7 @@ public class JShell implements AutoCloseable { ExecutionControlProvider executionControlProvider; Map executionControlParameters; String executionControlSpec; + Function fileManagerMapping; Builder() { } @@ -364,6 +369,28 @@ public class JShell implements AutoCloseable { return this; } + /** + * Configure the {@code FileManager} to be used by compilation and + * source analysis. + * If not set or passed null, the compiler's standard file manager will + * be used (identity mapping). + * For use in special applications where the compiler's normal file + * handling needs to be overridden. See the file manager APIs for more + * information. + * The file manager input enables forwarding file managers, if this + * is not needed, the incoming file manager can be ignored (constant + * function). + * + * @param mapping a function that given the compiler's standard file + * manager, returns a file manager to use + * @return the {@code Builder} instance (for use in chained + * initialization) + */ + public Builder fileManager(Function mapping) { + this.fileManagerMapping = mapping; + return this; + } + /** * Builds a JShell state engine. This is the entry-point to all JShell * functionality. This creates a remote process for execution. It is @@ -501,6 +528,7 @@ public class JShell implements AutoCloseable { * @throws IllegalStateException if this {@code JShell} instance is closed. */ public void addToClasspath(String path) { + checkIfAlive(); // Compiler taskFactory.addToClasspath(path); // Runtime @@ -543,17 +571,7 @@ public class JShell implements AutoCloseable { */ @Override public void close() { - if (!closed) { - closeDown(); - try { - executionControl().close(); - } catch (Throwable ex) { - // don't care about exceptions on close - } - if (sourceCodeAnalysis != null) { - sourceCodeAnalysis.close(); - } - } + closeDown(); } /** @@ -826,6 +844,15 @@ public class JShell implements AutoCloseable { } catch (Throwable thr) { // Don't care about dying exceptions } + try { + executionControl().close(); + } catch (Throwable ex) { + // don't care about exceptions on close + } + if (sourceCodeAnalysis != null) { + sourceCodeAnalysis.close(); + } + InternalDebugControl.release(this); } } diff --git a/langtools/src/jdk.jshell/share/classes/jdk/jshell/MemoryFileManager.java b/langtools/src/jdk.jshell/share/classes/jdk/jshell/MemoryFileManager.java index 82e1b954fdb3905b494badb544a47b9cc7f56b93..e426e0de29d3687fc59b5f47c9970ddbacae6508 100644 --- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/MemoryFileManager.java +++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/MemoryFileManager.java @@ -165,7 +165,9 @@ class MemoryFileManager implements JavaFileManager { } public MemoryFileManager(StandardJavaFileManager standardManager, JShell proc) { - this.stdFileManager = standardManager; + this.stdFileManager = proc.fileManagerMapping != null + ? proc.fileManagerMapping.apply(standardManager) + : standardManager; this.proc = proc; } @@ -185,6 +187,7 @@ class MemoryFileManager implements JavaFileManager { } // Make compatible with Jigsaw + @Override public String inferModuleName(Location location) { try { if (inferModuleNameMethod == null) { @@ -203,6 +206,7 @@ class MemoryFileManager implements JavaFileManager { } // Make compatible with Jigsaw + @Override public Iterable> listLocationsForModules(Location location) throws IOException { try { if (listLocationsForModulesMethod == null) { diff --git a/langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/JdiDefaultExecutionControl.java b/langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/JdiDefaultExecutionControl.java index bce34fe1179f5ed33f89c0d7a16ba533d377aa0d..18e10aafee7770380815120998d76c7e8f27ffe8 100644 --- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/JdiDefaultExecutionControl.java +++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/JdiDefaultExecutionControl.java @@ -33,6 +33,7 @@ import java.net.InetAddress; import java.net.ServerSocket; import java.net.Socket; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -97,7 +98,8 @@ public class JdiDefaultExecutionControl extends JdiExecutionControl { // Set-up the JDI connection JdiInitiator jdii = new JdiInitiator(port, - env.extraRemoteVMOptions(), remoteAgent, isLaunch, host, timeout); + env.extraRemoteVMOptions(), remoteAgent, isLaunch, host, + timeout, Collections.emptyMap()); VirtualMachine vm = jdii.vm(); Process process = jdii.process(); diff --git a/langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/JdiInitiator.java b/langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/JdiInitiator.java index 127b332a77686fe90a2aa33a782a5c3218c30ed2..d53cc81ba43faaf19cff4342bb4ddef621d8b611 100644 --- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/JdiInitiator.java +++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/execution/JdiInitiator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016,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 @@ -66,16 +66,20 @@ public class JdiInitiator { * Start the remote agent and establish a JDI connection to it. * * @param port the socket port for (non-JDI) commands - * @param remoteVMOptions any user requested VM options + * @param remoteVMOptions any user requested VM command-line options * @param remoteAgent full class name of remote agent to launch * @param isLaunch does JDI do the launch? That is, LaunchingConnector, * otherwise we start explicitly and use ListeningConnector * @param host explicit hostname to use, if null use discovered * hostname, applies to listening only (!isLaunch) - * @param timeout the start-up time-out in milliseconds + * @param timeout the start-up time-out in milliseconds. If zero or negative, + * will not wait thus will timeout immediately if not already started. + * @param customConnectorArgs custom arguments passed to the connector. + * These are JDI com.sun.jdi.connect.Connector arguments. */ public JdiInitiator(int port, List remoteVMOptions, String remoteAgent, - boolean isLaunch, String host, int timeout) { + boolean isLaunch, String host, int timeout, + Map customConnectorArgs) { this.remoteAgent = remoteAgent; this.connectTimeout = (int) (timeout * CONNECT_TIMEOUT_FACTOR); String connectorName @@ -96,6 +100,7 @@ public class JdiInitiator { argumentName2Value.put("localAddress", host); } } + argumentName2Value.putAll(customConnectorArgs); this.connectorArgs = mergeConnectorArgs(connector, argumentName2Value); this.vm = isLaunch ? launchTarget() diff --git a/langtools/src/jdk.jshell/share/classes/jdk/jshell/tool/resources/PRINTING.jsh b/langtools/src/jdk.jshell/share/classes/jdk/jshell/tool/resources/PRINTING.jsh index 52aaea48645e5064212a3a9e7ce0feaaa25a432c..3c6e5f6d164783780b246f00e145ea733ec1b858 100644 --- a/langtools/src/jdk.jshell/share/classes/jdk/jshell/tool/resources/PRINTING.jsh +++ b/langtools/src/jdk.jshell/share/classes/jdk/jshell/tool/resources/PRINTING.jsh @@ -17,5 +17,5 @@ void println(double d) { System.out.println(d); } void println(char s[]) { System.out.println(s); } void println(String s) { System.out.println(s); } void println(Object obj) { System.out.println(obj); } -void printf(Locale l, String format, Object... args) { System.out.printf(l, format, args); } +void printf(java.util.Locale l, String format, Object... args) { System.out.printf(l, format, args); } void printf(String format, Object... args) { System.out.printf(format, args); } diff --git a/langtools/test/jdk/javadoc/doclet/testOverview/TestOverview.java b/langtools/test/jdk/javadoc/doclet/testOverview/TestOverview.java new file mode 100644 index 0000000000000000000000000000000000000000..e4f105b8d8603992bb3e223ceff60ff3c6630f03 --- /dev/null +++ b/langtools/test/jdk/javadoc/doclet/testOverview/TestOverview.java @@ -0,0 +1,81 @@ +/* + * 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 8173302 + * @summary make sure the overview-summary and module-summary pages don't + * don't have the See link, and the overview is copied correctly. + * @library ../lib + * @modules jdk.javadoc/jdk.javadoc.internal.tool + * @build JavadocTester + * @run main TestOverview + */ + +public class TestOverview extends JavadocTester { + + public static void main(String... args) throws Exception { + TestOverview tester = new TestOverview(); + tester.runTests(); + } + + @Test + void test1() { + javadoc("-d", "out-1", + "-doctitle", "Document Title", + "-windowtitle", "Window Title", + "-overview", testSrc("overview.html"), + "-sourcepath", testSrc("src"), + "p1", "p2"); + checkExit(Exit.OK); + checkOutput("overview-summary.html", true, + "
\n" + + "

Document Title

\n" + + "
\n" + + "
\n" + + "
This is line1. This is line 2.
\n" + + "
\n" + + "
" + ); + } + + @Test + void test2() { + javadoc("-d", "out-2", + "-doctitle", "Document Title", + "-windowtitle", "Window Title", + "-overview", testSrc("overview.html"), + "-sourcepath", testSrc("msrc"), + "p1", "p2"); + checkExit(Exit.OK); + checkOutput("overview-summary.html", true, + "
\n" + + "

Document Title

\n" + + "
\n" + + "
\n" + + "
This is line1. This is line 2.
\n" + + "
\n" + + "
" + ); + } +} diff --git a/langtools/test/jdk/javadoc/doclet/testOverview/msrc/module-info.java b/langtools/test/jdk/javadoc/doclet/testOverview/msrc/module-info.java new file mode 100644 index 0000000000000000000000000000000000000000..c5d6328c3da4021d55746f786aeb76380ff1deae --- /dev/null +++ b/langtools/test/jdk/javadoc/doclet/testOverview/msrc/module-info.java @@ -0,0 +1,31 @@ +/* + * 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. + */ + +/** + * Test module acme. + */ +module acme { + exports p1; +} diff --git a/langtools/test/jdk/javadoc/doclet/testOverview/msrc/p1/C.java b/langtools/test/jdk/javadoc/doclet/testOverview/msrc/p1/C.java new file mode 100644 index 0000000000000000000000000000000000000000..db9ab5db9196cf03f094e271d5cb1ff69a1c86e7 --- /dev/null +++ b/langtools/test/jdk/javadoc/doclet/testOverview/msrc/p1/C.java @@ -0,0 +1,26 @@ +/* + * 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. + */ + +package p1; + +public class C {} diff --git a/langtools/test/jdk/javadoc/doclet/testOverview/msrc/p2/C2.java b/langtools/test/jdk/javadoc/doclet/testOverview/msrc/p2/C2.java new file mode 100644 index 0000000000000000000000000000000000000000..65039aa6be7eb52bdf444a1f27aa1049fa0d3b39 --- /dev/null +++ b/langtools/test/jdk/javadoc/doclet/testOverview/msrc/p2/C2.java @@ -0,0 +1,26 @@ +/* + * 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. + */ + +package p2; + +public class C2 {} diff --git a/langtools/test/jdk/javadoc/doclet/testOverview/overview.html b/langtools/test/jdk/javadoc/doclet/testOverview/overview.html new file mode 100644 index 0000000000000000000000000000000000000000..07351cdc86161069117277a4727c9979cfbcc741 --- /dev/null +++ b/langtools/test/jdk/javadoc/doclet/testOverview/overview.html @@ -0,0 +1,6 @@ + + + + This is line1. This is line 2. + + diff --git a/langtools/test/jdk/javadoc/doclet/testOverview/src/p1/C.java b/langtools/test/jdk/javadoc/doclet/testOverview/src/p1/C.java new file mode 100644 index 0000000000000000000000000000000000000000..db9ab5db9196cf03f094e271d5cb1ff69a1c86e7 --- /dev/null +++ b/langtools/test/jdk/javadoc/doclet/testOverview/src/p1/C.java @@ -0,0 +1,26 @@ +/* + * 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. + */ + +package p1; + +public class C {} diff --git a/langtools/test/jdk/javadoc/doclet/testOverview/src/p2/C2.java b/langtools/test/jdk/javadoc/doclet/testOverview/src/p2/C2.java new file mode 100644 index 0000000000000000000000000000000000000000..65039aa6be7eb52bdf444a1f27aa1049fa0d3b39 --- /dev/null +++ b/langtools/test/jdk/javadoc/doclet/testOverview/src/p2/C2.java @@ -0,0 +1,26 @@ +/* + * 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. + */ + +package p2; + +public class C2 {} diff --git a/langtools/test/jdk/javadoc/doclet/testSearch/TestSearch.java b/langtools/test/jdk/javadoc/doclet/testSearch/TestSearch.java index daceff16a6f93cebdf398aaa5d5cc443a52960b0..7f58063694e9d226ba89382c14b49a98be9bddd5 100644 --- a/langtools/test/jdk/javadoc/doclet/testSearch/TestSearch.java +++ b/langtools/test/jdk/javadoc/doclet/testSearch/TestSearch.java @@ -23,7 +23,7 @@ /* * @test - * @bug 8141492 8071982 8141636 8147890 8166175 + * @bug 8141492 8071982 8141636 8147890 8166175 8168965 * @summary Test the search feature of javadoc. * @author bpatel * @library ../lib @@ -486,6 +486,9 @@ public class TestSearch extends JavadocTester { checkOutput("search.js", true, "camelCaseRegexp = ($.ui.autocomplete.escapeRegex(request.term)).split(/(?=[A-Z])/).join(\"([a-z0-9_$]*?)\");", "var camelCaseMatcher = new RegExp(\"^\" + camelCaseRegexp);", - "camelCaseMatcher.test(item.l)"); + "camelCaseMatcher.test(item.l)", + "var secondaryresult = new Array();", + "function nestedName(e) {", + "function sortAndConcatResults(a1, a2) {"); } } diff --git a/langtools/test/jdk/jshell/FileManagerTest.java b/langtools/test/jdk/jshell/FileManagerTest.java new file mode 100644 index 0000000000000000000000000000000000000000..9e4f063da9ddbaa41df80190934b4299a4356e91 --- /dev/null +++ b/langtools/test/jdk/jshell/FileManagerTest.java @@ -0,0 +1,114 @@ +/* + * 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 8173845 + * @summary test custom file managers + * @build KullaTesting TestingInputStream + * @run testng FileManagerTest + */ + + +import java.io.File; +import java.io.IOException; + +import java.util.Set; +import javax.tools.ForwardingJavaFileManager; +import javax.tools.JavaFileObject; +import javax.tools.JavaFileObject.Kind; +import javax.tools.StandardJavaFileManager; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertTrue; + +@Test +public class FileManagerTest extends KullaTesting { + + boolean encountered; + + class MyFileManager extends ForwardingJavaFileManager + implements StandardJavaFileManager { + + protected MyFileManager(StandardJavaFileManager fileManager) { + super(fileManager); + } + + @Override + public Iterable list(Location location, + String packageName, + Set kinds, + boolean recurse) + throws IOException { + //System.out.printf("list(%s, %s, %s, %b)\n", + // location, packageName, kinds, recurse); + if (packageName.equals("java.lang.reflect")) { + encountered = true; + } + return fileManager.list(location, packageName, kinds, recurse); + } + + @Override + public Iterable getJavaFileObjectsFromFiles(Iterable files) { + return fileManager.getJavaFileObjectsFromFiles(files); + } + + @Override + public Iterable getJavaFileObjects(File... files) { + return fileManager.getJavaFileObjects(files); + } + + @Override + public Iterable getJavaFileObjectsFromStrings(Iterable names) { + return fileManager.getJavaFileObjectsFromStrings(names); + } + + @Override + public Iterable getJavaFileObjects(String... names) { + return fileManager.getJavaFileObjects(names); + } + + @Override + public void setLocation(Location location, Iterable files) throws IOException { + fileManager.setLocation(location, files); + } + + @Override + public Iterable getLocation(Location location) { + return fileManager.getLocation(location); + } + + } + + @BeforeMethod + @Override + public void setUp() { + setUp(b -> b.fileManager(fm -> new MyFileManager(fm))); + } + + public void testSnippetMemberAssignment() { + assertEval("java.lang.reflect.Array.get(new String[1], 0) == null"); + assertTrue(encountered, "java.lang.reflect not encountered"); + } + +} diff --git a/langtools/test/jdk/jshell/MyExecutionControl.java b/langtools/test/jdk/jshell/MyExecutionControl.java index 15b0e94f5e2f6f151219b76e7f8756827c674c11..8493638db576cc5a0773f532b255640d8ea15991 100644 --- a/langtools/test/jdk/jshell/MyExecutionControl.java +++ b/langtools/test/jdk/jshell/MyExecutionControl.java @@ -29,6 +29,7 @@ import java.io.OutputStream; import java.net.ServerSocket; import java.net.Socket; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -78,7 +79,7 @@ class MyExecutionControl extends JdiExecutionControl { + System.getProperty("path.separator") + System.getProperty("user.dir")); JdiInitiator jdii = new JdiInitiator(port, - opts, REMOTE_AGENT, true, null, TIMEOUT); + opts, REMOTE_AGENT, true, null, TIMEOUT, Collections.emptyMap()); VirtualMachine vm = jdii.vm(); Process process = jdii.process(); diff --git a/langtools/test/jdk/jshell/ReplToolTesting.java b/langtools/test/jdk/jshell/ReplToolTesting.java index 3f776eebb2177938ac78ca3ec3e31dbead60438f..5c31292fff311259c67c9e2ce72e196e8adb7c01 100644 --- a/langtools/test/jdk/jshell/ReplToolTesting.java +++ b/langtools/test/jdk/jshell/ReplToolTesting.java @@ -72,27 +72,27 @@ public class ReplToolTesting { final static List START_UP_CMD_METHOD = Stream.of() .collect(toList()); final static List PRINTING_CMD_METHOD = Stream.of( - "| print (boolean)void", - "| print (char)void", - "| print (int)void", - "| print (long)void", - "| print (float)void", - "| print (double)void", - "| print (char s[])void", - "| print (String)void", - "| print (Object)void", - "| println ()void", - "| println (boolean)void", - "| println (char)void", - "| println (int)void", - "| println (long)void", - "| println (float)void", - "| println (double)void", - "| println (char s[])void", - "| println (String)void", - "| println (Object)void", - "| printf (Locale,String,Object...)void", - "| printf (String,Object...)void") + "| void print(boolean)", + "| void print(char)", + "| void print(int)", + "| void print(long)", + "| void print(float)", + "| void print(double)", + "| void print(char s[])", + "| void print(String)", + "| void print(Object)", + "| void println()", + "| void println(boolean)", + "| void println(char)", + "| void println(int)", + "| void println(long)", + "| void println(float)", + "| void println(double)", + "| void println(char s[])", + "| void println(String)", + "| void println(Object)", + "| void printf(java.util.Locale,String,Object...)", + "| void printf(String,Object...)") .collect(toList()); final static List START_UP = Collections.unmodifiableList( Stream.concat(START_UP_IMPORTS.stream(), START_UP_METHODS.stream()) @@ -152,6 +152,7 @@ public class ReplToolTesting { return s -> { List lines = Stream.of(s.split("\n")) .filter(l -> !l.isEmpty()) + .filter(l -> !l.startsWith("| ")) // error/unresolved info .collect(Collectors.toList()); assertEquals(lines.size(), set.size(), message + " : expected: " + set.keySet() + "\ngot:\n" + lines); for (String line : lines) { @@ -664,7 +665,12 @@ public class ReplToolTesting { @Override public String toString() { - return String.format("%s %s", name, signature); + int i = signature.lastIndexOf(")") + 1; + if (i <= 0) { + return String.format("%s", name); + } else { + return String.format("%s %s%s", signature.substring(i), name, signature.substring(0, i)); + } } } diff --git a/langtools/test/jdk/jshell/ToolReloadTest.java b/langtools/test/jdk/jshell/ToolReloadTest.java index 770b017054213342dd517814dadee0c35f33040a..f3d008f07540ab47144730b4c9f4de0e8c335af6 100644 --- a/langtools/test/jdk/jshell/ToolReloadTest.java +++ b/langtools/test/jdk/jshell/ToolReloadTest.java @@ -92,8 +92,8 @@ public class ToolReloadTest extends ReplToolTesting { test(false, new String[]{"--no-startup"}, a -> assertVariable(a, "int", "a"), a -> dropVariable(a, "/dr 1", "int a = 0", "| dropped variable a"), - a -> assertMethod(a, "int b() { return 0; }", "()I", "b"), - a -> dropMethod(a, "/drop b", "b ()I", "| dropped method b()"), + a -> assertMethod(a, "int b() { return 0; }", "()int", "b"), + a -> dropMethod(a, "/drop b", "int b()", "| dropped method b()"), a -> assertClass(a, "class A {}", "class", "A"), a -> dropClass(a, "/dr A", "class A", "| dropped class A"), a -> assertCommand(a, "/reload", @@ -115,8 +115,8 @@ public class ToolReloadTest extends ReplToolTesting { test(false, new String[]{"--no-startup"}, a -> assertVariable(a, "int", "a"), a -> dropVariable(a, "/dr 1", "int a = 0", "| dropped variable a"), - a -> assertMethod(a, "int b() { return 0; }", "()I", "b"), - a -> dropMethod(a, "/drop b", "b ()I", "| dropped method b()"), + a -> assertMethod(a, "int b() { return 0; }", "()int", "b"), + a -> dropMethod(a, "/drop b", "int b()", "| dropped method b()"), a -> assertClass(a, "class A {}", "class", "A"), a -> dropClass(a, "/dr A", "class A", "| dropped class A"), a -> assertCommand(a, "/reload -quiet", diff --git a/langtools/test/jdk/jshell/ToolSimpleTest.java b/langtools/test/jdk/jshell/ToolSimpleTest.java index ff29a47a92f7a617466d6dcd737e5e4313de4a6a..8655d049ac7725f94a0378a01716ad0cfa49750f 100644 --- a/langtools/test/jdk/jshell/ToolSimpleTest.java +++ b/langtools/test/jdk/jshell/ToolSimpleTest.java @@ -23,7 +23,7 @@ /* * @test - * @bug 8153716 8143955 8151754 8150382 8153920 8156910 8131024 8160089 8153897 8167128 8154513 8170015 8170368 8172102 8172103 8165405 8173073 8173848 + * @bug 8153716 8143955 8151754 8150382 8153920 8156910 8131024 8160089 8153897 8167128 8154513 8170015 8170368 8172102 8172103 8165405 8173073 8173848 8174041 8173916 8174028 * @summary Simple jshell tool tests * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.main @@ -238,8 +238,8 @@ public class ToolSimpleTest extends ReplToolTesting { test(false, new String[]{"--no-startup"}, a -> assertVariable(a, "int", "a"), a -> dropVariable(a, "/drop 1", "int a = 0", "| dropped variable a"), - a -> assertMethod(a, "int b() { return 0; }", "()I", "b"), - a -> dropMethod(a, "/drop 2", "b ()I", "| dropped method b()"), + a -> assertMethod(a, "int b() { return 0; }", "()int", "b"), + a -> dropMethod(a, "/drop 2", "int b()", "| dropped method b()"), a -> assertClass(a, "class A {}", "class", "A"), a -> dropClass(a, "/drop 3", "class A", "| dropped class A"), a -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"), @@ -255,8 +255,8 @@ public class ToolSimpleTest extends ReplToolTesting { test(false, new String[]{"--no-startup"}, a -> assertVariable(a, "int", "a"), a -> dropVariable(a, "/drop a", "int a = 0", "| dropped variable a"), - a -> assertMethod(a, "int b() { return 0; }", "()I", "b"), - a -> dropMethod(a, "/drop b", "b ()I", "| dropped method b()"), + a -> assertMethod(a, "int b() { return 0; }", "()int", "b"), + a -> dropMethod(a, "/drop b", "int b()", "| dropped method b()"), a -> assertClass(a, "class A {}", "class", "A"), a -> dropClass(a, "/drop A", "class A", "| dropped class A"), a -> assertCommandCheckOutput(a, "/vars", assertVariables()), @@ -466,10 +466,50 @@ public class ToolSimpleTest extends ReplToolTesting { a -> assertCommandCheckOutput(a, "/methods print println printf", s -> checkLineToList(s, printingMethodList)), a -> assertCommandOutputStartsWith(a, "/methods g", - "| g ()void"), + "| void g()"), a -> assertCommandOutputStartsWith(a, "/methods f", - "| f ()int\n" + - "| f (int)void") + "| int f()\n" + + "| void f(int)") + ); + } + + @Test + public void testMethodsWithErrors() { + test(new String[]{"--no-startup"}, + a -> assertCommand(a, "double m(int x) { return x; }", + "| created method m(int)"), + a -> assertCommand(a, "GARBAGE junk() { return TRASH; }", + "| created method junk(), however, it cannot be referenced until class GARBAGE, and variable TRASH are declared"), + a -> assertCommand(a, "int w = 5;", + "w ==> 5"), + a -> assertCommand(a, "int tyer() { return w; }", + "| created method tyer()"), + a -> assertCommand(a, "String w = \"hi\";", + "w ==> \"hi\""), + a -> assertCommand(a, "/methods", + "| double m(int)\n" + + "| GARBAGE junk()\n" + + "| which cannot be referenced until class GARBAGE, and variable TRASH are declared\n" + + "| int tyer()\n" + + "| which cannot be invoked until this error is corrected: \n" + + "| incompatible types: java.lang.String cannot be converted to int\n" + + "| int tyer() { return w; }\n" + + "| ^\n") + ); + } + + @Test + public void testTypesWithErrors() { + test(new String[]{"--no-startup"}, + a -> assertCommand(a, "class C extends NONE { int x; }", + "| created class C, however, it cannot be referenced until class NONE is declared"), + a -> assertCommand(a, "class D { void m() { System.out.println(nada); } }", + "| created class D, however, it cannot be instanciated or its methods invoked until variable nada is declared"), + a -> assertCommand(a, "/types", + "| class C\n" + + "| which cannot be referenced until class NONE is declared\n" + + "| class D\n" + + "| which cannot be instanciated or its methods invoked until variable nada is declared\n") ); } diff --git a/langtools/test/tools/javac/T4093617/T4093617.java b/langtools/test/tools/javac/T4093617/T4093617.java index 5162097a8cbf78a46d52818b780d48f2292c50f2..8fa7dfaca559f5c7c0d3bec9a06b078037e6e0d6 100644 --- a/langtools/test/tools/javac/T4093617/T4093617.java +++ b/langtools/test/tools/javac/T4093617/T4093617.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -26,6 +26,6 @@ * @bug 4093617 * @summary Object has no superclass * @author Peter von der Ah\u00e9 - * @compile/module=java.base/fail/ref=T4093617.out -XDrawDiagnostics Object.java + * @compile/module=java.base/fail/ref=T4093617.out -XDrawDiagnostics java/lang/Object.java */ diff --git a/langtools/test/tools/javac/T4093617/java.base/Object.java b/langtools/test/tools/javac/T4093617/java.base/java/lang/Object.java similarity index 100% rename from langtools/test/tools/javac/T4093617/java.base/Object.java rename to langtools/test/tools/javac/T4093617/java.base/java/lang/Object.java diff --git a/langtools/test/tools/javac/T6234077.out b/langtools/test/tools/javac/T6234077.out index 2a77ac7e7f734e6c03436b87084e7792204aabaa..930d00d452a884171c39415774808ccff4108dd9 100644 --- a/langtools/test/tools/javac/T6234077.out +++ b/langtools/test/tools/javac/T6234077.out @@ -1,2 +1,2 @@ -T6234077.java:7:8: compiler.err.class.public.should.be.in.file: Foo +T6234077.java:7:8: compiler.err.class.public.should.be.in.file: kindname.class, Foo 1 error diff --git a/langtools/test/tools/javac/T8173955/MessageForClassTest.java b/langtools/test/tools/javac/T8173955/MessageForClassTest.java new file mode 100644 index 0000000000000000000000000000000000000000..5d2e256550a37c075d0a3ba09da7874e3070f8f9 --- /dev/null +++ b/langtools/test/tools/javac/T8173955/MessageForClassTest.java @@ -0,0 +1,8 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8174027 + * @summary error message should adapt to the corresponding top level element + * @compile/fail/ref=MessageForClassTest.out -XDrawDiagnostics MessageForClassTest.java + */ + +public class MessageForClassTest_ {} diff --git a/langtools/test/tools/javac/T8173955/MessageForClassTest.out b/langtools/test/tools/javac/T8173955/MessageForClassTest.out new file mode 100644 index 0000000000000000000000000000000000000000..454fca69ee8481d7db797faa9156805eef65601d --- /dev/null +++ b/langtools/test/tools/javac/T8173955/MessageForClassTest.out @@ -0,0 +1,2 @@ +MessageForClassTest.java:8:8: compiler.err.class.public.should.be.in.file: kindname.class, MessageForClassTest_ +1 error diff --git a/langtools/test/tools/javac/T8173955/MessageForEnumTest.java b/langtools/test/tools/javac/T8173955/MessageForEnumTest.java new file mode 100644 index 0000000000000000000000000000000000000000..343ef77b0706ef7e184bfcf8384eb81945a652a9 --- /dev/null +++ b/langtools/test/tools/javac/T8173955/MessageForEnumTest.java @@ -0,0 +1,8 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8174027 + * @summary error message should adapt to the corresponding top level element + * @compile/fail/ref=MessageForEnumTest.out -XDrawDiagnostics MessageForEnumTest.java + */ + +public enum MessageForEnumTest_ {} diff --git a/langtools/test/tools/javac/T8173955/MessageForEnumTest.out b/langtools/test/tools/javac/T8173955/MessageForEnumTest.out new file mode 100644 index 0000000000000000000000000000000000000000..ae9f60e1f0da51ef47a26100b1abcfd22746d38a --- /dev/null +++ b/langtools/test/tools/javac/T8173955/MessageForEnumTest.out @@ -0,0 +1,2 @@ +MessageForEnumTest.java:8:8: compiler.err.class.public.should.be.in.file: kindname.enum, MessageForEnumTest_ +1 error diff --git a/langtools/test/tools/javac/T8173955/MessageForInterfaceTest.java b/langtools/test/tools/javac/T8173955/MessageForInterfaceTest.java new file mode 100644 index 0000000000000000000000000000000000000000..563c58bedb57ff203d7c6cf53dbcf73e60a11376 --- /dev/null +++ b/langtools/test/tools/javac/T8173955/MessageForInterfaceTest.java @@ -0,0 +1,8 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8174027 + * @summary error message should adapt to the corresponding top level element + * @compile/fail/ref=MessageForInterfaceTest.out -XDrawDiagnostics MessageForInterfaceTest.java + */ + +public interface MessageForInterfaceTest_ {} diff --git a/langtools/test/tools/javac/T8173955/MessageForInterfaceTest.out b/langtools/test/tools/javac/T8173955/MessageForInterfaceTest.out new file mode 100644 index 0000000000000000000000000000000000000000..88cd9cd18aef114e16150783f885096b55992ca1 --- /dev/null +++ b/langtools/test/tools/javac/T8173955/MessageForInterfaceTest.out @@ -0,0 +1,2 @@ +MessageForInterfaceTest.java:8:8: compiler.err.class.public.should.be.in.file: kindname.interface, MessageForInterfaceTest_ +1 error diff --git a/langtools/test/tools/javac/doclint/NPEDuplicateClassNamesTest.java b/langtools/test/tools/javac/doclint/NPEDuplicateClassNamesTest.java new file mode 100644 index 0000000000000000000000000000000000000000..f55bf9049526e2a17325049f0ca41443a2369491 --- /dev/null +++ b/langtools/test/tools/javac/doclint/NPEDuplicateClassNamesTest.java @@ -0,0 +1,97 @@ +/* + * 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 8174073 + * @summary NPE caused by link reference to class + * @modules jdk.compiler/com.sun.tools.javac.api + * jdk.compiler/com.sun.tools.javac.main + * @library /tools/lib + * @build toolbox.JavacTask toolbox.TestRunner toolbox.ToolBox + * @run main NPEDuplicateClassNamesTest + */ + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; + +import toolbox.JavacTask; +import toolbox.Task; +import toolbox.TestRunner; +import toolbox.ToolBox; + +public class NPEDuplicateClassNamesTest extends TestRunner { + + public static void main(String... args) throws Exception { + NPEDuplicateClassNamesTest t = new NPEDuplicateClassNamesTest(); + t.runTests(); + } + + private final ToolBox tb = new ToolBox(); + private final String class1 = + "package com;\n" + + "/***/\n" + + "public class MyClass {}"; + private final String class2 = + "package com;\n" + + "/**\n" + + " * The following link tag causes a NullPointerException: {@link Requirements}. \n" + + " */\n" + + "public class MyClass {}"; + + NPEDuplicateClassNamesTest() throws IOException { + super(System.err); + } + + @Test + public void testDuplicateClassNames() throws IOException { + Path src = Paths.get("src"); + Path one = src.resolve("one"); + Path two = src.resolve("two"); + Path classes = Paths.get("classes"); + Files.createDirectories(classes); + tb.writeJavaFiles(one, class1); + tb.writeJavaFiles(two, class2); + + List expected = Arrays.asList( + "MyClass.java:5:8: compiler.err.duplicate.class: com.MyClass", + "MyClass.java:3:65: compiler.err.proc.messager: reference not found", + "2 errors"); + List output = new JavacTask(tb) + .outdir(classes) + .options("-XDrawDiagnostics", "-Xdoclint:all", "-XDdev") + .files(tb.findJavaFiles(src)) + .run(Task.Expect.FAIL) + .writeAll() + .getOutputLines(Task.OutputKind.DIRECT); + + if (!Objects.equals(output, expected)) { + throw new IllegalStateException("incorrect output; actual=" + output + "; expected=" + expected); + } + } +} diff --git a/langtools/test/tools/javac/generics/inference/8174249/T8174249a.java b/langtools/test/tools/javac/generics/inference/8174249/T8174249a.java new file mode 100644 index 0000000000000000000000000000000000000000..80ebfa48d753b13f6d237f88179e9a4abdda1dcd --- /dev/null +++ b/langtools/test/tools/javac/generics/inference/8174249/T8174249a.java @@ -0,0 +1,54 @@ +/* + * 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. + */ + +/* + * @test + * @bug 8174249 + * @summary Regression in generic method unchecked calls + * @compile T8174249a.java + */ + +import java.util.ArrayList; +import java.util.Collection; + +class T8174249a { + static T foo(Class c, Collection baz) { +return null; + } + + static void bar(String c) { } + + void test() { + // this works + bar(foo(String.class, new ArrayList())); + + // this works with a warning + String s = foo(String.class, new ArrayList()); + bar(s); + + // this causes an error on JDK9 but should work + bar(foo(String.class, new ArrayList())); + } +} diff --git a/langtools/test/tools/javac/generics/inference/8174249/T8174249b.java b/langtools/test/tools/javac/generics/inference/8174249/T8174249b.java new file mode 100644 index 0000000000000000000000000000000000000000..a7f175fc0d89be99568cd4e6bbe91dc548c24257 --- /dev/null +++ b/langtools/test/tools/javac/generics/inference/8174249/T8174249b.java @@ -0,0 +1,59 @@ +/* + * 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. + */ + +/* + * @test + * @bug 8174249 + * @summary Regression in generic method unchecked calls + * @compile T8174249b.java + */ + +import java.util.*; + +class T8174249b { + + static void cs(Collection cs) {} + + void test1(Collection c) { + cs(rawCollection((Class)null)); + Collection cs1 = rawCollection((Class)null); + } + + void test2(Collection c) { + cs(rawCollection2((Class)null)); + Collection cs2 = rawCollection2((Class)null); + } + + void test3(Collection c) { + cs(rawCollection3((Class)null)); + Collection cs3 = rawCollection2((Class)null); + } + + Collection rawCollection(Class cs) { return null; } + + Collection rawCollection2(Class cs) { return null; } + + Collection rawCollection3(Class cs) { return null; } +} diff --git a/langtools/test/tools/javac/modules/ModuleInfoTest.java b/langtools/test/tools/javac/modules/ModuleInfoTest.java index 3d08be1ceccea8dd54f50865c882ae9d62caa0c6..0c816f40fbb355cb40a9447850747f82d4848ce3 100644 --- a/langtools/test/tools/javac/modules/ModuleInfoTest.java +++ b/langtools/test/tools/javac/modules/ModuleInfoTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -94,7 +94,7 @@ public class ModuleInfoTest extends ModuleTestBase { .writeAll() .getOutput(Task.OutputKind.DIRECT); - if (!log.contains("module-info.java:1:8: compiler.err.class.public.should.be.in.file: C")) + if (!log.contains("module-info.java:1:8: compiler.err.class.public.should.be.in.file: kindname.class, C")) throw new Exception("expected output not found"); } diff --git a/langtools/test/tools/javac/redefineObject/Object1-test.java b/langtools/test/tools/javac/redefineObject/Object1-test.java index a654ecee5d5fe36a6ce86fed7fc947e8a6ab5df5..dae9667452d807bddfea579e54b99f1fadd8f08b 100644 --- a/langtools/test/tools/javac/redefineObject/Object1-test.java +++ b/langtools/test/tools/javac/redefineObject/Object1-test.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -27,6 +27,6 @@ * @summary java.lang.Object can't be redefined without crashing javac * @author gafter * - * @compile/module=java.base/fail/ref=Object1.out -XDrawDiagnostics Object1.java + * @compile/module=java.base/fail/ref=Object1.out -XDrawDiagnostics java/lang/Object1.java */ diff --git a/langtools/test/tools/javac/redefineObject/Object2-test.java b/langtools/test/tools/javac/redefineObject/Object2-test.java index 59eb4b670df267d902051bfc2fc3adf2d0505999..8eb033b5cfaba772e516ce880f170e7406779a0a 100644 --- a/langtools/test/tools/javac/redefineObject/Object2-test.java +++ b/langtools/test/tools/javac/redefineObject/Object2-test.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -27,5 +27,5 @@ * @summary java.lang.Object can't be redefined without crashing javac * @author gafter * - * @compile/module=java.base/fail/ref=Object2.out -XDrawDiagnostics Object2.java + * @compile/module=java.base/fail/ref=Object2.out -XDrawDiagnostics java/lang/Object2.java */ diff --git a/langtools/test/tools/javac/redefineObject/java.base/Object1.java b/langtools/test/tools/javac/redefineObject/java.base/java/lang/Object1.java similarity index 100% rename from langtools/test/tools/javac/redefineObject/java.base/Object1.java rename to langtools/test/tools/javac/redefineObject/java.base/java/lang/Object1.java diff --git a/langtools/test/tools/javac/redefineObject/java.base/Object2.java b/langtools/test/tools/javac/redefineObject/java.base/java/lang/Object2.java similarity index 100% rename from langtools/test/tools/javac/redefineObject/java.base/Object2.java rename to langtools/test/tools/javac/redefineObject/java.base/java/lang/Object2.java