Commit 3e652517 authored by Jinseong Jeon's avatar Jinseong Jeon
Browse files

UAST: make UDeclaration hasAnnotation conform to findAnnotation

...such that it can really findAnnotation when it hasAnnotation

^IDEA-353785 fixed
parent bdc6be5c
Branches unavailable Tags unavailable
No related merge requests found
Showing with 39 additions and 0 deletions
+39 -0
......@@ -49,6 +49,10 @@ interface UDeclaration : UElement, PsiJvmModifiersOwner, UAnnotated {
get() = UastVisibility[this]
override fun <D, R> accept(visitor: UastTypedVisitor<D, R>, data: D): R = visitor.visitDeclaration(this, data)
override fun hasAnnotation(fqName: String): Boolean {
return findAnnotation(fqName) != null
}
}
interface UDeclarationEx : UDeclaration {
......
......@@ -303,4 +303,39 @@ class JavaUastApiTest : AbstractJavaUastTest() {
)
TestCase.assertEquals(1, count)
}
@Test
fun testHasAndFindTypeUseAnnotation() {
val file = myFixture.configureByText(
"Test.java",
"""
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
@interface MyNullable {}
class Test {
@MyNullable String test() {
return null;
}
}
""".trimIndent()
)
val uFile = file.toUElementOfType<UFile>()!!
var count = 0
uFile.accept(
object : AbstractUastVisitor() {
override fun visitMethod(node: UMethod): Boolean {
if (node.hasAnnotation("MyNullable")) {
val anno = node.findAnnotation("MyNullable")
TestCase.assertNotNull(anno)
count++
}
return super.visitMethod(node)
}
}
)
// IDEA-336319: TYPE_USE should not be applicable to UMethod
TestCase.assertEquals(0, count)
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment