Debugger: do not insert ambiguous imports inside codeFragments

#KT-11927 Fixed
This commit is contained in:
Natalia Ukhorskaya
2016-04-05 18:57:17 +03:00
parent d7a87b2ff0
commit 070ee10872
3 changed files with 24 additions and 4 deletions
@@ -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)
}
}
}
@@ -1,10 +1,12 @@
LineBreakpoint created at createExpressionWithArray.kt:9
LineBreakpoint created at createExpressionWithArray.kt:11
!JDK_HOME!\bin\java -agentlib:jdwp=transport=dt_socket,address=!HOST_NAME!:!HOST_PORT!,suspend=y,server=n -Dfile.encoding=!FILE_ENCODING! -classpath !OUTPUT_PATH!;!KOTLIN_RUNTIME!;!CUSTOM_LIBRARY!;!RT_JAR! createExpressionWithArray.CreateExpressionWithArrayKt
Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
createExpressionWithArray.kt:9
createExpressionWithArray.kt:11
package createExpressionWithArray
import forTests.MyJavaClass
// do not remove this import, it checks that we do not insert ambiguous imports during EE
import forTests.MyJavaClass.InnerClass
fun main(args: Array<String>) {
val baseArray = arrayOf(MyJavaClass().getBaseClassValue())
@@ -1,6 +1,8 @@
package createExpressionWithArray
import forTests.MyJavaClass
// do not remove this import, it checks that we do not insert ambiguous imports during EE
import forTests.MyJavaClass.InnerClass
fun main(args: Array<String>) {
val baseArray = arrayOf(MyJavaClass().getBaseClassValue())