From b58ee608476943e9d8b926dd059a60fa76473da7 Mon Sep 17 00:00:00 2001 From: Roman Golyshev Date: Mon, 28 Oct 2024 12:22:23 +0100 Subject: [PATCH] KTIJ-31336 [kotlin] Revert temporary hacks from `OptimizedImportsBuilder` required for KTIJ-31070 This is basically a revert of d5c7dcca commit. Now, when KTIJ-30991 is fixed, the conflicts are properly analyzed, and we don't need the hacks from this commit at all. ^KTIJ-31336 Fixed (cherry picked from commit d545b059ea58cae513fe5861d9851062b470d8eb) IJ-CR-149236 GitOrigin-RevId: a82f036fe1a958c7e151abb5f66351b19b676897 --- .../imports/OptimizedImportsBuilder.kt | 20 ++----------------- .../NoRedundantThrowsImport.kt | 1 - .../NoRedundantThrowsImport.kt.after | 1 - 3 files changed, 2 insertions(+), 20 deletions(-) diff --git a/plugins/kotlin/code-insight/kotlin.code-insight.k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/imports/OptimizedImportsBuilder.kt b/plugins/kotlin/code-insight/kotlin.code-insight.k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/imports/OptimizedImportsBuilder.kt index 7d6ea74174c0..764081815896 100644 --- a/plugins/kotlin/code-insight/kotlin.code-insight.k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/imports/OptimizedImportsBuilder.kt +++ b/plugins/kotlin/code-insight/kotlin.code-insight.k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/imports/OptimizedImportsBuilder.kt @@ -114,11 +114,7 @@ internal class OptimizedImportsBuilder( symbols.asSequence() .filter { it is ClassLikeSymbolInfo } .mapNotNull { importSymbolWithMapping(it) } - .filterTo(classNamesToCheck) { - // TODO reconsider this after KTIJ-30991 is fixed - //needExplicitImport(it) - true - } + .filterTo(classNamesToCheck) { needExplicitImport(it) } if (fqNames.all { needExplicitImport(it) }) { importsToGenerate.add(starImportPath) @@ -133,13 +129,7 @@ internal class OptimizedImportsBuilder( val foundClassifiers = hierarchicalScope.findClassifiers(fqName.shortName()).firstOrNull() val singleFoundClassifier = foundClassifiers?.singleOrNull() - - val singleFoundClassifierFqName = singleFoundClassifier?.let { - // TODO reconsider this after KTIJ-30991 is fixed - importSymbolWithMapping(it) - } - - if (singleFoundClassifierFqName != fqName) { + if (singleFoundClassifier?.importableFqName != fqName) { // add explicit import if failed to import with * (or from current package) importsToGenerate.add(ImportPath(fqName, false)) @@ -255,12 +245,6 @@ internal class OptimizedImportsBuilder( return findCorrespondingKotlinFqName(importableName) ?: importableName } - private fun KaSession.importSymbolWithMapping(symbol: KaClassifierSymbol): FqName? { - val importableName = symbol.importableFqName ?: return null - - return findCorrespondingKotlinFqName(importableName) ?: importableName - } - private fun KaSession.canUseStarImport(importableSymbol: SymbolInfo, fqName: FqName): Boolean = when { fqName.parent().isRoot -> false // star import from objects is not allowed diff --git a/plugins/kotlin/idea/tests/testData/editor/optimizeImports/jvm/allUnderImports/NoRedundantThrowsImport.kt b/plugins/kotlin/idea/tests/testData/editor/optimizeImports/jvm/allUnderImports/NoRedundantThrowsImport.kt index ed111227b3c7..92c58b242334 100644 --- a/plugins/kotlin/idea/tests/testData/editor/optimizeImports/jvm/allUnderImports/NoRedundantThrowsImport.kt +++ b/plugins/kotlin/idea/tests/testData/editor/optimizeImports/jvm/allUnderImports/NoRedundantThrowsImport.kt @@ -1,5 +1,4 @@ // NAME_COUNT_TO_USE_STAR_IMPORT: 2 -// IGNORE_K2 package test @Throws diff --git a/plugins/kotlin/idea/tests/testData/editor/optimizeImports/jvm/allUnderImports/NoRedundantThrowsImport.kt.after b/plugins/kotlin/idea/tests/testData/editor/optimizeImports/jvm/allUnderImports/NoRedundantThrowsImport.kt.after index ed111227b3c7..92c58b242334 100644 --- a/plugins/kotlin/idea/tests/testData/editor/optimizeImports/jvm/allUnderImports/NoRedundantThrowsImport.kt.after +++ b/plugins/kotlin/idea/tests/testData/editor/optimizeImports/jvm/allUnderImports/NoRedundantThrowsImport.kt.after @@ -1,5 +1,4 @@ // NAME_COUNT_TO_USE_STAR_IMPORT: 2 -// IGNORE_K2 package test @Throws