From 94ebcdec8250e69f3bc88c9b3069fa4519dd2445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Thu, 16 Jan 2020 03:21:09 +0100 Subject: [PATCH] Don't forget annotation methods --- pmd-java/etc/grammar/Java.jjt | 2 +- .../lang/java/ast/ASTFieldDeclarationTest.kt | 1 - .../ast/ASTLocalVariableDeclarationTest.kt | 1 - .../lang/java/ast/ASTMethodDeclarationTest.kt | 20 +++++++++++++++++++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index ecd507949a..c49d374718 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -3160,7 +3160,7 @@ void AnnotationMethodDeclaration(int modifiers) #MethodDeclaration: Type() #ResultType t= ("(" ")") #FormalParameters(true) - ( "[" "]" )* // TODO use ArrayTypeDims + [ Dims() ] [ DefaultValue() ] ";" { jjtThis.setImage(t.image); diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTFieldDeclarationTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTFieldDeclarationTest.kt index 67ec1f9bf9..a7a6a06703 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTFieldDeclarationTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTFieldDeclarationTest.kt @@ -7,7 +7,6 @@ package net.sourceforge.pmd.lang.java.ast import net.sourceforge.pmd.lang.ast.test.shouldBe import net.sourceforge.pmd.lang.java.ast.ASTPrimitiveType.PrimitiveType.INT -import net.sourceforge.pmd.lang.java.ast.ParserTestCtx.Companion.EnclosedDeclarationParsingCtx class ASTFieldDeclarationTest : ParserTestSpec({ diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTLocalVariableDeclarationTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTLocalVariableDeclarationTest.kt index a12135a804..2c992b38a2 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTLocalVariableDeclarationTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTLocalVariableDeclarationTest.kt @@ -7,7 +7,6 @@ package net.sourceforge.pmd.lang.java.ast import net.sourceforge.pmd.lang.ast.test.shouldBe import net.sourceforge.pmd.lang.java.ast.ASTPrimitiveType.PrimitiveType.INT -import net.sourceforge.pmd.lang.java.ast.ParserTestCtx.Companion.StatementParsingCtx class ASTLocalVariableDeclarationTest : ParserTestSpec({ diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTMethodDeclarationTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTMethodDeclarationTest.kt index 61e6b1898e..9901387387 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTMethodDeclarationTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTMethodDeclarationTest.kt @@ -220,6 +220,7 @@ class ASTMethodDeclarationTest : ParserTestSpec({ formalsList(0) } } + "int bar() default 2;" should parseAs { annotationMethod { it::getResultType shouldBe resultType { @@ -231,6 +232,22 @@ class ASTMethodDeclarationTest : ParserTestSpec({ } } + "int bar() @NonZero [];" should parseAs { + annotationMethod { + it::getResultType shouldBe resultType { + primitiveType(PrimitiveType.INT) + } + it::getFormalParameters shouldBe formalsList(0) + + it::getDefaultClause shouldBe null + it::getExtraDimensions shouldBe child { + arrayDim { + annotation("NonZero") + } + } + } + } + "Override bar() default @Override;" should parseAs { annotationMethod { it::getResultType shouldBe resultType { @@ -249,6 +266,9 @@ class ASTMethodDeclarationTest : ParserTestSpec({ } it::getFormalParameters shouldBe formalsList(0) + it::getExtraDimensions shouldBe child { + arrayDim {} + } it::getDefaultClause shouldBe defaultValue { memberValueArray { annotation("Override")