Skip to content

Commit

Permalink
#1205 Parse error on lambda with if
Browse files Browse the repository at this point in the history
  • Loading branch information
adangel committed Jul 17, 2014
1 parent f4d767d commit ec088bd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pmd/etc/grammar/Java.jjt
@@ -1,4 +1,8 @@
/**
* Fix for Lambda expressions with two or three variables.
*
* Andreas Dangel 07/2014
*====================================================================
* Added support for Java 8 language constructs.
*
* Andreas Dangel 01/2014
Expand Down Expand Up @@ -1761,6 +1765,7 @@ void PrimaryPrefix() :
Literal()
| "this" {jjtThis.setUsesThisModifier();}
| "super" {jjtThis.setUsesSuperModifier();}
| LOOKAHEAD( "(" VariableDeclaratorId() "," VariableDeclaratorId() ["," VariableDeclaratorId()] ")" "->" ) LambdaExpression()
| LOOKAHEAD( LambdaExpression() ) LambdaExpression()
| LOOKAHEAD( <IDENTIFIER> "->" ) LambdaExpression()
| LOOKAHEAD(3) "(" Expression() ")"
Expand Down
2 changes: 2 additions & 0 deletions pmd/src/site/markdown/changelog.md
Expand Up @@ -6,6 +6,7 @@

* Fixed [bug #1181]: unused import false positive if used as parameter in javadoc only.
* Fixed [bug #1192]: Ecmascript fails to parse this operator " ^= "
* Fixed [bug #1205]: Parse error on lambda with if
* Fixed [bug #1206]: SummaryHTMLRenderer always shows suppressed warnings/violations
* Fixed [bug #1208]: yahtml's outputDir property does not work
* Fixed [bug #1209]: XPath 2.0 following-sibling incorrectly includes context node
Expand All @@ -20,6 +21,7 @@

[bug #1181]: https://sourceforge.net/p/pmd/bugs/1181/
[bug #1192]: https://sourceforge.net/p/pmd/bugs/1192/
[bug #1205]: https://sourceforge.net/p/pmd/bugs/1205/
[bug #1206]: https://sourceforge.net/p/pmd/bugs/1206/
[bug #1208]: https://sourceforge.net/p/pmd/bugs/1208/
[bug #1209]: https://sourceforge.net/p/pmd/bugs/1209/
Expand Down
Expand Up @@ -11,6 +11,7 @@
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.Supplier;
import java.util.stream.Stream;

/**
* Java 8 language syntax
Expand Down Expand Up @@ -120,6 +121,20 @@ public void typeAnnotations() {
}
class UnmodifiableList<T> implements @Readonly List<@Readonly T> {}
void monitorTemperature() throws @Critical TemperatureException {}

// https://sourceforge.net/p/pmd/bugs/1205/
public static class X {
public void lambaWithIf() {
Stream.of(1, 2, 3)
.sorted((a, b) -> {
int x = a.hashCode() - b.hashCode();
if(a.equals(new X()))
x = 1;
return x;
})
.count();
}
}
}

interface DefaultIterator<E> {
Expand Down

0 comments on commit ec088bd

Please sign in to comment.