@@ -55,6 +55,7 @@ import org.utbot.framework.plugin.api.util.objectClassId
55
55
import org.utbot.framework.plugin.api.util.shortClassId
56
56
import org.utbot.framework.plugin.api.util.signature
57
57
import org.utbot.framework.plugin.api.util.underlyingType
58
+ import soot.Scene
58
59
import java.lang.reflect.Method
59
60
import java.lang.reflect.Modifier
60
61
@@ -210,13 +211,24 @@ internal fun infiniteInts(): Sequence<Int> =
210
211
211
212
internal const val MAX_ARRAY_INITIALIZER_SIZE = 10
212
213
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
+
213
225
/* *
214
226
* Checks if we have already imported a class with such simple name.
215
227
* If so, we cannot import [type] (because it will be used with simple name and will be clashed with already imported)
216
228
* and should use its fully qualified name instead.
217
229
*/
218
230
private fun CgContextOwner.doesNotHaveSimpleNameClash (type : ClassId ): Boolean =
219
- importedClasses.none { it.simpleName == type.simpleName }
231
+ importedClasses.none { it.simpleName == type.simpleName } && type.simpleName !in simpleNamesNotRequiringImports
220
232
221
233
fun CgContextOwner.importIfNeeded (type : ClassId ) {
222
234
// TODO: for now we consider that tests are generated in the same package as CUT, but this may change
0 commit comments