mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
UAST: make UDeclaration hasAnnotation conform to findAnnotation
...such that it can really findAnnotation when it hasAnnotation ^IDEA-353785 fixed GitOrigin-RevId: a3e9becfbfc258e5474bdf873c5bd2ee9a577f7c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f9e3bd1baa
commit
2c69d30a89
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user