140 likes | 275 Views
JTransformer Framework. Tobias Windeln windeln@cs.uni-bonn.de Institut für Informatik III Rheinische Friedrich-Wilhelms-Universität Bonn. JTransformer Framework. Motivation Idea Overview program representation Query and Transformation API Conditional Transformations
E N D
JTransformer Framework Tobias Windeln windeln@cs.uni-bonn.de Institut für Informatik III Rheinische Friedrich-Wilhelms-Universität Bonn
JTransformer Framework • Motivation • Idea • Overview • program representation • Query and Transformation API • Conditional Transformations • Future Work: Eclipse Integration • Demo? JTransformer: A Transformationsframework for Java - Tobias Windeln - 2003
Motivation • our need for a program transformation tool • with complete source code representation • powerful query and transformation API • Applications • program analysis • refactorings • design pattern detection • design pattern editor • aspect oriented programming • additional requirements • source to source • byte code analysis (interface of types) JTransformer: A Transformationsframework for Java - Tobias Windeln - 2003
Idea • combine existing approaches • logic meta-programming (TyRuBa) • generative program creation • powerful reasoning about programs • Conditional Transformations (JContract) • formally structured transformation description • enables transformation analysis • Solution • generate a program presentation readable for a logic programming language • use a logic prog. lang. to analyse and transform the program JTransformer: A Transformationsframework for Java - Tobias Windeln - 2003
Java Byte code Java Source code Condition Transformations Parser Condition Action transformed Java source code Writer JTransformer Overview generation of Prolog facts Transformation Module CT Module Abstract Syntax Tree in Prolog fact presentation apply Transformation Engine JTransformer: A Transformationsframework for Java - Tobias Windeln - 2003
Parser + Program Representation • parses Java Source and Byte Code • checks Java syntax and semantics for source code • adds attributes to tree elements • method call: called method • field access: referenced field • object instantiation: called constructor • ... • generates Prolog facts for the whole Abstract Syntax Tree (AST) • for every node class one predicate • elementNameT(ID, parentID,…) • includes all transitively referenced types JTransformer: A Transformationsframework for Java - Tobias Windeln - 2003
Translation Example package example; class Test { String s; public void setS(String val) { s = val; } } Test.java packageT(100002, 'example'). toplevelT(100001, 100002, 'example/Test.java', [100003]). classDefT(100003, 100002, 'Test', [100005, 100006, 100014]). extendsT(100003, 100019). varDefT(100005, 100003, 100003, type(class, 100004, 0), 's', 'null'). methodDefT(100006, 100003,'setS',[100007],type(basic, 'void', 0),[],100008). modifierT(100006, 'public'). varDefT(100007, 100006, 100006, type(class, 100004, 0), 'val', 'null'). blockT(100008, 100006, 100006, [100009]). execT(100009, 100008, 100006, 100010). assignT(100010, 100009, 100006, 100011, 100012). selectT(100011, 100010, 100006, 's', 100013, 100005). identT(100013, 100011, 100006, 'this', 100003). identT(100012, 100010, 100006, 'val', 100007). methodDefT(100014, 100003,'<init>',[],type(basic, 'void', 0),[],100015). blockT(100015, 100014, 100014, [100016]). execT(100016, 100015, 100014, 100017). applyT(100017, 100016, 100014, 100018, []). identT(100018, 100017, 100014, 'super', 100019). classDefT(100004, 100025, 'String', [108037, 108038,..., 108240]). ... world.pl JTransformer: A Transformationsframework for Java - Tobias Windeln - 2003
Transformation and Query Engine • logic programming language Prolog • analyse + transform program • predicate library • subtype • full qualified method • ... • higher level predicates for AST Elements • getField, setField, … • transformation predicates • AOP (before, after, around) • ... JTransformer: A Transformationsframework for Java - Tobias Windeln - 2003
Conditional Transformation (CT) • structure of CTs • precondition • structural requirements on the program • binds variables • Prolog term without side effects • action • transformation of the program • changes the program based on the variable binding in the precondition • list of Prolog predicates with side effects • add, delete, replace AST Elements JTransformer: A Transformationsframework for Java - Tobias Windeln - 2003
Accessor CT Precondition ct(addGetterMethods, ( class(_CID, _, _,_), not(externT(_CID)), field(_VID, _CID, _Type, _Name, _), concat('get$',_Name,_MethName), not(method(_, _CID, _MethName, [], _, _, _)), newIDs([_MethID, _BodyID, _ReturnID, _ReadFID]),( Action add(method(_MethID, _CID, _MethName, [], _Type, [], _BodyID)), add(blockT(_BodyID, _MethID, _MethID, [_ReturnID])), add(returnT(_ReturnID, _BodyID, _MethID, _ReadFID)), add(getField(_ReadFID, _ReturnID, _MethID,'null',VID)))). class C { int i; String s; } int get$i() { return i; } String get$s() { return s; } JTransformer: A Transformationsframework for Java - Tobias Windeln - 2003
Transformation Module Compiler Java Editor Abstract Syntax Tree in Prolog fact representation Abstract Syntax Tree synchronized JTransformer Eclipse Eclipse JDT Integration • general transformation API for Eclipse • synchronized with program representation in Eclipse with the JTransformer Framework JTransformer: A Transformationsframework for Java - Tobias Windeln - 2003
Advantages of the Integration • current approach • each transformation step involves • fact generation • transformation • source generation • compiler run on new sources • the source code format and comments are not preserved • Eclipse integration • complete fact generation only once • afterwards incremental generation of changed source code • JTransformer only communicates the changed parts of the AST • Eclipse preserves the source code format and comments JTransformer: A Transformationsframework for Java - Tobias Windeln - 2003
Eclipse JDT Integration (3) • will be implemented in the upcoming eXtreme Programming internchip JTransformer: A Transformationsframework for Java - Tobias Windeln - 2003
Work Based on JTransformer • ConDor • Conflict Detector for CTs • LogicAJ • logic meta-programming extension of AspectJ • „An Aspect Language with Genericity and Interference Analysis“ • DPDetect • design pattern detection (Lava Patterns) • PatchWork (???) JTransformer: A Transformationsframework for Java - Tobias Windeln - 2003