@@ -112,7 +112,7 @@ class TypeResolver(private val typeRegistry: TypeRegistry, private val hierarchy
112
112
if (numDimensions == 0 ) baseType else baseType.makeArrayType(numDimensions)
113
113
}
114
114
115
- return TypeStorage (type, concretePossibleTypes).filterInappropriateClassesForCodeGeneration ()
115
+ return TypeStorage (type, concretePossibleTypes).removeInappropriateTypes ()
116
116
}
117
117
118
118
private fun isInappropriateOrArrayOfMocksOrLocals (numDimensions : Int , baseType : Type ? ): Boolean {
@@ -182,46 +182,40 @@ class TypeResolver(private val typeRegistry: TypeRegistry, private val hierarchy
182
182
else -> error(" Unexpected type $type " )
183
183
}
184
184
185
- return TypeStorage (type, possibleTypes).filterInappropriateClassesForCodeGeneration ()
185
+ return TypeStorage (type, possibleTypes).removeInappropriateTypes ()
186
186
}
187
187
188
188
/* *
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.
192
190
*/
193
- private fun TypeStorage.filterInappropriateClassesForCodeGeneration (): TypeStorage {
194
- val unwantedTypes = mutableSetOf<Type >()
195
- val concreteTypes = mutableSetOf<Type >()
196
-
191
+ private fun TypeStorage.removeInappropriateTypes (): TypeStorage {
197
192
val leastCommonSootClass = (leastCommonType as ? RefType )?.sootClass
198
193
val keepArtificialEntities = leastCommonSootClass?.isArtificialEntity == true
199
194
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
205
206
}
206
- when {
207
- sootClass.isUtMock -> unwantedTypes + = it
208
- sootClass.isArtificialEntity -> {
209
- if (sootClass.isLambda) {
210
- unwantedTypes + = it
211
- } else if (keepArtificialEntities) {
212
- concreteTypes + = it
213
- }
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
214
212
}
215
- workaround(WorkaroundReason .HACK ) { leastCommonSootClass == OBJECT_TYPE && sootClass.isOverridden } -> Unit
216
- else -> concreteTypes + = it
217
213
}
218
- }
219
214
220
- return if (concreteTypes.isEmpty()) {
221
- copy(possibleConcreteTypes = unwantedTypes)
222
- } else {
223
- copy(possibleConcreteTypes = concreteTypes)
224
- }
215
+ return @filter true
216
+ }.toSet()
217
+
218
+ return copy(possibleConcreteTypes = appropriateTypes)
225
219
}
226
220
227
221
/* *
0 commit comments