J2K: Speed-up add imports
This commit is contained in:
@@ -92,14 +92,21 @@ class NewJavaToKotlinConverter(
|
|||||||
|
|
||||||
private fun KtFile.addImports(imports: Collection<FqName>) {
|
private fun KtFile.addImports(imports: Collection<FqName>) {
|
||||||
val factory = KtPsiFactory(this)
|
val factory = KtPsiFactory(this)
|
||||||
var importList = importList
|
|
||||||
for (import in imports) {
|
|
||||||
val importDirective = factory.createImportDirective(ImportPath(import, isAllUnder = false))
|
if (imports.isEmpty()) return
|
||||||
if (importList == null) {
|
val importPsi = factory.createImportDirectives(
|
||||||
importList = addImportList(importDirective.parent as KtImportList)
|
imports.map { ImportPath(it, isAllUnder = false) }
|
||||||
} else {
|
)
|
||||||
importList.add(importDirective)
|
val createdImportList = importPsi.first().parent as KtImportList
|
||||||
}
|
val importList = importList
|
||||||
|
if (importList == null) {
|
||||||
|
addImportList(createdImportList)
|
||||||
|
} else {
|
||||||
|
val updatedList = if(importList.firstChild != null) {
|
||||||
|
createdImportList.addRangeBefore(importList.firstChild, importList.lastChild, createdImportList.firstChild)
|
||||||
|
} else createdImportList
|
||||||
|
importList.replace(updatedList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user