提交 9d3e1bbe 编写于 作者: J jjg

6999438: remove support for exotic identifiers from JDK 7

Reviewed-by: mcimadamore
上级 16fd7d73
......@@ -174,9 +174,6 @@ public enum Source {
public boolean allowUnderscoresInLiterals() {
return compareTo(JDK1_7) >= 0;
}
public boolean allowExoticIdentifiers() {
return compareTo(JDK1_7) >= 0;
}
public boolean allowStringsInSwitch() {
return compareTo(JDK1_7) >= 0;
}
......
......@@ -2615,7 +2615,6 @@ public class ClassReader implements Completer {
String binaryName = fileManager.inferBinaryName(currentLoc, fo);
String simpleName = binaryName.substring(binaryName.lastIndexOf(".") + 1);
if (SourceVersion.isIdentifier(simpleName) ||
fo.getKind() == JavaFileObject.Kind.CLASS ||
simpleName.equals("package-info"))
includeClassFile(p, fo);
break;
......
......@@ -66,10 +66,6 @@ public class Scanner implements Lexer {
*/
private boolean allowUnderscoresInLiterals;
/** Allow exotic identifiers.
*/
private boolean allowExoticIdentifiers;
/** The source language setting.
*/
private Source source;
......@@ -143,7 +139,6 @@ public class Scanner implements Lexer {
allowBinaryLiterals = source.allowBinaryLiterals();
allowHexFloats = source.allowHexFloats();
allowUnderscoresInLiterals = source.allowBinaryLiterals();
allowExoticIdentifiers = source.allowExoticIdentifiers(); // for invokedynamic
}
private static final boolean hexFloatsWork = hexFloatsWork();
......@@ -295,7 +290,7 @@ public class Scanner implements Lexer {
/** Read next character in character or string literal and copy into sbuf.
*/
private void scanLitChar(boolean forBytecodeName) {
private void scanLitChar() {
if (ch == '\\') {
if (buf[bp+1] == '\\' && unicodeConversionBp != bp) {
bp++;
......@@ -335,18 +330,6 @@ public class Scanner implements Lexer {
putChar('\"'); scanChar(); break;
case '\\':
putChar('\\'); scanChar(); break;
case '|': case ',': case '?': case '%':
case '^': case '_': case '{': case '}':
case '!': case '-': case '=':
if (forBytecodeName) {
// Accept escape sequences for dangerous bytecode chars.
// This is illegal in normal Java string or character literals.
// Note that the escape sequence itself is passed through.
putChar('\\'); putChar(ch); scanChar();
} else {
lexError(bp, "illegal.esc.char");
}
break;
default:
lexError(bp, "illegal.esc.char");
}
......@@ -355,24 +338,6 @@ public class Scanner implements Lexer {
putChar(ch); scanChar();
}
}
private void scanLitChar() {
scanLitChar(false);
}
/** Read next character in an exotic name #"foo"
*/
private void scanBytecodeNameChar() {
switch (ch) {
// reject any "dangerous" char which is illegal somewhere in the JVM spec
// cf. http://blogs.sun.com/jrose/entry/symbolic_freedom_in_the_vm
case '/': case '.': case ';': // illegal everywhere
case '<': case '>': // illegal in methods, dangerous in classes
case '[': // illegal in classes
lexError(bp, "illegal.bytecode.ident.char", String.valueOf((int)ch));
break;
}
scanLitChar(true);
}
private void scanDigits(int digitRadix) {
char saveCh;
......@@ -970,30 +935,6 @@ public class Scanner implements Lexer {
lexError(pos, "unclosed.str.lit");
}
return;
case '#':
scanChar();
if (ch == '\"') {
if (!allowExoticIdentifiers) {
lexError("unsupported.exotic.id", source.name);
allowExoticIdentifiers = true;
}
scanChar();
if (ch == '\"')
lexError(pos, "empty.bytecode.ident");
while (ch != '\"' && ch != CR && ch != LF && bp < buflen) {
scanBytecodeNameChar();
}
if (ch == '\"') {
name = names.fromChars(sbuf, 0, sp);
token = IDENTIFIER; // even if #"int" or #"do"
scanChar();
} else {
lexError(pos, "unclosed.bytecode.ident");
}
} else {
lexError("illegal.char", String.valueOf((int)'#'));
}
return;
default:
if (isSpecial(ch)) {
scanOperator();
......
......@@ -153,8 +153,6 @@ compiler.err.duplicate.default.label=\
compiler.err.else.without.if=\
''else'' without ''if''
compiler.err.empty.bytecode.ident=\
empty bytecode identifier
compiler.err.empty.char.lit=\
empty character literal
compiler.err.encl.class.required=\
......@@ -201,8 +199,6 @@ compiler.err.generic.throwable=\
compiler.err.icls.cant.have.static.decl=\
inner classes cannot have static declarations
compiler.err.illegal.bytecode.ident.char=\
illegal bytecode identifier character: \\{0}
compiler.err.illegal.char=\
illegal character: \\{0}
compiler.err.illegal.char.for.encoding=\
......@@ -472,8 +468,6 @@ compiler.err.type.var.more.than.once.in.result=\
compiler.err.types.incompatible.diff.ret=\
types {0} and {1} are incompatible; both define {2}, but with unrelated return types
compiler.err.unclosed.bytecode.ident=\
unclosed bytecode identifier
compiler.err.unclosed.char.lit=\
unclosed character literal
compiler.err.unclosed.comment=\
......@@ -1269,10 +1263,6 @@ compiler.err.unsupported.underscore.lit=\
underscores in literals are not supported in -source {0}\n\
(use -source 7 or higher to enable underscores in literals)
compiler.err.unsupported.exotic.id=\
exotic identifiers #"___" are not supported in -source {0}\n\
(use -source 7 or higher to enable exotic identifiers)
compiler.err.try.with.resources.not.supported.in.source=\
try-with-resources is not supported in -source {0}\n\
(use -source 7 or higher to enable try-with-resources)
......
/*
* Copyright (c) 2010, 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.
*/
// key: compiler.err.empty.bytecode.ident
class EmptyBytecodeIdent {
int #"" = 3;
}
/*
* Copyright (c) 2010, 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.
*/
// key: compiler.err.illegal.bytecode.ident.char
class IllegalBytecodeIdentChar {
int #"abc/def" = 3;
}
/*
* Copyright (c) 2010, 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.
*/
// key: compiler.err.unclosed.bytecode.ident
class UnclosedBytecodeIdent {
int #"abc
}
/*
* Copyright (c) 2010, 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.
*/
// key: compiler.err.unsupported.exotic.id
// options: -source 6
class UnsupportedExoticID {
void m() {
Object #"Hello!" = null;
}
}
......@@ -58,7 +58,7 @@ public class InvokeDyn {
ojunk = InvokeDynamic.greet(x, "mundus", 456);
ojunk = InvokeDynamic.greet(x, "kosmos", 789);
ojunk = (String) InvokeDynamic.cogitate(10.11121, 3.14);
InvokeDynamic.#"yow: what I mean to say is, please treat this one specially"(null);
//InvokeDynamic.#"yow: what I mean to say is, please treat this one specially"(null);
ijunk = (int) InvokeDynamic.invoke("goodbye");
}
}
/*
* Copyright (c) 2008-2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2010, 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
......@@ -53,7 +53,7 @@ public class InvokeDynTrans {
InvokeDynamic.greet(x, "mundus", 456);
InvokeDynamic.greet(x, "kosmos", 789);
InvokeDynamic.<String>cogitate(10.11121, 3.14);
InvokeDynamic.<void>#"yow: what I mean to say is, please treat this one specially"(null);
//InvokeDynamic.<void>#"yow: what I mean to say is, please treat this one specially"(null);
InvokeDynamic.<int>invoke("goodbye");
}
}
InvokeDynTrans.java:55:39: compiler.warn.type.parameter.on.polymorphic.signature
InvokeDynTrans.java:56:91: compiler.warn.type.parameter.on.polymorphic.signature
InvokeDynTrans.java:57:34: compiler.warn.type.parameter.on.polymorphic.signature
- compiler.err.warnings.and.werror
1 error
3 warnings
2 warnings
/*
* Copyright (c) 2008, 2010, 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 6746458
* @summary Verify correct lexing of quoted identifiers.
* @author jrose
* @ignore 6877225 test fails on Windows:
* QuotedIdent.java:81: error while writing QuotedIdent.*86: PATH\QuotedIdent$*86.class
* (The filename, directory name, or volume label syntax is incorrect)
*
* @library ..
* @compile -source 7 -target 7 -XDinvokedynamic QuotedIdent.java
* @run main quid.QuotedIdent
*/
/*
* Standalone testing:
* <code>
* $ cd $MY_REPO_DIR/langtools
* $ (cd make; make)
* $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/quid/QuotedIdent.java
* $ java -version # should print 1.6 or later
* $ java -cp dist quid.QuotedIdent
* </code>
*/
package quid;
public class QuotedIdent {
static void check(int testid, String have, String expect)
throws RuntimeException {
if ((have == null && have != expect) ||
(have != null && !have.equals(expect))) {
String msg =
"TEST " + testid + ": HAVE \"" +
have + "\" EXPECT \"" + expect + "\"";
System.out.println("StringConversion: " + msg);
throw new RuntimeException(msg);
}
}
// negative tests:
//static class #"" { } //BAD empty ident name
//static class #"<foo>" { } //BAD bad char in ident name
/*static class /*(//BAD ident name interrupted by newline) #"jump:
" { } /* uncomment previous line to attempt class w/ bad name */
static class #"int" extends Number {
final int #"int";
#"int"(int #"int") {
this.#"int" = #"int";
}
static #"int" valueOf(int #"int") {
return new #"int"(#"int");
}
public int intValue() { return #"int"; }
public long longValue() { return #"int"; }
public float floatValue() { return #"int"; }
public double doubleValue() { return #"int"; }
public String toString() { return String.valueOf(#"int"); }
}
class #"*86" {
String #"555-1212"() { return "[*86.555-1212]"; }
}
static#"*86"#"MAKE-*86"() { // note close spacing
return new QuotedIdent().new#"*86"();
}
static String bar() { return "[bar]"; }
public static void main(String[] args) throws Exception {
String s;
String #"sticky \' wicket" = "wicked ' stick";
s = #"sticky ' wicket";
check(11, s, "wicked \' stick");
check(12, #"s", s);
check(13, #"\163", s);
s = #"QuotedIdent".bar();
check(21, s, "[bar]");
s = #"int".valueOf(123).toString();
check(22, s, "123");
s = #"MAKE-*86"().#"555-1212"();
check(23, s, "[*86.555-1212]");
class#"{{{inmost}}}" { }
s = new#"{{{inmost}}}"().getClass().getName();
if (!s.endsWith("{{{inmost}}}"))
check(24, s, "should end with \"{{{inmost}}}\"");
s = #"Yog-Shoggoth".#"(nameless ululation)";
check(25, s, "Tekeli-li!");
s = #"int".class.getName();
check(31, s, QuotedIdent.class.getName()+"$int");
Class<?> x86 = Class.forName(QuotedIdent.class.getName()+"$*86");
if (x86 != #"*86".class)
check(32, "reflected "+x86, "static "+#"*86".class);
s = (String) x86.getDeclaredMethod("555-1212").invoke(#"MAKE-*86"());
check(31, s, "[*86.555-1212]");
System.out.println("OK");
}
}
interface #"Yog-Shoggoth" {
final String #"(nameless ululation)" = "Tekeli-li!";
}
/*
* Copyright (c) 2008, 2010, 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 6746458
* @summary Verify correct separate compilation of classes with extended identifiers.
* @author jrose
* @ignore 6877225 test fails on Windows:
* QuotedIdent.java:81: error while writing QuotedIdent.*86: PATH\QuotedIdent$*86.class
* (The filename, directory name, or volume label syntax is incorrect)
*
* @library ..
* @compile -source 7 -target 7 -XDinvokedynamic QuotedIdent.java
* @run main quid.QuotedIdent2
*/
/*
* Standalone testing:
* <code>
* $ cd $MY_REPO_DIR/langtools
* $ (cd make; make)
* $ ./dist/bootstrap/bin/javac -d dist test/tools/javac/quid/QuotedIdent.java
* $ ./dist/bootstrap/bin/javac -d dist -cp dist test/tools/javac/quid/QuotedIdent2.java
* $ java -version # should print 1.6 or later
* $ java -cp dist QuotedIdent2
* </code>
*/
package quid;
import quid.QuotedIdent.*;
import quid.QuotedIdent.#"*86";
import static quid.QuotedIdent.#"MAKE-*86";
public class QuotedIdent2 {
static void check(int testid, String have, String expect)
throws RuntimeException {
QuotedIdent.check(testid, have, expect);
}
public static void main(String[] args) throws Exception {
String s;
s = #"int".valueOf(123).toString();
check(22, s, "123");
s = #"MAKE-*86"().#"555-1212"();
check(23, s, "[*86.555-1212]");
s = #"Yog-Shoggoth".#"(nameless ululation)";
check(25, s, "Tekeli-li!");
s = QuotedIdent.#"int".class.getName();
check(31, s, QuotedIdent.class.getName()+"$int");
Class<?> x86 = Class.forName(QuotedIdent.class.getName()+"$*86");
if (x86 != #"*86".class)
check(32, "reflected "+x86, "static "+#"*86".class);
s = (String) x86.getDeclaredMethod("555-1212").invoke(QuotedIdent.#"MAKE-*86"());
check(31, s, "[*86.555-1212]");
System.out.println("OK");
}
}
/* @test /nodynamiccopyright/
* @bug 6999438
* @summary remove support for exotic identifiers from JDK 7
* @compile/fail/ref=T6999438.out -XDrawDiagnostics -source 7 T6999438.java
*/
class Test {
int #"not supported";
}
T6999438.java:8:9: compiler.err.illegal.char: 35
T6999438.java:8:10: compiler.err.illegal.start.of.type
T6999438.java:8:25: compiler.err.expected: token.identifier
T6999438.java:8:26: compiler.err.expected: ';'
T6999438.java:9:2: compiler.err.premature.eof
5 errors
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册