[AA] resolve array access expression to corresponding set operator
k1 would suggest `get` as well but with current fir structure with fake desugaring get is moved to the separate fake psi which doesn't exist thus the problem is ignored for now ^ KTIJ-24025
This commit is contained in:
+12
@@ -661,6 +661,12 @@ public class Fe10IdeNormalAnalysisSourceModuleReferenceResolveTestGenerated exte
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/arrayAccess/setOperator.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("SetOperatorInc.kt")
|
||||
public void testSetOperatorInc() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/arrayAccess/SetOperatorInc.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("analysis/analysis-api/testData/referenceResolve/arrayAccess/withErrors")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@@ -681,6 +687,12 @@ public class Fe10IdeNormalAnalysisSourceModuleReferenceResolveTestGenerated exte
|
||||
public void testSetFunction() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/arrayAccess/withErrors/setFunction.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("SetOperatorInc.kt")
|
||||
public void testSetOperatorInc() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/arrayAccess/withErrors/SetOperatorInc.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-4
@@ -5,14 +5,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.references
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.fir.buildSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.fir.getCandidateSymbols
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.getOrBuildFirSafe
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.getOrBuildFir
|
||||
import org.jetbrains.kotlin.fir.expressions.FirFunctionCall
|
||||
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
||||
import org.jetbrains.kotlin.psi.KtArrayAccessExpression
|
||||
|
||||
class KtFirArrayAccessReference(
|
||||
@@ -20,7 +20,11 @@ class KtFirArrayAccessReference(
|
||||
) : KtArrayAccessReference(expression), KtFirReference {
|
||||
override fun KtAnalysisSession.resolveToSymbols(): Collection<KtSymbol> {
|
||||
check(this is KtFirAnalysisSession)
|
||||
val fir = element.getOrBuildFirSafe<FirFunctionCall>(firResolveSession) ?: return emptyList()
|
||||
return fir.getCandidateSymbols().map { it.fir.buildSymbol(firSymbolBuilder) }
|
||||
val fir = element.getOrBuildFir(firResolveSession) ?: return emptyList()
|
||||
return when (fir) {
|
||||
is FirFunctionCall -> fir.getCandidateSymbols().map { it.fir.buildSymbol(firSymbolBuilder) }
|
||||
is FirResolvedNamedReference -> listOf(fir.resolvedSymbol.buildSymbol(firSymbolBuilder))
|
||||
else -> emptyList()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -661,6 +661,12 @@ public class FirIdeDependentAnalysisSourceModuleReferenceResolveTestGenerated ex
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/arrayAccess/setOperator.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("SetOperatorInc.kt")
|
||||
public void testSetOperatorInc() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/arrayAccess/SetOperatorInc.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("analysis/analysis-api/testData/referenceResolve/arrayAccess/withErrors")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@@ -681,6 +687,12 @@ public class FirIdeDependentAnalysisSourceModuleReferenceResolveTestGenerated ex
|
||||
public void testSetFunction() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/arrayAccess/withErrors/setFunction.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("SetOperatorInc.kt")
|
||||
public void testSetOperatorInc() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/arrayAccess/withErrors/SetOperatorInc.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -660,6 +660,12 @@ public class FirIdeNormalAnalysisLibrarySourceModuleReferenceResolveTestGenerate
|
||||
public void testSetOperator() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/arrayAccess/setOperator.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("SetOperatorInc.kt")
|
||||
public void testSetOperatorInc() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/arrayAccess/SetOperatorInc.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+12
@@ -661,6 +661,12 @@ public class FirIdeNormalAnalysisSourceModuleReferenceResolveTestGenerated exten
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/arrayAccess/setOperator.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("SetOperatorInc.kt")
|
||||
public void testSetOperatorInc() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/arrayAccess/SetOperatorInc.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("analysis/analysis-api/testData/referenceResolve/arrayAccess/withErrors")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@@ -681,6 +687,12 @@ public class FirIdeNormalAnalysisSourceModuleReferenceResolveTestGenerated exten
|
||||
public void testSetFunction() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/arrayAccess/withErrors/setFunction.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("SetOperatorInc.kt")
|
||||
public void testSetOperatorInc() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/arrayAccess/withErrors/SetOperatorInc.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
@@ -661,6 +661,12 @@ public class FirStandaloneNormalAnalysisSourceModuleReferenceResolveTestGenerate
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/arrayAccess/setOperator.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("SetOperatorInc.kt")
|
||||
public void testSetOperatorInc() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/arrayAccess/SetOperatorInc.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("analysis/analysis-api/testData/referenceResolve/arrayAccess/withErrors")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@@ -681,6 +687,12 @@ public class FirStandaloneNormalAnalysisSourceModuleReferenceResolveTestGenerate
|
||||
public void testSetFunction() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/arrayAccess/withErrors/setFunction.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("SetOperatorInc.kt")
|
||||
public void testSetOperatorInc() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/referenceResolve/arrayAccess/withErrors/SetOperatorInc.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
Resolved to:
|
||||
0: (in test.B) operator fun get(i: kotlin.Int): test.B
|
||||
1: (in test.B) operator fun set(i: kotlin.Int, a: test.B)
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package test
|
||||
|
||||
class B(val n: Int) {
|
||||
operator fun set(i: Int, a: B) {}
|
||||
operator fun get(i: Int) : B { return B(i) }
|
||||
operator fun inc() : B {return B(n + 1)}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
var a = B(1)
|
||||
a<caret>[2]++
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
Resolved to:
|
||||
0: (in test.B) operator fun set(i: kotlin.Int, a: test.B)
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// UNRESOLVED_REFERENCE
|
||||
package test
|
||||
|
||||
class B(val n: Int) {
|
||||
operator fun inc() : B {return B(n + 1)}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
var a = B(1)
|
||||
a<caret>[2]++
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
Resolved to:
|
||||
0: (in test.B) operator fun set(i: kotlin.Int, a: test.B)
|
||||
@@ -0,0 +1,12 @@
|
||||
package test
|
||||
|
||||
class B(val n: Int) {
|
||||
operator fun set(i: Int, a: B) {}
|
||||
operator fun get(i: Int) : B {}
|
||||
operator fun inc() : B {}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
var a = B(1)
|
||||
<expr>a[2]</expr>++
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
KT element: KtArrayAccessExpression
|
||||
FIR element: FirResolvedNamedReferenceImpl
|
||||
FIR source kind: KtRealSourceElementKind
|
||||
|
||||
FIR element rendered:
|
||||
R|test/B.set|
|
||||
+6
@@ -210,6 +210,12 @@ public class GetOrBuildFirTestGenerated extends AbstractGetOrBuildFirTest {
|
||||
public void testQualifiedWholeCall() throws Exception {
|
||||
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/calls/qualifiedWholeCall.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("setOperator.kt")
|
||||
public void testSetOperator() throws Exception {
|
||||
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/calls/setOperator.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
Reference in New Issue
Block a user