Debugger: do not insert ambiguous imports inside codeFragments
#KT-11927 Fixed
This commit is contained in:
@@ -99,13 +99,25 @@ abstract class KtCodeFragment(
|
||||
|
||||
override fun addImportsFromString(imports: String?) {
|
||||
if (imports == null || imports.isEmpty()) return
|
||||
this.imports.addAll(imports.split(IMPORT_SEPARATOR))
|
||||
|
||||
imports.split(IMPORT_SEPARATOR).forEach {
|
||||
addImport(it)
|
||||
}
|
||||
|
||||
// we need this code to force re-highlighting, otherwise it does not work by some reason
|
||||
val tempElement = KtPsiFactory(project).createColon()
|
||||
add(tempElement).delete()
|
||||
}
|
||||
|
||||
fun addImport(import: String) {
|
||||
val contextFile = getContextContainingFile()
|
||||
if (contextFile != null) {
|
||||
if (contextFile.importDirectives.find { it.text == import } == null) {
|
||||
imports.add(import)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun importsAsImportList(): KtImportList? {
|
||||
if (!imports.isEmpty() && context != null) {
|
||||
return KtPsiFactory(this).createAnalyzableFile("imports_for_codeFragment.kt", imports.joinToString("\n"), context).importList
|
||||
@@ -146,7 +158,11 @@ abstract class KtCodeFragment(
|
||||
|
||||
private fun initImports(imports: String?) {
|
||||
if (imports != null && !imports.isEmpty()) {
|
||||
this.imports.addAll(imports.split(IMPORT_SEPARATOR).map { it.check { it.startsWith("import ") } ?: "import $it" })
|
||||
|
||||
val importsWithPrefix = imports.split(IMPORT_SEPARATOR).map { it.check { it.startsWith("import ") } ?: "import ${it.trim()}" }
|
||||
importsWithPrefix.forEach {
|
||||
addImport(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user