K2: Update reference shortener to handle import alias

The existing reference shortener does not use import alias when it
shortens a symbol. Instead, it adds a new import directive for the
symbol that is already imported. This commit updates reference shortener
to let it reuse the existing import alias rather than adding a new one:

 1. When shortening a symbol, check whether the symbol is already
    imported.
 2. If it is already imported by an import alias, keep the symbol
    reference expression and the import alias as a string together in
    `ShortenCommand`.

The actual PSI update (shortening) based on the ShortenCommand is done
by IntelliJ.

^KTIJ-27205
This commit is contained in:
Jaebaek Seo
2023-10-03 12:19:24 -07:00
committed by teamcity
parent 02c12ae26f
commit e80f044847
24 changed files with 379 additions and 39 deletions
@@ -274,6 +274,36 @@ public class FirStandaloneNormalAnalysisSourceModuleReferenceShortenerTestGenera
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/functionalType_parameterPosition.kt");
}
@Test
@TestMetadata("importAliasAndStarImport.kt")
public void testImportAliasAndStarImport() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/importAliasAndStarImport.kt");
}
@Test
@TestMetadata("importAliasForFunction.kt")
public void testImportAliasForFunction() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/importAliasForFunction.kt");
}
@Test
@TestMetadata("importAliasForProperty.kt")
public void testImportAliasForProperty() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/importAliasForProperty.kt");
}
@Test
@TestMetadata("importAliasForType.kt")
public void testImportAliasForType() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/importAliasForType.kt");
}
@Test
@TestMetadata("importAliasForTypeQualifier.kt")
public void testImportAliasForTypeQualifier() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/importAliasForTypeQualifier.kt");
}
@Test
@TestMetadata("kdoc.kt")
public void testKdoc() throws Exception {
@@ -310,6 +340,18 @@ public class FirStandaloneNormalAnalysisSourceModuleReferenceShortenerTestGenera
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/multipleImport.kt");
}
@Test
@TestMetadata("multipleImportAlias.kt")
public void testMultipleImportAlias() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/multipleImportAlias.kt");
}
@Test
@TestMetadata("multipleImportAlias2.kt")
public void testMultipleImportAlias2() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/multipleImportAlias2.kt");
}
@Test
@TestMetadata("nestedClass.kt")
public void testNestedClass() throws Exception {
@@ -490,6 +532,12 @@ public class FirStandaloneNormalAnalysisSourceModuleReferenceShortenerTestGenera
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/shortenAlreadyImportedFunction4.kt");
}
@Test
@TestMetadata("starImport.kt")
public void testStarImport() throws Exception {
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/starImport.kt");
}
@Test
@TestMetadata("staticMethodFromBaseClassConflict.kt")
public void testStaticMethodFromBaseClassConflict() throws Exception {