From 0450f9a9d7995e15dd250ed61b918391c01a4c56 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sun, 2 Nov 2014 10:47:51 +0100 Subject: [PATCH] #1258 Java 8 Lambda parse error on direct field access --- pmd-java/etc/grammar/Java.jjt | 5 +++++ .../net/sourceforge/pmd/ast/ParserCornerCases18.java | 8 ++++++++ src/site/markdown/overview/changelog.md | 1 + 3 files changed, 14 insertions(+) diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index 7d9435c504..feddd07397 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -1,4 +1,8 @@ /** + * Fix for Lambda expressions without variables. + * + * Andreas Dangel 11/2014 + *==================================================================== * Fix for Lambda expressions with two or three variables. * * Andreas Dangel 07/2014 @@ -1765,6 +1769,7 @@ void PrimaryPrefix() : Literal() | "this" {jjtThis.setUsesThisModifier();} | "super" {jjtThis.setUsesSuperModifier();} +| LOOKAHEAD( "(" ")" "->" ) LambdaExpression() | LOOKAHEAD( "->" ) LambdaExpression() | LOOKAHEAD( "(" VariableDeclaratorId() "," VariableDeclaratorId() ["," VariableDeclaratorId()] ")" "->" ) LambdaExpression() | LOOKAHEAD( "(" FormalParameter() "," FormalParameter() ["," FormalParameter() ] ")" "->" ) LambdaExpression() diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/ast/ParserCornerCases18.java b/pmd-java/src/test/resources/net/sourceforge/pmd/ast/ParserCornerCases18.java index 6c306e76e1..5078cba600 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/ast/ParserCornerCases18.java +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/ast/ParserCornerCases18.java @@ -144,6 +144,14 @@ public class ParserCornerCases18 { }) .count(); } + // https://sourceforge.net/p/pmd/bugs/1258/ + public void lambdaWithPropertyAssignment() { + object.event = () -> { + Request request = new Request(); + request.id = 42; +// request.setId(42); + }; + } } } diff --git a/src/site/markdown/overview/changelog.md b/src/site/markdown/overview/changelog.md index e15565afd0..f122f920ff 100644 --- a/src/site/markdown/overview/changelog.md +++ b/src/site/markdown/overview/changelog.md @@ -15,6 +15,7 @@ * [#1253](https://sourceforge.net/p/pmd/bugs/1253/): Document default behaviour when CPD command line arguments "encoding" and "ignoreAnnotations" are not specified * [#1255](https://sourceforge.net/p/pmd/bugs/1255/): UseUtilityClass false positive with Exceptions * [#1256](https://sourceforge.net/p/pmd/bugs/1256/): PositionLiteralsFirstInComparisons false positive with Characters +* [#1258](https://sourceforge.net/p/pmd/bugs/1258/): Java 8 Lambda parse error on direct field access * [#1259](https://sourceforge.net/p/pmd/bugs/1259/): CloseResource rule ignores conditionnals within finally blocks * [#1261](https://sourceforge.net/p/pmd/bugs/1261/): False positive "Avoid unused private methods" with Generics * [#1262](https://sourceforge.net/p/pmd/bugs/1262/): False positive for MissingBreakInSwitch