From 455b1c4dedc53230396a05a69b53b55a5a88334e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Wed, 25 Jan 2017 13:11:07 -0300 Subject: [PATCH] Fix grammar for annotation members - The lookahead (3 tokens) was too small, and without reaching the opening parenthesis assumed it was parsing a method and not a field. - Using a larger lookahead solves the issue. - Fixes #206 --- pmd-java/etc/grammar/Java.jjt | 7 ++++++- .../sourceforge/pmd/lang/java/ast/ParserCornersTest.java | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index a180a16f4f..0548fdf6d0 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -1,4 +1,9 @@ /** + * Change lookahead for AnnotationMethodDeclaration in AnnotationTypeMemberDeclaration. + * Bug #206 + * + * Juan Martin Sotuyo Dodero 01/2017 + *==================================================================== * Allow method references to specify generics. * Bug #207 * @@ -2282,7 +2287,7 @@ void AnnotationTypeMemberDeclaration(): { modifiers = Modifiers() ( - LOOKAHEAD(3) AnnotationMethodDeclaration(modifiers) + LOOKAHEAD(Type() "(") AnnotationMethodDeclaration(modifiers) | ClassOrInterfaceDeclaration(modifiers) | diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/ParserCornersTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/ParserCornersTest.java index 1a025ec9ca..4e151479e7 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/ParserCornersTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/ParserCornersTest.java @@ -143,6 +143,15 @@ public class ParserCornersTest extends ParserTst { parseJava18(c); } + @Test + public void testBug206() throws Exception { + String code = "public @interface Foo {" + PMD.EOL + + "static final ThreadLocal> interner =" + PMD.EOL + + " ThreadLocal.withInitial(Interners::newStrongInterner);" + PMD.EOL + + "}"; + parseJava18(code); + } + /** * This triggered bug #1484 UnusedLocalVariable - false positive - parenthesis * @throws Exception