FIR IDE: More strictly navigate to parent KtDotQualifiedExpression
This commit is contained in:
+5
@@ -85,6 +85,11 @@ public class FirShortenRefsTestGenerated extends AbstractFirShortenRefsTest {
|
||||
public void testSelfReferencingFunction() throws Exception {
|
||||
runTest("idea/testData/shortenRefsFir/calls/selfReferencingFunction.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("variableNotShortened.kt")
|
||||
public void testVariableNotShortened() throws Exception {
|
||||
runTest("idea/testData/shortenRefsFir/calls/variableNotShortened.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/shortenRefsFir/quailfiers")
|
||||
|
||||
+8
-3
@@ -9,7 +9,9 @@ import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.SmartPsiElementPointer
|
||||
import com.intellij.util.containers.addIfNotNull
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.declarations.FirClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvedImport
|
||||
import org.jetbrains.kotlin.fir.expressions.FirFunctionCall
|
||||
@@ -230,7 +232,7 @@ internal class KtFirReferenceShortener(
|
||||
super.visitResolvedNamedReference(resolvedNamedReference)
|
||||
|
||||
val referenceExpression = resolvedNamedReference.psi as? KtNameReferenceExpression
|
||||
val qualifiedProperty = referenceExpression?.parent as? KtDotQualifiedExpression ?: return
|
||||
val qualifiedProperty = referenceExpression?.getDotQualifiedExpressionForSelector() ?: return
|
||||
|
||||
val propertyId = (resolvedNamedReference.resolvedSymbol as? FirCallableSymbol<*>)?.callableId ?: return
|
||||
|
||||
@@ -246,7 +248,7 @@ internal class KtFirReferenceShortener(
|
||||
super.visitFunctionCall(functionCall)
|
||||
|
||||
val callExpression = functionCall.psi as? KtCallExpression ?: return
|
||||
val qualifiedCallExpression = callExpression.parent as? KtDotQualifiedExpression ?: return
|
||||
val qualifiedCallExpression = callExpression.getDotQualifiedExpressionForSelector() ?: return
|
||||
|
||||
val resolvedNamedReference = functionCall.calleeReference as? FirResolvedNamedReference ?: return
|
||||
val callableId = (resolvedNamedReference.resolvedSymbol as? FirCallableSymbol<*>)?.callableId ?: return
|
||||
@@ -266,7 +268,7 @@ internal class KtFirReferenceShortener(
|
||||
val wholeClassQualifier = resolvedQualifier.classId ?: return
|
||||
val wholeQualifierElement = when (val qualifierPsi = resolvedQualifier.psi) {
|
||||
is KtDotQualifiedExpression -> qualifierPsi
|
||||
is KtNameReferenceExpression -> qualifierPsi.parent as? KtDotQualifiedExpression ?: return
|
||||
is KtNameReferenceExpression -> qualifierPsi.getDotQualifiedExpressionForSelector() ?: return
|
||||
else -> return
|
||||
}
|
||||
|
||||
@@ -344,6 +346,9 @@ private class ShortenCommandImpl(
|
||||
}
|
||||
}
|
||||
|
||||
private fun KtElement.getDotQualifiedExpressionForSelector(): KtDotQualifiedExpression? =
|
||||
getQualifiedExpressionForSelector() as? KtDotQualifiedExpression
|
||||
|
||||
private tailrec fun KtTypeElement?.unwrapNullable(): KtTypeElement? =
|
||||
if (this is KtNullableType) this.innerType.unwrapNullable() else this
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// FIR_COMPARISON
|
||||
fun usage(c: Any) {
|
||||
<selection>c.toString()</selection>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// FIR_COMPARISON
|
||||
fun usage(c: Any) {
|
||||
c.toString()
|
||||
}
|
||||
Reference in New Issue
Block a user