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?) {
|
override fun addImportsFromString(imports: String?) {
|
||||||
if (imports == null || imports.isEmpty()) return
|
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
|
// we need this code to force re-highlighting, otherwise it does not work by some reason
|
||||||
val tempElement = KtPsiFactory(project).createColon()
|
val tempElement = KtPsiFactory(project).createColon()
|
||||||
add(tempElement).delete()
|
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? {
|
fun importsAsImportList(): KtImportList? {
|
||||||
if (!imports.isEmpty() && context != null) {
|
if (!imports.isEmpty() && context != null) {
|
||||||
return KtPsiFactory(this).createAnalyzableFile("imports_for_codeFragment.kt", imports.joinToString("\n"), context).importList
|
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?) {
|
private fun initImports(imports: String?) {
|
||||||
if (imports != null && !imports.isEmpty()) {
|
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
|
!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'
|
Connected to the target VM, address: '!HOST_NAME!:PORT_NAME!', transport: 'socket'
|
||||||
createExpressionWithArray.kt:9
|
createExpressionWithArray.kt:11
|
||||||
package createExpressionWithArray
|
package createExpressionWithArray
|
||||||
|
|
||||||
import forTests.MyJavaClass
|
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>) {
|
fun main(args: Array<String>) {
|
||||||
val baseArray = arrayOf(MyJavaClass().getBaseClassValue())
|
val baseArray = arrayOf(MyJavaClass().getBaseClassValue())
|
||||||
|
|||||||
+2
@@ -1,6 +1,8 @@
|
|||||||
package createExpressionWithArray
|
package createExpressionWithArray
|
||||||
|
|
||||||
import forTests.MyJavaClass
|
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>) {
|
fun main(args: Array<String>) {
|
||||||
val baseArray = arrayOf(MyJavaClass().getBaseClassValue())
|
val baseArray = arrayOf(MyJavaClass().getBaseClassValue())
|
||||||
|
|||||||
Reference in New Issue
Block a user