From 3c988d95d9bf98e33b764a2b65dba99f4bc2c479 Mon Sep 17 00:00:00 2001 From: Oliver Burn Date: Mon, 18 Jul 2011 14:07:36 +1000 Subject: [PATCH] Fix parsing error which was triggered when a comment line is on a line with out newline character. Thanks to Evgeny Mandrikov for patch #3367782. --- .../tools/checkstyle/grammars/java.g | 2 +- .../grammars/LineCommentAtTheEndOfFile.java | 5 +++ .../LineCommentAtTheEndOfFileTest.java | 45 +++++++++++++++++++ src/xdocs/releasenotes.xml | 23 ++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/testinputs/com/puppycrawl/tools/checkstyle/grammars/LineCommentAtTheEndOfFile.java create mode 100644 src/tests/com/puppycrawl/tools/checkstyle/grammars/LineCommentAtTheEndOfFileTest.java diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/grammars/java.g b/src/checkstyle/com/puppycrawl/tools/checkstyle/grammars/java.g index 9613bdc35..9852e3def 100755 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/grammars/java.g +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/grammars/java.g @@ -1599,7 +1599,7 @@ SL_COMMENT : "//" { mCommentListener.reportSingleLineComment("//", getLine(), getColumn() - 3); } - (~('\n'|'\r'))* ('\n'|'\r'('\n')?) + (~('\n'|'\r'))* ('\n'|'\r'('\n')?|) {$setType(Token.SKIP); newline();} ; diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/grammars/LineCommentAtTheEndOfFile.java b/src/testinputs/com/puppycrawl/tools/checkstyle/grammars/LineCommentAtTheEndOfFile.java new file mode 100644 index 000000000..87697ea69 --- /dev/null +++ b/src/testinputs/com/puppycrawl/tools/checkstyle/grammars/LineCommentAtTheEndOfFile.java @@ -0,0 +1,5 @@ +package com.puppycrawl.tools.checkstyle.grammars; + +public class LineCommentAtTheEndOfFile +{ +} // EOF on this line \ No newline at end of file diff --git a/src/tests/com/puppycrawl/tools/checkstyle/grammars/LineCommentAtTheEndOfFileTest.java b/src/tests/com/puppycrawl/tools/checkstyle/grammars/LineCommentAtTheEndOfFileTest.java new file mode 100644 index 000000000..be5e43b01 --- /dev/null +++ b/src/tests/com/puppycrawl/tools/checkstyle/grammars/LineCommentAtTheEndOfFileTest.java @@ -0,0 +1,45 @@ +//////////////////////////////////////////////////////////////////////////////// +// checkstyle: Checks Java source code for adherence to a set of rules. +// Copyright (C) 2001-2011 Oliver Burn +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library 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 +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +//////////////////////////////////////////////////////////////////////////////// +package com.puppycrawl.tools.checkstyle.grammars; + +import com.puppycrawl.tools.checkstyle.BaseCheckTestSupport; +import com.puppycrawl.tools.checkstyle.DefaultConfiguration; +import com.puppycrawl.tools.checkstyle.checks.naming.MemberNameCheck; +import org.junit.Test; + +/** + * Checks that file can be parsed, when it ends on line-comment but without + * new-line. + * + * @author Evgeny Mandrikov + */ +public class LineCommentAtTheEndOfFileTest + extends BaseCheckTestSupport +{ + @Test + public void testCanParse() + throws Exception + { + final DefaultConfiguration checkConfig = + createCheckConfig(MemberNameCheck.class); + final String[] expected = {}; + verify(checkConfig, getPath("grammars/LineCommentAtTheEndOfFile.java"), + expected); + } +} diff --git a/src/xdocs/releasenotes.xml b/src/xdocs/releasenotes.xml index fe5edaa61..9658d07c8 100755 --- a/src/xdocs/releasenotes.xml +++ b/src/xdocs/releasenotes.xml @@ -10,6 +10,29 @@ +
+

New features:

+ +

Bug fixes:

+ +

Notes:

+ +
+

New features: