This commit is contained in:
Lana Steuck 2016-03-10 09:51:46 -08:00
commit aebad3705f
28 changed files with 2656 additions and 528 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2016, 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,7 +26,7 @@
package com.sun.tools.javac.code;
import java.io.IOException;
import java.io.File;
import java.nio.file.Path;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
@ -45,7 +45,6 @@ import com.sun.tools.javac.code.Symbol.CompletionFailure;
import com.sun.tools.javac.code.Symbol.PackageSymbol;
import com.sun.tools.javac.code.Symbol.TypeSymbol;
import com.sun.tools.javac.comp.Annotate;
import com.sun.tools.javac.comp.Enter;
import com.sun.tools.javac.file.JRTIndex;
import com.sun.tools.javac.file.JavacFileManager;
import com.sun.tools.javac.jvm.ClassReader;
@ -535,25 +534,25 @@ public class ClassFinder {
if (fileManager instanceof StandardJavaFileManager) {
StandardJavaFileManager fm = (StandardJavaFileManager)fileManager;
if (haveSourcePath && wantSourceFiles) {
List<File> path = List.nil();
for (File file : fm.getLocation(SOURCE_PATH)) {
path = path.prepend(file);
List<Path> path = List.nil();
for (Path sourcePath : fm.getLocationAsPaths(SOURCE_PATH)) {
path = path.prepend(sourcePath);
}
log.printVerbose("sourcepath", path.reverse().toString());
} else if (wantSourceFiles) {
List<File> path = List.nil();
for (File file : fm.getLocation(CLASS_PATH)) {
path = path.prepend(file);
List<Path> path = List.nil();
for (Path classPath : fm.getLocationAsPaths(CLASS_PATH)) {
path = path.prepend(classPath);
}
log.printVerbose("sourcepath", path.reverse().toString());
}
if (wantClassFiles) {
List<File> path = List.nil();
for (File file : fm.getLocation(PLATFORM_CLASS_PATH)) {
path = path.prepend(file);
List<Path> path = List.nil();
for (Path platformPath : fm.getLocationAsPaths(PLATFORM_CLASS_PATH)) {
path = path.prepend(platformPath);
}
for (File file : fm.getLocation(CLASS_PATH)) {
path = path.prepend(file);
for (Path classPath : fm.getLocationAsPaths(CLASS_PATH)) {
path = path.prepend(classPath);
}
log.printVerbose("classpath", path.reverse().toString());
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2016, 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
@ -25,7 +25,6 @@
package com.sun.tools.javac.file;
import java.io.File;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.InvalidPathException;

View File

@ -33,8 +33,7 @@ import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.util.*;
import static com.sun.tools.javac.code.Kinds.Kind.MTH;
import static com.sun.tools.javac.code.TypeTag.DOUBLE;
import static com.sun.tools.javac.code.TypeTag.LONG;
import static com.sun.tools.javac.code.TypeTag.*;
import static com.sun.tools.javac.jvm.ByteCodes.*;
import static com.sun.tools.javac.tree.JCTree.Tag.PLUS;
import com.sun.tools.javac.jvm.Items.*;
@ -142,6 +141,25 @@ public abstract class StringConcat {
return res.append(tree);
}
/**
* If the type is not accessible from current context, try to figure out the
* sharpest accessible supertype.
*
* @param originalType type to sharpen
* @return sharped type
*/
Type sharpestAccessible(Type originalType) {
if (originalType.hasTag(ARRAY)) {
return types.makeArrayType(sharpestAccessible(types.elemtype(originalType)));
}
Type type = originalType;
while (!rs.isAccessible(gen.getAttrEnv(), type.asElement())) {
type = types.supertype(type);
}
return type;
}
/**
* "Legacy" bytecode flavor: emit the StringBuilder.append chains for string
* concatenation.
@ -314,7 +332,7 @@ public abstract class StringConcat {
if (arg.type == syms.botType) {
dynamicArgs.add(types.boxedClass(syms.voidType).type);
} else {
dynamicArgs.add(arg.type);
dynamicArgs.add(sharpestAccessible(arg.type));
}
gen.genExpr(arg, arg.type).load();
}
@ -415,7 +433,7 @@ public abstract class StringConcat {
} else {
// Ordinary arguments come through the dynamic arguments.
recipe.append(TAG_ARG);
dynamicArgs.add(arg.type);
dynamicArgs.add(sharpestAccessible(arg.type));
gen.genExpr(arg, arg.type).load();
}
}

View File

@ -31,6 +31,7 @@ import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Path;
import java.util.*;
import java.util.regex.*;
import java.util.stream.Collectors;
@ -42,6 +43,7 @@ import javax.lang.model.util.*;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
import static javax.tools.StandardLocation.*;
import com.sun.source.util.TaskEvent;
@ -79,6 +81,7 @@ import com.sun.tools.javac.util.Name;
import com.sun.tools.javac.util.Names;
import com.sun.tools.javac.util.Options;
import com.sun.tools.javac.util.ServiceLoader;
import static com.sun.tools.javac.code.Lint.LintCategory.PROCESSING;
import static com.sun.tools.javac.code.Kinds.Kind.*;
import static com.sun.tools.javac.main.Option.*;
@ -317,9 +320,9 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
if (fileManager instanceof JavacFileManager) {
StandardJavaFileManager standardFileManager = (JavacFileManager) fileManager;
Iterable<? extends File> workingPath = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH)
? standardFileManager.getLocation(ANNOTATION_PROCESSOR_PATH)
: standardFileManager.getLocation(CLASS_PATH);
Iterable<? extends Path> workingPath = fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH)
? standardFileManager.getLocationAsPaths(ANNOTATION_PROCESSOR_PATH)
: standardFileManager.getLocationAsPaths(CLASS_PATH);
if (needClassLoader(options.get(PROCESSOR), workingPath) )
handleException(key, e);
@ -1298,14 +1301,14 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
* Called retroactively to determine if a class loader was required,
* after we have failed to create one.
*/
private boolean needClassLoader(String procNames, Iterable<? extends File> workingpath) {
private boolean needClassLoader(String procNames, Iterable<? extends Path> workingpath) {
if (procNames != null)
return true;
URL[] urls = new URL[1];
for(File pathElement : workingpath) {
for(Path pathElement : workingpath) {
try {
urls[0] = pathElement.toURI().toURL();
urls[0] = pathElement.toUri().toURL();
if (ServiceProxy.hasService(Processor.class, urls))
return true;
} catch (MalformedURLException ex) {

View File

@ -1,6 +1,5 @@
apple.laf.*: hidden
apple.security.*: hidden
com.apple.concurrent.*: hidden
com.apple.eawt.*: hidden
com.apple.eawt.event.*: hidden
com.apple.eio.*: hidden

View File

@ -38,7 +38,7 @@ enum Profile {
"jdk.httpserver", "jdk.security.auth",
"jdk.naming.dns", "jdk.naming.rmi",
"jdk.management"),
FULL_JRE("Full JRE", 4, "java.se", "jdk.deploy.osx", "jdk.charsets",
FULL_JRE("Full JRE", 4, "java.se", "jdk.charsets",
"jdk.crypto.ec", "jdk.crypto.pkcs11",
"jdk.crypto.mscapi", "jdk.crypto.ucrypto", "jdk.jvmstat",
"jdk.localedata", "jdk.scripting.nashorn", "jdk.zipfs");

View File

@ -0,0 +1,271 @@
/*
* Copyright (c) 1995, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.internal.jshell.tool;
import java.util.Arrays;
import java.util.stream.Stream;
/**
* Parse command arguments, derived from StreamTokenizer by
* @author James Gosling
*/
class ArgTokenizer {
private final String str;
private final int length;
private int next = 0;
private char buf[] = new char[20];
private int mark;
private final byte ctype[] = new byte[256];
private static final byte CT_ALPHA = 0;
private static final byte CT_WHITESPACE = 1;
private static final byte CT_QUOTE = 8;
private String sval;
private boolean isQuoted = false;
ArgTokenizer(String arg) {
this.str = arg;
this.length = arg.length();
quoteChar('"');
quoteChar('\'');
whitespaceChars(0x09, 0x0D);
whitespaceChars(0x1C, 0x20);
whitespaceChars(0x85, 0x85);
whitespaceChars(0xA0, 0xA0);
}
String next() {
nextToken();
return sval;
}
String[] next(String... strings) {
return next(Arrays.stream(strings));
}
String[] next(Stream<String> stream) {
nextToken();
if (sval == null) {
return null;
}
String[] matches = stream
.filter(s -> s.startsWith(sval))
.toArray(size -> new String[size]);
return matches;
}
String val() {
return sval;
}
boolean isQuoted() {
return isQuoted;
}
String whole() {
return str;
}
void mark() {
mark = next;
}
void rewind() {
next = mark;
}
/**
* Reads a single character.
*
* @return The character read, or -1 if the end of the stream has been
* reached
*/
private int read() {
if (next >= length) {
return -1;
}
return str.charAt(next++);
}
/**
* Specifies that all characters <i>c</i> in the range
* <code>low&nbsp;&lt;=&nbsp;<i>c</i>&nbsp;&lt;=&nbsp;high</code>
* are white space characters. White space characters serve only to
* separate tokens in the input stream.
*
* <p>Any other attribute settings for the characters in the specified
* range are cleared.
*
* @param low the low end of the range.
* @param hi the high end of the range.
*/
private void whitespaceChars(int low, int hi) {
if (low < 0)
low = 0;
if (hi >= ctype.length)
hi = ctype.length - 1;
while (low <= hi)
ctype[low++] = CT_WHITESPACE;
}
/**
* Specifies that matching pairs of this character delimit string
* constants in this tokenizer.
* <p>
* If a string quote character is encountered, then a string is
* recognized, consisting of all characters after (but not including)
* the string quote character, up to (but not including) the next
* occurrence of that same string quote character, or a line
* terminator, or end of file. The usual escape sequences such as
* {@code "\u005Cn"} and {@code "\u005Ct"} are recognized and
* converted to single characters as the string is parsed.
*
* <p>Any other attribute settings for the specified character are cleared.
*
* @param ch the character.
*/
private void quoteChar(int ch) {
if (ch >= 0 && ch < ctype.length)
ctype[ch] = CT_QUOTE;
}
private int unicode2ctype(int c) {
switch (c) {
case 0x1680:
case 0x180E:
case 0x200A:
case 0x202F:
case 0x205F:
case 0x3000:
return CT_WHITESPACE;
default:
return CT_ALPHA;
}
}
/**
* Parses the next token of this tokenizer.
*/
public void nextToken() {
byte ct[] = ctype;
int c;
int lctype;
sval = null;
isQuoted = false;
do {
c = read();
if (c < 0) {
return;
}
lctype = (c < 256) ? ct[c] : unicode2ctype(c);
} while (lctype == CT_WHITESPACE);
if (lctype == CT_ALPHA) {
int i = 0;
do {
if (i >= buf.length) {
buf = Arrays.copyOf(buf, buf.length * 2);
}
buf[i++] = (char) c;
c = read();
lctype = c < 0 ? CT_WHITESPACE : (c < 256)? ct[c] : unicode2ctype(c);
} while (lctype == CT_ALPHA);
if (c >= 0) --next; // push last back
sval = String.copyValueOf(buf, 0, i);
return;
}
if (lctype == CT_QUOTE) {
int quote = c;
int i = 0;
/* Invariants (because \Octal needs a lookahead):
* (i) c contains char value
* (ii) d contains the lookahead
*/
int d = read();
while (d >= 0 && d != quote) {
if (d == '\\') {
c = read();
int first = c; /* To allow \377, but not \477 */
if (c >= '0' && c <= '7') {
c = c - '0';
int c2 = read();
if ('0' <= c2 && c2 <= '7') {
c = (c << 3) + (c2 - '0');
c2 = read();
if ('0' <= c2 && c2 <= '7' && first <= '3') {
c = (c << 3) + (c2 - '0');
d = read();
} else
d = c2;
} else
d = c2;
} else {
switch (c) {
case 'a':
c = 0x7;
break;
case 'b':
c = '\b';
break;
case 'f':
c = 0xC;
break;
case 'n':
c = '\n';
break;
case 'r':
c = '\r';
break;
case 't':
c = '\t';
break;
case 'v':
c = 0xB;
break;
}
d = read();
}
} else {
c = d;
d = read();
}
if (i >= buf.length) {
buf = Arrays.copyOf(buf, buf.length * 2);
}
buf[i++] = (char)c;
}
if (d == quote) {
isQuoted = true;
}
sval = String.copyValueOf(buf, 0, i);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2016, 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
@ -231,7 +231,7 @@ class CompletenessAnalyzer {
// Declarations and type parameters (thus expressions)
EXTENDS(TokenKind.EXTENDS, XEXPR|XDECL), // extends
COMMA(TokenKind.COMMA, XEXPR|XDECL|XSTART), // ,
COMMA(TokenKind.COMMA, XEXPR|XDECL), // ,
AMP(TokenKind.AMP, XEXPR|XDECL), // &
GT(TokenKind.GT, XEXPR|XDECL), // >
LT(TokenKind.LT, XEXPR|XDECL1), // <

View File

@ -61,6 +61,7 @@ import javax.lang.model.util.Elements;
import javax.tools.FileObject;
import jdk.jshell.MemoryFileManager.SourceMemoryJavaFileObject;
import jdk.jshell.ClassTracker.ClassInfo;
import jdk.Version;
/**
* The primary interface to the compiler API. Parsing, analysis, and
@ -73,6 +74,7 @@ class TaskFactory {
private final MemoryFileManager fileManager;
private final JShell state;
private String classpath = System.getProperty("java.class.path");
private final static Version INITIAL_SUPPORTED_VER = Version.parse("9");
TaskFactory(JShell state) {
this.state = state;
@ -80,7 +82,8 @@ class TaskFactory {
if (compiler == null) {
throw new UnsupportedOperationException("Compiler not available, must be run with full JDK 9.");
}
if (!System.getProperty("java.specification.version").equals("9")) {
Version current = Version.parse(System.getProperty("java.specification.version"));
if (INITIAL_SUPPORTED_VER.compareToIgnoreOpt(current) > 0) {
throw new UnsupportedOperationException("Wrong compiler, must be run with full JDK 9.");
}
this.fileManager = new MemoryFileManager(

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2016, 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
@ -50,13 +50,9 @@ import org.testng.annotations.Test;
public class CommandCompletionTest extends ReplToolTesting {
public void testCommand() {
assertCompletion("/f|", false, "/feedback ");
assertCompletion("/deb|", false);
assertCompletion("/feedback v|", false, "verbose");
assertCompletion("/c|", false, "/classes ", "/classpath ");
assertCompletion("/h|", false, "/help ", "/history ");
assertCompletion("/feedback |", false,
"?", "concise", "default", "normal", "off", "verbose");
}
public void testList() {
@ -108,7 +104,7 @@ public class CommandCompletionTest extends ReplToolTesting {
public void testSave() throws IOException {
Compiler compiler = new Compiler();
assertCompletion("/s|", false, "/save ", "/seteditor ", "/setstart ");
assertCompletion("/s|", false, "/save ", "/set ");
List<String> p1 = listFiles(Paths.get(""));
Collections.addAll(p1, "all ", "history ", "start ");
FileSystems.getDefault().getRootDirectories().forEach(s -> p1.add(s.toString()));

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2016, 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
@ -23,6 +23,7 @@
/*
* @test
* @bug 8149524
* @summary Test SourceCodeAnalysis
* @build KullaTesting TestingInputStream
* @run testng CompletenessTest
@ -60,6 +61,7 @@ public class CompletenessTest extends KullaTesting {
"try { } finally { }",
"try (java.util.zip.ZipFile zf = new java.util.zip.ZipFile(zipFileName)) { }",
"foo: while (true) { printf(\"Innn\"); break foo; }",
"class Case<E1 extends Enum<E1>, E2 extends Enum<E2>, E3 extends Enum<E3>> {}",
";",
};

View File

@ -113,7 +113,7 @@ public class ExternalEditorTest extends EditorTestBase {
@Override
public void testEditor(boolean defaultStartup, String[] args, ReplTest... tests) {
ReplTest[] t = new ReplTest[tests.length + 1];
t[0] = a -> assertCommandCheckOutput(a, "/seteditor " + executionScript,
t[0] = a -> assertCommandCheckOutput(a, "/set editor " + executionScript,
assertStartsWith("| Editor set to: " + executionScript));
System.arraycopy(tests, 0, t, 1, tests.length);
super.testEditor(defaultStartup, args, t);
@ -193,8 +193,8 @@ public class ExternalEditorTest extends EditorTestBase {
@Test
public void setUnknownEditor() {
test(
a -> assertCommand(a, "/seteditor", "| /seteditor requires a path argument\n"),
a -> assertCommand(a, "/seteditor UNKNOWN", "| Editor set to: UNKNOWN\n"),
a -> assertCommand(a, "/set editor", "| /set editor requires a path argument\n"),
a -> assertCommand(a, "/set editor UNKNOWN", "| Editor set to: UNKNOWN\n"),
a -> assertCommand(a, "int a;", null),
a -> assertCommand(a, "/e 1",
"| Edit Error: process IO failure: Cannot run program \"UNKNOWN\": error=2, No such file or directory\n")
@ -204,7 +204,7 @@ public class ExternalEditorTest extends EditorTestBase {
@Test(enabled = false)
public void testRemoveTempFile() {
test(new String[]{"-nostartup"},
a -> assertCommandCheckOutput(a, "/seteditor " + executionScript,
a -> assertCommandCheckOutput(a, "/set editor " + executionScript,
assertStartsWith("| Editor set to: " + executionScript)),
a -> assertVariable(a, "int", "a", "0", "0"),
a -> assertEditOutput(a, "/e 1", assertStartsWith("| Edit Error: Failure read edit file:"), () -> {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2016, 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
@ -397,6 +397,15 @@ public class ReplToolTesting {
assertCommand(after, cmd, out, "", null, "", "");
}
public void assertCommandOutputContains(boolean after, String cmd, String has) {
assertCommandCheckOutput(after, cmd, (s) ->
assertTrue(s.contains(has), "Output: \'" + s + "' does not contain: " + has));
}
public void assertCommandOutputStartsWith(boolean after, String cmd, String starts) {
assertCommandCheckOutput(after, cmd, assertStartsWith(starts));
}
public void assertCommandCheckOutput(boolean after, String cmd, Consumer<String> check) {
if (!after) {
assertCommand(false, cmd, null);
@ -437,13 +446,13 @@ public class ReplToolTesting {
}
private List<String> computeCompletions(String code, boolean isSmart) {
JShellTool repl = this.repl != null ? this.repl
JShellTool js = this.repl != null ? this.repl
: new JShellTool(null, null, null, null, null, null, null);
int cursor = code.indexOf('|');
code = code.replace("|", "");
assertTrue(cursor > -1, "'|' not found: " + code);
List<Suggestion> completions =
repl.commandCompletionSuggestions(code, cursor, new int[1]); //XXX: ignoring anchor for now
js.commandCompletionSuggestions(code, cursor, new int[1]); //XXX: ignoring anchor for now
return completions.stream()
.filter(s -> isSmart == s.isSmart)
.map(s -> s.continuation)
@ -481,6 +490,15 @@ public class ReplToolTesting {
return name.hashCode();
}
@Override
public boolean equals(Object o) {
if (o instanceof MemberInfo) {
MemberInfo mi = (MemberInfo) o;
return name.equals(mi.name);
}
return false;
}
public abstract Consumer<String> checkOutput();
public String getSource() {
@ -536,6 +554,11 @@ public class ReplToolTesting {
"Output: " + output + " does not fit pattern: " + finalPattern);
}
@Override
public int hashCode() {
return name.hashCode();
}
@Override
public boolean equals(Object o) {
if (o instanceof VariableInfo) {
@ -585,6 +608,10 @@ public class ReplToolTesting {
return s -> assertTrue(checkOutput.test(s), "Expected: '" + expectedOutput + "', actual: " + s);
}
@Override
public int hashCode() {
return (name.hashCode() << 2) ^ type.hashCode() ;
}
@Override
public boolean equals(Object o) {
@ -615,6 +642,11 @@ public class ReplToolTesting {
return s -> assertTrue(checkOutput.test(s), "Expected: '" + expectedOutput + "', actual: " + s);
}
@Override
public int hashCode() {
return name.hashCode() ;
}
@Override
public boolean equals(Object o) {
if (o instanceof ClassInfo) {
@ -640,6 +672,11 @@ public class ReplToolTesting {
return s -> assertTrue("".equals(s), "Expected: '', actual: " + s);
}
@Override
public int hashCode() {
return (name.hashCode() << 2) ^ type.hashCode() ;
}
@Override
public boolean equals(Object o) {
if (o instanceof ImportInfo) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2016, 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
@ -23,7 +23,7 @@
/*
* @test
* @bug 8143037 8142447 8144095 8140265 8144906 8146138 8147887 8147886
* @bug 8143037 8142447 8144095 8140265 8144906 8146138 8147887 8147886 8148316 8148317
* @requires os.family != "solaris"
* @summary Tests for Basic tests for REPL tool
* @library /tools/lib
@ -90,8 +90,7 @@ public class ToolBasicTest extends ReplToolTesting {
public void elideStartUpFromList() {
test(
(a) -> assertCommandCheckOutput(a, "123", (s) ->
assertTrue(s.contains("type int"), s)),
(a) -> assertCommandOutputContains(a, "123", "type int"),
(a) -> assertCommandCheckOutput(a, "/list", (s) -> {
int cnt;
try (Scanner scanner = new Scanner(s)) {
@ -112,8 +111,7 @@ public class ToolBasicTest extends ReplToolTesting {
Compiler compiler = new Compiler();
Path path = compiler.getPath("myfile");
test(
(a) -> assertCommandCheckOutput(a, "123",
(s) -> assertTrue(s.contains("type int"), s)),
(a) -> assertCommandOutputContains(a, "123", "type int"),
(a) -> assertCommand(a, "/save " + path.toString(), "")
);
try (Stream<String> lines = Files.lines(path)) {
@ -594,12 +592,12 @@ public class ToolBasicTest extends ReplToolTesting {
(a) -> assertMethod(a, "void f() {}", "()V", "f"),
(a) -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"),
(a) -> assertCommand(a, "/save " + startUpFile.toString(), null),
(a) -> assertCommand(a, "/setstart " + startUpFile.toString(), null)
(a) -> assertCommand(a, "/set start " + startUpFile.toString(), null)
);
Path unknown = compiler.getPath("UNKNOWN");
test(
(a) -> assertCommand(a, "/setstart " + unknown.toString(),
"| File '" + unknown + "' for /setstart is not found.\n")
(a) -> assertCommand(a, "/set start " + unknown.toString(),
"| File '" + unknown + "' for /set start is not found.\n")
);
test(false, new String[0],
(a) -> {
@ -619,7 +617,7 @@ public class ToolBasicTest extends ReplToolTesting {
}
private void removeStartup() {
Preferences preferences = Preferences.userRoot().node("tool/REPL");
Preferences preferences = Preferences.userRoot().node("tool/JShell");
if (preferences != null) {
preferences.remove("STARTUP");
}
@ -636,7 +634,7 @@ public class ToolBasicTest extends ReplToolTesting {
}
public void testNoArgument() {
String[] commands = {"/save", "/open", "/setstart"};
String[] commands = {"/save", "/open", "/set start"};
test(Stream.of(commands)
.map(cmd -> {
String c = cmd;
@ -670,8 +668,7 @@ public class ToolBasicTest extends ReplToolTesting {
test(
a -> assertVariable(a, "int", "x"),
a -> assertCommandCheckOutput(a, "/vars", assertVariables()),
a -> assertCommandCheckOutput(a, "System.exit(5);", s ->
assertTrue(s.contains("terminated"), s)),
a -> assertCommandOutputContains(a, "System.exit(5);", "terminated"),
a -> assertCommandCheckOutput(a, "/vars", s ->
assertTrue(s.trim().isEmpty(), s)),
a -> assertMethod(a, "void f() { }", "()void", "f"),
@ -699,8 +696,7 @@ public class ToolBasicTest extends ReplToolTesting {
s -> assertEquals(s, "| No definition or id named " + arg +
" found. There are no active definitions.\n")),
a -> assertVariable(a, "int", "aardvark"),
a -> assertCommandCheckOutput(a, "/list aardvark",
s -> assertTrue(s.contains("aardvark"))),
a -> assertCommandOutputContains(a, "/list aardvark", "aardvark"),
a -> assertCommandCheckOutput(a, "/list start",
s -> checkLineToList(s, START_UP)),
a -> assertCommandCheckOutput(a, "/list all",
@ -714,14 +710,14 @@ public class ToolBasicTest extends ReplToolTesting {
}
public void testFeedbackNegative() {
test(a -> assertCommandCheckOutput(a, "/feedback aaaa",
assertStartsWith("| Follow /feedback with of the following")));
test(a -> assertCommandCheckOutput(a, "/set feedback aaaa",
assertStartsWith("| Does not match any current feedback mode")));
}
public void testFeedbackOff() {
for (String off : new String[]{"o", "off"}) {
test(
a -> assertCommand(a, "/feedback " + off, ""),
a -> assertCommand(a, "/set feedback " + off, ""),
a -> assertCommand(a, "int a", ""),
a -> assertCommand(a, "void f() {}", ""),
a -> assertCommandCheckOutput(a, "aaaa", assertStartsWith("| Error:")),
@ -730,23 +726,6 @@ public class ToolBasicTest extends ReplToolTesting {
}
}
public void testFeedbackConcise() {
Compiler compiler = new Compiler();
Path testConciseFile = compiler.getPath("testConciseFeedback");
String[] sources = new String[] {"int a", "void f() {}", "class A {}", "a = 10"};
compiler.writeToFile(testConciseFile, sources);
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")
);
}
}
public void testFeedbackNormal() {
Compiler compiler = new Compiler();
Path testNormalFile = compiler.getPath("testConciseNormal");
@ -759,58 +738,20 @@ public class ToolBasicTest extends ReplToolTesting {
"| Variable a has been assigned the value 10\n"
};
compiler.writeToFile(testNormalFile, sources2);
for (String feedback : new String[]{"/f", "/feedback"}) {
for (String feedbackState : new String[]{"n", "normal", "v", "verbose"}) {
String f = null;
if (feedbackState.startsWith("n")) {
f = "normal";
} else if (feedbackState.startsWith("v")) {
f = "verbose";
}
final String finalF = f;
for (String feedback : new String[]{"/set f", "/set feedback"}) {
for (String feedbackState : new String[]{"n", "normal", "o", "off"}) {
test(
a -> assertCommand(a, feedback + " " + feedbackState, "| Feedback mode: " + finalF +"\n"),
a -> assertCommand(a, feedback + " " + feedbackState, "| Feedback mode: normal\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 " + testNormalFile.toString(),
"| Modified variable a of type int\n" +
"| Modified method f()\n" +
"| Update overwrote method f()\n" +
"| Modified class A\n" +
"| Update overwrote class A\n" +
"| Variable a has been assigned the value 10\n")
a -> assertCommand(a, "/o " + testNormalFile.toString(), "")
);
}
}
}
public void testFeedbackDefault() {
Compiler compiler = new Compiler();
Path testDefaultFile = compiler.getPath("testDefaultFeedback");
String[] sources = new String[] {"int a", "void f() {}", "class A {}", "a = 10"};
String[] output = new String[] {
"| Added variable a of type int\n",
"| Added method f()\n",
"| Added class A\n",
"| Variable a has been assigned the value 10\n"
};
compiler.writeToFile(testDefaultFile, sources);
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() {
test(false, new String[]{"-nostartup"},
a -> assertVariable(a, "int", "a"),
@ -906,7 +847,7 @@ public class ToolBasicTest extends ReplToolTesting {
public void testCommandPrefix() {
test(a -> assertCommandCheckOutput(a, "/s",
assertStartsWith("| Command: /s is ambiguous: /seteditor, /save, /setstart")),
assertStartsWith("| Command: /s is ambiguous: /save, /set")),
a -> assertCommand(a, "int var", "| Added variable var of type int\n"),
a -> assertCommandCheckOutput(a, "/va",
assertStartsWith("| int var = 0")),

View File

@ -0,0 +1,159 @@
/*
* Copyright (c) 2016, 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 8148316 8148317
* @summary Tests for output customization
* @library /tools/lib
* @build KullaTesting TestingInputStream ToolBox Compiler
* @run testng ToolFormatTest
*/
import org.testng.annotations.Test;
@Test
public class ToolFormatTest extends ReplToolTesting {
public void testSetFormat() {
try {
test(
(a) -> assertCommandOutputStartsWith(a, "/set newmode test command", "| Created new feedback mode: test"),
(a) -> assertCommand(a, "/set field test pre '$ '", ""),
(a) -> assertCommand(a, "/set field test post ''", ""),
(a) -> assertCommand(a, "/set field test action 'ADD ' added-primary", ""),
(a) -> assertCommand(a, "/set field test action 'MOD ' modified-primary", ""),
(a) -> assertCommand(a, "/set field test action 'REP ' replaced-primary", ""),
(a) -> assertCommand(a, "/set field test action 'UP-ADD ' added-update", ""),
(a) -> assertCommand(a, "/set field test action 'UP-MOD ' modified-update", ""),
(a) -> assertCommand(a, "/set field test action 'UP-REP ' replaced-update", ""),
(a) -> assertCommand(a, "/set field test resolve 'OK' ok-*", ""),
(a) -> assertCommand(a, "/set field test resolve 'DEF' defined-*", ""),
(a) -> assertCommand(a, "/set field test resolve 'NODEF' notdefined-*", ""),
(a) -> assertCommand(a, "/set field test name ':%s ' ", ""),
(a) -> assertCommand(a, "/set field test type '[%s]' ", ""),
(a) -> assertCommand(a, "/set field test result '=%s ' ", ""),
(a) -> assertCommand(a, "/set format test '{pre}{action}{type}{name}{result}{resolve}' *-*-*", ""),
(a) -> assertCommand(a, "/set format test '{pre}HI this is enum' enum", ""),
(a) -> assertCommand(a, "/set feedback test", "$ Feedback mode: test"),
(a) -> assertCommand(a, "class D {}", "$ ADD :D OK"),
(a) -> assertCommand(a, "void m() {}", "$ ADD []:m OK"),
(a) -> assertCommand(a, "interface EX extends EEX {}", "$ ADD :EX NODEF"),
(a) -> assertCommand(a, "56", "$ ADD [int]:$4 =56 OK"),
(a) -> assertCommand(a, "class D { int hh; }", "$ REP :D OK$ OVERWROTE-UPDATE:D OK"),
(a) -> assertCommandOutputStartsWith(a, "/set feedback normal", "| Feedback mode: normal")
);
} finally {
assertCommandCheckOutput(false, "/set feedback normal", s -> {
});
}
}
public void testNewModeQuiet() {
try {
test(
(a) -> assertCommandOutputStartsWith(a, "/set newmode nmq quiet normal", "| Created new feedback mode: nmq"),
(a) -> assertCommand(a, "/set feedback nmq", ""),
(a) -> assertCommand(a, "/se ne nmq2 q nor", ""),
(a) -> assertCommand(a, "/se fee nmq2", ""),
(a) -> assertCommand(a, "/set newmode nmc command normal", ""),
(a) -> assertCommandOutputStartsWith(a, "/set feedback nmc", "| Feedback mode: nmc"),
(a) -> assertCommandOutputStartsWith(a, "/set newmode nm", "| Created new feedback mode: nm"),
(a) -> assertCommandOutputStartsWith(a, "/set feedback nm", "| Feedback mode: nm")
);
} finally {
assertCommandCheckOutput(false, "/set feedback normal", s -> {
});
}
}
public void testSetError() {
try {
test(
(a) -> assertCommandOutputStartsWith(a, "/set newmode te command normal", "| Created new feedback mode: te"),
(a) -> assertCommand(a, "/set field te errorpre 'ERROR: '", ""),
(a) -> assertCommandOutputStartsWith(a, "/set feedback te", ""),
(a) -> assertCommandCheckOutput(a, "/set ", assertStartsWith("ERROR: The /set command requires arguments")),
(a) -> assertCommandCheckOutput(a, "/set xyz", assertStartsWith("ERROR: Not a valid argument to /set")),
(a) -> assertCommandCheckOutput(a, "/set f", assertStartsWith("ERROR: Ambiguous argument to /set")),
(a) -> assertCommandCheckOutput(a, "/set feedback", assertStartsWith("ERROR: Expected a feedback mode")),
(a) -> assertCommandCheckOutput(a, "/set feedback xyz", assertStartsWith("ERROR: Does not match any current feedback mode")),
(a) -> assertCommandCheckOutput(a, "/set format", assertStartsWith("ERROR: Expected a feedback mode")),
(a) -> assertCommandCheckOutput(a, "/set format xyz", assertStartsWith("ERROR: Does not match any current feedback mode")),
(a) -> assertCommandCheckOutput(a, "/set format te", assertStartsWith("ERROR: Expected format missing")),
(a) -> assertCommandCheckOutput(a, "/set format te aaa", assertStartsWith("ERROR: Format 'aaa' must be quoted")),
(a) -> assertCommandCheckOutput(a, "/set format te 'aaa'", assertStartsWith("ERROR: At least one selector required")),
(a) -> assertCommandCheckOutput(a, "/set format te 'aaa' frog", assertStartsWith("ERROR: Not a valid case")),
(a) -> assertCommandCheckOutput(a, "/set format te 'aaa' import-frog", assertStartsWith("ERROR: Not a valid action")),
(a) -> assertCommandCheckOutput(a, "/set newmode", assertStartsWith("ERROR: Expected new feedback mode")),
(a) -> assertCommandCheckOutput(a, "/set newmode te", assertStartsWith("ERROR: Expected a new feedback mode name")),
(a) -> assertCommandCheckOutput(a, "/set newmode x xyz", assertStartsWith("ERROR: Specify either 'command' or 'quiet'")),
(a) -> assertCommandCheckOutput(a, "/set newmode x quiet y", assertStartsWith("ERROR: Does not match any current feedback mode")),
(a) -> assertCommandCheckOutput(a, "/set prompt", assertStartsWith("ERROR: Expected a feedback mode")),
(a) -> assertCommandCheckOutput(a, "/set prompt te", assertStartsWith("ERROR: Expected format missing")),
(a) -> assertCommandCheckOutput(a, "/set prompt te aaa xyz", assertStartsWith("ERROR: Format 'aaa' must be quoted")),
(a) -> assertCommandCheckOutput(a, "/set prompt te 'aaa' xyz", assertStartsWith("ERROR: Format 'xyz' must be quoted")),
(a) -> assertCommandCheckOutput(a, "/set prompt", assertStartsWith("ERROR: Expected a feedback mode")),
(a) -> assertCommandCheckOutput(a, "/set prompt te", assertStartsWith("ERROR: Expected format missing")),
(a) -> assertCommandCheckOutput(a, "/set prompt te aaa", assertStartsWith("ERROR: Format 'aaa' must be quoted")),
(a) -> assertCommandCheckOutput(a, "/set prompt te 'aaa'", assertStartsWith("ERROR: Expected format missing")),
(a) -> assertCommandCheckOutput(a, "/set field", assertStartsWith("ERROR: Expected a feedback mode")),
(a) -> assertCommandCheckOutput(a, "/set field xyz", assertStartsWith("ERROR: Does not match any current feedback mode: xyz")),
(a) -> assertCommandCheckOutput(a, "/set field te xyz", assertStartsWith("ERROR: Not a valid field: xyz, must be one of: when")),
(a) -> assertCommandCheckOutput(a, "/set field te action", assertStartsWith("ERROR: Expected format missing")),
(a) -> assertCommandCheckOutput(a, "/set field te action 'act'", assertStartsWith("ERROR: At least one selector required"))
);
} finally {
assertCommandCheckOutput(false, "/set feedback normal", s -> {
});
}
}
public void testSetHelp() {
try {
test(
(a) -> assertCommandOutputContains(a, "/help /set", "command to launch"),
(a) -> assertCommandOutputContains(a, "/help /set format", "vardecl"),
(a) -> assertCommandOutputContains(a, "/hel /se for", "vardecl"),
(a) -> assertCommandOutputContains(a, "/help /set editor", "temporary file")
);
} finally {
assertCommandCheckOutput(false, "/set feedback normal", s -> {
});
}
}
public void testSetHelpError() {
try {
test(
(a) -> assertCommandOutputStartsWith(a, "/set newmode te command normal", "| Created new feedback mode: te"),
(a) -> assertCommand(a, "/set field te errorpre 'ERROR: '", ""),
(a) -> assertCommandOutputStartsWith(a, "/set feedback te", "| Feedback mode: te"),
(a) -> assertCommandOutputContains(a, "/help /set xyz", "ERROR: Not a valid argument to /set: xyz"),
(a) -> assertCommandOutputContains(a, "/help /set f", "ERROR: Ambiguous argument to /set: f")
);
} finally {
assertCommandCheckOutput(false, "/set feedback normal", s -> {
});
}
}
}

View File

@ -0,0 +1,111 @@
/*
* Copyright (c) 2015, 2016, 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.
*/
import com.sun.tools.classfile.*;
import com.sun.tools.classfile.BootstrapMethods_attribute.BootstrapMethodSpecifier;
import com.sun.tools.classfile.ConstantPool.CONSTANT_InvokeDynamic_info;
import com.sun.tools.classfile.ConstantPool.CONSTANT_MethodHandle_info;
import java.io.File;
/*
* @test
* @bug 8148483 8151516 8151223
* @summary Test that StringConcat is working for JDK >= 9
* @modules jdk.jdeps/com.sun.tools.classfile
*
* @clean TestIndyStringConcat*
* @compile -source 6 -target 6 TestIndyStringConcat.java
* @run main TestIndyStringConcat false
*
* @clean TestIndyStringConcat*
* @compile -source 7 -target 7 TestIndyStringConcat.java
* @run main TestIndyStringConcat false
*
* @clean TestIndyStringConcat*
* @compile -source 8 -target 8 TestIndyStringConcat.java
* @run main TestIndyStringConcat false
*
* @clean TestIndyStringConcat*
* @compile -XDstringConcat=inline -source 9 -target 9 TestIndyStringConcat.java
* @run main TestIndyStringConcat false
*
* @clean TestIndyStringConcat*
* @compile -XDstringConcat=indy -source 9 -target 9 TestIndyStringConcat.java
* @run main TestIndyStringConcat true
*
* @clean TestIndyStringConcat*
* @compile -XDstringConcat=indyWithConstants -source 9 -target 9 TestIndyStringConcat.java
* @run main TestIndyStringConcat true
*/
public class TestIndyStringConcat {
static String other;
public static String test() {
return "Foo" + other;
}
public static void main(String[] args) throws Exception {
boolean expected = Boolean.valueOf(args[0]);
boolean actual = hasStringConcatFactoryCall("test");
if (expected != actual) {
throw new AssertionError("expected = " + expected + ", actual = " + actual);
}
}
public static boolean hasStringConcatFactoryCall(String methodName) throws Exception {
ClassFile classFile = ClassFile.read(new File(System.getProperty("test.classes", "."),
TestIndyStringConcat.class.getName() + ".class"));
ConstantPool constantPool = classFile.constant_pool;
BootstrapMethods_attribute bsm_attr =
(BootstrapMethods_attribute)classFile
.getAttribute(Attribute.BootstrapMethods);
for (Method method : classFile.methods) {
if (method.getName(constantPool).equals(methodName)) {
Code_attribute code = (Code_attribute) method.attributes
.get(Attribute.Code);
for (Instruction i : code.getInstructions()) {
if (i.getOpcode() == Opcode.INVOKEDYNAMIC) {
CONSTANT_InvokeDynamic_info indyInfo =
(CONSTANT_InvokeDynamic_info) constantPool.get(i.getUnsignedShort(1));
BootstrapMethodSpecifier bsmSpec =
bsm_attr.bootstrap_method_specifiers[indyInfo.bootstrap_method_attr_index];
CONSTANT_MethodHandle_info bsmInfo =
(CONSTANT_MethodHandle_info) constantPool.get(bsmSpec.bootstrap_method_ref);
if (bsmInfo.getCPRefInfo().getClassName().equals("java/lang/invoke/StringConcatFactory")) {
return true;
}
}
}
}
}
return false;
}
}

View File

@ -0,0 +1,98 @@
/*
* Copyright (c) 2016, 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 Holder {
public Private_PublicClass c1 = new Private_PublicClass();
public Private_PublicInterface c2 = new Private_PublicInterface();
public Private_PrivateInterface1 c3 = new Private_PrivateInterface1();
public Private_PrivateInterface2 c4 = new Private_PrivateInterface2();
public Public_PublicClass c5 = new Public_PublicClass();
public Public_PublicInterface c6 = new Public_PublicInterface();
public Public_PrivateInterface1 c7 = new Public_PrivateInterface1();
public Public_PrivateInterface2 c8 = new Public_PrivateInterface2();
public Private_PublicClass[] ac1 = new Private_PublicClass[0];
public Private_PublicInterface[] ac2 = new Private_PublicInterface[0];
public Private_PrivateInterface1[] ac3 = new Private_PrivateInterface1[0];
public Private_PrivateInterface2[] ac4 = new Private_PrivateInterface2[0];
public Public_PublicClass[] ac5 = new Public_PublicClass[0];
public Public_PublicInterface[] ac6 = new Public_PublicInterface[0];
public Public_PrivateInterface1[] ac7 = new Public_PrivateInterface1[0];
public Public_PrivateInterface2[] ac8 = new Public_PrivateInterface2[0];
public Private_PublicClass[][] aac1 = new Private_PublicClass[0][];
public Private_PublicInterface[][] aac2 = new Private_PublicInterface[0][];
public Private_PrivateInterface1[][] aac3 = new Private_PrivateInterface1[0][];
public Private_PrivateInterface2[][] aac4 = new Private_PrivateInterface2[0][];
public Public_PublicClass[][] aac5 = new Public_PublicClass[0][];
public Public_PublicInterface[][] aac6 = new Public_PublicInterface[0][];
public Public_PrivateInterface1[][] aac7 = new Public_PrivateInterface1[0][];
public Public_PrivateInterface2[][] aac8 = new Public_PrivateInterface2[0][];
public PublicInterface i1 = new Private_PublicInterface();
public PrivateInterface1 i2 = new Private_PrivateInterface1();
public PrivateInterface2 i3 = new Private_PrivateInterface2();
public PublicInterface[] ai1 = new Private_PublicInterface[0];
public PrivateInterface1[] ai2 = new Private_PrivateInterface1[0];
public PrivateInterface2[] ai3 = new Private_PrivateInterface2[0];
public PublicInterface[][] aai1 = new Private_PublicInterface[0][];
public PrivateInterface1[][] aai2 = new Private_PrivateInterface1[0][];
public PrivateInterface2[][] aai3 = new Private_PrivateInterface2[0][];
}
interface PrivateInterface1 {
}
interface PrivateInterface2 extends PublicInterface {
}
class Private_PublicClass extends PublicClass {
public String toString() {
return "passed";
}
}
class Private_PublicInterface implements PublicInterface {
public String toString() {
return "passed";
}
}
class Private_PrivateInterface1 implements PrivateInterface1 {
public String toString() {
return "passed";
}
}
class Private_PrivateInterface2 implements PrivateInterface2 {
public String toString() {
return "passed";
}
}

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2016, 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 PublicClass {
}

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2016, 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 interface PublicInterface {
}

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2016, 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 Public_PrivateInterface1 implements PrivateInterface1 {
public String toString() {
return "passed";
}
}

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2016, 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 Public_PrivateInterface2 implements PrivateInterface2 {
public String toString() {
return "passed";
}
}

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2016, 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 Public_PublicClass {
public String toString() {
return "passed";
}
}

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2016, 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 Public_PublicInterface implements PublicInterface {
public String toString() {
return "passed";
}
}

View File

@ -0,0 +1,196 @@
/*
* Copyright (c) 2016, 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.
*/
import com.sun.tools.classfile.*;
import com.sun.tools.classfile.ConstantPool.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/*
* @test
* @bug 8151223
* @summary String concatenation fails with implicit toString() on package-private class
* @modules jdk.jdeps/com.sun.tools.classfile
*
* @clean *
* @compile -XDstringConcat=indy Holder.java PublicClass.java PublicInterface.java Public_PublicClass.java Public_PublicInterface.java Public_PrivateInterface1.java Public_PrivateInterface2.java Test.java
* @run main Test
*
* @clean *
* @compile -XDstringConcat=indyWithConstants Holder.java PublicClass.java PublicInterface.java Public_PublicClass.java Public_PublicInterface.java Public_PrivateInterface1.java Public_PrivateInterface2.java Test.java
* @run main Test
*/
public class Test {
static List<String> actualTypes;
public static void main(String[] argv) throws Exception {
readIndyTypes();
p1.Holder holder = new p1.Holder();
int idx = 0;
// ----------------------------------------------------------------------------
// public Private_PublicClass c1 = new Private_PublicClass();
test("" + holder.c1, idx++, "(Lp1/PublicClass;)Ljava/lang/String;");
// public Private_PublicInterface c2 = new Private_PublicInterface();
test("" + holder.c2, idx++, "(Ljava/lang/Object;)Ljava/lang/String;");
// public Private_PrivateInterface1 c3 = new Private_PrivateInterface1();
test("" + holder.c3, idx++, "(Ljava/lang/Object;)Ljava/lang/String;");
// public Private_PrivateInterface2 c4 = new Private_PrivateInterface2();
test("" + holder.c4, idx++, "(Ljava/lang/Object;)Ljava/lang/String;");
// public Public_PublicClass c5 = new Public_PublicClass();
test("" + holder.c5, idx++, "(Lp1/Public_PublicClass;)Ljava/lang/String;");
// public Public_PublicInterface c6 = new Public_PublicInterface();
test("" + holder.c6, idx++, "(Lp1/Public_PublicInterface;)Ljava/lang/String;");
// public Public_PrivateInterface1 c7 = new Public_PrivateInterface1();
test("" + holder.c7, idx++, "(Lp1/Public_PrivateInterface1;)Ljava/lang/String;");
// public Public_PrivateInterface2 c8 = new Public_PrivateInterface2();
test("" + holder.c8, idx++, "(Lp1/Public_PrivateInterface2;)Ljava/lang/String;");
// ----------------------------------------------------------------------------
// public Private_PublicClass[] ac1 = new Private_PublicClass[0];
test("" + holder.ac1, idx++, "([Lp1/PublicClass;)Ljava/lang/String;");
// public Private_PublicInterface[] ac2 = new Private_PublicInterface[0];
test("" + holder.ac2, idx++, "([Ljava/lang/Object;)Ljava/lang/String;");
// public Private_PrivateInterface1[] ac3 = new Private_PrivateInterface1[0];
test("" + holder.ac3, idx++, "([Ljava/lang/Object;)Ljava/lang/String;");
// public Private_PrivateInterface2[] ac4 = new Private_PrivateInterface2[0];
test("" + holder.ac4, idx++, "([Ljava/lang/Object;)Ljava/lang/String;");
// public Public_PublicClass[] ac5 = new Public_PublicClass[0];
test("" + holder.ac5, idx++, "([Lp1/Public_PublicClass;)Ljava/lang/String;");
// public Public_PublicInterface[] ac6 = new Public_PublicInterface[0];
test("" + holder.ac6, idx++, "([Lp1/Public_PublicInterface;)Ljava/lang/String;");
// public Public_PrivateInterface1[] ac7 = new Public_PrivateInterface1[0];
test("" + holder.ac7, idx++, "([Lp1/Public_PrivateInterface1;)Ljava/lang/String;");
// public Public_PrivateInterface2[] ac8 = new Public_PrivateInterface2[0];
test("" + holder.ac8, idx++, "([Lp1/Public_PrivateInterface2;)Ljava/lang/String;");
// ----------------------------------------------------------------------------
// public Private_PublicClass[][] aac1 = new Private_PublicClass[0][];
test("" + holder.aac1, idx++, "([[Lp1/PublicClass;)Ljava/lang/String;");
// public Private_PublicInterface[][] aac2 = new Private_PublicInterface[0][];
test("" + holder.aac2, idx++, "([[Ljava/lang/Object;)Ljava/lang/String;");
// public Private_PrivateInterface1[][] aac3 = new Private_PrivateInterface1[0][];
test("" + holder.aac3, idx++, "([[Ljava/lang/Object;)Ljava/lang/String;");
// public Private_PrivateInterface2[][] aac4 = new Private_PrivateInterface2[0][];
test("" + holder.aac4, idx++, "([[Ljava/lang/Object;)Ljava/lang/String;");
// public Public_PublicClass[][] aac5 = new Public_PublicClass[0][];
test("" + holder.aac5, idx++, "([[Lp1/Public_PublicClass;)Ljava/lang/String;");
// public Public_PublicInterface[][] aac6 = new Public_PublicInterface[0][];
test("" + holder.aac6, idx++, "([[Lp1/Public_PublicInterface;)Ljava/lang/String;");
// public Public_PrivateInterface1[][] aac7 = new Public_PrivateInterface1[0][];
test("" + holder.aac7, idx++, "([[Lp1/Public_PrivateInterface1;)Ljava/lang/String;");
// public Public_PrivateInterface2[][] aac8 = new Public_PrivateInterface2[0][];
test("" + holder.aac8, idx++, "([[Lp1/Public_PrivateInterface2;)Ljava/lang/String;");
// ----------------------------------------------------------------------------
// public PublicInterface i1 = new Private_PublicInterface();
test("" + holder.i1, idx++, "(Lp1/PublicInterface;)Ljava/lang/String;");
// public PrivateInterface1 i2 = new Private_PrivateInterface1();
test("" + holder.i2, idx++, "(Ljava/lang/Object;)Ljava/lang/String;");
// public PrivateInterface2 i3 = new Private_PrivateInterface2();
test("" + holder.i3, idx++, "(Ljava/lang/Object;)Ljava/lang/String;");
// public PublicInterface[] ai1 = new Private_PublicInterface[0];
test("" + holder.ai1, idx++, "([Lp1/PublicInterface;)Ljava/lang/String;");
// public PrivateInterface1[] ai2 = new Private_PrivateInterface1[0];
test("" + holder.ai2, idx++, "([Ljava/lang/Object;)Ljava/lang/String;");
// public PrivateInterface2[] ai3 = new Private_PrivateInterface2[0];
test("" + holder.ai3, idx++, "([Ljava/lang/Object;)Ljava/lang/String;");
// public PublicInterface[][] aai1 = new Private_PublicInterface[0][];
test("" + holder.aai1, idx++, "([[Lp1/PublicInterface;)Ljava/lang/String;");
// public PrivateInterface1[][] aai2 = new Private_PrivateInterface1[0][];
test("" + holder.aai2, idx++, "([[Ljava/lang/Object;)Ljava/lang/String;");
// public PrivateInterface2[][] aai3 = new Private_PrivateInterface2[0][];
test("" + holder.aai3, idx++, "([[Ljava/lang/Object;)Ljava/lang/String;");
}
public static void test(String actual, int index, String expectedType) {
if (!"passed".equals(actual) && !actual.startsWith("[")) {
throw new IllegalStateException("Unexpected result: " + actual);
}
String actualType = actualTypes.get(index);
if (!actualType.equals(expectedType)) {
throw new IllegalStateException("Unexpected type: expected = " + expectedType + ", actual = " + actualType);
}
}
public static void readIndyTypes() throws Exception {
actualTypes = new ArrayList<String>();
ClassFile classFile = ClassFile.read(new File(System.getProperty("test.classes", "."),
Test.class.getName() + ".class"));
ConstantPool constantPool = classFile.constant_pool;
for (Method method : classFile.methods) {
if (method.getName(constantPool).equals("main")) {
Code_attribute code = (Code_attribute) method.attributes
.get(Attribute.Code);
for (Instruction i : code.getInstructions()) {
if (i.getOpcode() == Opcode.INVOKEDYNAMIC) {
CONSTANT_InvokeDynamic_info indyInfo = (CONSTANT_InvokeDynamic_info) constantPool.get(i.getUnsignedShort(1));
CONSTANT_NameAndType_info natInfo = indyInfo.getNameAndTypeInfo();
actualTypes.add(natInfo.getType());
}
}
}
}
}
}

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2016, 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 8139474
* @summary -release 7 -verbose causes Javac exception
* @compile -release 7 -verbose DashRelease7DashVerboseTest.java
*/
public class DashRelease7DashVerboseTest {}

View File

@ -1,74 +0,0 @@
/*
* Copyright (c) 2015, 2016, 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
* @summary Test that StringConcat is working for JDK >= 9
* @compile -source 6 -target 6 TestIndyStringConcat.java
* @run main TestIndyStringConcat false
* @clean TestIndyStringConcat*
* @compile -source 7 -target 7 TestIndyStringConcat.java
* @run main TestIndyStringConcat false
* @clean TestIndyStringConcat*
* @compile -source 8 -target 8 TestIndyStringConcat.java
* @run main TestIndyStringConcat false
* @clean TestIndyStringConcat*
* @compile -XDstringConcat=inline -source 9 -target 9 TestIndyStringConcat.java
* @run main TestIndyStringConcat false
* @clean TestIndyStringConcat*
* @compile -XDstringConcat=indy -source 9 -target 9 TestIndyStringConcat.java
* @run main TestIndyStringConcat true
* @clean TestIndyStringConcat*
* @compile -XDstringConcat=indyWithConstants -source 9 -target 9 TestIndyStringConcat.java
* @run main TestIndyStringConcat true
*/
public class TestIndyStringConcat {
private static class MyObject {
public String toString() {
throw new RuntimeException("Boyyaa");
}
}
class Inner { }
public static void main(String[] args) {
boolean useIndyConcat = Boolean.valueOf(args[0]);
try {
String s = "Foo" + new MyObject();
} catch (RuntimeException ex) {
boolean indifiedStringConcat = false;
ex.printStackTrace();
for (StackTraceElement e : ex.getStackTrace()) {
if (e.getClassName().contains("$$StringConcat") &&
e.getMethodName().equals("concat")) {
indifiedStringConcat = true;
break;
}
}
if (indifiedStringConcat != useIndyConcat) {
throw new AssertionError();
}
}
}
}