From 33fd84d521517d91fbc020cadecc84f7e21329f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Wed, 25 Jan 2017 12:44:40 -0300 Subject: [PATCH 1/2] [java] Support generics in method references - Fixes #207 - Extend the Java grammar to support generics in method references: `Type::method` --- pmd-java/etc/grammar/Java.jjt | 7 ++++++- .../sourceforge/pmd/lang/java/ast/ParserCornersTest.java | 6 ++++++ .../net/sourceforge/pmd/lang/java/ast/GitHubBug207.java | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/GitHubBug207.java diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index 24b576ddd2..a180a16f4f 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -1,4 +1,9 @@ /** + * Allow method references to specify generics. + * Bug #207 + * + * Juan Martin Sotuyo Dodero 01/2017 + *==================================================================== * Fix for regression introduced in previous changeset. * The syntactic lookahead was not properly handled by javacc, * so it was converted to a semantic one @@ -1806,7 +1811,7 @@ Token t; void MethodReference() : {Token t; checkForBadMethodReferenceUsage();} { - "::" ("new" {jjtThis.setImage("new");} | t= {jjtThis.setImage(t.image);} ) + "::" ("new" {jjtThis.setImage("new");} | [TypeArguments()] t= {jjtThis.setImage(t.image);} ) } void PrimaryPrefix() : 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 eaae58d7e1..1a025ec9ca 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 @@ -136,6 +136,12 @@ public class ParserCornersTest extends ParserTst { String c = IOUtils.toString(this.getClass().getResourceAsStream("Bug1530.java")); parseJava18(c); } + + @Test + public void testGitHubBug207() throws Exception { + String c = IOUtils.toString(this.getClass().getResourceAsStream("GitHubBug207.java")); + parseJava18(c); + } /** * This triggered bug #1484 UnusedLocalVariable - false positive - parenthesis diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/GitHubBug207.java b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/GitHubBug207.java new file mode 100644 index 0000000000..63bd151c29 --- /dev/null +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/GitHubBug207.java @@ -0,0 +1,5 @@ +public class GitHubBug207 { + private static HttpMessageWriter resourceHttpMessageWriter(BodyInserter.Context context) { + return context.map(BodyInserters::cast); + } +} \ No newline at end of file From 78e31f7cbfe6d4d8ada01870d4ffa17636de3899 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 27 Jan 2017 19:11:53 +0100 Subject: [PATCH 2/2] Update changelog, references #207 --- src/site/markdown/overview/changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/site/markdown/overview/changelog.md b/src/site/markdown/overview/changelog.md index 4bdc49c89d..9638920dfa 100644 --- a/src/site/markdown/overview/changelog.md +++ b/src/site/markdown/overview/changelog.md @@ -42,6 +42,7 @@ See also [bugfix #1556](https://sourceforge.net/p/pmd/bugs/1556/). ### Fixed Issues * java + * [#207](https://github.com/pmd/pmd/issues/207): \[java] Parse error on method reference with generics * [#213](https://github.com/pmd/pmd/issues/213): \[java] CPD: OutOfMemory when analyzing Lucene * java-design * [#1552](https://sourceforge.net/p/pmd/bugs/1552/): \[java] MissingBreakInSwitch - False positive for continue