mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
K2 UAST: use function symbol for accessors of Java synthetic property
...which are literally closer to the resolution result as PsiMethod than KtProperty(G|S)etterSymbol, which seems to be subject to change depending on the underlying frontend change. ^KT-66785 GitOrigin-RevId: cce265b6dad74db82dae1c45262a78270c5e3afe
This commit is contained in:
committed by
intellij-monorepo-bot
parent
780106c7b0
commit
cf666d61ff
+39
-1
@@ -1311,7 +1311,7 @@ interface UastResolveApiFixtureTestBase : UastPluginSelection {
|
||||
)
|
||||
}
|
||||
|
||||
fun checkResolveSyntheticJavaPropertyAccessor(myFixture: JavaCodeInsightTestFixture) {
|
||||
fun checkResolveSyntheticJavaPropertyAccessor_setter(myFixture: JavaCodeInsightTestFixture) {
|
||||
myFixture.addClass(
|
||||
"""public class X {
|
||||
|String getFoo();
|
||||
@@ -1340,6 +1340,44 @@ interface UastResolveApiFixtureTestBase : UastPluginSelection {
|
||||
TestCase.assertEquals("setFoo", (resolvedPsiElements.single() as PsiMethod).name)
|
||||
}
|
||||
|
||||
fun checkResolveSyntheticJavaPropertyAccessor_getter(myFixture: JavaCodeInsightTestFixture) {
|
||||
myFixture.addClass(
|
||||
"""public class X {
|
||||
|String getFoo();
|
||||
|void setFoo(String s);
|
||||
|}""".trimMargin()
|
||||
)
|
||||
|
||||
myFixture.addClass(
|
||||
"""public interface I {
|
||||
|String getFoo();
|
||||
|}""".trimMargin()
|
||||
)
|
||||
|
||||
myFixture.configureByText(
|
||||
"main.kt", """
|
||||
class Y : X(), I {
|
||||
}
|
||||
fun box(y : Y): Boolean {
|
||||
val yo = y.foo ?: return false
|
||||
return yo == "42"
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
val visitor = PropertyAccessorVisitor { it.endsWith("foo") || it.endsWith("getFoo") }
|
||||
myFixture.file.toUElement()!!.accept(visitor)
|
||||
TestCase.assertEquals(2, visitor.resolvedElements.size)
|
||||
val nodes = visitor.resolvedElements.keys
|
||||
TestCase.assertTrue(nodes.any { it is USimpleNameReferenceExpression })
|
||||
// Will create on-the-fly accessor call for Java synthetic property
|
||||
TestCase.assertTrue(nodes.any { it is UCallExpression})
|
||||
// Both simple name reference (`foo`) and its on-the-fly accessor call are resolved to the same Java synthetic property accessor.
|
||||
val resolvedPsiElements = visitor.resolvedElements.values.toSet()
|
||||
TestCase.assertEquals(1, resolvedPsiElements.size)
|
||||
TestCase.assertEquals("getFoo", (resolvedPsiElements.single() as PsiMethod).name)
|
||||
}
|
||||
|
||||
fun checkResolveKotlinPropertyAccessor(myFixture: JavaCodeInsightTestFixture) {
|
||||
myFixture.configureByText(
|
||||
"Foo.kt", """
|
||||
|
||||
+6
-5
@@ -268,11 +268,12 @@ interface FirKotlinUastResolveProviderService : BaseKotlinUastResolveProviderSer
|
||||
val variableAccessCall = ktSimpleNameExpression.resolveCall()?.singleCallOrNull<KtSimpleVariableAccessCall>() ?: return null
|
||||
val propertySymbol = variableAccessCall.symbol as? KtSyntheticJavaPropertySymbol ?: return null
|
||||
when (variableAccessCall.simpleAccess) {
|
||||
is KtSimpleVariableAccess.Read ->
|
||||
toPsiMethod(propertySymbol.getter, ktSimpleNameExpression)
|
||||
|
||||
is KtSimpleVariableAccess.Write ->
|
||||
toPsiMethod(propertySymbol.setter ?: return null, ktSimpleNameExpression)
|
||||
is KtSimpleVariableAccess.Read -> {
|
||||
toPsiMethod(propertySymbol.javaGetterSymbol, ktSimpleNameExpression)
|
||||
}
|
||||
is KtSimpleVariableAccess.Write -> {
|
||||
toPsiMethod(propertySymbol.javaSetterSymbol?: return null, ktSimpleNameExpression)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -196,8 +196,12 @@ class FirUastResolveApiFixtureTest : KotlinLightCodeInsightFixtureTestCase(), Ua
|
||||
checkResolveSyntheticJavaPropertyCompoundAccess(myFixture)
|
||||
}
|
||||
|
||||
fun testResolveSyntheticJavaPropertyAccessor() {
|
||||
checkResolveSyntheticJavaPropertyAccessor(myFixture)
|
||||
fun testResolveSyntheticJavaPropertyAccessor_setter() {
|
||||
checkResolveSyntheticJavaPropertyAccessor_setter(myFixture)
|
||||
}
|
||||
|
||||
fun testResolveSyntheticJavaPropertyAccessor_getter() {
|
||||
checkResolveSyntheticJavaPropertyAccessor_getter(myFixture)
|
||||
}
|
||||
|
||||
fun testResolveKotlinPropertyAccessor() {
|
||||
|
||||
+6
-2
@@ -151,8 +151,12 @@ class FE1UastResolveApiFixtureTest : KotlinLightCodeInsightFixtureTestCase(), Ua
|
||||
checkResolveSyntheticJavaPropertyCompoundAccess(myFixture, isK2 = false)
|
||||
}
|
||||
|
||||
fun testResolveSyntheticJavaPropertyAccessor() {
|
||||
checkResolveSyntheticJavaPropertyAccessor(myFixture)
|
||||
fun testResolveSyntheticJavaPropertyAccessor_setter() {
|
||||
checkResolveSyntheticJavaPropertyAccessor_setter(myFixture)
|
||||
}
|
||||
|
||||
fun testResolveSyntheticJavaPropertyAccessor_getter() {
|
||||
checkResolveSyntheticJavaPropertyAccessor_getter(myFixture)
|
||||
}
|
||||
|
||||
fun testResolveKotlinPropertyAccessor() {
|
||||
|
||||
Reference in New Issue
Block a user