diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt index f828c69a4bc..a7267f4eefd 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/KotlinUastLanguagePlugin.kt @@ -70,8 +70,15 @@ class KotlinUastLanguagePlugin : UastLanguagePlugin { if (element is KtLightClassForFacade) return convertDeclaration(element, null, requiredType) val parentCallback = fun(): UElement? { - val parent = KotlinConverter.unwrapElements(element.parent) ?: return null - return convertElementWithParent(parent, null) + val parent = element.parent + val parentUnwrapped = KotlinConverter.unwrapElements(parent) ?: return null + if (parent is KtValueArgument && parentUnwrapped is KtAnnotationEntry) { + val argumentName = parent.getArgumentName()?.asName?.asString() ?: "" + return (convertElementWithParent(parentUnwrapped, null) as UAnnotation) + .attributeValues.find { it.name == argumentName } + } + else + return convertElementWithParent(parentUnwrapped, null) } return convertDeclaration(element, parentCallback, requiredType) ?: KotlinConverter.convertPsiElement(element, parentCallback, requiredType) @@ -168,7 +175,7 @@ class KotlinUastLanguagePlugin : UastLanguagePlugin { is KtFile -> el { KotlinUFile(original, this@KotlinUastLanguagePlugin) } is FakeFileForLightClass -> el { KotlinUFile(original.navigationElement, this@KotlinUastLanguagePlugin) } - + is KtAnnotationEntry -> el(build(::KotlinUAnnotation)) else -> null } } @@ -200,6 +207,7 @@ internal object KotlinConverter { internal tailrec fun unwrapElements(element: PsiElement?): PsiElement? = when (element) { is KtValueArgumentList -> unwrapElements(element.parent) is KtValueArgument -> unwrapElements(element.parent) + is KtDeclarationModifierList -> unwrapElements(element.parent) else -> element } diff --git a/plugins/uast-kotlin/tests/KotlinUastApiTest.kt b/plugins/uast-kotlin/tests/KotlinUastApiTest.kt index 3f2a583119e..2075b64d6fb 100644 --- a/plugins/uast-kotlin/tests/KotlinUastApiTest.kt +++ b/plugins/uast-kotlin/tests/KotlinUastApiTest.kt @@ -4,6 +4,7 @@ import com.intellij.psi.PsiModifier import org.jetbrains.kotlin.psi.KtLiteralStringTemplateEntry import org.jetbrains.kotlin.psi.KtStringTemplateExpression import org.jetbrains.kotlin.psi.psiUtil.getParentOfType +import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase import org.jetbrains.uast.* import org.jetbrains.uast.test.env.findElementByText import org.junit.Assert @@ -18,7 +19,11 @@ class KotlinUastApiTest : AbstractKotlinUastTest() { doTest("AnnotationParameters") { _, file -> val annotation = file.findElementByText("@IntRange(from = 10, to = 0)") assertEquals(annotation.findAttributeValue("from")?.evaluate(), 10) - assertEquals(annotation.findAttributeValue("to")?.evaluate(), 0) + val toAttribute = annotation.findAttributeValue("to")!! + assertEquals(toAttribute.evaluate(), 0) + KtUsefulTestCase.assertInstanceOf(annotation.psi.toUElement(), UAnnotation::class.java) + KtUsefulTestCase.assertInstanceOf(toAttribute.uastParent, UNamedExpression::class.java) + KtUsefulTestCase.assertInstanceOf(toAttribute.psi.toUElement()?.uastParent, UNamedExpression::class.java) } }