diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index 7325b4dc01..84b3ea6e56 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -1717,6 +1717,7 @@ int Modifiers() #void: } { ( + LOOKAHEAD(2) ( "public" { modifiers |= AccessNode.PUBLIC; } | "static" { modifiers |= AccessNode.STATIC; } @@ -1730,7 +1731,7 @@ int Modifiers() #void: | "volatile" { modifiers |= AccessNode.VOLATILE; } | "strictfp" { modifiers |= AccessNode.STRICTFP; } | "default" { modifiers |= AccessNode.DEFAULT; checkForBadDefaultImplementationUsage(); } - | LOOKAHEAD("@" ) Annotation() + | Annotation() ) )* { @@ -2252,6 +2253,10 @@ void Expression() #AssignmentExpression(>1): // as a workaround. {AssignmentOp op = null;} { + LOOKAHEAD( "->", {!inSwitchLabel} ) LambdaExpression() +| LOOKAHEAD( "(" ( "," )* ")" "->" , {!inSwitchLabel} ) LambdaExpression() +| LOOKAHEAD( LambdaParameterList() "->", {!inSwitchLabel} ) LambdaExpression() +| ConditionalExpression() [ LOOKAHEAD(2) op=AssignmentOperator() {jjtThis.setOp(op);} Expression() @@ -2438,11 +2443,20 @@ void UnaryExpressionNotPlusMinus() #UnaryExpression((jjtn000.getImage() != null) ("(" AnnotatedType() ")" UnaryExpression()) #CastExpression // here we avoid looking ahead for a whole unary expression, instead just testing the token after ")" | LOOKAHEAD("(" TypeAnnotationList() IntersectionType(true) ")" UnaryExprNotPmStart() ) - ("(" TypeAnnotationList() IntersectionType(true) ")" UnaryExpressionNotPlusMinus()) #CastExpression + ("(" TypeAnnotationList() IntersectionType(true) ")" CastSubject()) #CastExpression | PostfixExpression() | SwitchExpression() } +private void CastSubject() #void: +{} +{ + LOOKAHEAD( "->", {!inSwitchLabel} ) LambdaExpression() + | LOOKAHEAD( "(" ( "," )* ")" "->" , {!inSwitchLabel} ) LambdaExpression() + | LOOKAHEAD( LambdaParameterList() "->", {!inSwitchLabel} ) LambdaExpression() + | UnaryExpressionNotPlusMinus() +} + private void UnaryExprNotPmStart() #void: {} { @@ -2500,14 +2514,6 @@ void PrimaryPrefix() #void : | "." "class" #ClassLiteral(1) ) - -// todo we can probably simplify the lambda lookaheads -// by moving them out of primary prefix! -| LOOKAHEAD( "->", {!inSwitchLabel} ) LambdaExpression() -| LOOKAHEAD( "(" ( "," )* ")" "->" , {!inSwitchLabel} ) LambdaExpression() -| LOOKAHEAD( LambdaParameterList() "->", {!inSwitchLabel} ) LambdaExpression() - - | ("(" Expression() ")") #ParenthesizedExpression | AmbiguousName() [ LOOKAHEAD(Step2Lahead()) PrimaryStep2() ] }