diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index 06a4ecb812..e9b86982c1 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -2499,7 +2499,7 @@ 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() + "~" | "!" | "(" | "switch" | "new" | "this" | "super" | Literal() | "@" | | "void" | PrimitiveType() } diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTMethodReferenceTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTMethodReferenceTest.kt index 8cdf8232cc..ff424b84a0 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTMethodReferenceTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTMethodReferenceTest.kt @@ -209,6 +209,21 @@ class ASTMethodReferenceTest : ParserTestSpec({ it::getTypeArguments shouldBe null } } + + // annotated method ref in cast ctx (lookahead trickery) + "(Foo) @Vernal Date::getDay" should parseAs { + castExpr { + classType("Foo") + + methodRef(methodName = "getDay") { + classType("Date") { + annotation("Vernal") + } + + it::getTypeArguments shouldBe null + } + } + } } } })