Uast: resolve compiled annotation parameters (KT-34564)
This commit is contained in:
+12
-1
@@ -353,10 +353,21 @@ internal fun resolveToDeclaration(sourcePsi: KtExpression, declarationDescriptor
|
|||||||
}
|
}
|
||||||
|
|
||||||
resolveToPsiClass({ sourcePsi.toUElement() }, declarationDescriptor, sourcePsi)?.let { return it }
|
resolveToPsiClass({ sourcePsi.toUElement() }, declarationDescriptor, sourcePsi)?.let { return it }
|
||||||
|
|
||||||
if (declarationDescriptor is DeclarationDescriptorWithSource) {
|
if (declarationDescriptor is DeclarationDescriptorWithSource) {
|
||||||
declarationDescriptor.source.getPsi()?.let { it.getMaybeLightElement() ?: it }?.let { return it }
|
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? {
|
private fun resolveContainingDeserializedClass(context: KtElement, memberDescriptor: DeserializedCallableMemberDescriptor): PsiClass? {
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
package org.jetbrains.uast.test.kotlin
|
package org.jetbrains.uast.test.kotlin
|
||||||
|
|
||||||
import com.intellij.psi.PsiClassType
|
import com.intellij.psi.PsiClassType
|
||||||
|
import com.intellij.psi.PsiMethod
|
||||||
import com.intellij.psi.PsiType
|
import com.intellij.psi.PsiType
|
||||||
import com.intellij.psi.PsiVariable
|
|
||||||
import com.intellij.testFramework.LightProjectDescriptor
|
import com.intellij.testFramework.LightProjectDescriptor
|
||||||
import junit.framework.TestCase
|
import junit.framework.TestCase
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||||
@@ -286,7 +286,6 @@ class KotlinUastResolveApiTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun testLocalResolve() {
|
fun testLocalResolve() {
|
||||||
|
|
||||||
myFixture.configureByText(
|
myFixture.configureByText(
|
||||||
"MyClass.kt", """
|
"MyClass.kt", """
|
||||||
fun foo() {
|
fun foo() {
|
||||||
@@ -297,10 +296,24 @@ class KotlinUastResolveApiTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
val uCallExpression = myFixture.file.findElementAt(myFixture.caretOffset).toUElement().getUCallExpression().orFail("cant convert to UCallExpression")
|
val uCallExpression = myFixture.file.findElementAt(myFixture.caretOffset).toUElement().getUCallExpression().orFail("cant convert to UCallExpression")
|
||||||
val resolved = uCallExpression.resolve().orFail("cant resolve from $uCallExpression")
|
val resolved = uCallExpression.resolve().orFail("cant resolve from $uCallExpression")
|
||||||
TestCase.assertEquals("bar", resolved.name)
|
TestCase.assertEquals("bar", resolved.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun testResolveCompiledAnnotation() {
|
||||||
|
myFixture.configureByText(
|
||||||
|
"MyClass.kt", """
|
||||||
|
@Deprecated(message = "deprecated")
|
||||||
|
fun foo() {}
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
val compiledAnnotationParameter = myFixture.file.toUElement()!!.findElementByTextFromPsi<USimpleNameReferenceExpression>("message")
|
||||||
|
val resolved = compiledAnnotationParameter.resolve() as PsiMethod
|
||||||
|
TestCase.assertEquals("message", resolved.name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user