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
This commit is contained in:
Roman Golyshev
2024-11-22 10:54:10 +00:00
committed by intellij-monorepo-bot
parent 94249cf315
commit b58ee60847
3 changed files with 2 additions and 20 deletions
@@ -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
@@ -1,5 +1,4 @@
// NAME_COUNT_TO_USE_STAR_IMPORT: 2
// IGNORE_K2
package test
@Throws
@@ -1,5 +1,4 @@
// NAME_COUNT_TO_USE_STAR_IMPORT: 2
// IGNORE_K2
package test
@Throws