Skip to content

Commit ab5069e

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

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

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

Lines changed: 24 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,40 @@ 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 except anonymous functions should be filtered out if we have another types
200+
if (sootClass.isArtificialEntity) {
201+
if (sootClass.isLambda) {
202+
return@filter true
203+
}
204+
205+
return@filter keepArtificialEntities
205206
}
206-
when {
207-
sootClass.isUtMock -> unwantedTypes += it
208-
sootClass.isArtificialEntity -> {
209-
if (keepArtificialEntities || sootClass.isLambda) {
210-
concreteTypes += it
211-
}
207+
208+
// All wrappers should filtered out because they could not be instantiated
209+
workaround(WorkaroundReason.HACK) {
210+
if (leastCommonSootClass == OBJECT_TYPE && sootClass.isOverridden) {
211+
return@filter false
212212
}
213-
workaround(WorkaroundReason.HACK) { leastCommonSootClass == OBJECT_TYPE && sootClass.isOverridden } -> Unit
214-
else -> concreteTypes += it
215213
}
216-
}
217214

218-
return if (concreteTypes.isEmpty()) {
219-
copy(possibleConcreteTypes = unwantedTypes)
220-
} else {
221-
copy(possibleConcreteTypes = concreteTypes)
222-
}
215+
return@filter true
216+
}.toSet()
217+
218+
return copy(possibleConcreteTypes = appropriateTypes)
223219
}
224220

225221
/**

0 commit comments

Comments
 (0)