KT-62676 [AA] Collect redundant this qualifiers in reference shortener
^KT-62676 Fixed
This commit is contained in:
+8
-4
@@ -102,6 +102,7 @@ internal class KtFirReferenceShortener(
|
||||
//TODO: collect all usages of available symbols in the file and prevent importing symbols that could introduce name clashes, which
|
||||
// may alter the meaning of existing code.
|
||||
val collector = ElementsToShortenCollector(
|
||||
shortenOptions,
|
||||
context,
|
||||
towerContext,
|
||||
selection,
|
||||
@@ -404,6 +405,7 @@ private class ShortenKDocQualifier(
|
||||
) : ElementToShorten()
|
||||
|
||||
private class ElementsToShortenCollector(
|
||||
private val shortenOptions: ShortenOptions,
|
||||
private val shorteningContext: FirShorteningContext,
|
||||
private val towerContextProvider: FirTowerContextProvider,
|
||||
private val selection: TextRange,
|
||||
@@ -1138,11 +1140,13 @@ private class ElementsToShortenCollector(
|
||||
}
|
||||
|
||||
private fun canBePossibleToDropReceiver(qualifiedAccess: FirQualifiedAccessExpression): Boolean {
|
||||
// we can remove receiver only if it is a qualifier
|
||||
if (qualifiedAccess.explicitReceiver !is FirResolvedQualifier) return false
|
||||
return when {
|
||||
qualifiedAccess.explicitReceiver is FirThisReceiverExpression -> shortenOptions.removeThis
|
||||
|
||||
// if there is no extension receiver necessary, then it can be removed
|
||||
return qualifiedAccess.extensionReceiver == null
|
||||
qualifiedAccess.explicitReceiver is FirResolvedQualifier -> qualifiedAccess.extensionReceiver == null
|
||||
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
private fun findUnambiguousReferencedCallableId(namedReference: FirNamedReference): FirCallableSymbol<*>? {
|
||||
|
||||
+10
@@ -72,6 +72,16 @@ public class FirIdeNormalAnalysisScriptSourceModuleReferenceShortenerTestGenerat
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/thisReference")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class ThisReference {
|
||||
@Test
|
||||
public void testAllFilesPresentInThisReference() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/thisReference"), Pattern.compile("^(.+)\\.kts$"), null, true);
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
+88
@@ -816,6 +816,94 @@ public class FirIdeNormalAnalysisSourceModuleReferenceShortenerTestGenerated ext
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/thisReference")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class ThisReference {
|
||||
@Test
|
||||
public void testAllFilesPresentInThisReference() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/thisReference"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("this_extensionFunction_fromExtensionFunction.kt")
|
||||
public void testThis_extensionFunction_fromExtensionFunction() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/thisReference/this_extensionFunction_fromExtensionFunction.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("this_extensionFunction_fromExtensionFunction_conflictWithLocal.kt")
|
||||
public void testThis_extensionFunction_fromExtensionFunction_conflictWithLocal() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/thisReference/this_extensionFunction_fromExtensionFunction_conflictWithLocal.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("this_memberFunction_fromMemberFunction.kt")
|
||||
public void testThis_memberFunction_fromMemberFunction() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/thisReference/this_memberFunction_fromMemberFunction.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("this_memberFunction_fromMemberFunction_conflictWithLocal.kt")
|
||||
public void testThis_memberFunction_fromMemberFunction_conflictWithLocal() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/thisReference/this_memberFunction_fromMemberFunction_conflictWithLocal.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("this_memberProperty_fromInit.kt")
|
||||
public void testThis_memberProperty_fromInit() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/thisReference/this_memberProperty_fromInit.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("this_memberProperty_fromInit_conflictWithParameter.kt")
|
||||
public void testThis_memberProperty_fromInit_conflictWithParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/thisReference/this_memberProperty_fromInit_conflictWithParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("this_memberProperty_fromMemberFunction.kt")
|
||||
public void testThis_memberProperty_fromMemberFunction() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/thisReference/this_memberProperty_fromMemberFunction.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("this_memberProperty_fromMemberFunctionWithContextReceiver.kt")
|
||||
public void testThis_memberProperty_fromMemberFunctionWithContextReceiver() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/thisReference/this_memberProperty_fromMemberFunctionWithContextReceiver.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("this_memberProperty_fromMemberFunction_conflictWithLocal.kt")
|
||||
public void testThis_memberProperty_fromMemberFunction_conflictWithLocal() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/thisReference/this_memberProperty_fromMemberFunction_conflictWithLocal.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("this_memberProperty_fromMemberFunction_conflictWithParameter.kt")
|
||||
public void testThis_memberProperty_fromMemberFunction_conflictWithParameter() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/thisReference/this_memberProperty_fromMemberFunction_conflictWithParameter.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("this_memberProperty_fromMemberFunction_noConflictWithLocal.kt")
|
||||
public void testThis_memberProperty_fromMemberFunction_noConflictWithLocal() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/thisReference/this_memberProperty_fromMemberFunction_noConflictWithLocal.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("this_nullableReceiver.kt")
|
||||
public void testThis_nullableReceiver() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/thisReference/this_nullableReceiver.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("this_safeCall.kt")
|
||||
public void testThis_safeCall() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/thisReference/this_safeCall.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("analysis/analysis-api/testData/components/referenceShortener/referenceShortener/typeParameters")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
|
||||
Reference in New Issue
Block a user