diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index d855fc0e22..ed83b3a4e6 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -2203,10 +2203,10 @@ void BlockStatement() #void: // or a local variable declaration follows. // This allows more modifiers for local variables than actually allowed - // The ModifierList is adopted by the next class to open + // The ModifierList is adopted by the next node to open ModifierList() ( LOOKAHEAD({localTypeDeclAfterModifiers()}) LocalTypeDecl() - | LOOKAHEAD({true}) LocalVariableDeclaration() ";" { fixLastToken(); } + | LOOKAHEAD({true}) LocalVariableDeclarationPendingModifiers() ";" { fixLastToken(); } ) | LOOKAHEAD(1, ) ( @@ -2263,6 +2263,15 @@ void LocalVariableDeclaration() : ( "," VariableDeclarator() )* } +void LocalVariableDeclarationPendingModifiers() #LocalVariableDeclaration: +{} +{ + // no ModifierList, it's pending at this time + LocalVariableType() + VariableDeclarator() + ( "," VariableDeclarator() )* +} + private void LocalVarModifierList() #ModifierList: {Set set = Collections.emptySet(); } { diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/Bug1429.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/Bug1429.txt index ff40731fd7..e166451b30 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/Bug1429.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/Bug1429.txt @@ -55,7 +55,6 @@ +- Block[@Size = "5", @containsComment = "false"] +- LocalVariableDeclaration[@TypeInferred = "false", @Visibility = "local"] | +- ModifierList[@EffectiveModifiers = "{final}", @ExplicitModifiers = "{final}"] - | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | +- VariableDeclarator[@Initializer = "true", @Name = "key"] | +- VariableDeclaratorId[@ArrayType = "false", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "key", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "package"] @@ -64,7 +63,6 @@ | +- VariableAccess[@AccessType = "READ", @CompileTimeConstant = "false", @Image = "obj", @Name = "obj", @ParenthesisDepth = "0", @Parenthesized = "false"] +- LocalVariableDeclaration[@TypeInferred = "false", @Visibility = "local"] | +- ModifierList[@EffectiveModifiers = "{final}", @ExplicitModifiers = "{final}"] - | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | +- ClassOrInterfaceType[@FullyQualified = "false", @SimpleName = "String"] | +- VariableDeclarator[@Initializer = "true", @Name = "value"] | +- VariableDeclaratorId[@ArrayType = "false", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "value", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "package"] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/ParserCornerCases17.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/ParserCornerCases17.txt index de720d7008..edff15e87b 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/ParserCornerCases17.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/ParserCornerCases17.txt @@ -96,7 +96,6 @@ | +- Block[@Size = "2", @containsComment = "false"] | +- LocalVariableDeclaration[@TypeInferred = "false", @Visibility = "local"] | | +- ModifierList[@EffectiveModifiers = "{final}", @ExplicitModifiers = "{final}"] - | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"] | | +- PrimitiveType[@Boolean = "false", @Image = "int", @ModelConstant = "int"] | | +- VariableDeclarator[@Initializer = "true", @Name = "register"] | | +- VariableDeclaratorId[@ArrayType = "false", @EnumConstant = "false", @ExceptionBlockParameter = "false", @Field = "false", @FormalParameter = "false", @LambdaParameter = "false", @LocalVariable = "true", @Name = "register", @PatternBinding = "false", @RecordComponent = "false", @ResourceDeclaration = "false", @TypeInferred = "false", @Visibility = "package"]