Skip to content

Commit a60c0e2

Browse files
committed
Removed keeping UtMock in TypeStorage, refactoring
1 parent b81c51d commit a60c0e2

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

utbot-framework/src/main/kotlin/org/utbot/engine/TypeResolver.kt

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class TypeResolver(private val typeRegistry: TypeRegistry, private val hierarchy
112112
if (numDimensions == 0) baseType else baseType.makeArrayType(numDimensions)
113113
}
114114

115-
return TypeStorage(type, concretePossibleTypes).filterInappropriateClassesForCodeGeneration()
115+
return TypeStorage(type, concretePossibleTypes).removeInappropriateTypes()
116116
}
117117

118118
private fun isInappropriateOrArrayOfMocksOrLocals(numDimensions: Int, baseType: Type?): Boolean {
@@ -182,44 +182,36 @@ class TypeResolver(private val typeRegistry: TypeRegistry, private val hierarchy
182182
else -> error("Unexpected type $type")
183183
}
184184

185-
return TypeStorage(type, possibleTypes).filterInappropriateClassesForCodeGeneration()
185+
return TypeStorage(type, possibleTypes).removeInappropriateTypes()
186186
}
187187

188188
/**
189-
* Where possible, remove types that are not currently supported by code generation.
190-
* For example, we filter out artificial entities (lambdas are an example of them)
191-
* if the least common type is **not** artificial itself.
189+
* Remove wrapper types and, if any other type is available, artificial entities.
192190
*/
193-
private fun TypeStorage.filterInappropriateClassesForCodeGeneration(): TypeStorage {
194-
val unwantedTypes = mutableSetOf<Type>()
195-
val concreteTypes = mutableSetOf<Type>()
196-
191+
private fun TypeStorage.removeInappropriateTypes(): TypeStorage {
197192
val leastCommonSootClass = (leastCommonType as? RefType)?.sootClass
198193
val keepArtificialEntities = leastCommonSootClass?.isArtificialEntity == true
199194

200-
possibleConcreteTypes.forEach {
201-
val sootClass = (it.baseType as? RefType)?.sootClass ?: run {
202-
// All not RefType should be included in the concreteTypes, e.g., arrays
203-
concreteTypes += it
204-
return@forEach
195+
val appropriateTypes = possibleConcreteTypes.filter {
196+
// All not RefType should be included in the concreteTypes, e.g., arrays
197+
val sootClass = (it.baseType as? RefType)?.sootClass ?: return@filter true
198+
199+
// All artificial entities should be filtered out if we have another types
200+
if (sootClass.isArtificialEntity) {
201+
return@filter keepArtificialEntities
205202
}
206-
when {
207-
sootClass.isUtMock -> unwantedTypes += it
208-
sootClass.isArtificialEntity -> {
209-
if (keepArtificialEntities || sootClass.isLambda) {
210-
concreteTypes += it
211-
}
203+
204+
// All wrappers should filtered out because they could not be instantiated
205+
workaround(WorkaroundReason.HACK) {
206+
if (leastCommonSootClass == OBJECT_TYPE && sootClass.isOverridden) {
207+
return@filter false
212208
}
213-
workaround(WorkaroundReason.HACK) { leastCommonSootClass == OBJECT_TYPE && sootClass.isOverridden } -> Unit
214-
else -> concreteTypes += it
215209
}
216-
}
217210

218-
return if (concreteTypes.isEmpty()) {
219-
copy(possibleConcreteTypes = unwantedTypes)
220-
} else {
221-
copy(possibleConcreteTypes = concreteTypes)
222-
}
211+
return@filter true
212+
}.toSet()
213+
214+
return copy(possibleConcreteTypes = appropriateTypes)
223215
}
224216

225217
/**

0 commit comments

Comments
 (0)