diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/internal/kotlinInternalUastUtils.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/internal/kotlinInternalUastUtils.kt index ffa0b1acad5..ae924c63845 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/internal/kotlinInternalUastUtils.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/internal/kotlinInternalUastUtils.kt @@ -353,10 +353,21 @@ internal fun resolveToDeclaration(sourcePsi: KtExpression, declarationDescriptor } resolveToPsiClass({ sourcePsi.toUElement() }, declarationDescriptor, sourcePsi)?.let { return it } + if (declarationDescriptor is DeclarationDescriptorWithSource) { declarationDescriptor.source.getPsi()?.let { it.getMaybeLightElement() ?: it }?.let { return it } } - return resolveDeserialized(sourcePsi, declarationDescriptor, sourcePsi.readWriteAccess()) + + resolveDeserialized(sourcePsi, declarationDescriptor, sourcePsi.readWriteAccess())?.let { return it } + + if (declarationDescriptor is ValueParameterDescriptor) { + val parentDeclaration = resolveToDeclaration(sourcePsi, declarationDescriptor.containingDeclaration) + if (parentDeclaration is PsiClass && parentDeclaration.isAnnotationType) { + parentDeclaration.findMethodsByName(declarationDescriptor.name.asString(), false).firstOrNull()?.let { return it } + } + } + + return null } private fun resolveContainingDeserializedClass(context: KtElement, memberDescriptor: DeserializedCallableMemberDescriptor): PsiClass? { diff --git a/plugins/uast-kotlin/tests/KotlinUastResolveApiTest.kt b/plugins/uast-kotlin/tests/KotlinUastResolveApiTest.kt index 55adb32f051..138c7d7d51f 100644 --- a/plugins/uast-kotlin/tests/KotlinUastResolveApiTest.kt +++ b/plugins/uast-kotlin/tests/KotlinUastResolveApiTest.kt @@ -6,8 +6,8 @@ package org.jetbrains.uast.test.kotlin import com.intellij.psi.PsiClassType +import com.intellij.psi.PsiMethod import com.intellij.psi.PsiType -import com.intellij.psi.PsiVariable import com.intellij.testFramework.LightProjectDescriptor import junit.framework.TestCase import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase @@ -286,7 +286,6 @@ class KotlinUastResolveApiTest : KotlinLightCodeInsightFixtureTestCase() { } fun testLocalResolve() { - myFixture.configureByText( "MyClass.kt", """ fun foo() { @@ -297,10 +296,24 @@ class KotlinUastResolveApiTest : KotlinLightCodeInsightFixtureTestCase() { """ ) + val uCallExpression = myFixture.file.findElementAt(myFixture.caretOffset).toUElement().getUCallExpression().orFail("cant convert to UCallExpression") val resolved = uCallExpression.resolve().orFail("cant resolve from $uCallExpression") TestCase.assertEquals("bar", resolved.name) } + + fun testResolveCompiledAnnotation() { + myFixture.configureByText( + "MyClass.kt", """ + @Deprecated(message = "deprecated") + fun foo() {} + """ + ) + + val compiledAnnotationParameter = myFixture.file.toUElement()!!.findElementByTextFromPsi("message") + val resolved = compiledAnnotationParameter.resolve() as PsiMethod + TestCase.assertEquals("message", resolved.name) + } }