Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering
Up to now we used type terms to represent information about types. This was an easy way for basic types (int, boolean …), references to simple types (String, Object …) and arrays. In JTransformer 3.0 we added support for generics, so there are types which are way more complex:
HashMap<? extends A<ArrayList<String>>, HashMap<Integer, ? super X<A<String>>>>
With type terms we could not represent this type information. Extending the type terms would have resulted in big, nested, unreadable terms, so we decided to represent this information as a subtree.
In every PEF where a type term was used, it is replaced with a type reference.
java code: | int count; |
---|---|
type terms: | localT(#id, #parent, #enclMethod, type(basic, 'int', 0), 'count', #init). |
type references: | localT(#id, #parent, #enclMethod, #typeRef, 'count', #init). typeRefT(#typeRef, #id, #id, #int). basicTypeT(#int, 'int'). |
java code: | String name; |
---|---|
type terms: | localT(#id, #parent, #enclMethod, type(class, 10005, 0), 'name', #init). |
type references: | localT(#id, #parent, #enclMethod, #arrayRef, 'name', #init). typeRefT(#typeRef, #id, #id, 10005). |
java code: | Object[] objectArray; |
---|---|
type terms: | localT(#id, #parent, #enclMethod, type(class, 10001, 1), 'objectArray', #init). |
type references: | localT(#id, #parent, #enclMethod, #arrayRef, 'objectArray', #init). arrayTypeT(#arrayRef, #id, #typeRef, 1). typeRefT(#typeRef, #arrayRef, #id, 10001). |
java code: | ArrayList<Integer> intList; |
---|---|
type terms: | localT(#id, #parent, #enclMethod, type(class, #id_of_array_list, 0), 'intList', #init).
Here we are losing the information for the Integer type parameter |
type references: | localT(#id, #parent, #enclMethod, #paramRef, 'intList', #init). parameterizedTypeT(#paramRef, #id_of_array_list, #typeRef). typeRefT(#typeRef, #paramRef, #id, #id_of_integer). |
java code: | HashMap<? extends A<ArrayList<String>>, HashMap<Integer, ? super X<A<String>>>> whatAType; |
---|---|
type terms: | localT(#id, #parent, #enclMethod, type(class, #id_of_hash_map, 0), 'intList', #init).
Again … we are losing the type information |
type references: | localT(#id,#parent,#enclosing,#type,t,null). parameterizedTypeT(#type,#id,#ref_to_hashmap,[#wildcard,#nested_type_4]). wildCardT(#wildcard,#type,extends,#nested_type_1). parameterizedTypeT(#nested_type_1,#wildcard,#ref_to_a,[#nested_type_2]). parameterizedTypeT(#nested_type_2,#nested_type_1,#ref_to_array_list,[#nested_type_3]). typeRefT(#nested_type_3,#nested_type_2,#enclosing,#ref_to_string). parameterizedTypeT(#nested_type_4,#type,#ref_to_hashmap,[#nested_type_5,#another_wildcard]). typeRefT(#nested_type_5,#nested_type_4,#enclosing,#ref_to_integer). wildCardT(#another_wildcard,#nested_type_4,super,#nested_type_6). parameterizedTypeT(#nested_type_6,#another_wildcard,#ref_to_x,[#nested_type_7]). parameterizedTypeT(#nested_type_7,#nested_type_6,#ref_to_a,[#nested_type_8]). typeRefT(#nested_type_8,#nested_type_7,#enclosing,#ref_to_string). |
Transformations with the new type system are not so easy. There are some helper predicates, see: Using the new type system in CTs.