[Analysis API] Do not shorten qualifiers outside the selection range
^KTIJ-25116 Fixed
This commit is contained in:
committed by
teamcity
parent
ed7a3299f0
commit
da5f33d762
+5
-2
@@ -375,7 +375,7 @@ private class ElementsToShortenCollector(
|
||||
else -> null
|
||||
}?.unwrapNullability() as? KtUserType ?: return
|
||||
|
||||
if (!typeElement.textRange.intersects(selection)) return
|
||||
if (typeElement.referenceExpression?.textRange?.intersects(selection) != true) return
|
||||
if (typeElement.qualifier == null) return
|
||||
|
||||
val classifierId = nonErrorResolvedTypeRef.type.lowerBoundIfFlexible().candidateClassId ?: return
|
||||
@@ -896,9 +896,12 @@ private class ElementsToShortenCollector(
|
||||
if (!canBePossibleToDropReceiver(functionCall)) return
|
||||
|
||||
val qualifiedCallExpression = functionCall.psi as? KtDotQualifiedExpression ?: return
|
||||
if (!qualifiedCallExpression.textRange.intersects(selection)) return
|
||||
val callExpression = qualifiedCallExpression.selectorExpression as? KtCallExpression ?: return
|
||||
|
||||
val calleeTextRange = callExpression.calleeExpression?.textRange
|
||||
val qualifierTextRange = qualifiedCallExpression.receiverExpression.textRange
|
||||
if (calleeTextRange?.intersects(selection) != true && !qualifierTextRange.intersects(selection)) return
|
||||
|
||||
val calleeReference = functionCall.calleeReference
|
||||
val calledSymbol = findUnambiguousReferencedCallableId(calleeReference) ?: return
|
||||
|
||||
|
||||
+12
@@ -172,6 +172,12 @@ public class FirIdeNormalAnalysisSourceModuleReferenceShortenerTestGenerated ext
|
||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/companionUsedOutOfClass.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constructorParameter.kt")
|
||||
public void testConstructorParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/constructorParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("contextReceiver.kt")
|
||||
public void testContextReceiver() throws Exception {
|
||||
@@ -376,6 +382,12 @@ public class FirIdeNormalAnalysisSourceModuleReferenceShortenerTestGenerated ext
|
||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/superEntry.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeArgument.kt")
|
||||
public void testTypeArgument() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeArgument.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeParams.kt")
|
||||
public void testTypeParams() throws Exception {
|
||||
|
||||
+12
@@ -172,6 +172,12 @@ public class FirStandaloneNormalAnalysisSourceModuleReferenceShortenerTestGenera
|
||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/companionUsedOutOfClass.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("constructorParameter.kt")
|
||||
public void testConstructorParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/constructorParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("contextReceiver.kt")
|
||||
public void testContextReceiver() throws Exception {
|
||||
@@ -376,6 +382,12 @@ public class FirStandaloneNormalAnalysisSourceModuleReferenceShortenerTestGenera
|
||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/superEntry.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeArgument.kt")
|
||||
public void testTypeArgument() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeArgument.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeParams.kt")
|
||||
public void testTypeParams() throws Exception {
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// FILE: main.kt
|
||||
import dependency.A
|
||||
|
||||
fun test() {
|
||||
val b = A.B(<expr>dependency.Foo()</expr>)
|
||||
}
|
||||
// FILE: dependency.kt
|
||||
package dependency
|
||||
|
||||
class Foo
|
||||
|
||||
sealed class A {
|
||||
class B(foo: Foo): A()
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
Before shortening: dependency.Foo()
|
||||
with DO_NOT_SHORTEN:
|
||||
with SHORTEN_IF_ALREADY_IMPORTED:
|
||||
with SHORTEN_AND_IMPORT:
|
||||
[qualifier] dependency.Foo()
|
||||
with SHORTEN_AND_STAR_IMPORT:
|
||||
[qualifier] dependency.Foo()
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
// FILE: main.kt
|
||||
import dependency.A
|
||||
|
||||
fun test() {
|
||||
val b: A.B<<expr>dependency.Foo</expr>>
|
||||
}
|
||||
// FILE: dependency.kt
|
||||
package dependency
|
||||
|
||||
class Foo
|
||||
|
||||
sealed class A {
|
||||
class B<T>: A()
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
Before shortening: dependency.Foo
|
||||
with DO_NOT_SHORTEN:
|
||||
with SHORTEN_IF_ALREADY_IMPORTED:
|
||||
with SHORTEN_AND_IMPORT:
|
||||
[type] dependency.Foo
|
||||
with SHORTEN_AND_STAR_IMPORT:
|
||||
[type] dependency.Foo
|
||||
Reference in New Issue
Block a user