[AA FIR] add missing new line to addImportToFile

^KTIJ-24928
This commit is contained in:
Dmitrii Gridin
2023-04-12 19:06:59 +02:00
committed by Space Team
parent df35e5431c
commit 9724febf88
@@ -46,6 +46,7 @@ fun addImportToFile(
if (file is KtCodeFragment) { if (file is KtCodeFragment) {
val newDirective = psiFactory.createImportDirective(importPath) val newDirective = psiFactory.createImportDirective(importPath)
file.addImportsFromString(newDirective.text) file.addImportsFromString(newDirective.text)
return
} }
if (allUnder) { if (allUnder) {
@@ -57,17 +58,17 @@ fun addImportToFile(
val newDirective = psiFactory.createImportDirective(importPath) val newDirective = psiFactory.createImportDirective(importPath)
val imports = importList.imports val imports = importList.imports
if (imports.isEmpty()) { //TODO: strange hack if (imports.isEmpty()) {
importList.add(psiFactory.createNewLine()) importList.add(psiFactory.createNewLine(2))
importList.add(newDirective) importList.add(newDirective)
} else { } else {
val insertAfter = imports val insertAfter = imports.lastOrNull {
.lastOrNull { val directivePath = it.importPath
val directivePath = it.importPath directivePath != null && SimpleImportPathComparator.compare(directivePath, importPath) <= 0
}
directivePath != null && SimpleImportPathComparator.compare(directivePath, importPath) <= 0 importList.addAfter(newDirective, insertAfter).also {
} importList.addBefore(psiFactory.createNewLine(1), it)
}
importList.addAfter(newDirective, insertAfter)
} }
} }