Added filter that suppresses audit events according to source file
comments, contributed by Mike McMahon (module SuppressionCommentFilter,
requests 732196 and 931327).
+
+
Better information for unexpected char (request 666188).
+
diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/TreeWalker.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/TreeWalker.java
index 0fb7854d4..49a392739 100644
--- a/src/checkstyle/com/puppycrawl/tools/checkstyle/TreeWalker.java
+++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/TreeWalker.java
@@ -32,6 +32,8 @@ import java.util.Set;
import antlr.RecognitionException;
import antlr.TokenStreamException;
+import antlr.TokenStreamRecognitionException;
+
import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck;
import com.puppycrawl.tools.checkstyle.api.Check;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
@@ -244,12 +246,37 @@ public final class TreeWalker
.debug("RecognitionException occured.", re);
getMessageCollector().add(
new LocalizedMessage(
- 0,
+ re.getLine(),
+ re.getColumn(),
Defn.CHECKSTYLE_BUNDLE,
"general.exception",
new String[] {re.getMessage()},
this.getClass()));
}
+ catch (TokenStreamRecognitionException tre) {
+ Utils.getExceptionLogger()
+ .debug("TokenStreamRecognitionException occured.", tre);
+ final RecognitionException re = tre.recog;
+ if (re != null) {
+ getMessageCollector().add(
+ new LocalizedMessage(
+ re.getLine(),
+ re.getColumn(),
+ Defn.CHECKSTYLE_BUNDLE,
+ "general.exception",
+ new String[] {re.getMessage()},
+ this.getClass()));
+ }
+ else {
+ getMessageCollector().add(
+ new LocalizedMessage(
+ 0,
+ Defn.CHECKSTYLE_BUNDLE,
+ "general.exception",
+ new String[] {re.getMessage()},
+ this.getClass()));
+ }
+ }
catch (TokenStreamException te) {
Utils.getExceptionLogger()
.debug("TokenStreamException occured.", te);
diff --git a/src/testinputs/com/puppycrawl/tools/checkstyle/grammars/InputGrammar.java b/src/testinputs/com/puppycrawl/tools/checkstyle/grammars/InputGrammar.java
new file mode 100644
index 000000000..c743ce294
--- /dev/null
+++ b/src/testinputs/com/puppycrawl/tools/checkstyle/grammars/InputGrammar.java
@@ -0,0 +1,9 @@
+package com.puppycrawl.tools.checkstyle.grammars;
+
+/**
+ * Input for grammar test.
+ */
+public class InputGrammar
+{
+ int é = 1; // illegal, unless UTF-8
+}
diff --git a/src/tests/com/puppycrawl/tools/checkstyle/AllTests.java b/src/tests/com/puppycrawl/tools/checkstyle/AllTests.java
index 82a734bae..281cd6765 100644
--- a/src/tests/com/puppycrawl/tools/checkstyle/AllTests.java
+++ b/src/tests/com/puppycrawl/tools/checkstyle/AllTests.java
@@ -32,7 +32,8 @@ public class AllTests {
suite.addTest(com.puppycrawl.tools.checkstyle.api.AllTests.suite());
suite.addTest(com.puppycrawl.tools.checkstyle.checks.AllTests.suite());
suite.addTest(com.puppycrawl.tools.checkstyle.filters.AllTests.suite());
-
+ suite.addTest(
+ com.puppycrawl.tools.checkstyle.grammars.AllTests.suite());
//$JUnit-END$
return suite;
}
diff --git a/src/tests/com/puppycrawl/tools/checkstyle/grammars/AllTests.java b/src/tests/com/puppycrawl/tools/checkstyle/grammars/AllTests.java
new file mode 100644
index 000000000..579ea6fb3
--- /dev/null
+++ b/src/tests/com/puppycrawl/tools/checkstyle/grammars/AllTests.java
@@ -0,0 +1,21 @@
+package com.puppycrawl.tools.checkstyle.grammars;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Describe class AllTests.
+ * @author Rick Giles
+ * @version Jun 21, 2004
+ */
+public class AllTests {
+
+ public static Test suite() {
+ TestSuite suite =
+ new TestSuite("Test for com.puppycrawl.tools.checkstyle.grammars");
+ //$JUnit-BEGIN$
+ suite.addTest(new TestSuite(GeneratedJava14LexerTest.class));
+ //$JUnit-END$
+ return suite;
+ }
+}
diff --git a/src/tests/com/puppycrawl/tools/checkstyle/grammars/GeneratedJava14LexerTest.java b/src/tests/com/puppycrawl/tools/checkstyle/grammars/GeneratedJava14LexerTest.java
new file mode 100644
index 000000000..262ff4a15
--- /dev/null
+++ b/src/tests/com/puppycrawl/tools/checkstyle/grammars/GeneratedJava14LexerTest.java
@@ -0,0 +1,25 @@
+package com.puppycrawl.tools.checkstyle.grammars;
+
+import java.io.IOException;
+
+import com.puppycrawl.tools.checkstyle.BaseCheckTestCase;
+import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
+import com.puppycrawl.tools.checkstyle.checks.naming.MemberNameCheck;
+
+/**
+ * Tests GeneratedJava14Lexer.
+ * @author Rick Giles
+ */
+public class GeneratedJava14LexerTest
+ extends BaseCheckTestCase
+{
+ public void testUnexpectedChar() throws IOException, Exception
+ {
+ final DefaultConfiguration checkConfig =
+ createCheckConfig(MemberNameCheck.class);
+ final String[] expected = {
+ "8:10: Got an exception - unexpected char: 0xA9",
+ };
+ verify(checkConfig, getPath("grammars/InputGrammar.java"), expected);
+ }
+}