From 06ad6ef04fec83a9ee111e7fab77e49462c81806 Mon Sep 17 00:00:00 2001 From: jjg Date: Tue, 3 Jan 2012 11:37:00 -0800 Subject: [PATCH] 4881269: improve diagnostic for ill-formed tokens Reviewed-by: mcimadamore --- .../sun/tools/javac/parser/JavaTokenizer.java | 3 +- .../tools/javac/resources/compiler.properties | 3 ++ .../javac/diags/examples/IllegalDot.java | 30 ++++++++++++++++ test/tools/javac/parser/T4881269.java | 35 +++++++++++++++++++ test/tools/javac/parser/T4881269.out | 9 +++++ 5 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 test/tools/javac/diags/examples/IllegalDot.java create mode 100644 test/tools/javac/parser/T4881269.java create mode 100644 test/tools/javac/parser/T4881269.out diff --git a/src/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java b/src/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java index f0945389..b46070b9 100644 --- a/src/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java +++ b/src/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java @@ -535,13 +535,14 @@ public class JavaTokenizer { reader.putChar('.'); scanFractionAndSuffix(pos); } else if (reader.ch == '.') { + int savePos = reader.bp; reader.putChar('.'); reader.putChar('.', true); if (reader.ch == '.') { reader.scanChar(); reader.putChar('.'); tk = TokenKind.ELLIPSIS; } else { - lexError(pos, "malformed.fp.lit"); + lexError(savePos, "illegal.dot"); } } else { tk = TokenKind.DOT; diff --git a/src/share/classes/com/sun/tools/javac/resources/compiler.properties b/src/share/classes/com/sun/tools/javac/resources/compiler.properties index 14f1d605..2f70ae7d 100644 --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties @@ -384,6 +384,9 @@ compiler.err.illegal.nonascii.digit=\ compiler.err.illegal.underscore=\ illegal underscore +compiler.err.illegal.dot=\ + illegal ''.'' + # 0: symbol compiler.err.illegal.qual.not.icls=\ illegal qualifier; {0} is not an inner class diff --git a/test/tools/javac/diags/examples/IllegalDot.java b/test/tools/javac/diags/examples/IllegalDot.java new file mode 100644 index 00000000..15684a5d --- /dev/null +++ b/test/tools/javac/diags/examples/IllegalDot.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2011, 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.dot +// key: compiler.err.expected +// key: compiler.err.illegal.start.of.type + +class X { + void m(Object.. args) { } +} diff --git a/test/tools/javac/parser/T4881269.java b/test/tools/javac/parser/T4881269.java new file mode 100644 index 00000000..c830a4e8 --- /dev/null +++ b/test/tools/javac/parser/T4881269.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2011, 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 4881269 + * @summary improve diagnostic for ill-formed tokens + * @compile/fail/ref=T4881269.out -XDrawDiagnostics T4881269.java + */ + +public class T4881269 { + java.io..PrintStream s; + void m() { System.err..println(); } + void m(Object.. o) { } +} diff --git a/test/tools/javac/parser/T4881269.out b/test/tools/javac/parser/T4881269.out new file mode 100644 index 00000000..b6b26981 --- /dev/null +++ b/test/tools/javac/parser/T4881269.out @@ -0,0 +1,9 @@ +T4881269.java:32:13: compiler.err.illegal.dot +T4881269.java:33:27: compiler.err.illegal.dot +T4881269.java:33:22: compiler.err.not.stmt +T4881269.java:34:19: compiler.err.illegal.dot +T4881269.java:34:20: compiler.err.expected: ';' +T4881269.java:34:22: compiler.err.illegal.start.of.type +T4881269.java:34:23: compiler.err.expected: token.identifier +T4881269.java:34:25: compiler.err.expected: ';' +8 errors -- GitLab