@@ -202,14 +202,65 @@ const typet &require_type::require_java_non_generic_type(
202
202
return type;
203
203
}
204
204
205
- // / Verify that a class is a valid java generic class
205
+ // / Checks that the given type is a complete class.
206
+ // / \param class_type type of the class
207
+ // / \return class_type of the class
208
+ class_typet require_complete_class (const typet &class_type)
209
+ {
210
+ REQUIRE (class_type.id () == ID_struct);
211
+
212
+ const class_typet &class_class_type = to_class_type (class_type);
213
+ REQUIRE (class_class_type.is_class ());
214
+ REQUIRE_FALSE (class_class_type.get_bool (ID_incomplete_class));
215
+
216
+ return class_class_type;
217
+ }
218
+
219
+ // / Verify that a class is a complete, valid java generic class with the
220
+ // / specified list of variables.
206
221
// / \param class_type: the class
222
+ // / \param type_variables: vector of type variables
207
223
// / \return: A reference to the java generic class type.
208
- java_generics_class_typet &
209
- require_type::require_java_generic_class (const class_typet &class_type)
224
+ java_generics_class_typet require_type::require_java_generic_class (
225
+ const typet &class_type,
226
+ const optionalt<std::initializer_list<irep_idt>> &type_variables)
210
227
{
211
- java_class_typet java_class_type = to_java_class_type (class_type);
228
+ const class_typet &class_class_type = require_complete_class (class_type);
229
+ java_class_typet java_class_type = to_java_class_type (class_class_type);
212
230
213
231
REQUIRE (is_java_generics_class_type (java_class_type));
214
- return to_java_generics_class_type (java_class_type);
232
+ java_generics_class_typet java_generic_class_type =
233
+ to_java_generics_class_type (java_class_type);
234
+
235
+ if (type_variables)
236
+ {
237
+ const java_generics_class_typet::generic_typest &generic_type_vars =
238
+ java_generic_class_type.generic_types ();
239
+ REQUIRE (generic_type_vars.size () == type_variables.value ().size ());
240
+ REQUIRE (
241
+ std::equal (
242
+ type_variables->begin (),
243
+ type_variables->end (),
244
+ generic_type_vars.begin (),
245
+ [](
246
+ const irep_idt &type_var_name, const java_generic_parametert ¶m) {
247
+ REQUIRE (!is_java_generic_inst_parameter ((param)));
248
+ return param.type_variable ().get_identifier () == type_var_name;
249
+ }));
250
+ }
251
+ return java_generic_class_type;
252
+ }
253
+
254
+ // / Verify that a class is a complete, valid nongeneric java class
255
+ // / \param class_type: the class
256
+ // / \return: A reference to the java generic class type.
257
+ java_class_typet
258
+ require_type::require_java_non_generic_class (const typet &class_type)
259
+ {
260
+ const class_typet &class_class_type = require_complete_class (class_type);
261
+ java_class_typet java_class_type = to_java_class_type (class_class_type);
262
+
263
+ REQUIRE (!is_java_generics_class_type (java_class_type));
264
+
265
+ return java_class_type;
215
266
}
0 commit comments