Swing to SWT and Back: Patterns for API Migration by Wrapping Thiago Tonelli Bartolomei Ralf L¨ ammel Krzysztof Czarnecki University of Waterloo University of Koblenz-Landau September 15, 2010
Outline
Outline 1 - API Migration 2 - Study Design 3 - Study Results 4 - Conclusion and Future Work 3
1 - API Migration
API Migration Source Uses Application API 5
API Migration Source Uses Application API Target API 6
API Migration Source Uses Application API Rewrite Modified Application Uses Target API 7
API Migration Source Uses Application API Adapt Implements Rewrite Modified Wrapper Application Wraps Uses Target API 8
Related Work
API Migration Source Uses Application API Rewrite Modified Application Uses Target API 10
API Migration Source Uses Application API Procedural Chow,Notkin [ICSM96] Rewrite Padioleau et al. [EuroSys08] Modified Application Uses Target API 11
API Migration Source Uses Application API Procedural Chow,Notkin [ICSM96] Rewrite Padioleau et al. [EuroSys08] Simple OO la n et al. [ ] Modified Nita,Notkin [IC 0] Application Uses Target API 12
API Migration Source Uses Application API Procedural Chow,Notkin [ICSM96] Rewrite Padioleau et al. [EuroSys08] Simple OO la n et al. [ ] Modified Nita,Notkin [IC 0] Application Upgrade el, iwan [ICSE0 ] Perkins [PASTE0 ] Uses Target API 13
API Migration Source Uses Application API Adapt Implements Wrapper Wraps Target API 14
API Migration Source Uses Application API Adapt Implements Pro cedural to OO r I Wrapper Wraps Target API 15
API Migration Source Uses Application API Adapt Implements Procedural to OO r I To Services a a l Wrapper Wraps Target API 16
API Migration Source Uses Application API Adapt Implements Procedural to OO r I To Services a a l Wrapper Upgrade l i l I Wraps Target API 17
API Migration Source Uses Application API Adapt Implements Wrapper Wraps Target API 18
Limitations (Motivations)
Limitations (Motivations) Simple APIs 20
Limitations (Motivations) Simple APIs No Deep Inheritance Hierarchies 20
Limitations (Motivations) Simple APIs No Deep Inheritance Hierarchies Simple Mappings 20
2 - Study Design
Research Questions
Research Questions 1. What are the design challenges faced by developers when implementing wrapping layers around OO APIs? 23
Research Questions 1. What are the design challenges faced by developers when implementing wrapping layers around OO APIs? 2. What are the solutions employed in practice? 23
Subjects
Subjects S wingWT SWTSwing 31 Kloc 65 Kloc 25
Subjects Swing v1.4, 234 Kloc Wraps SwingWT SWTSwing 31 Kloc 65 Kloc Wraps SWT v3.2.2, 90 Kloc 26
Subjects Swing v1.4, 234 Kloc Wraps SwingWT SWTSwing XOM2JDOM 31 Kloc 65 Kloc 7 Kloc Wraps SWT v3.2.2, 90 Kloc 27
Subjects Swing XOM v1.4, 234 Kloc v1.2.1, 19 Kloc Wraps SwingWT SWTSwing XOM2JDOM 31 Kloc 65 Kloc 7 Kloc Wraps Wraps SWT JDOM v3.2.2, 90 Kloc v1.1, 9 Kloc 28
Methodology
Methodology 1. Uncover design challenges 30
Methodology 1. Uncover design challenges Source Code Original Developers Type Correspondences 30
Methodology 1. Uncover design challenges Source Code Original Developers Type Correspondences 2. Understand solutions 30
Methodology 1. Uncover design challenges Source Code Original Developers Type Correspondences 2. Understand solutions Source Code Code Queries Design Patterns 30
Methodology 1. Uncover design challenges Source Code Original Developers Type Correspondences 2. Understand solutions Source Code Code Queries Design Patterns 3. Measure presence of design patterns 30
Methodology 1. Uncover design challenges Source Code Original Developers Type Correspondences 2. Understand solutions Source Code Code Queries Design Patterns 3. Measure presence of design patterns Metrics 30
3 - Study Results
API Wrapping Challenges & Design Patterns
API Wrapping Challenges and Design Patterns Challenge Design Pattern Non-trivial Mapping Multiplicities Layered Adapter Stateful Adapter Inversion of Control Inverse Delegation Correspondence of Object Identities Wrapping Identity Map Varying Creation and Wiring Protocols Delayed Instantiation Varying Type Hierarchies 33
ADAPTER Pattern
Java Vectors to ArrayLists
Vector to ArrayList V ector Application 36
Vector to ArrayList V ector Application i cla Vector i Vector i void add Object i void setSize int 37
Vector to ArrayList V ector Application ro 38
Vector to ArrayList V ector Application ro i cla Vector i Vector i void add Object i void setSize int 39
Vector to ArrayList V ector Application Arra ro i cla Vector i Vector i void add Object i void setSize int 40
Vector to ArrayList V ector Application Arra ro i cla Vector ArrayList ptee i Vector i void add Object i void setSize int 41
Vector to ArrayList V ector Application Arra ro i cla Vector ArrayList ptee i Vector a ptee ArrayList i void add Object a ptee add o i void setSize int le a ptee size a ptee add le a ptee size a ptee o ve 42
Sample GUI Application
Sample GUI Application SWT Swing 44
SWT GUI
SWT GUI 46
SWT GUI Shell 47
SWT GUI Display Shell 48
SWT GUI Display Shell List data 49
SWT GUI Display Shell List data 50
SWT GUI Display Shell List data 51
SWT GUI Display Shell List data Sel i s 52
SWT GUI Display Shell List data Sel i s 53
Swing GUI
Swing GUI 55
Swing GUI JFrame Container 56
Swing GUI JFrame Container JScrollPane 57
Swing GUI JFrame a JScrollPane data 58
Swing GUI JFrame a JScrollPane data 59
Swing GUI JFrame a JScrollPane data n 60
Swing GUI JFrame Container JScrollPane ListModel data n onListener 61
Swing GUI JFrame Container JScrollPane JList ListModel data JCheckBox JButton ActionListener 62
Swing GUI JFrame Container JScrollPane JList ListModel data JCheckBox JButton ActionListener 63
Mapping SWT to Swing
SWT to Swing a Display ai Shell l a Li st st List data data Sel i s i s 65
SWT to Swing Display Shell 66
SWT to Swing JFrame Display Container Shell 67
SWT to Swing JFrame Display Container Shell 68
SWT to Swing JFrame Display Container Shell isDisposed() 69
SWT to Swing a Display ai Shell Li st 70
SWT to Swing a Display ai Shell l a Li st st List data 71
SWT to Swing a Display ai Shell l a Li st st List data 72
SWT to Swing a Display ai Shell l a Li st st List data 73
SWT to Swing a Display ai Shell l a Li st st List data 74
SWT to Swing a Display ai Shell l a Li st st List data 75
SWT to Swing a Display ai Shell l a Li st st List data 76
SWT to Swing a Display ai Shell l a Li st st List data 77
SWT to Swing a Display ai Shell l a Li st st List data 78
Non-trivial Mapping Multiplicities
Target Multiplicities Name Example Display → ∅ No Target Vector → ArrayList Single Target Button → JButton | JCheckBox Alternative Targets List → JList, ListModel Composite Targets 80
Target Multiplicities Name Example Display → ∅ No Target Vector → ArrayList Single Target Button → JButton | JCheckBox Alternative Targets List → JList, ListModel Composite Targets Alternative and Composite List → ( JList, ListModel ) | ( JList, ListModel, JScrollPane ) 80
Layered Adapter
Layered Adapter SimpleJListAdapter ScrollableJListAdapter 82
Layered Adapter SimpleJListAdapter ScrollableJListAdapter Alternative and Composite List → ( JList, ListModel ) | ( JList, ListModel, JScrollPane ) 82
Stateful Adapter
Stateful Adapter 84
SWT to Swing a Display ai Shell l a Li st st List data 85
SWT to Swing a Display ai Shell l a Li st st List data Sel i s 86
SWT to Swing a Display ai Shell l a Li st st List data Sel i s i s 87
SWT to Swing a Display ai Shell l a Li st st List data Sel i s i s 88
Inversion of Control
Inverse Delegation
Recommend
More recommend