FIR IDE: Avoid resolving elvis operator, because it doesn't make sense
There are intrinsics to which elvis operator's usages are resolved; however, we do not want to expose those intrinsics through the high-level resolve
This commit is contained in:
+2
@@ -119,6 +119,8 @@ internal class KtFe10CallResolver(
|
|||||||
get() = analysisSession.token
|
get() = analysisSession.token
|
||||||
|
|
||||||
override fun resolveCall(psi: KtElement): KtCallInfo? = with(analysisContext.analyze(psi, AnalysisMode.PARTIAL_WITH_DIAGNOSTICS)) {
|
override fun resolveCall(psi: KtElement): KtCallInfo? = with(analysisContext.analyze(psi, AnalysisMode.PARTIAL_WITH_DIAGNOSTICS)) {
|
||||||
|
if (psi.isNotResolvable()) return null
|
||||||
|
|
||||||
val parentBinaryExpression = psi.parentOfType<KtBinaryExpression>()
|
val parentBinaryExpression = psi.parentOfType<KtBinaryExpression>()
|
||||||
val lhs = KtPsiUtil.deparenthesize(parentBinaryExpression?.left)
|
val lhs = KtPsiUtil.deparenthesize(parentBinaryExpression?.left)
|
||||||
val unwrappedPsi = KtPsiUtil.deparenthesize(psi as? KtExpression) ?: psi
|
val unwrappedPsi = KtPsiUtil.deparenthesize(psi as? KtExpression) ?: psi
|
||||||
|
|||||||
+36
@@ -648,6 +648,42 @@ public class KtFe10ResolveCallTestGenerated extends AbstractKtFe10ResolveCallTes
|
|||||||
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/smartCastImplicitExtensionReceiver.kt");
|
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/smartCastImplicitExtensionReceiver.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unresolvableOperator_elvis_1.kt")
|
||||||
|
public void testUnresolvableOperator_elvis_1() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/unresolvableOperator_elvis_1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unresolvableOperator_elvis_2.kt")
|
||||||
|
public void testUnresolvableOperator_elvis_2() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/unresolvableOperator_elvis_2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unresolvableOperator_eqeqeq_1.kt")
|
||||||
|
public void testUnresolvableOperator_eqeqeq_1() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/unresolvableOperator_eqeqeq_1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unresolvableOperator_eqeqeq_2.kt")
|
||||||
|
public void testUnresolvableOperator_eqeqeq_2() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/unresolvableOperator_eqeqeq_2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unresolvableOperator_excleqeq_1.kt")
|
||||||
|
public void testUnresolvableOperator_excleqeq_1() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/unresolvableOperator_excleqeq_1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unresolvableOperator_excleqeq_2.kt")
|
||||||
|
public void testUnresolvableOperator_excleqeq_2() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/unresolvableOperator_excleqeq_2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("unresolvedSuperReference.kt")
|
@TestMetadata("unresolvedSuperReference.kt")
|
||||||
public void testUnresolvedSuperReference() throws Exception {
|
public void testUnresolvedSuperReference() throws Exception {
|
||||||
|
|||||||
+2
-1
@@ -69,7 +69,8 @@ internal class KtFirCallResolver(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun resolveCall(psi: KtElement): KtCallInfo? = withValidityAssertion {
|
override fun resolveCall(psi: KtElement): KtCallInfo? = withValidityAssertion {
|
||||||
if (psi is KtBinaryExpression && psi.operationToken in nonCallBinaryOperator) return null
|
if (psi.isNotResolvable()) return null
|
||||||
|
|
||||||
val containingCallExpressionForCalleeExpression = psi.getContainingCallExpressionForCalleeExpression()
|
val containingCallExpressionForCalleeExpression = psi.getContainingCallExpressionForCalleeExpression()
|
||||||
val containingBinaryExpressionForLhs = psi.getContainingBinaryExpressionForIncompleteLhs()
|
val containingBinaryExpressionForLhs = psi.getContainingBinaryExpressionForIncompleteLhs()
|
||||||
val containingUnaryExpressionForIncOrDec = psi.getContainingUnaryIncOrDecExpression()
|
val containingUnaryExpressionForIncOrDec = psi.getContainingUnaryIncOrDecExpression()
|
||||||
|
|||||||
+36
@@ -648,6 +648,42 @@ public class FirResolveCallTestGenerated extends AbstractFirResolveCallTest {
|
|||||||
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/smartCastImplicitExtensionReceiver.kt");
|
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/smartCastImplicitExtensionReceiver.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unresolvableOperator_elvis_1.kt")
|
||||||
|
public void testUnresolvableOperator_elvis_1() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/unresolvableOperator_elvis_1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unresolvableOperator_elvis_2.kt")
|
||||||
|
public void testUnresolvableOperator_elvis_2() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/unresolvableOperator_elvis_2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unresolvableOperator_eqeqeq_1.kt")
|
||||||
|
public void testUnresolvableOperator_eqeqeq_1() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/unresolvableOperator_eqeqeq_1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unresolvableOperator_eqeqeq_2.kt")
|
||||||
|
public void testUnresolvableOperator_eqeqeq_2() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/unresolvableOperator_eqeqeq_2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unresolvableOperator_excleqeq_1.kt")
|
||||||
|
public void testUnresolvableOperator_excleqeq_1() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/unresolvableOperator_excleqeq_1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("unresolvableOperator_excleqeq_2.kt")
|
||||||
|
public void testUnresolvableOperator_excleqeq_2() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/callResolver/resolveCall/unresolvableOperator_excleqeq_2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("unresolvedSuperReference.kt")
|
@TestMetadata("unresolvedSuperReference.kt")
|
||||||
public void testUnresolvedSuperReference() throws Exception {
|
public void testUnresolvedSuperReference() throws Exception {
|
||||||
|
|||||||
+12
-1
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.analysis.api.calls.KtCompoundAccess
|
|||||||
import org.jetbrains.kotlin.analysis.api.calls.KtExplicitReceiverValue
|
import org.jetbrains.kotlin.analysis.api.calls.KtExplicitReceiverValue
|
||||||
import org.jetbrains.kotlin.analysis.api.components.KtCallResolver
|
import org.jetbrains.kotlin.analysis.api.components.KtCallResolver
|
||||||
import org.jetbrains.kotlin.analysis.api.impl.barebone.parentOfType
|
import org.jetbrains.kotlin.analysis.api.impl.barebone.parentOfType
|
||||||
|
import org.jetbrains.kotlin.lexer.KtSingleValueToken
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
|
||||||
@@ -44,6 +45,16 @@ abstract class AbstractKtCallResolver : KtCallResolver() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected companion object {
|
protected companion object {
|
||||||
val nonCallBinaryOperator = setOf(KtTokens.ELVIS, KtTokens.EQEQEQ, KtTokens.EXCLEQEQEQ)
|
private val nonCallBinaryOperator: Set<KtSingleValueToken> = setOf(KtTokens.ELVIS, KtTokens.EQEQEQ, KtTokens.EXCLEQEQEQ)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We don't want to resolve the operators from the [AbstractKtCallResolver.nonCallBinaryOperator] list, because it's either
|
||||||
|
* not possible or not desirable.
|
||||||
|
*/
|
||||||
|
fun KtElement.isNotResolvable(): Boolean {
|
||||||
|
return this is KtBinaryExpression && operationToken in nonCallBinaryOperator ||
|
||||||
|
this is KtOperationReferenceExpression && operationSignTokenType in nonCallBinaryOperator
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
class A
|
||||||
|
|
||||||
|
fun test(a: A, b: A) {
|
||||||
|
<expr>a ?: b</expr>
|
||||||
|
}
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
null
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
class A
|
||||||
|
|
||||||
|
fun test(a: A, b: A) {
|
||||||
|
a <expr>?:</expr> b
|
||||||
|
}
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
null
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
class A
|
||||||
|
|
||||||
|
fun test(a: A, b: A) {
|
||||||
|
<expr>a === b</expr>
|
||||||
|
}
|
||||||
analysis/analysis-api/testData/components/callResolver/resolveCall/unresolvableOperator_eqeqeq_1.txt
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
null
|
||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
class A
|
||||||
|
|
||||||
|
fun test(a: A, b: A) {
|
||||||
|
a <expr>===</expr> b
|
||||||
|
}
|
||||||
analysis/analysis-api/testData/components/callResolver/resolveCall/unresolvableOperator_eqeqeq_2.txt
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
null
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
class A
|
||||||
|
|
||||||
|
fun test(a: A, b: A) {
|
||||||
|
<expr>a !== b</expr>
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
null
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
class A
|
||||||
|
|
||||||
|
fun test(a: A, b: A) {
|
||||||
|
a <expr>!==</expr> b
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
null
|
||||||
Reference in New Issue
Block a user