提交 3062587f 编写于 作者: L lana

Merge

/*
* 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<AttrContext> 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());
......
......@@ -3994,11 +3994,17 @@ public class Attr extends JCTree.Visitor {
rs.methodArguments(argtypes.map(checkDeferredMap)),
kindName(sym.location()),
sym.location());
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) &&
sym.type.getReturnType().containsAny(((ForAll)sym.type).tvars)) ?
......
/*
* 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<AttrContext> getClassEnv(TypeSymbol sym) {
Env<AttrContext> localEnv = getEnv(sym);
if (localEnv == null) return null;
Env<AttrContext> 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() &&
......
......@@ -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)
......
......@@ -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.
......
/*
* 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
......
/*
* 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
......
/*
* 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;
......
......@@ -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.
*
......
......@@ -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<String> 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<String> 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<String> 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*");
}
......
......@@ -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,21 +845,15 @@ 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();
......@@ -864,9 +861,18 @@ public class JShellTool implements MessageHandler {
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
}
}
}
closeState();
}
private EditorSetting configEditor() {
// Read retained editor setting (if any)
......@@ -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<Diag> 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<Diag> 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<Diag> 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<String> 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<Diag> 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<Diag> errors) {
this(ste.snippet(), ste.status(), toAction(ste.status(), ste.previousStatus(), ste.isSignatureChange()), update, value, errors);
DisplayEvent(Snippet sn, Status status, boolean resolve, List<Diag> errors) {
this(sn, status, resolve, FormatAction.USED, FormatWhen.UPDATE, null, errors);
}
DisplayEvent(Snippet sn, Status status, FormatAction action, boolean update, String value, List<Diag> errors) {
private DisplayEvent(Snippet sn, Status status, boolean resolve,
FormatAction action, FormatWhen update, String value, List<Diag> 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),
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);
if (interactive()) {
cmdout.print(display);
}
}
......
/*
* 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<Snippet, Integer, String> idGenerator;
final List<String> extraRemoteVMOptions;
final List<String> extraCompilerOptions;
final Function<StandardJavaFileManager, StandardJavaFileManager> 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<String,String> executionControlParameters;
String executionControlSpec;
Function<StandardJavaFileManager, StandardJavaFileManager> 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<StandardJavaFileManager, StandardJavaFileManager> 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();
}
}
}
/**
......@@ -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);
}
}
......
......@@ -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<Set<Location>> listLocationsForModules(Location location) throws IOException {
try {
if (listLocationsForModulesMethod == null) {
......
......@@ -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();
......
/*
* 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<String> remoteVMOptions, String remoteAgent,
boolean isLaunch, String host, int timeout) {
boolean isLaunch, String host, int timeout,
Map<String, String> 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()
......
......@@ -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); }
/*
* 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,
"<div class=\"header\">\n"
+ "<h1 class=\"title\">Document Title</h1>\n"
+ "</div>\n"
+ "<div class=\"contentContainer\">\n"
+ "<div class=\"block\">This is line1. This is line 2.</div>\n"
+ "</div>\n"
+ "<div class=\"contentContainer\">"
);
}
@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,
"<div class=\"header\">\n"
+ "<h1 class=\"title\">Document Title</h1>\n"
+ "</div>\n"
+ "<div class=\"contentContainer\">\n"
+ "<div class=\"block\">This is line1. This is line 2.</div>\n"
+ "</div>\n"
+ "<div class=\"contentContainer\">"
);
}
}
/*
* 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;
}
/*
* 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 {}
/*
* 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 {}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<body bgcolor="white">
This is line1. This is line 2.
</body>
</html>
/*
* 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 {}
/*
* 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 {}
......@@ -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) {");
}
}
/*
* 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<StandardJavaFileManager>
implements StandardJavaFileManager {
protected MyFileManager(StandardJavaFileManager fileManager) {
super(fileManager);
}
@Override
public Iterable<JavaFileObject> list(Location location,
String packageName,
Set<Kind> 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<? extends JavaFileObject> getJavaFileObjectsFromFiles(Iterable<? extends File> files) {
return fileManager.getJavaFileObjectsFromFiles(files);
}
@Override
public Iterable<? extends JavaFileObject> getJavaFileObjects(File... files) {
return fileManager.getJavaFileObjects(files);
}
@Override
public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) {
return fileManager.getJavaFileObjectsFromStrings(names);
}
@Override
public Iterable<? extends JavaFileObject> getJavaFileObjects(String... names) {
return fileManager.getJavaFileObjects(names);
}
@Override
public void setLocation(Location location, Iterable<? extends File> files) throws IOException {
fileManager.setLocation(location, files);
}
@Override
public Iterable<? extends File> 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");
}
}
......@@ -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();
......
......@@ -72,27 +72,27 @@ public class ReplToolTesting {
final static List<String> START_UP_CMD_METHOD = Stream.<String>of()
.collect(toList());
final static List<String> 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<String> START_UP = Collections.unmodifiableList(
Stream.concat(START_UP_IMPORTS.stream(), START_UP_METHODS.stream())
......@@ -152,6 +152,7 @@ public class ReplToolTesting {
return s -> {
List<String> 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));
}
}
}
......
......@@ -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",
......
......@@ -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")
);
}
......
/*
* 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
*/
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
/*
* @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_ {}
MessageForClassTest.java:8:8: compiler.err.class.public.should.be.in.file: kindname.class, MessageForClassTest_
1 error
/*
* @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_ {}
MessageForEnumTest.java:8:8: compiler.err.class.public.should.be.in.file: kindname.enum, MessageForEnumTest_
1 error
/*
* @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_ {}
MessageForInterfaceTest.java:8:8: compiler.err.class.public.should.be.in.file: kindname.interface, MessageForInterfaceTest_
1 error
/*
* 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<String> 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<String> 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);
}
}
}
/*
* 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> T foo(Class<T> c, Collection<? super T> baz) {
return null;
}
static void bar(String c) { }
void test() {
// this works
bar(foo(String.class, new ArrayList<String>()));
// 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()));
}
}
/*
* 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<String> cs) {}
void test1(Collection c) {
cs(rawCollection((Class)null));
Collection<String> cs1 = rawCollection((Class)null);
}
void test2(Collection c) {
cs(rawCollection2((Class)null));
Collection<String> cs2 = rawCollection2((Class)null);
}
void test3(Collection c) {
cs(rawCollection3((Class)null));
Collection<String> cs3 = rawCollection2((Class)null);
}
Collection<Integer> rawCollection(Class<String> cs) { return null; }
<Z> Collection<Integer> rawCollection2(Class<Z> cs) { return null; }
<Z> Collection<Z> rawCollection3(Class<Z> cs) { return null; }
}
/*
* 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");
}
......
/*
* 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
*/
/*
* 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
*/
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册