forked from phoedos/pmd
Merge branch 'master' into pmd/7.0.x
This commit is contained in:
commit
44c065e5b2
@ -40,6 +40,7 @@ AbstractTokenizer and the custom tokenizers of Fortran, Perl and Ruby are deprec
|
||||
* [#2756](https://github.com/pmd/pmd/issues/2756): \[java] TypeTestUtil fails with NPE for anonymous class
|
||||
* [#2759](https://github.com/pmd/pmd/issues/2759): \[java] False positive in UnusedAssignment
|
||||
* [#2767](https://github.com/pmd/pmd/issues/2767): \[java] IndexOutOfBoundsException when parsing an initializer BlockStatement
|
||||
* [#2783](https://github.com/pmd/pmd/issues/2783): \[java] Error while parsing with lambda of custom interface
|
||||
|
||||
|
||||
### API Changes
|
||||
|
@ -1492,11 +1492,23 @@ void UnaryExpressionNotPlusMinus() #UnaryExpressionNotPlusMinus((jjtn000.getImag
|
||||
* meaning we can't be explicit as to what can be casted depending on the cast type (primitive or otherwise)
|
||||
*/
|
||||
| LOOKAHEAD("(" (Annotation())* PrimitiveType() ")") CastExpression()
|
||||
| LOOKAHEAD("(" (Annotation())* Type() ( "&" ReferenceType() )* ")" UnaryExpressionNotPlusMinus()) CastExpression()
|
||||
| PostfixExpression()
|
||||
| LOOKAHEAD("(" (Annotation())* Type() ( "&" ReferenceType() )* ")" UnaryExprNotPmStart()) CastExpression()
|
||||
| PostfixExpression() // this may be a parenthesized expr, which is why we have lookaheads
|
||||
| SwitchExpression()
|
||||
}
|
||||
|
||||
|
||||
private void UnaryExprNotPmStart() #void:
|
||||
{}
|
||||
{
|
||||
// Condensed FIRST set of UnaryExpressionNotPlusMinus
|
||||
// Avoid looking ahead for a whole UnaryExpressionNotPlusMinus, but just for a token
|
||||
|
||||
"~" | "!" | "(" | "switch" | "new" | "this" | "super" | Literal() | "@"
|
||||
| <IDENTIFIER>
|
||||
| "void" | PrimitiveType()
|
||||
}
|
||||
|
||||
void PostfixExpression() #PostfixExpression((jjtn000.getImage() != null)):
|
||||
{}
|
||||
{
|
||||
|
@ -172,6 +172,11 @@ public class ParserCornersTest {
|
||||
java8.parseResource("GitHubBug207.java");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLambda2783() {
|
||||
java8.parseResource("LambdaBug2783.java");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGitHubBug2767() {
|
||||
// PMD fails to parse an initializer block.
|
||||
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LambdaBug2783 {
|
||||
// https://github.com/pmd/pmd/issues/2783
|
||||
|
||||
public Spec<String> test() {
|
||||
// cast, block body (the failing case)
|
||||
Spec<String> result = (Spec<String>) (a, b) -> {
|
||||
return a.toArray(String[]::new);
|
||||
};
|
||||
// no cast, block body
|
||||
result = (a, b) -> {
|
||||
return a.toArray(String[]::new);
|
||||
};
|
||||
// cast, expression body
|
||||
result = (Spec<String>) (a, b) -> a.toArray(String[]::new);
|
||||
|
||||
// return position?
|
||||
return (Spec<String>) (a, b) -> {
|
||||
return a.toArray(String[]::new);
|
||||
};
|
||||
}
|
||||
|
||||
interface Spec<T> {
|
||||
String[] process(List<T> var1, List<?> var2);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user