Uast: UastKotlinPsiVariable made isEquivalentTo it's physical PSI (KT-39174)
This commit is contained in:
@@ -67,6 +67,8 @@ class UastKotlinPsiVariable private constructor(
|
|||||||
return ktElement == (other as? UastKotlinPsiVariable)?.ktElement
|
return ktElement == (other as? UastKotlinPsiVariable)?.ktElement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun isEquivalentTo(another: PsiElement?): Boolean = this == another || ktElement.isEquivalentTo(another)
|
||||||
|
|
||||||
override fun hashCode() = ktElement.hashCode()
|
override fun hashCode() = ktElement.hashCode()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
@@ -5,14 +5,13 @@
|
|||||||
|
|
||||||
package org.jetbrains.uast.test.kotlin
|
package org.jetbrains.uast.test.kotlin
|
||||||
|
|
||||||
import com.intellij.psi.PsiClassType
|
import com.intellij.psi.*
|
||||||
import com.intellij.psi.PsiMethod
|
|
||||||
import com.intellij.psi.PsiType
|
|
||||||
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
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||||
import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner
|
import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner
|
||||||
|
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||||
import org.jetbrains.uast.*
|
import org.jetbrains.uast.*
|
||||||
import org.jetbrains.uast.kotlin.KotlinUFunctionCallExpression
|
import org.jetbrains.uast.kotlin.KotlinUFunctionCallExpression
|
||||||
import org.jetbrains.uast.test.env.kotlin.findElementByText
|
import org.jetbrains.uast.test.env.kotlin.findElementByText
|
||||||
@@ -37,7 +36,16 @@ class KotlinUastResolveApiTest : KotlinLightCodeInsightFixtureTestCase() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
val refs = file.findUElementByTextFromPsi<UQualifiedReferenceExpression>("s.toUpperCase()")
|
val refs = file.findUElementByTextFromPsi<UQualifiedReferenceExpression>("s.toUpperCase()")
|
||||||
TestCase.assertNotNull((refs.receiver.getExpressionType() as PsiClassType).resolve())
|
val receiver = refs.receiver
|
||||||
|
TestCase.assertEquals(CommonClassNames.JAVA_LANG_STRING, (receiver.getExpressionType() as PsiClassType).resolve()!!.qualifiedName!!)
|
||||||
|
val resolve = receiver.cast<UReferenceExpression>().resolve()
|
||||||
|
|
||||||
|
val variable = file.findUElementByTextFromPsi<UVariable>("val s = \"abc\"")
|
||||||
|
TestCase.assertEquals(resolve, variable.javaPsi)
|
||||||
|
TestCase.assertTrue(
|
||||||
|
"resolved expression $resolve should be equivalent to ${variable.sourcePsi}",
|
||||||
|
PsiManager.getInstance(project).areElementsEquivalent(resolve, variable.sourcePsi)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testMultiResolve() {
|
fun testMultiResolve() {
|
||||||
|
|||||||
Reference in New Issue
Block a user