Don't forget annotation methods

This commit is contained in:
Clément Fournier
2020-01-16 03:21:09 +01:00
parent d3908cb2bb
commit 94ebcdec82
4 changed files with 21 additions and 3 deletions

View File

@ -3160,7 +3160,7 @@ void AnnotationMethodDeclaration(int modifiers) #MethodDeclaration:
Type() #ResultType
t=<IDENTIFIER>
("(" ")") #FormalParameters(true)
( "[" "]" )* // TODO use ArrayTypeDims
[ Dims() ]
[ DefaultValue() ] ";"
{
jjtThis.setImage(t.image);

View File

@ -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({

View File

@ -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({

View File

@ -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")