This commit is contained in:
Lana Steuck 2015-11-30 13:27:57 -08:00
commit 0379d3dc4f
31 changed files with 397 additions and 389 deletions

View File

@ -241,8 +241,6 @@ public class Analyzer {
}
for (Type t : inferredArgs) {
if (!types.isSameType(t, explicitArgs.head)) {
log.warning(oldTree.clazz, "diamond.redundant.args.1",
oldTree.clazz.type, newTree.clazz.type);
return;
}
explicitArgs = explicitArgs.tail;

View File

@ -931,7 +931,7 @@ public class LambdaToMethod extends TreeTranslator {
private JCExpression makeReceiver(VarSymbol rcvr) {
if (rcvr == null) return null;
JCExpression rcvrExpr = make.Ident(rcvr);
Type rcvrType = tree.sym.enclClass().type;
Type rcvrType = tree.ownerAccessible ? tree.sym.enclClass().type : tree.expr.type;
if (rcvrType == syms.arrayClass.type) {
// Map the receiver type to the actually type, not just "array"
rcvrType = tree.getQualifierExpression().type;

View File

@ -1669,12 +1669,6 @@ compiler.warn.raw.class.use=\
compiler.warn.diamond.redundant.args=\
Redundant type arguments in new expression (use diamond operator instead).
# 0: type, 1: list of type
compiler.warn.diamond.redundant.args.1=\
Redundant type arguments in new expression (use diamond operator instead).\n\
explicit: {0}\n\
inferred: {1}
compiler.warn.potential.lambda.found=\
This anonymous inner class creation can be turned into a lambda expression.

View File

@ -97,8 +97,8 @@ import static java.util.stream.Collectors.toList;
public class JShellTool {
private static final Pattern LINEBREAK = Pattern.compile("\\R");
private static final Pattern HISTORY_ALL_FILENAME = Pattern.compile(
"((?<cmd>(all|history))(\\z|\\p{javaWhitespace}+))?(?<filename>.*)");
private static final Pattern HISTORY_ALL_START_FILENAME = Pattern.compile(
"((?<cmd>(all|history|start))(\\z|\\p{javaWhitespace}+))?(?<filename>.*)");
final InputStream cmdin;
final PrintStream cmdout;
@ -504,15 +504,30 @@ public class JShellTool {
arg = cmd.substring(idx + 1).trim();
cmd = cmd.substring(0, idx);
}
Command command = commands.get(cmd);
if (command == null || command.kind == CommandKind.HELP_ONLY) {
Command[] candidates = findCommand(cmd, c -> c.kind != CommandKind.HELP_ONLY);
if (candidates.length == 0) {
hard("No such command: %s", cmd);
fluff("Type /help for help.");
} else if (candidates.length == 1) {
candidates[0].run.accept(arg);
} else {
command.run.accept(arg);
hard("Command: %s is ambiguous: %s", cmd, Arrays.stream(candidates).map(c -> c.command).collect(Collectors.joining(", ")));
fluff("Type /help for help.");
}
}
private Command[] findCommand(String cmd, Predicate<Command> filter) {
Command exact = commands.get(cmd);
if (exact != null)
return new Command[] {exact};
return commands.values()
.stream()
.filter(filter)
.filter(command -> command.command.startsWith(cmd))
.toArray(size -> new Command[size]);
}
private static Path toPathResolvingUserHome(String pathString) {
if (pathString.replace(File.separatorChar, '/').startsWith("~/"))
return Paths.get(System.getProperty("user.home"), pathString.substring(2));
@ -521,19 +536,19 @@ public class JShellTool {
}
static final class Command {
public final String[] aliases;
public final String command;
public final String params;
public final String description;
public final Consumer<String> run;
public final CompletionProvider completions;
public final CommandKind kind;
public Command(String command, String alias, String params, String description, Consumer<String> run, CompletionProvider completions) {
this(command, alias, params, description, run, completions, CommandKind.NORMAL);
public Command(String command, String params, String description, Consumer<String> run, CompletionProvider completions) {
this(command, params, description, run, completions, CommandKind.NORMAL);
}
public Command(String command, String alias, String params, String description, Consumer<String> run, CompletionProvider completions, CommandKind kind) {
this.aliases = alias != null ? new String[] {command, alias} : new String[] {command};
public Command(String command, String params, String description, Consumer<String> run, CompletionProvider completions, CommandKind kind) {
this.command = command;
this.params = params;
this.description = description;
this.run = run;
@ -582,9 +597,7 @@ public class JShellTool {
private static final CompletionProvider FILE_COMPLETION_PROVIDER = fileCompletions(p -> true);
private final Map<String, Command> commands = new LinkedHashMap<>();
private void registerCommand(Command cmd) {
for (String str : cmd.aliases) {
commands.put(str, cmd);
}
commands.put(cmd.command, cmd);
}
private static CompletionProvider fileCompletions(Predicate<Path> accept) {
return (code, cursor, anchor) -> {
@ -632,7 +645,7 @@ public class JShellTool {
}
private static CompletionProvider saveCompletion() {
CompletionProvider keyCompletion = new FixedCompletionProvider("all ", "history ");
CompletionProvider keyCompletion = new FixedCompletionProvider("all ", "history ", "start ");
return (code, cursor, anchor) -> {
List<Suggestion> result = new ArrayList<>();
int space = code.indexOf(' ');
@ -648,75 +661,78 @@ public class JShellTool {
// Table of commands -- with command forms, argument kinds, help message, implementation, ...
{
registerCommand(new Command("/list", "/l", "[all]", "list the source you have typed",
registerCommand(new Command("/list", "[all]", "list the source you have typed",
arg -> cmdList(arg),
new FixedCompletionProvider("all")));
registerCommand(new Command("/seteditor", null, "<executable>", "set the external editor command to use",
registerCommand(new Command("/seteditor", "<executable>", "set the external editor command to use",
arg -> cmdSetEditor(arg),
EMPTY_COMPLETION_PROVIDER));
registerCommand(new Command("/edit", "/e", "<name or id>", "edit a source entry referenced by name or id",
registerCommand(new Command("/edit", "<name or id>", "edit a source entry referenced by name or id",
arg -> cmdEdit(arg),
editCompletion()));
registerCommand(new Command("/drop", "/d", "<name or id>", "delete a source entry referenced by name or id",
registerCommand(new Command("/drop", "<name or id>", "delete a source entry referenced by name or id",
arg -> cmdDrop(arg),
editCompletion()));
registerCommand(new Command("/save", "/s", "[all|history] <file>", "save the source you have typed",
registerCommand(new Command("/save", "[all|history|start] <file>", "save: <none> - current source;\n" +
" all - source including overwritten, failed, and start-up code;\n" +
" history - editing history;\n" +
" start - default start-up definitions",
arg -> cmdSave(arg),
saveCompletion()));
registerCommand(new Command("/open", "/o", "<file>", "open a file as source input",
registerCommand(new Command("/open", "<file>", "open a file as source input",
arg -> cmdOpen(arg),
FILE_COMPLETION_PROVIDER));
registerCommand(new Command("/vars", "/v", null, "list the declared variables and their values",
registerCommand(new Command("/vars", null, "list the declared variables and their values",
arg -> cmdVars(),
EMPTY_COMPLETION_PROVIDER));
registerCommand(new Command("/methods", "/m", null, "list the declared methods and their signatures",
registerCommand(new Command("/methods", null, "list the declared methods and their signatures",
arg -> cmdMethods(),
EMPTY_COMPLETION_PROVIDER));
registerCommand(new Command("/classes", "/c", null, "list the declared classes",
registerCommand(new Command("/classes", null, "list the declared classes",
arg -> cmdClasses(),
EMPTY_COMPLETION_PROVIDER));
registerCommand(new Command("/imports", "/i", null, "list the imported items",
registerCommand(new Command("/imports", null, "list the imported items",
arg -> cmdImports(),
EMPTY_COMPLETION_PROVIDER));
registerCommand(new Command("/exit", "/x", null, "exit the REPL",
registerCommand(new Command("/exit", null, "exit the REPL",
arg -> cmdExit(),
EMPTY_COMPLETION_PROVIDER));
registerCommand(new Command("/reset", "/r", null, "reset everything in the REPL",
registerCommand(new Command("/reset", null, "reset everything in the REPL",
arg -> cmdReset(),
EMPTY_COMPLETION_PROVIDER));
registerCommand(new Command("/feedback", "/f", "<level>", "feedback information: off, concise, normal, verbose, default, or ?",
registerCommand(new Command("/feedback", "<level>", "feedback information: off, concise, normal, verbose, default, or ?",
arg -> cmdFeedback(arg),
new FixedCompletionProvider("off", "concise", "normal", "verbose", "default", "?")));
registerCommand(new Command("/prompt", "/p", null, "toggle display of a prompt",
registerCommand(new Command("/prompt", null, "toggle display of a prompt",
arg -> cmdPrompt(),
EMPTY_COMPLETION_PROVIDER));
registerCommand(new Command("/classpath", "/cp", "<path>", "add a path to the classpath",
registerCommand(new Command("/classpath", "<path>", "add a path to the classpath",
arg -> cmdClasspath(arg),
classPathCompletion()));
registerCommand(new Command("/history", "/h", null, "history of what you have typed",
registerCommand(new Command("/history", null, "history of what you have typed",
arg -> cmdHistory(),
EMPTY_COMPLETION_PROVIDER));
registerCommand(new Command("/setstart", null, "<file>", "read file and set as the new start-up definitions",
registerCommand(new Command("/setstart", "<file>", "read file and set as the new start-up definitions",
arg -> cmdSetStart(arg),
FILE_COMPLETION_PROVIDER));
registerCommand(new Command("/savestart", null, "<file>", "save the default start-up definitions to the file",
arg -> cmdSaveStart(arg),
FILE_COMPLETION_PROVIDER));
registerCommand(new Command("/debug", "/db", "", "toggle debugging of the REPL",
registerCommand(new Command("/debug", "", "toggle debugging of the REPL",
arg -> cmdDebug(arg),
EMPTY_COMPLETION_PROVIDER,
CommandKind.HIDDEN));
registerCommand(new Command("/help", "/?", "", "this help message",
registerCommand(new Command("/help", "", "this help message",
arg -> cmdHelp(),
EMPTY_COMPLETION_PROVIDER));
registerCommand(new Command("/!", null, "", "re-run last snippet",
registerCommand(new Command("/?", "", "this help message",
arg -> cmdHelp(),
EMPTY_COMPLETION_PROVIDER));
registerCommand(new Command("/!", "", "re-run last snippet",
arg -> cmdUseHistoryEntry(-1),
EMPTY_COMPLETION_PROVIDER));
registerCommand(new Command("/<n>", null, "", "re-run n-th snippet",
registerCommand(new Command("/<n>", "", "re-run n-th snippet",
arg -> { throw new IllegalStateException(); },
EMPTY_COMPLETION_PROVIDER,
CommandKind.HELP_ONLY));
registerCommand(new Command("/-<n>", null, "", "re-run n-th previous snippet",
registerCommand(new Command("/-<n>", "", "re-run n-th previous snippet",
arg -> { throw new IllegalStateException(); },
EMPTY_COMPLETION_PROVIDER,
CommandKind.HELP_ONLY));
@ -732,16 +748,16 @@ public class JShellTool {
.stream()
.distinct()
.filter(cmd -> cmd.kind != CommandKind.HIDDEN && cmd.kind != CommandKind.HELP_ONLY)
.map(cmd -> cmd.aliases[0])
.map(cmd -> cmd.command)
.filter(key -> key.startsWith(prefix))
.map(key -> new Suggestion(key + " ", false));
anchor[0] = 0;
} else {
String arg = prefix.substring(space + 1);
String cmd = prefix.substring(0, space);
Command command = commands.get(cmd);
if (command != null) {
result = command.completions.completionSuggestions(arg, cursor - space, anchor).stream();
Command[] candidates = findCommand(cmd, c -> true);
if (candidates.length == 1) {
result = candidates[0].completions.completionSuggestions(arg, cursor - space, anchor).stream();
anchor[0] += space + 1;
} else {
result = Stream.empty();
@ -885,12 +901,7 @@ public class JShellTool {
if (cmd.kind == CommandKind.HIDDEN)
continue;
StringBuilder synopsis = new StringBuilder();
if (cmd.aliases.length > 1) {
synopsis.append(String.format("%-3s or ", cmd.aliases[1]));
} else {
synopsis.append(" ");
}
synopsis.append(cmd.aliases[0]);
synopsis.append(cmd.command);
if (cmd.params != null)
synopsis.append(" ").append(cmd.params);
synopsis2Description.put(synopsis.toString(), cmd.description);
@ -901,7 +912,9 @@ public class JShellTool {
for (Entry<String, String> e : synopsis2Description.entrySet()) {
cmdout.print(String.format("%-" + synopsisLen + "s", e.getKey()));
cmdout.print(" -- ");
cmdout.println(e.getValue());
String indentedNewLine = System.getProperty("line.separator") +
String.format("%-" + (synopsisLen + 4) + "s", "");
cmdout.println(e.getValue().replace("\n", indentedNewLine));
}
cmdout.println();
cmdout.println("Supported shortcuts include:");
@ -1141,13 +1154,14 @@ public class JShellTool {
}
private void cmdSave(String arg_filename) {
Matcher mat = HISTORY_ALL_FILENAME.matcher(arg_filename);
Matcher mat = HISTORY_ALL_START_FILENAME.matcher(arg_filename);
if (!mat.find()) {
hard("Malformed argument to the /save command: %s", arg_filename);
return;
}
boolean useHistory = false;
boolean saveAll = false;
boolean saveStart = false;
String cmd = mat.group("cmd");
if (cmd != null) switch (cmd) {
case "all":
@ -1156,6 +1170,9 @@ public class JShellTool {
case "history":
useHistory = true;
break;
case "start":
saveStart = true;
break;
}
String filename = mat.group("filename");
if (filename == null ||filename.isEmpty()) {
@ -1170,6 +1187,8 @@ public class JShellTool {
writer.write(s);
writer.write("\n");
}
} else if (saveStart) {
writer.append(DEFAULT_STARTUP);
} else {
for (Snippet sn : state.snippets()) {
if (saveAll || notInStartUp(sn)) {
@ -1203,22 +1222,6 @@ public class JShellTool {
}
}
private void cmdSaveStart(String filename) {
if (filename.isEmpty()) {
hard("The /savestart command requires a filename argument.");
} else {
try {
Files.write(toPathResolvingUserHome(filename), DEFAULT_STARTUP.getBytes());
} catch (AccessDeniedException e) {
hard("File '%s' for /savestart is not accessible.", filename);
} catch (NoSuchFileException e) {
hard("File '%s' for /savestart cannot be located.", filename);
} catch (Exception e) {
hard("Exception while saving default startup file: %s", e);
}
}
}
private void cmdVars() {
for (VarSnippet vk : state.variables()) {
String val = state.status(vk) == Status.VALID

View File

@ -100,9 +100,9 @@ public class CommandCompletionTest extends ReplToolTesting {
public void testSave() throws IOException {
Compiler compiler = new Compiler();
assertCompletion("/s|", false, "/save ", "/savestart ", "/seteditor ", "/setstart ");
assertCompletion("/s|", false, "/save ", "/seteditor ", "/setstart ");
List<String> p1 = listFiles(Paths.get(""));
Collections.addAll(p1, "all ", "history ");
Collections.addAll(p1, "all ", "history ", "start ");
FileSystems.getDefault().getRootDirectories().forEach(s -> p1.add(s.toString()));
Collections.sort(p1);
assertCompletion("/save |", false, p1.toArray(new String[p1.size()]));

View File

@ -23,6 +23,7 @@
/*
* @test
* @bug 8143037
* @summary Tests for Basic tests for REPL tool
* @ignore 8139873
* @library /tools/lib
@ -124,28 +125,28 @@ public class ToolBasicTest extends ReplToolTesting {
interrupt,
(a) -> assertCommand(a, "int a\u0003", ""),
(a) -> assertCommand(a, "int a = 2 + 2\u0003", ""),
(a) -> assertCommandCheckOutput(a, "/v", assertVariables()),
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
(a) -> evaluateExpression(a, "int", "2", "2"),
(a) -> assertCommandCheckOutput(a, "/v", assertVariables()),
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
(a) -> assertCommand(a, "void f() {", ""),
(a) -> assertCommand(a, "int q = 10;" + s, ""),
interrupt,
(a) -> assertCommand(a, "void f() {}\u0003", ""),
(a) -> assertCommandCheckOutput(a, "/m", assertMethods()),
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
(a) -> assertMethod(a, "int f() { return 0; }", "()int", "f"),
(a) -> assertCommandCheckOutput(a, "/m", assertMethods()),
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
(a) -> assertCommand(a, "class A {" + s, ""),
interrupt,
(a) -> assertCommand(a, "class A {}\u0003", ""),
(a) -> assertCommandCheckOutput(a, "/c", assertClasses()),
(a) -> assertCommandCheckOutput(a, "/classes", assertClasses()),
(a) -> assertClass(a, "interface A {}", "interface", "A"),
(a) -> assertCommandCheckOutput(a, "/c", assertClasses()),
(a) -> assertCommandCheckOutput(a, "/classes", assertClasses()),
(a) -> assertCommand(a, "import java.util.stream." + s, ""),
interrupt,
(a) -> assertCommand(a, "import java.util.stream.\u0003", ""),
(a) -> assertCommandCheckOutput(a, "/i", assertImports()),
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()),
(a) -> assertImport(a, "import java.util.stream.Stream", "", "java.util.stream.Stream"),
(a) -> assertCommandCheckOutput(a, "/i", assertImports())
(a) -> assertCommandCheckOutput(a, "/imports", assertImports())
);
}
}
@ -265,10 +266,10 @@ public class ToolBasicTest extends ReplToolTesting {
public void testDebug() {
test(
(a) -> assertCommand(a, "/db", "| Debugging on\n"),
(a) -> assertCommand(a, "/deb", "| Debugging on\n"),
(a) -> assertCommand(a, "/debug", "| Debugging off\n"),
(a) -> assertCommand(a, "/debug", "| Debugging on\n"),
(a) -> assertCommand(a, "/db", "| Debugging off\n")
(a) -> assertCommand(a, "/deb", "| Debugging off\n")
);
}
@ -295,106 +296,70 @@ public class ToolBasicTest extends ReplToolTesting {
public void defineVariables() {
test(
(a) -> assertCommandCheckOutput(a, "/l", assertList()),
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
(a) -> assertCommandCheckOutput(a, "/v", assertVariables()),
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
(a) -> assertVariable(a, "int", "a"),
(a) -> assertCommandCheckOutput(a, "/l", assertList()),
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
(a) -> assertCommandCheckOutput(a, "/v", assertVariables()),
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
(a) -> assertVariable(a, "double", "a", "1", "1.0"),
(a) -> assertCommandCheckOutput(a, "/l", assertList()),
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
(a) -> assertCommandCheckOutput(a, "/v", assertVariables()),
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
(a) -> evaluateExpression(a, "double", "2 * a", "2.0"),
(a) -> assertCommandCheckOutput(a, "/l", assertList()),
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
(a) -> assertCommandCheckOutput(a, "/v", assertVariables()),
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables())
);
}
public void defineMethods() {
test(
(a) -> assertCommandCheckOutput(a, "/l", assertList()),
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
(a) -> assertCommandCheckOutput(a, "/m", assertMethods()),
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
(a) -> assertMethod(a, "int f() { return 0; }", "()int", "f"),
(a) -> assertCommandCheckOutput(a, "/l", assertList()),
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
(a) -> assertCommandCheckOutput(a, "/m", assertMethods()),
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
(a) -> assertMethod(a, "void f(int a) { g(); }", "(int)void", "f"),
(a) -> assertCommandCheckOutput(a, "/l", assertList()),
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
(a) -> assertCommandCheckOutput(a, "/m", assertMethods()),
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
(a) -> assertMethod(a, "void g() {}", "()void", "g"),
(a) -> assertCommandCheckOutput(a, "/l", assertList()),
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
(a) -> assertCommandCheckOutput(a, "/m", assertMethods()),
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods())
);
}
public void defineClasses() {
test(
(a) -> assertCommandCheckOutput(a, "/l", assertList()),
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
(a) -> assertCommandCheckOutput(a, "/c", assertClasses()),
(a) -> assertCommandCheckOutput(a, "/classes", assertClasses()),
(a) -> assertClass(a, "class A { }", "class", "A"),
(a) -> assertCommandCheckOutput(a, "/l", assertList()),
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
(a) -> assertCommandCheckOutput(a, "/c", assertClasses()),
(a) -> assertCommandCheckOutput(a, "/classes", assertClasses()),
(a) -> assertClass(a, "interface A { }", "interface", "A"),
(a) -> assertCommandCheckOutput(a, "/l", assertList()),
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
(a) -> assertCommandCheckOutput(a, "/c", assertClasses()),
(a) -> assertCommandCheckOutput(a, "/classes", assertClasses()),
(a) -> assertClass(a, "enum A { }", "enum", "A"),
(a) -> assertCommandCheckOutput(a, "/l", assertList()),
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
(a) -> assertCommandCheckOutput(a, "/c", assertClasses()),
(a) -> assertCommandCheckOutput(a, "/classes", assertClasses()),
(a) -> assertClass(a, "@interface A { }", "@interface", "A"),
(a) -> assertCommandCheckOutput(a, "/l", assertList()),
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
(a) -> assertCommandCheckOutput(a, "/c", assertClasses()),
(a) -> assertCommandCheckOutput(a, "/classes", assertClasses())
);
}
public void defineImports() {
test(
(a) -> assertCommandCheckOutput(a, "/l", assertList()),
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
(a) -> assertCommandCheckOutput(a, "/i", assertImports()),
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()),
(a) -> assertImport(a, "import java.util.stream.Stream;", "", "java.util.stream.Stream"),
(a) -> assertCommandCheckOutput(a, "/l", assertList()),
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
(a) -> assertCommandCheckOutput(a, "/i", assertImports()),
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()),
(a) -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"),
(a) -> assertCommandCheckOutput(a, "/l", assertList()),
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
(a) -> assertCommandCheckOutput(a, "/i", assertImports()),
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()),
(a) -> assertImport(a, "import static java.lang.Math.PI;", "static", "java.lang.Math.PI"),
(a) -> assertCommandCheckOutput(a, "/l", assertList()),
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
(a) -> assertCommandCheckOutput(a, "/i", assertImports()),
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()),
(a) -> assertImport(a, "import static java.lang.Math.*;", "static", "java.lang.Math.*"),
(a) -> assertCommandCheckOutput(a, "/l", assertList()),
(a) -> assertCommandCheckOutput(a, "/list", assertList()),
(a) -> assertCommandCheckOutput(a, "/i", assertImports()),
(a) -> assertCommandCheckOutput(a, "/imports", assertImports())
);
}
@ -405,7 +370,7 @@ public class ToolBasicTest extends ReplToolTesting {
compiler.compile(outDir, "package pkg; public class A { public String toString() { return \"A\"; } }");
Path classpath = compiler.getPath(outDir);
test(
(a) -> assertCommand(a, "/cp " + classpath, String.format("| Path %s added to classpath\n", classpath)),
(a) -> assertCommand(a, "/classpath " + classpath, String.format("| Path %s added to classpath\n", classpath)),
(a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "\"A\"")
);
test(new String[] { "-cp", classpath.toString() },
@ -471,20 +436,20 @@ public class ToolBasicTest extends ReplToolTesting {
public void testReset() {
test(
(a) -> assertReset(a, "/r"),
(a) -> assertCommandCheckOutput(a, "/m", assertMethods()),
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
(a) -> assertVariable(a, "int", "x"),
(a) -> assertCommandCheckOutput(a, "/v", assertVariables()),
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
(a) -> assertMethod(a, "void f() { }", "()void", "f"),
(a) -> assertCommandCheckOutput(a, "/m", assertMethods()),
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
(a) -> assertClass(a, "class A { }", "class", "A"),
(a) -> assertCommandCheckOutput(a, "/c", assertClasses()),
(a) -> assertCommandCheckOutput(a, "/classes", assertClasses()),
(a) -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"),
(a) -> assertCommandCheckOutput(a, "/i", assertImports()),
(a) -> assertCommandCheckOutput(a, "/imports", assertImports()),
(a) -> assertReset(a, "/reset"),
(a) -> assertCommandCheckOutput(a, "/v", assertVariables()),
(a) -> assertCommandCheckOutput(a, "/m", assertMethods()),
(a) -> assertCommandCheckOutput(a, "/c", assertClasses()),
(a) -> assertCommandCheckOutput(a, "/i", assertImports())
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
(a) -> assertCommandCheckOutput(a, "/classes", assertClasses()),
(a) -> assertCommandCheckOutput(a, "/imports", assertImports())
);
}
@ -508,11 +473,11 @@ public class ToolBasicTest extends ReplToolTesting {
loadClass(a, "class A { public String toString() { return \"A\"; } }",
"class", "A");
loadImport(a, "import java.util.stream.*;", "", "java.util.stream.*");
assertCommandCheckOutput(a, "/c", assertClasses());
assertCommandCheckOutput(a, "/classes", assertClasses());
},
(a) -> assertCommandCheckOutput(a, "/m", assertMethods()),
(a) -> assertCommandCheckOutput(a, "/v", assertVariables()),
(a) -> assertCommandCheckOutput(a, "/i", assertImports())
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
(a) -> assertCommandCheckOutput(a, "/imports", assertImports())
);
Path unknown = compiler.getPath("UNKNOWN.repl");
test(
@ -531,15 +496,13 @@ public class ToolBasicTest extends ReplToolTesting {
"int a;",
"class A { public String toString() { return \"A\"; } }"
);
for (String s : new String[]{"/s", "/save"}) {
test(
(a) -> assertVariable(a, "int", "a"),
(a) -> assertClass(a, "class A { public String toString() { return \"A\"; } }", "class", "A"),
(a) -> assertCommand(a, s + " " + path.toString(), "")
);
assertEquals(Files.readAllLines(path), list);
}
for (String s : new String[]{"/s", "/save"}) {
test(
(a) -> assertVariable(a, "int", "a"),
(a) -> assertClass(a, "class A { public String toString() { return \"A\"; } }", "class", "A"),
(a) -> assertCommand(a, "/save " + path.toString(), "")
);
assertEquals(Files.readAllLines(path), list);
{
List<String> output = new ArrayList<>();
test(
(a) -> assertCommand(a, "int a;", null),
@ -550,24 +513,22 @@ public class ToolBasicTest extends ReplToolTesting {
.map(str -> str.substring(str.indexOf(':') + 2))
.filter(str -> !str.startsWith("/"))
.collect(Collectors.toList()))),
(a) -> assertCommand(a, s + " all " + path.toString(), "")
(a) -> assertCommand(a, "/save all " + path.toString(), "")
);
assertEquals(Files.readAllLines(path), output);
}
for (String s : new String[]{"/s", "/save"}) {
List<String> output = new ArrayList<>();
test(
(a) -> assertVariable(a, "int", "a"),
(a) -> assertClass(a, "class A { public String toString() { return \"A\"; } }", "class", "A"),
(a) -> assertCommandCheckOutput(a, "/h", (out) ->
output.addAll(Stream.of(out.split("\n"))
.filter(str -> !str.isEmpty())
.collect(Collectors.toList()))),
(a) -> assertCommand(a, s + " history " + path.toString(), "")
);
output.add(s + " history " + path.toString());
assertEquals(Files.readAllLines(path), output);
}
List<String> output = new ArrayList<>();
test(
(a) -> assertVariable(a, "int", "a"),
(a) -> assertClass(a, "class A { public String toString() { return \"A\"; } }", "class", "A"),
(a) -> assertCommandCheckOutput(a, "/history", (out) ->
output.addAll(Stream.of(out.split("\n"))
.filter(str -> !str.isEmpty())
.collect(Collectors.toList()))),
(a) -> assertCommand(a, "/save history " + path.toString(), "")
);
output.add("/save history " + path.toString());
assertEquals(Files.readAllLines(path), output);
}
public void testStartSet() throws BackingStoreException {
@ -579,7 +540,7 @@ public class ToolBasicTest extends ReplToolTesting {
(a) -> assertVariable(a, "double", "b", "10", "10.0"),
(a) -> assertMethod(a, "void f() {}", "()V", "f"),
(a) -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"),
(a) -> assertCommand(a, "/s " + startUpFile.toString(), null),
(a) -> assertCommand(a, "/save " + startUpFile.toString(), null),
(a) -> assertCommand(a, "/setstart " + startUpFile.toString(), null)
);
Path unknown = compiler.getPath("UNKNOWN");
@ -593,11 +554,11 @@ public class ToolBasicTest extends ReplToolTesting {
loadVariable(a, "double", "b", "10.0", "10.0");
loadMethod(a, "void f() {}", "()void", "f");
loadImport(a, "import java.util.stream.*;", "", "java.util.stream.*");
assertCommandCheckOutput(a, "/c", assertClasses());
assertCommandCheckOutput(a, "/classes", assertClasses());
},
(a) -> assertCommandCheckOutput(a, "/v", assertVariables()),
(a) -> assertCommandCheckOutput(a, "/m", assertMethods()),
(a) -> assertCommandCheckOutput(a, "/i", assertImports())
(a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
(a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
(a) -> assertCommandCheckOutput(a, "/imports", assertImports())
);
} finally {
removeStartup();
@ -618,24 +579,14 @@ public class ToolBasicTest extends ReplToolTesting {
}
public void testEmptyClassPath() {
String[] commands = {"/cp", "/classpath"};
test(Stream.of(commands)
.map(cmd -> (ReplTest) after -> assertCommand(after, cmd, "| /classpath requires a path argument\n"))
.toArray(ReplTest[]::new));
test(after -> assertCommand(after, "/classpath", "| /classpath requires a path argument\n"));
}
public void testNoArgument() {
String[] commands = {"/s", "/save", "/o", "/open", "/setstart", "/savestart"};
String[] commands = {"/save", "/open", "/setstart"};
test(Stream.of(commands)
.map(cmd -> {
String c = cmd;
if ("/s".equals(cmd)) {
c = "/save";
}
if ("/o".equals(cmd)) {
c = "/open";
}
final String finalC = c;
return (ReplTest) after -> assertCommand(after, cmd,
"| The " + finalC + " command requires a filename argument.\n");
@ -646,7 +597,7 @@ public class ToolBasicTest extends ReplToolTesting {
public void testStartSave() throws IOException {
Compiler compiler = new Compiler();
Path startSave = compiler.getPath("startSave.txt");
test(a -> assertCommand(a, "/savestart " + startSave.toString(), null));
test(a -> assertCommand(a, "/save start " + startSave.toString(), null));
List<String> lines = Files.lines(startSave)
.filter(s -> !s.isEmpty())
.collect(Collectors.toList());
@ -673,49 +624,42 @@ public class ToolBasicTest extends ReplToolTesting {
public void testRemoteExit() {
test(
a -> assertVariable(a, "int", "x"),
a -> assertCommandCheckOutput(a, "/v", assertVariables()),
a -> assertCommandCheckOutput(a, "/vars", assertVariables()),
a -> assertCommandCheckOutput(a, "System.exit(5);", s ->
assertTrue(s.contains("terminated"), s)),
a -> assertCommandCheckOutput(a, "/v", s ->
a -> assertCommandCheckOutput(a, "/vars", s ->
assertTrue(s.trim().isEmpty(), s)),
a -> assertMethod(a, "void f() { }", "()void", "f"),
a -> assertCommandCheckOutput(a, "/m", assertMethods())
a -> assertCommandCheckOutput(a, "/methods", assertMethods())
);
}
public void testListArgs() {
Consumer<String> assertList = s -> assertTrue(s.split("\n").length >= 7, s);
Consumer<String> assertList = s -> assertTrue(s.split("\n").length >= 4, s);
String arg = "qqqq";
Consumer<String> assertError = s -> assertEquals(s, "| Invalid /list argument: " + arg + "\n");
test(
a -> assertCommandCheckOutput(a, "/l all", assertList),
a -> assertCommandCheckOutput(a, "/list all", assertList),
a -> assertCommandCheckOutput(a, "/l " + arg, assertError),
a -> assertCommandCheckOutput(a, "/list " + arg, assertError),
a -> assertVariable(a, "int", "a"),
a -> assertCommandCheckOutput(a, "/l history", assertList),
a -> assertCommandCheckOutput(a, "/list history", assertList)
);
}
public void testFeedbackNegative() {
for (String feedback : new String[]{"/f", "/feedback"}) {
test(a -> assertCommandCheckOutput(a, feedback + " aaaa",
assertStartsWith("| Follow /feedback with of the following")));
}
test(a -> assertCommandCheckOutput(a, "/feedback aaaa",
assertStartsWith("| Follow /feedback with of the following")));
}
public void testFeedbackOff() {
for (String feedback : new String[]{"/f", "/feedback"}) {
for (String off : new String[]{"o", "off"}) {
test(
a -> assertCommand(a, feedback + " " + off, ""),
a -> assertCommand(a, "int a", ""),
a -> assertCommand(a, "void f() {}", ""),
a -> assertCommandCheckOutput(a, "aaaa", assertStartsWith("| Error:")),
a -> assertCommandCheckOutput(a, "public void f() {}", assertStartsWith("| Warning:"))
);
}
for (String off : new String[]{"o", "off"}) {
test(
a -> assertCommand(a, "/feedback " + off, ""),
a -> assertCommand(a, "int a", ""),
a -> assertCommand(a, "void f() {}", ""),
a -> assertCommandCheckOutput(a, "aaaa", assertStartsWith("| Error:")),
a -> assertCommandCheckOutput(a, "public void f() {}", assertStartsWith("| Warning:"))
);
}
}
@ -724,17 +668,15 @@ public class ToolBasicTest extends ReplToolTesting {
Path testConciseFile = compiler.getPath("testConciseFeedback");
String[] sources = new String[] {"int a", "void f() {}", "class A {}", "a = 10"};
compiler.writeToFile(testConciseFile, sources);
for (String feedback : new String[]{"/f", "/feedback"}) {
for (String concise : new String[]{"c", "concise"}) {
test(
a -> assertCommand(a, feedback + " " + concise, ""),
a -> assertCommand(a, sources[0], ""),
a -> assertCommand(a, sources[1], ""),
a -> assertCommand(a, sources[2], ""),
a -> assertCommand(a, sources[3], "| a : 10\n"),
a -> assertCommand(a, "/o " + testConciseFile.toString(), "| a : 10\n")
);
}
for (String concise : new String[]{"c", "concise"}) {
test(
a -> assertCommand(a, "/feedback " + concise, ""),
a -> assertCommand(a, sources[0], ""),
a -> assertCommand(a, sources[1], ""),
a -> assertCommand(a, sources[2], ""),
a -> assertCommand(a, sources[3], "| a : 10\n"),
a -> assertCommand(a, "/o " + testConciseFile.toString(), "| a : 10\n")
);
}
}
@ -788,65 +730,59 @@ public class ToolBasicTest extends ReplToolTesting {
"| Variable a has been assigned the value 10\n"
};
compiler.writeToFile(testDefaultFile, sources);
for (String feedback : new String[]{"/f", "/feedback"}) {
for (String defaultFeedback : new String[]{"", "d", "default"}) {
test(
a -> assertCommand(a, "/f o", ""),
a -> assertCommand(a, "int x", ""),
a -> assertCommand(a, feedback + " " + defaultFeedback, "| Feedback mode: default\n"),
a -> assertCommand(a, sources[0], output[0]),
a -> assertCommand(a, sources[1], output[1]),
a -> assertCommand(a, sources[2], output[2]),
a -> assertCommand(a, sources[3], output[3]),
a -> assertCommand(a, "/o " + testDefaultFile.toString(), "")
);
}
for (String defaultFeedback : new String[]{"", "d", "default"}) {
test(
a -> assertCommand(a, "/feedback o", ""),
a -> assertCommand(a, "int x", ""),
a -> assertCommand(a, "/feedback " + defaultFeedback, "| Feedback mode: default\n"),
a -> assertCommand(a, sources[0], output[0]),
a -> assertCommand(a, sources[1], output[1]),
a -> assertCommand(a, sources[2], output[2]),
a -> assertCommand(a, sources[3], output[3]),
a -> assertCommand(a, "/o " + testDefaultFile.toString(), "")
);
}
}
public void testDrop() {
for (String drop : new String[]{"/d", "/drop"}) {
test(false, new String[]{"-nostartup"},
a -> assertVariable(a, "int", "a"),
a -> dropVariable(a, drop + " 1", "int a = 0"),
a -> assertMethod(a, "int b() { return 0; }", "()I", "b"),
a -> dropMethod(a, drop + " 2", "b ()I"),
a -> assertClass(a, "class A {}", "class", "A"),
a -> dropClass(a, drop + " 3", "class A"),
a -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"),
a -> dropImport(a, drop + " 4", "import java.util.stream.*"),
a -> assertCommandCheckOutput(a, "/v", assertVariables()),
a -> assertCommandCheckOutput(a, "/m", assertMethods()),
a -> assertCommandCheckOutput(a, "/c", assertClasses()),
a -> assertCommandCheckOutput(a, "/i", assertImports())
);
test(false, new String[]{"-nostartup"},
a -> assertVariable(a, "int", "a"),
a -> dropVariable(a, drop + " a", "int a = 0"),
a -> assertMethod(a, "int b() { return 0; }", "()I", "b"),
a -> dropMethod(a, drop + " b", "b ()I"),
a -> assertClass(a, "class A {}", "class", "A"),
a -> dropClass(a, drop + " A", "class A"),
a -> assertCommandCheckOutput(a, "/v", assertVariables()),
a -> assertCommandCheckOutput(a, "/m", assertMethods()),
a -> assertCommandCheckOutput(a, "/c", assertClasses()),
a -> assertCommandCheckOutput(a, "/i", assertImports())
);
}
test(false, new String[]{"-nostartup"},
a -> assertVariable(a, "int", "a"),
a -> dropVariable(a, "/drop 1", "int a = 0"),
a -> assertMethod(a, "int b() { return 0; }", "()I", "b"),
a -> dropMethod(a, "/drop 2", "b ()I"),
a -> assertClass(a, "class A {}", "class", "A"),
a -> dropClass(a, "/drop 3", "class A"),
a -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"),
a -> dropImport(a, "/drop 4", "import java.util.stream.*"),
a -> assertCommandCheckOutput(a, "/vars", assertVariables()),
a -> assertCommandCheckOutput(a, "/methods", assertMethods()),
a -> assertCommandCheckOutput(a, "/classes", assertClasses()),
a -> assertCommandCheckOutput(a, "/imports", assertImports())
);
test(false, new String[]{"-nostartup"},
a -> assertVariable(a, "int", "a"),
a -> dropVariable(a, "/drop a", "int a = 0"),
a -> assertMethod(a, "int b() { return 0; }", "()I", "b"),
a -> dropMethod(a, "/drop b", "b ()I"),
a -> assertClass(a, "class A {}", "class", "A"),
a -> dropClass(a, "/drop A", "class A"),
a -> assertCommandCheckOutput(a, "/vars", assertVariables()),
a -> assertCommandCheckOutput(a, "/methods", assertMethods()),
a -> assertCommandCheckOutput(a, "/classes", assertClasses()),
a -> assertCommandCheckOutput(a, "/imports", assertImports())
);
}
public void testDropNegative() {
for (String drop : new String[]{"/d", "/drop"}) {
test(false, new String[]{"-nostartup"},
a -> assertCommand(a, drop + " 0", "| No definition or id named 0 found. See /classes /methods /vars or /list\n"),
a -> assertCommand(a, drop + " a", "| No definition or id named a found. See /classes /methods /vars or /list\n"),
a -> assertCommandCheckOutput(a, drop,
assertStartsWith("| In the /drop argument, please specify an import, variable, method, or class to drop.")),
a -> assertVariable(a, "int", "a"),
a -> assertCommand(a, "a", "| Variable a of type int has value 0\n"),
a -> assertCommand(a, drop + " 2", "| The argument did not specify an import, variable, method, or class to drop.\n")
);
}
test(false, new String[]{"-nostartup"},
a -> assertCommand(a, "/drop 0", "| No definition or id named 0 found. See /classes /methods /vars or /list\n"),
a -> assertCommand(a, "/drop a", "| No definition or id named a found. See /classes /methods /vars or /list\n"),
a -> assertCommandCheckOutput(a, "/drop",
assertStartsWith("| In the /drop argument, please specify an import, variable, method, or class to drop.")),
a -> assertVariable(a, "int", "a"),
a -> assertCommand(a, "a", "| Variable a of type int has value 0\n"),
a -> assertCommand(a, "/drop 2", "| The argument did not specify an import, variable, method, or class to drop.\n")
);
}
public void testAmbiguousDrop() {
@ -855,25 +791,23 @@ public class ToolBasicTest extends ReplToolTesting {
int lines = s.split("\n").length;
assertEquals(lines, 5, "Expected 3 ambiguous keys, but found: " + (lines - 2) + "\n" + s);
};
for (String drop : new String[]{"/d", "/drop"}) {
test(
a -> assertVariable(a, "int", "a"),
a -> assertMethod(a, "int a() { return 0; }", "()int", "a"),
a -> assertClass(a, "class a {}", "class", "a"),
a -> assertCommandCheckOutput(a, drop + " a", check),
a -> assertCommandCheckOutput(a, "/v", assertVariables()),
a -> assertCommandCheckOutput(a, "/m", assertMethods()),
a -> assertCommandCheckOutput(a, "/c", assertClasses()),
a -> assertCommandCheckOutput(a, "/i", assertImports())
);
test(
a -> assertMethod(a, "int a() { return 0; }", "()int", "a"),
a -> assertMethod(a, "double a(int a) { return 0; }", "(int)double", "a"),
a -> assertMethod(a, "double a(double a) { return 0; }", "(double)double", "a"),
a -> assertCommandCheckOutput(a, drop + " a", check),
a -> assertCommandCheckOutput(a, "/m", assertMethods())
);
}
test(
a -> assertVariable(a, "int", "a"),
a -> assertMethod(a, "int a() { return 0; }", "()int", "a"),
a -> assertClass(a, "class a {}", "class", "a"),
a -> assertCommandCheckOutput(a, "/drop a", check),
a -> assertCommandCheckOutput(a, "/vars", assertVariables()),
a -> assertCommandCheckOutput(a, "/methods", assertMethods()),
a -> assertCommandCheckOutput(a, "/classes", assertClasses()),
a -> assertCommandCheckOutput(a, "/imports", assertImports())
);
test(
a -> assertMethod(a, "int a() { return 0; }", "()int", "a"),
a -> assertMethod(a, "double a(int a) { return 0; }", "(int)double", "a"),
a -> assertMethod(a, "double a(double a) { return 0; }", "(double)double", "a"),
a -> assertCommandCheckOutput(a, "/drop a", check),
a -> assertCommandCheckOutput(a, "/methods", assertMethods())
);
}
public void testHistoryReference() {
@ -893,4 +827,14 @@ public class ToolBasicTest extends ReplToolTesting {
a -> assertCommand(a, "/1", "System.err.println(1)\n", "", null, "", "1\n")
);
}
public void testCommandPrefix() {
test(a -> assertCommandCheckOutput(a, "/s",
assertStartsWith("| Command: /s is ambiguous: /seteditor, /save, /setstart")),
a -> assertCommand(a, "int var", "| Added variable var of type int\n"),
a -> assertCommandCheckOutput(a, "/va",
assertStartsWith("| int var = 0")),
a -> assertCommandCheckOutput(a, "/save",
assertStartsWith("| The /save command requires a filename argument.")));
}
}

View File

@ -1,5 +1,3 @@
T6939780.java:22:28: compiler.warn.diamond.redundant.args
T6939780.java:23:28: compiler.warn.diamond.redundant.args.1: T6939780.Foo<java.lang.Integer>, T6939780.Foo<java.lang.Number>
T6939780.java:31:19: compiler.warn.diamond.redundant.args
T6939780.java:32:19: compiler.warn.diamond.redundant.args.1: T6939780.Foo<java.lang.Integer>, T6939780.Foo<java.lang.Number>
4 warnings
2 warnings

View File

@ -1,7 +1,5 @@
T6939780.java:21:33: compiler.warn.diamond.redundant.args
T6939780.java:22:28: compiler.warn.diamond.redundant.args
T6939780.java:23:28: compiler.warn.diamond.redundant.args.1: T6939780.Foo<java.lang.Integer>, T6939780.Foo<java.lang.Number>
T6939780.java:30:19: compiler.warn.diamond.redundant.args
T6939780.java:31:19: compiler.warn.diamond.redundant.args
T6939780.java:32:19: compiler.warn.diamond.redundant.args.1: T6939780.Foo<java.lang.Integer>, T6939780.Foo<java.lang.Number>
6 warnings
4 warnings

View File

@ -1,13 +1,9 @@
T6939780.java:21:33: compiler.warn.diamond.redundant.args
T6939780.java:22:28: compiler.warn.diamond.redundant.args
T6939780.java:23:28: compiler.warn.diamond.redundant.args.1: T6939780.Foo<java.lang.Integer>, T6939780.Foo<java.lang.Number>
T6939780.java:24:33: compiler.warn.diamond.redundant.args
T6939780.java:25:28: compiler.warn.diamond.redundant.args
T6939780.java:26:28: compiler.warn.diamond.redundant.args.1: T6939780.Foo<java.lang.Integer>, T6939780.Foo<java.lang.Number>
T6939780.java:30:19: compiler.warn.diamond.redundant.args
T6939780.java:31:19: compiler.warn.diamond.redundant.args
T6939780.java:32:19: compiler.warn.diamond.redundant.args.1: T6939780.Foo<java.lang.Integer>, T6939780.Foo<java.lang.Number>
T6939780.java:33:19: compiler.warn.diamond.redundant.args
T6939780.java:34:19: compiler.warn.diamond.redundant.args
T6939780.java:35:19: compiler.warn.diamond.redundant.args.1: T6939780.Foo<java.lang.Integer>, T6939780.Foo<java.lang.Number>
12 warnings
8 warnings

View File

@ -1,10 +1,34 @@
/*
* @test /nodynamiccopyright/
* @bug 7002837 8064365
* Copyright (c) 2015, 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 7002837 8064365 8078660
*
* @summary Diamond: javac generates diamond inference errors when in 'finder' mode
* @author mcimadamore
* @compile/fail/ref=T7002837.out -Werror -XDrawDiagnostics -XDfind=diamond T7002837.java
* @compile -Werror -XDrawDiagnostics -XDfind=diamond T7002837.java
*
*/

View File

@ -1,4 +0,0 @@
T7002837.java:13:19: compiler.warn.diamond.redundant.args.1: T7002837<java.lang.Integer>, T7002837<java.lang.Object&java.io.Serializable&java.lang.Comparable<?>>
- compiler.err.warnings.and.werror
1 error
1 warning

View File

@ -1,8 +1,32 @@
/*
* @test /nodynamiccopyright/
* @bug 8078473
* Copyright (c) 2015, 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 8078473 8078660
* @summary javac diamond finder crashes when used to build java.base module
* @compile/ref=T8078473.out T8078473.java -XDrawDiagnostics -XDfind=diamond
* @compile -Werror T8078473.java -XDrawDiagnostics -XDfind=diamond
*/
class T8078473<P, Q> {

View File

@ -1,3 +0,0 @@
T8078473.java:15:14: compiler.warn.diamond.redundant.args.1: T8078473.C<Q,Q>, T8078473.C<java.lang.Object,java.lang.Object>
T8078473.java:16:14: compiler.warn.diamond.redundant.args.1: T8078473.C<Q,Q>, T8078473.C<java.lang.Object,java.lang.Object>
2 warnings

View File

@ -1,8 +1,32 @@
/*
* @test /nodynamiccopyright/
* @bug 8078473
* Copyright (c) 2015, 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 8078473 8078660
* @summary javac diamond finder crashes when used to build java.base module
* @compile/ref=T8078473_2.out T8078473_2.java -XDrawDiagnostics -XDfind=diamond
* @compile -Werror T8078473_2.java -XDrawDiagnostics -XDfind=diamond
*/
package java.util.stream;

View File

@ -1,3 +0,0 @@
T8078473_2.java:17:13: compiler.warn.diamond.redundant.args.1: java.util.stream.T8078473_2.C<Q,Q>, java.util.stream.T8078473_2.C<java.lang.Object,java.lang.Object>
T8078473_2.java:18:13: compiler.warn.diamond.redundant.args.1: java.util.stream.T8078473_2.C<Q,Q>, java.util.stream.T8078473_2.C<java.lang.Object,java.lang.Object>
2 warnings

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2015, 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 8143647
* @summary Javac compiles method reference that allows results in an IllegalAccessError
* @run main MethodReference75
*/
import pkg.PublicDerived8143647;
public class MethodReference75 {
public static void main(String[] args) {
if (java.util.Arrays
.asList(new PublicDerived8143647())
.stream()
.map(PublicDerived8143647::getX)
.findFirst()
.get()
.equals("PackagePrivateBase"))
System.out.println("OK");
else
throw new AssertionError("Unexpected output");
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 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
@ -21,9 +21,13 @@
* questions.
*/
// key: compiler.warn.diamond.redundant.args.1
// options: -XDfind=diamond
package pkg;
class DiamondRedundantArgs1<X> {
DiamondRedundantArgs1<?> fs = new DiamondRedundantArgs1<String>();
abstract class PackagePrivateBase8143647 {
public String getX() {
return "PackagePrivateBase";
}
}
public class PublicDerived8143647 extends PackagePrivateBase8143647 {
}

View File

@ -273,6 +273,34 @@ public class ToolBox {
Files.delete(Paths.get(file));
}
/**
* Deletes all content of a directory (but not the directory itself).
* @param root the directory to be cleaned
*/
public void cleanDirectory(Path root) throws IOException {
if (!Files.isDirectory(root)) {
throw new IOException(root + " is not a directory");
}
Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes a) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
if (e != null) {
throw e;
}
if (!dir.equals(root)) {
Files.delete(dir);
}
return FileVisitResult.CONTINUE;
}
});
}
/**
* Moves a file.
* If the given destination exists and is a directory, the file will be moved

View File

@ -36,6 +36,7 @@
* @run main Wrapper CompileCircularSources
*/
import java.io.IOException;
import java.util.*;
import java.nio.file.*;
@ -46,13 +47,11 @@ public class CompileCircularSources extends SJavacTester {
}
void test() throws Exception {
clean(TEST_ROOT);
Files.createDirectories(BIN);
clean(GENSRC, BIN);
Files.createDirectories(GENSRC);
Map<String,Long> previous_bin_state = collectState(BIN);
ToolBox tb = new ToolBox();
tb.writeFile(GENSRC.resolve("alfa/omega/A.java"),
"package alfa.omega; public class A { beta.B b; }");
tb.writeFile(GENSRC.resolve("beta/B.java"),
@ -74,6 +73,5 @@ public class CompileCircularSources extends SJavacTester {
BIN + "/beta/B.class",
BIN + "/gamma/C.class",
BIN + "/javac_state");
clean(GENSRC, BIN);
}
}

View File

@ -47,9 +47,7 @@ public class CompileExcludingDependency extends SJavacTester {
// Verify that excluding classes from compilation but not from linking works
void test() throws Exception {
clean(TEST_ROOT);
Files.createDirectories(BIN);
clean(GENSRC,BIN);
Map<String,Long> previous_bin_state = collectState(BIN);
ToolBox tb = new ToolBox();
tb.writeFile(GENSRC.resolve("alfa/omega/A.java"),
@ -69,6 +67,5 @@ public class CompileExcludingDependency extends SJavacTester {
verifyThatFilesHaveBeenAdded(previous_bin_state, new_bin_state,
BIN + "/alfa/omega/A.class",
BIN + "/javac_state");
clean(GENSRC, BIN);
}
}

View File

@ -46,8 +46,6 @@ public class CompileWithAtFile extends SJavacTester {
}
void test() throws Exception {
clean(TEST_ROOT);
ToolBox tb = new ToolBox();
tb.writeFile(GENSRC.resolve("list.txt"),
"-if */alfa/omega/A.java\n" +
"-if */beta/B.java\n" +
@ -55,11 +53,11 @@ public class CompileWithAtFile extends SJavacTester {
"-d " + BIN + "\n" +
"--state-dir=" + BIN + "\n");
tb.writeFile(GENSRC.resolve("alfa/omega/A.java"),
"package alfa.omega; import beta.B; public class A { B b; }");
"package alfa.omega; import beta.B; public class A { B b; }");
tb.writeFile(GENSRC.resolve("beta/B.java"),
"package beta; public class B { }");
"package beta; public class B { }");
tb.writeFile(GENSRC.resolve("beta/C.java"),
"broken");
"broken");
Files.createDirectory(BIN);
Map<String,Long> previous_bin_state = collectState(BIN);
@ -71,6 +69,5 @@ public class CompileWithAtFile extends SJavacTester {
BIN + "/javac_state",
BIN + "/alfa/omega/A.class",
BIN + "/beta/B.class");
clean(GENSRC, BIN);
}
}

View File

@ -49,9 +49,7 @@ public class CompileWithInvisibleSources extends SJavacTester {
// gensrc2 contains broken code in beta.B, thus exclude that package
// gensrc3 contains a proper beta.B
void test() throws Exception {
clean(TEST_ROOT);
Files.createDirectories(BIN);
clean(GENSRC, GENSRC2, GENSRC3, BIN);
Map<String,Long> previous_bin_state = collectState(BIN);
@ -82,7 +80,7 @@ public class CompileWithInvisibleSources extends SJavacTester {
BIN + "/javac_state");
System.out.println("----- Compile with exluded beta went well!");
clean(BIN);
tb.cleanDirectory(BIN);
compileExpectFailure(GENSRC.toString(),
"-sourcepath", GENSRC2.toString(),
"-sourcepath", GENSRC3.toString(),
@ -93,6 +91,5 @@ public class CompileWithInvisibleSources extends SJavacTester {
SERVER_ARG);
System.out.println("----- Compile without exluded beta failed, as expected! Good!");
clean(GENSRC, BIN);
}
}

View File

@ -48,9 +48,7 @@ public class CompileWithOverrideSources extends SJavacTester {
// Compile gensrc and gensrc2. However do not compile broken beta.B in gensrc,
// only compile ok beta.B in gensrc2
void test() throws Exception {
clean(TEST_ROOT);
Files.createDirectories(BIN);
clean(GENSRC, GENSRC2, GENSRC3, BIN);
Map<String,Long> previous_bin_state = collectState(BIN);
ToolBox tb = new ToolBox();
@ -80,7 +78,7 @@ public class CompileWithOverrideSources extends SJavacTester {
BIN + "/javac_state");
System.out.println("----- Compile with exluded beta went well!");
clean(BIN);
tb.cleanDirectory(BIN);
compileExpectFailure(GENSRC.toString(),
GENSRC2.toString(),
"-d", BIN.toString(),
@ -90,6 +88,5 @@ public class CompileWithOverrideSources extends SJavacTester {
SERVER_ARG);
System.out.println("----- Compile without exluded beta failed, as expected! Good!");
clean(GENSRC, GENSRC2, BIN);
}
}

View File

@ -51,7 +51,6 @@ public class IncCompileChangeNative extends SJavacTester {
ToolBox tb = new ToolBox();
void test() throws Exception {
clean(TEST_ROOT);
Files.createDirectories(GENSRC);
Files.createDirectories(BIN);
Files.createDirectories(HEADERS);
@ -59,8 +58,6 @@ public class IncCompileChangeNative extends SJavacTester {
initialCompile();
incrementalCompileDropAllNatives();
incrementalCompileAddNative();
clean(GENSRC, BIN, HEADERS);
}
// Update B.java with one less native method i.e. it has no longer any methods

View File

@ -51,15 +51,12 @@ public class IncCompileDropClasses extends SJavacTester {
ToolBox tb = new ToolBox();
void test() throws Exception {
clean(TEST_ROOT);
Files.createDirectories(GENSRC);
Files.createDirectories(BIN);
Files.createDirectories(HEADERS);
initialCompile();
incrementalCompileDroppingClasses();
clean(GENSRC, BIN, HEADERS);
}
// Testing that deleting AA.java deletes all generated inner class including AA.class

View File

@ -50,15 +50,12 @@ public class IncCompileNoChanges extends SJavacTester {
Map<String,Long> previous_headers_state;
void test() throws Exception {
clean(Paths.get(getClass().getSimpleName()));
Files.createDirectories(GENSRC);
Files.createDirectories(BIN);
Files.createDirectories(HEADERS);
initialCompile();
incrementalCompileNoChanges();
clean(GENSRC, BIN, HEADERS);
}
// Testing that no change in sources implies no change in binaries

View File

@ -51,15 +51,12 @@ public class IncCompileUpdateNative extends SJavacTester {
ToolBox tb = new ToolBox();
void test() throws Exception {
clean(TEST_ROOT);
Files.createDirectories(GENSRC);
Files.createDirectories(BIN);
Files.createDirectories(HEADERS);
initialCompile();
incrementalCompileChangeNative();
clean(GENSRC, BIN, HEADERS);
}
// Update B.java with a new value for the final static annotated with @Native

View File

@ -46,8 +46,6 @@ public class NoState extends SJavacTester {
}
public void run() throws Exception {
clean(TEST_ROOT);
ToolBox tb = new ToolBox();
tb.writeFile(GENSRC.resolve("pkg/A.java"), "package pkg; class A {}");
Files.createDirectory(BIN);
compile("-d", BIN.toString(),

View File

@ -47,9 +47,7 @@ public class PermittedArtifact extends SJavacTester {
//Verify that --permit-artifact=bin works
void test() throws Exception {
clean(TEST_ROOT);
Files.createDirectories(BIN);
clean(GENSRC, BIN);
Map<String,Long> previous_bin_state = collectState(BIN);
@ -73,6 +71,5 @@ public class PermittedArtifact extends SJavacTester {
BIN + "/alfa/omega/A.class",
BIN + "/alfa/omega/AA.class",
BIN + "/javac_state");
clean(GENSRC, BIN);
}
}

View File

@ -34,6 +34,7 @@ public class SJavacTester {
+ "portfile=testportfile,"
+ "background=false";
final ToolBox tb = new ToolBox();
final Path TEST_ROOT = Paths.get(getClass().getSimpleName());
// Generated sources that will test aspects of sjavac
@ -53,7 +54,6 @@ public class SJavacTester {
void initialCompile() throws Exception {
System.out.println("\nInitial compile of gensrc.");
ToolBox tb = new ToolBox();
tb.writeFile(GENSRC.resolve("alfa/omega/AINT.java"),
"package alfa.omega; public interface AINT { void aint(); }");
tb.writeFile(GENSRC.resolve("alfa/omega/A.java"),
@ -101,30 +101,6 @@ public class SJavacTester {
}
}
void delete(final Path root) throws IOException {
if (!Files.exists(root)) return;
Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
{
Files.delete(file);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException
{
if (e == null) {
if (!dir.equals(root)) Files.delete(dir);
return FileVisitResult.CONTINUE;
} else {
// directory iteration failed
throw e;
}
}
});
}
void compile(String... args) throws Exception {
int rc = Main.go(args);
if (rc != 0) throw new Exception("Error during compile!");
@ -265,10 +241,4 @@ public class SJavacTester {
throw new Exception("The dir should not differ! But it does!");
}
}
void clean(Path... listOfDirs) throws Exception {
for (Path dir : listOfDirs) {
delete(dir);
}
}
}

View File

@ -46,7 +46,6 @@ public class StateDir extends SJavacTester {
}
void test() throws Exception {
clean(TEST_ROOT);
Path BAR = TEST_ROOT.resolve("bar");
Files.createDirectories(BAR);
Files.createDirectories(BIN);
@ -69,6 +68,5 @@ public class StateDir extends SJavacTester {
Map<String,Long> new_bar_state = collectState(BAR);
verifyThatFilesHaveBeenAdded(previous_bar_state, new_bar_state,
BAR + "/javac_state");
clean(GENSRC, BIN, BAR);
}
}