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
This commit is contained in:
Juan Martín Sotuyo Dodero
2017-01-25 13:11:07 -03:00
committed by Andreas Dangel
parent aff9fc90ef
commit 455b1c4ded
2 changed files with 15 additions and 1 deletions

View File

@ -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() <IDENTIFIER> "(") AnnotationMethodDeclaration(modifiers)
|
ClassOrInterfaceDeclaration(modifiers)
|

View File

@ -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<Integer>> interner =" + PMD.EOL
+ " ThreadLocal.withInitial(Interners::newStrongInterner);" + PMD.EOL
+ "}";
parseJava18(code);
}
/**
* This triggered bug #1484 UnusedLocalVariable - false positive - parenthesis
* @throws Exception