@@ -55,6 +55,7 @@ import org.utbot.framework.plugin.api.util.objectClassId
5555import org.utbot.framework.plugin.api.util.shortClassId
5656import org.utbot.framework.plugin.api.util.signature
5757import org.utbot.framework.plugin.api.util.underlyingType
58+ import soot.Scene
5859import java.lang.reflect.Method
5960import java.lang.reflect.Modifier
6061
@@ -210,13 +211,24 @@ internal fun infiniteInts(): Sequence<Int> =
210211
211212internal const val MAX_ARRAY_INITIALIZER_SIZE = 10
212213
214+ private val simpleNamesNotRequiringImports by lazy { findSimpleNamesNotRequiringImports() }
215+
216+ /* *
217+ * Some class names do not require imports, but may lead to simple names clash.
218+ * For example, custom class [Compiler] may clash with [java.lang.Compiler].
219+ */
220+ private fun findSimpleNamesNotRequiringImports (): Set <String > =
221+ Scene .v().classes
222+ .filter { it.packageName == " java.lang" }
223+ .mapNotNullTo(mutableSetOf ()) { it.shortName }
224+
213225/* *
214226 * Checks if we have already imported a class with such simple name.
215227 * If so, we cannot import [type] (because it will be used with simple name and will be clashed with already imported)
216228 * and should use its fully qualified name instead.
217229 */
218230private fun CgContextOwner.doesNotHaveSimpleNameClash (type : ClassId ): Boolean =
219- importedClasses.none { it.simpleName == type.simpleName }
231+ importedClasses.none { it.simpleName == type.simpleName } && type.simpleName !in simpleNamesNotRequiringImports
220232
221233fun CgContextOwner.importIfNeeded (type : ClassId ) {
222234 // TODO: for now we consider that tests are generated in the same package as CUT, but this may change
0 commit comments