SDA SE Wiki

Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering

User Tools

Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
research:jtransformer:api:java:migration:3.0 [2013/05/21 13:31]
127.0.0.1 external edit
research:jtransformer:api:java:migration:3.0 [2018/05/09 01:59] (current)
Line 1: Line 1:
 +====== New type system in AST Version 3.0 ======
 +<​note>​
 +**See also:** \\
 +  * [[..:​pefs:​3.0:​java_pef_overview|new PEF-Overview for JT 3.0]] \\
 +  * [[..:​transformations:​copy_type_subtree]]
 +  * [[..:​type_migration|predicates for backward compatibility]]
 +</​note>​
  
 +=== Motivation ===
 +Up to now we used [[..:​pefs:​2.9:​typeterm|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:
 +<Code lang-java>​
 +HashMap<?​ extends A<​ArrayList<​String>>,​ HashMap<​Integer,​ ? super X<​A<​String>>>>​
 +</​Code>​
 +
 +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.
 +
 +=== Type Representation since JT 3.0 ===
 +
 +-> [[..:​typesinjt3|Types in JT 3.0]]
 +
 +=== Replace type terms with type references ===
 +
 +In every PEF where a type term was used, it is replaced with a type reference.
 +
 +== Example 1: Basic Type ==
 +^ java code: ^           \\ <Code lang-java>​int count;</​Code> ​          ^
 +| type terms: | \\ <​Code>​localT(#​id,​ #parent, #​enclMethod,​ type(basic, '​int',​ 0), '​count',​ #​init).</​Code>​ |
 +| type references: | \\ <​Code>​localT(#​id,​ #parent, #​enclMethod,​ #typeRef, '​count',​ #init).
 +typeRefT(#​typeRef,​ #id, #id, #int).
 +basicTypeT(#​int,​ '​int'​).</​Code>​| ​
 +
 +== Example 2: Simple Type ==
 +^ java code: ^           \\ <Code lang-java>​String name;</​Code> ​          ^
 +| type terms: | \\ <​Code>​localT(#​id,​ #parent, #​enclMethod,​ type(class, 10005, 0), '​name',​ #​init).</​Code>​ |
 +| type references: | \\ <​Code>​localT(#​id,​ #parent, #​enclMethod,​ #arrayRef, '​name',​ #init).
 +typeRefT(#​typeRef,​ #id, #id, 10005).</​Code>​| ​
 +
 +== Example 3: Array Type ==
 +^ java code: ^           \\ <Code lang-java>​Object[] objectArray;</​Code> ​          ^
 +| type terms: | \\ <​Code>​localT(#​id,​ #parent, #​enclMethod,​ type(class, 10001, 1), '​objectArray',​ #​init).</​Code>​ |
 +| type references: | \\ <​Code>​localT(#​id,​ #parent, #​enclMethod,​ #arrayRef, '​objectArray',​ #init).
 +arrayTypeT(#​arrayRef,​ #id, #typeRef, 1).
 +typeRefT(#​typeRef,​ #arrayRef, #id, 10001).</​Code>​| ​
 +
 +== Example 4: Parameterized Type ==
 +^ java code: ^           \\ <Code lang-java>​ArrayList<​Integer>​ intList;</​Code> ​          ^
 +| type terms: | \\ <​Code>​localT(#​id,​ #parent, #​enclMethod,​ type(class, #​id_of_array_list,​ 0), '​intList',​ #​init).</​Code>​ Here we are losing the information for the //Integer// type parameter :-? |
 +| type references: | \\ <​Code>​localT(#​id,​ #parent, #​enclMethod,​ #paramRef, '​intList',​ #init).
 +parameterizedTypeT(#​paramRef,​ #​id_of_array_list,​ #typeRef).
 +typeRefT(#​typeRef,​ #paramRef, #id, #​id_of_integer).</​Code>​| ​
 +
 +== Example 5: Nested Parameterized Type ==
 +^ java code: ^           \\ <Code lang-java>​HashMap<?​ extends A<​ArrayList<​String>>,​ HashMap<​Integer,​ ? super X<​A<​String>>>>​ whatAType;</​Code> ​          ^
 +| type terms: | \\ <​Code>​localT(#​id,​ #parent, #​enclMethod,​ type(class, #​id_of_hash_map,​ 0), '​intList',​ #​init).</​Code>​ Again ... we are losing the type information :-? |
 +| type references: | \\ <​Code>​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).</​Code>​| ​
 +
 +
 +=== Transformations with new type system ===
 +Transformations with the new type system are not so easy. There are some helper predicates, see: [[..:​transformations:​copy_type_subtree]].
research/jtransformer/api/java/migration/3.0.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2019