[Analysis API] Shorten qualifier of unresolved reference
^KTIJ-25115
This commit is contained in:
committed by
teamcity
parent
2d945b7226
commit
ed7a3299f0
+13
-6
@@ -365,15 +365,22 @@ private class ElementsToShortenCollector(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun processTypeRef(resolvedTypeRef: FirResolvedTypeRef) {
|
private fun processTypeRef(resolvedTypeRef: FirResolvedTypeRef) {
|
||||||
val wholeTypeReference = resolvedTypeRef.realPsi as? KtTypeReference ?: return
|
val nonErrorResolvedTypeRef = if (resolvedTypeRef is FirErrorTypeRef) {
|
||||||
if (!wholeTypeReference.textRange.intersects(selection)) return
|
resolvedTypeRef.partiallyResolvedTypeRef as? FirResolvedTypeRef ?: resolvedTypeRef
|
||||||
|
} else resolvedTypeRef
|
||||||
|
|
||||||
val wholeClassifierId = resolvedTypeRef.type.lowerBoundIfFlexible().candidateClassId ?: return
|
val typeElement = when (val realPsi = nonErrorResolvedTypeRef.realPsi) {
|
||||||
val wholeTypeElement = wholeTypeReference.typeElement?.unwrapNullability() as? KtUserType ?: return
|
is KtTypeReference -> realPsi.typeElement
|
||||||
|
is KtNameReferenceExpression -> realPsi.parent as? KtTypeElement
|
||||||
|
else -> null
|
||||||
|
}?.unwrapNullability() as? KtUserType ?: return
|
||||||
|
|
||||||
if (wholeTypeElement.qualifier == null) return
|
if (!typeElement.textRange.intersects(selection)) return
|
||||||
|
if (typeElement.qualifier == null) return
|
||||||
|
|
||||||
findTypeToShorten(wholeClassifierId, wholeTypeElement)?.let(::addElementToShorten)
|
val classifierId = nonErrorResolvedTypeRef.type.lowerBoundIfFlexible().candidateClassId ?: return
|
||||||
|
|
||||||
|
findTypeToShorten(classifierId, typeElement)?.let(::addElementToShorten)
|
||||||
}
|
}
|
||||||
|
|
||||||
val ConeKotlinType.candidateClassId: ClassId?
|
val ConeKotlinType.candidateClassId: ClassId?
|
||||||
|
|||||||
+24
@@ -46,6 +46,12 @@ public class FirIdeNormalAnalysisSourceModuleReferenceShortenerTestGenerated ext
|
|||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/referenceShortener/referenceShortener"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/referenceShortener/referenceShortener"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("annotaiton.kt")
|
||||||
|
public void testAnnotaiton() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/annotaiton.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("classScopes.kt")
|
@TestMetadata("classScopes.kt")
|
||||||
public void testClassScopes() throws Exception {
|
public void testClassScopes() throws Exception {
|
||||||
@@ -76,6 +82,12 @@ public class FirIdeNormalAnalysisSourceModuleReferenceShortenerTestGenerated ext
|
|||||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/classType2.kt");
|
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/classType2.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("classWithWrongNumberOfTypeArguments.kt")
|
||||||
|
public void testClassWithWrongNumberOfTypeArguments() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/classWithWrongNumberOfTypeArguments.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("classesWithSameName.kt")
|
@TestMetadata("classesWithSameName.kt")
|
||||||
public void testClassesWithSameName() throws Exception {
|
public void testClassesWithSameName() throws Exception {
|
||||||
@@ -250,6 +262,12 @@ public class FirIdeNormalAnalysisSourceModuleReferenceShortenerTestGenerated ext
|
|||||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/parameterTypeTopLevelTypeLoses.kt");
|
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/parameterTypeTopLevelTypeLoses.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("qualifierOfUnresolvedReference.kt")
|
||||||
|
public void testQualifierOfUnresolvedReference() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/qualifierOfUnresolvedReference.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("receiver.kt")
|
@TestMetadata("receiver.kt")
|
||||||
public void testReceiver() throws Exception {
|
public void testReceiver() throws Exception {
|
||||||
@@ -352,6 +370,12 @@ public class FirIdeNormalAnalysisSourceModuleReferenceShortenerTestGenerated ext
|
|||||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/superClass.kt");
|
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/superClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("superEntry.kt")
|
||||||
|
public void testSuperEntry() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/superEntry.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("typeParams.kt")
|
@TestMetadata("typeParams.kt")
|
||||||
public void testTypeParams() throws Exception {
|
public void testTypeParams() throws Exception {
|
||||||
|
|||||||
+24
@@ -46,6 +46,12 @@ public class FirStandaloneNormalAnalysisSourceModuleReferenceShortenerTestGenera
|
|||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/referenceShortener/referenceShortener"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/referenceShortener/referenceShortener"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("annotaiton.kt")
|
||||||
|
public void testAnnotaiton() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/annotaiton.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("classScopes.kt")
|
@TestMetadata("classScopes.kt")
|
||||||
public void testClassScopes() throws Exception {
|
public void testClassScopes() throws Exception {
|
||||||
@@ -76,6 +82,12 @@ public class FirStandaloneNormalAnalysisSourceModuleReferenceShortenerTestGenera
|
|||||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/classType2.kt");
|
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/classType2.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("classWithWrongNumberOfTypeArguments.kt")
|
||||||
|
public void testClassWithWrongNumberOfTypeArguments() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/classWithWrongNumberOfTypeArguments.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("classesWithSameName.kt")
|
@TestMetadata("classesWithSameName.kt")
|
||||||
public void testClassesWithSameName() throws Exception {
|
public void testClassesWithSameName() throws Exception {
|
||||||
@@ -250,6 +262,12 @@ public class FirStandaloneNormalAnalysisSourceModuleReferenceShortenerTestGenera
|
|||||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/parameterTypeTopLevelTypeLoses.kt");
|
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/parameterTypeTopLevelTypeLoses.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("qualifierOfUnresolvedReference.kt")
|
||||||
|
public void testQualifierOfUnresolvedReference() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/qualifierOfUnresolvedReference.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("receiver.kt")
|
@TestMetadata("receiver.kt")
|
||||||
public void testReceiver() throws Exception {
|
public void testReceiver() throws Exception {
|
||||||
@@ -352,6 +370,12 @@ public class FirStandaloneNormalAnalysisSourceModuleReferenceShortenerTestGenera
|
|||||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/superClass.kt");
|
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/superClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("superEntry.kt")
|
||||||
|
public void testSuperEntry() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/superEntry.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("typeParams.kt")
|
@TestMetadata("typeParams.kt")
|
||||||
public void testTypeParams() throws Exception {
|
public void testTypeParams() throws Exception {
|
||||||
|
|||||||
Vendored
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package some
|
||||||
|
|
||||||
|
annotation class SomeAnnotation
|
||||||
|
|
||||||
|
class Complete(@set:<expr>some.SomeAnnotation</expr> var field: Int)
|
||||||
Vendored
+8
@@ -0,0 +1,8 @@
|
|||||||
|
Before shortening: some.SomeAnnotation
|
||||||
|
with DO_NOT_SHORTEN:
|
||||||
|
with SHORTEN_IF_ALREADY_IMPORTED:
|
||||||
|
[type] some.SomeAnnotation
|
||||||
|
with SHORTEN_AND_IMPORT:
|
||||||
|
[type] some.SomeAnnotation
|
||||||
|
with SHORTEN_AND_STAR_IMPORT:
|
||||||
|
[type] some.SomeAnnotation
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
// WITH_STDLIB
|
||||||
|
// FILE: main.kt
|
||||||
|
fun other() : <expr>java.util.SortedSet</expr>
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
Before shortening: java.util.SortedSet
|
||||||
|
with DO_NOT_SHORTEN:
|
||||||
|
with SHORTEN_IF_ALREADY_IMPORTED:
|
||||||
|
with SHORTEN_AND_IMPORT:
|
||||||
|
[type] java.util.SortedSet
|
||||||
|
with SHORTEN_AND_STAR_IMPORT:
|
||||||
|
[type] java.util.SortedSet
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
// FILE: main.kt
|
||||||
|
package x.y.z
|
||||||
|
|
||||||
|
fun test(a: <expr>a.b.c.A.f</expr>) {}
|
||||||
|
// FILE: dependency.kt
|
||||||
|
package a.b.c
|
||||||
|
|
||||||
|
class A
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
Before shortening: a.b.c.A.f
|
||||||
|
with DO_NOT_SHORTEN:
|
||||||
|
with SHORTEN_IF_ALREADY_IMPORTED:
|
||||||
|
with SHORTEN_AND_IMPORT:
|
||||||
|
[type] a.b.c.A
|
||||||
|
with SHORTEN_AND_STAR_IMPORT:
|
||||||
|
[type] a.b.c.A
|
||||||
Vendored
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package foo.bar
|
||||||
|
interface A {
|
||||||
|
fun foo(i: Int) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface B {
|
||||||
|
fun foo(i2: Int) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class C : A, B {
|
||||||
|
override fun foo(j: Int) {
|
||||||
|
super<<expr>foo.bar.A</expr>>.foo()
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+8
@@ -0,0 +1,8 @@
|
|||||||
|
Before shortening: foo.bar.A
|
||||||
|
with DO_NOT_SHORTEN:
|
||||||
|
with SHORTEN_IF_ALREADY_IMPORTED:
|
||||||
|
[type] foo.bar.A
|
||||||
|
with SHORTEN_AND_IMPORT:
|
||||||
|
[type] foo.bar.A
|
||||||
|
with SHORTEN_AND_STAR_IMPORT:
|
||||||
|
[type] foo.bar.A
|
||||||
Reference in New Issue
Block a user