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

research:jtransformer:tutorial:transformation [2018/04/18 10:38]
Günter Kniesel [Conditional Tranformations (CTs)]
research:jtransformer:tutorial:transformation [2018/05/09 01:59]
Line 1: Line 1:
-====== Writing your own transformation ====== 
-<​note>​ 
-This tutorial explains how to write your own transformation. If you are just interested in how to add your transformation as a quickfix to a JT analysis, have a look at [[quickfix|this page]]. 
-</​note>​ 
  
-A strength of JTransformer is that it capable of doing analysis on the source code **and** transformations. In this section, we are writing a transformation that could be applied to code found by the ''​System.out.println''​ detector from the [[analysis|"​Write your own analysis"​-Example]]. 
- 
-===== Conditional Tranformations (CTs) ===== 
- 
-If you want to learn what Conditional Transformations are and how you can use them (run a ct, run a sequence of cts, examine the results of a ct ...) please have a look at this page: [[cts|Conditional Tranformations]]. If you need more examples for transformations you can have a look at the [[getting_started#​load_example_projects|Tutorial Project]] ((New -> Example -> JTransformer Example Projects -> JTransformer Tutorial - Prolog Files -> refactorings)). 
- 
-{{:​research:​jtransformer:​tutorial:​transformation_example.png|}} 
- 
-The transformation for our ''​System.out.println''​ detector has to replace the call to ''​System.out.println''​ by a call to a logging method. How the logging method can be detected has to be defined in the condition part of the ct. 
- 
-<Code linenums:​1>​ 
-:- multifile(user:​ct/​3). ​    % Dont forget the declaration! 
- 
-user:ct( replaceSysoutWithLogging(CallId), ​             % HEAD 
-    (                                                   % CONDITION 
-      sysout_analysis:​sysout_call(CallId,​CallParent,​ Enclosing, FieldAccess,​ StaticTypeRef,​ Argument), 
-                                                        % Call the analysis predicate and bind all IDs 
-      get_term(FieldAccess,​ FieldAccessTerm), ​          % get the terms which should be deleted 
-      get_term(StaticTypeRef,​ StaticTypeRefTerm),​ 
-            ​ 
-      classT(MyLoggerClass,​ _, '​MyLogger',​ _, _),       % Get the ID belonging to class '​MyLogger'​ 
-      methodT(LoggingMethod,​ MyLoggerClass,​ println, _, MethodType, _, _, _), 
-                                                        % ... and the ID for the logging method 
- 
-      new_id(NewTypeRef) ​                               % NewTypeRef is a yet unused ID 
-    ), 
-    (                                                   % TRANSFORMATION:​ 
-      delete(FieldAccessTerm), ​                         % delete the field access 
-      delete(StaticTypeRefTerm), ​                       % delete the static type reference 
-      ​ 
-      replace(callT(CallId,​ CallParent, Enclosing, NewTypeRef, [Argument], LoggingMethod,​ [], MethodType)) 
-                                                        % replace the existing callT fact with the new one  
-                                                        % (call the logging method instead of System.out.println) 
-      ​ 
-      add(staticTypeRefT(NewTypeRef,​ CallId, Enclosing, MyLoggerClass)),​ 
-                                                        % add the static type reference to the class "​MyLogger"​ 
-    ) 
-). 
-</​Code>​ 
research/jtransformer/tutorial/transformation.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2018