SlideShare a Scribd company logo
Extracting Executable
Transformations from
Distilled Code Changes
Reinout Stevens
resteven@vub.ac.be
@ReinoutStevens
Coen De Roover
cderoove@vub.ac.be
@oniroi
1
Context: Distilled Code Changes
B. Fluri, M. Würsch, M. Pinzger, and H. C. Gall.
Change distilling: Tree differencing for fine-grained source code change extraction.
Transactions on Software Engineering, 2007.
2
1. update(0,1)
2. move(int y = 0;)
3. insert(public int foo()…)
4. delete(int z = 0;)
Output:
00 public class Example {
01 public Integer run(Integer x) {
02 return x;
03 }
04
05 public void test() {
06 int x = 0;
07 int y = 0;
08 int z = 0;
09 run(x);
10 }
11 }
00 public class Example {
01 public Integer run(Integer x) {
02 int y = 0;
03 return x;
04 }
05
06 public int foo() {
07 return 42;
08 }
09
10 public void test() {
11 int x = 1;
12 run(x);
13 }
14 }
Insert
Delete
Move
Update
00 public class Example {
01 public Integer run(Integer x) {
02 return x;
03 }
04
05 public void test() {
06 int x = 0;
07 int y = 0;
08 int z = 0;
09 run(x);
10 }
11 }
00 public class Example {
01 public Integer run(Integer x) {
02 int y = 0;
03 return x;
04 }
05
06 public int foo() {
07 return 42;
08 }
09
10 public void test() {
11 int x = 1;
12 run(x);
13 }
14 }
Revision 1 Revision 2
Goal: Extracting Executable Transformations
3
Insert Insert Move Delete Update Insert Move Delete
Delete Insert Insert Move Insert Delete Update Delete
Update Move Insert Insert Update Update Move …
Naive Approach: Logic Queries over Changes
public class Example {
int x = 0;
}
public class Example {
int y = 0;
}
1. update(“x”, “y”)
1 (defn rename-field [changes]
2 (run* [?update]
3 (member ?update changes)
4 (change|update ?update)
5 (change|update-original ?update ?val|source)
6 (ast :SimpleName ?val|source)
7 (ast-parent ?val|source ?parent|source)
8 (ast :VariableDeclarationFragment ?parent|source)
9 (update-newval ?update ?val|target)
0 (ast :SimpleName ?val|target)
1 (name-name|different ?val|source ?val|target))
4
Revision 1 Revision 2
changes
look for an update
that modifies a field
its name
1. delete(“int x = 0;”)
2. insert(“int aLongerName = 0;”)
1 (defn rename-field [changes]
2 (run* [?insert ?delete]
3 (fresh [?insert|source’ ?delete|original ?i-name ?d-name]
4 (member ?delete changes)
5 (member ?insert changes)
6 (== ?sequence (list ?insert ?delete))
7 (change|insert ?insert)
8 (change|delete ?delete)
9 (insert-node ?insert ?insert|source’)
0 (ast :VariableDeclarationFragment ?insert|source’)
1 (delete-node ?delete ?delete|original)
2 (ast :VariableDeclarationFragment ?delete|source)
3 (has :name ?insert|source’ ?i-name)
4 (has :name ?delete|source ?d-name)
5 (name-name|different ?i-name ?d-name))) 5
public class Example {
int x = 0;
}
public class Example {
int aLongerName = 0;
}
changes
Revision 1 Revision 2
look for a
delete and insert
that introduce a field
and remove a field with
a different name
Naive Approach: Logic Queries over Changes
Problem: Change Equivalence
1. update(“x”, “y”)
1. delete(“int x = 0;”)
2. insert(“int y = 0;”)
1. insert(“int y = 0;”)
2. delete(“int x = 0;”)
Possible 

Changes Sequences
public class Example {
int x = 0;
}
Revision 1
public class Example {
int y = 0;
}
Revision 2
6
One change distiller may produce different change sequences for
the same source code transformation in different commits:
• different change types
• different length
• different subjects of changes
7
Problem: Change Equivalence
or
or
…
Problem Summary
Multiple change sequences implement the same source
code transformation
It is not possible for a user to enumerate all the change
sequences that implement a transformation in a query
8
9
initial state
sought-after state
1 (defn field-rename [esg]
2 (run* [?es]
3 (query-changes esg ?es [?orig-ast ?field]
4 (in-current-es [es ast]
5 (== ?orig-ast ast)
6 (ast-field ast ?field))
7 change->+
8 (in-current-es [es ast]
9 (fresh [?renamed ?new-name]
0 (ast-field ast ?renamed)
1 (ast-field|absent ast ?field)
2 (ast-field|absent ?orig-ast ?renamed)))))
public class Example {
int x = 0;
}
public class Example {
int y = 0;
}
Approach: Before&After AST Specification
10
public class Example {
int x = 0;
int y = 1;
}
public class Example {
}
Source AST Target AST
1 3
2 4
Regular Dependency
List Dependency
Change Dependency Graph
1. insert(int x, Example, Example, nil, :BodyDeclarations, 0)
2. insert(int y, Example, Example, nil, :BodyDeclarations, 1)
3. insert(0, nil, int x, nil, :Initializer, nil)
4. insert(1, nil, int y, nil, :Initializer, nil)
Distilled Change Sequence
public class Example {
}
public class Example {
int x = 0;
int y = 1;
}
public class Example {
int x;
}
public class Example {
int x = 0;
}
public class Example {
int x = 0;
int y;
}
public class Example {
int x;
int y;
}
public class Example {
int x;
int y = 1;
}
public class Example {
int y;
}
public class Example {
int y = 1;
}
1
2
3
2
1
4
2
3 4
1
34
Evolution State Graph
Implementation Overview
11
1 3
2 4
Regular Dependency
List Dependency
1. insert(int x, Example, Example, nil, :BodyDeclarations, 0)
2. insert(int y, Example, Example, nil, :BodyDeclarations, 1)
3. insert(0, nil, int x, nil, :Initializer, nil)
4. insert(1, nil, int y, nil, :Initializer, nil)
Solution: Change Dependency Graph
Insert Dependency List Dependency
Source SourceTarget Target
Move Dependency
Source Target
α
12
Solution: Change Dependency Graph
13
1. insert(int x, Example, Example, nil, :BodyDeclarations, 0)
2. insert(int y, Example, Example, nil, :BodyDeclarations, 1)
3. insert(0, nil, int x, nil, :Initializer, nil)
4. insert(1, nil, int y, nil, :Initializer, nil)
public class Example {
}
public class Example {
int x = 0;
int y = 1;
}
public class Example {
int x;
}
public class Example {
int x = 0;
}
public class Example {
int x = 0;
int y;
}
public class Example {
int x;
int y;
}
public class Example {
int x;
int y = 1;
}
public class Example {
int y;
}
public class Example {
int y = 1;
}
1
2
3
2
1
4
2
3 4
1
34
Solution: Evolution State Graph
• Detect instances of refactorings in open-source
projects using a single evolution query per
refactoring
• Ensure returned change sequences are minimal
and executable
• Compare our approach with the naive approach
K. Prete, N. Rachatasumrit, N. Sudan, and M. Kim,
“Template-based reconstruction of complex refactorings,”
in Proc. of the 2010 Int. Conf. on Software Maintenance (ICSM10)
E. Murphy-Hill, C. Parnin, and A. P. Black,
“How we refactor, and how we know it,”
Transactions on Software Engineering, vol. 38, pp. 5–18, 2012.
14
Evaluation: Outline
15
ChangeNodes
Distiller
Known Refactorings
Magic
Constant
Field
Rename
Unused
Method
public class Example {
}
public class Example {
int x = 0;
int y = 1;
}
public class Example {
int x;
}
public class Example {
int x = 0;
}
public class Example {
int x = 0;
int y;
}
public class Example {
int x;
int y;
}
public class Example {
int x;
int y = 1;
}
public class Example {
int y;
}
public class Example {
int y = 1;
}
1
2
3
2
1
4
2
3 4
1
34
Evolution State Graph
Change Dependency Graph
1 3
2 4
Regular Dependency
List Dependency
Evolution Query
1 (query-changes esg ?es
2 [?absent ?method …]
3 (in-current-es [es ast]
4 (== ast ?absent)
5 (ast-method ast ?method)
6 (child+ ?method ?literal)
7 (literal-value ?literal ?value))
8 change->*
9 (in-current-es [es ast]
0 (ast-ast-field|introduced ?absent ast ?field)
1 (field-value|initialized ?field ?value)
2 (ast-method-method|corresponding …)
3 (child+ ?cmethod ?field-access)
4 (field-name|accessed ?field ?field-access)))
Minimal Executable Code Transformation
Insert Move Insert
Code Rev1
Code Rev2
Insert Move …
Evaluation: Outline
16
1 1 public class Jar extends Zip {
2 2 private static final String INDEX_NAME="META-INF/INDEX.LIST";
3 + private static final String MANIFEST_NAME="META-INF/MANIFEST.MF";
3 4 private Manifest configuredManifest;
4 5 private Manifest savedConfiguredManifest;
5 6
6 7 protected void zipFile( ) throws IOException {
7 - if ("META-INF/MANIFEST.MF".equalsIgnoreCase(vPath)) {
8 + if (MANIFEST_NAME.equalsIgnoreCase(vPath)) {
8 9 if (!doubleFilePass || (doubleFilePass && skipWriting)) {
9 10 filesetManifest(fromArchive,is);
10 11 }
11 12 }
12 13 else {
13 14 super.zipFile(is,zOut,vPath,lastModified,fromArchive,mode);
14 15 }
15 16 }
16 17 }
Evaluation: Replace Magic Constant
17
1 (query-changes esg ?es
2 [?absent ?method ?literal value ?cmethod ?field ?field-access]
3 (in-current-es [es ast]
4 (== ast ?absent)
5 (ast-method ast ?method)
6 (child+ ?method ?literal)
7 (literal-value ?literal ?value))
8 change->*
9 (in-current-es [es ast]
0 (ast-ast-field|introduced ?absent ast ?field)
1 (field-value|initialized ?field ?value)
2 (ast-method-method|corresponding ast ?method ?cmethod)
3 (child+ ?cmethod ?field-access)
4 (field-name|accessed ?field ?field-access)))
protected void zipFile(…) {
if (“META-INF/MANIFEST.MF”
.equalsIgnoreCase(vPath)) {
…
private String MANIFEST_NAME =
“META-INF/MANIFEST.MF";
…
protected void zipFile(…) {
if (MANIFEST_NAME
.equalsIgnoreCase(vPath)) {
…
Evaluation: Replace Magic Constant
18
Legend
insert
delete
move
solution
dependency
update
• Total Changes: 74
• Solution Length Our Approach: 4
• Solution Length Replaying Sequence: 23
Evaluation: Inspecting the Solution
19
Evaluation: Result Summary
NumberofChanges
0
50
100
150
200
250
300
350
Refactoring
Constant Constant Constant Constant Constant Constant Method Method Method Field Field Field Field
6
1513
3
39
12655
10
48
213
24
57
9
264
1214
118
199
1000
23
82
221
27
63
10
291
5
11
25
149
245
1244
74
202
Total Changes Solution Length Replaying Sequence Solution Length Our Approach
Conclusion
• The change equivalence problem renders specifying
a sought-after code transformation in terms of
changes difficult
• Our approach supports specifying code
transformations using before&after states in logic
queries
• Solutions to our queries are a minimal, executable
subsequence of changes that implements the sought-
after transformation
20
Discussion
Do ad-hoc solutions to the change equivalence
problem invalidate existing MSR studies?
21

More Related Content

What's hot

Metaprogramming in julia
Metaprogramming in juliaMetaprogramming in julia
Metaprogramming in julia
岳華 杜
 
Java PRACTICAL file
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL file
RACHIT_GUPTA
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
gekiaruj
 
Coding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeCoding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean Code
Ganesh Samarthyam
 
Java Puzzle
Java PuzzleJava Puzzle
Java Puzzle
SFilipp
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
Upender Upr
 
(chapter 6) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 6) A Concise and Practical Introduction to Programming Algorithms in...(chapter 6) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 6) A Concise and Practical Introduction to Programming Algorithms in...
Frank Nielsen
 
The Ring programming language version 1.6 book - Part 184 of 189
The Ring programming language version 1.6 book - Part 184 of 189The Ring programming language version 1.6 book - Part 184 of 189
The Ring programming language version 1.6 book - Part 184 of 189
Mahmoud Samir Fayed
 
16. Java stacks and queues
16. Java stacks and queues16. Java stacks and queues
16. Java stacks and queues
Intro C# Book
 
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
Uehara Junji
 
Java_practical_handbook
Java_practical_handbookJava_practical_handbook
Java_practical_handbook
Manusha Dilan
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paper
fntsofttech
 
Java Performance Puzzlers
Java Performance PuzzlersJava Performance Puzzlers
Java Performance Puzzlers
Doug Hawkins
 
Class method
Class methodClass method
Class method
kamal kotecha
 
Groovy 1.8の新機能について
Groovy 1.8の新機能についてGroovy 1.8の新機能について
Groovy 1.8の新機能について
Uehara Junji
 
Is java8 a true functional programming language
Is java8 a true functional programming languageIs java8 a true functional programming language
Is java8 a true functional programming language
SQLI
 
Is java8a truefunctionallanguage
Is java8a truefunctionallanguageIs java8a truefunctionallanguage
Is java8a truefunctionallanguage
Samir Chekkal
 
Easy Going Groovy 2nd season on DevLOVE
Easy Going Groovy 2nd season on DevLOVEEasy Going Groovy 2nd season on DevLOVE
Easy Going Groovy 2nd season on DevLOVE
Uehara Junji
 
Java practical(baca sem v)
Java practical(baca sem v)Java practical(baca sem v)
Java practical(baca sem v)
mehul patel
 
Java Generics
Java GenericsJava Generics
Java Generics
Zülfikar Karakaya
 

What's hot (20)

Metaprogramming in julia
Metaprogramming in juliaMetaprogramming in julia
Metaprogramming in julia
 
Java PRACTICAL file
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL file
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
 
Coding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean CodeCoding Guidelines - Crafting Clean Code
Coding Guidelines - Crafting Clean Code
 
Java Puzzle
Java PuzzleJava Puzzle
Java Puzzle
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
 
(chapter 6) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 6) A Concise and Practical Introduction to Programming Algorithms in...(chapter 6) A Concise and Practical Introduction to Programming Algorithms in...
(chapter 6) A Concise and Practical Introduction to Programming Algorithms in...
 
The Ring programming language version 1.6 book - Part 184 of 189
The Ring programming language version 1.6 book - Part 184 of 189The Ring programming language version 1.6 book - Part 184 of 189
The Ring programming language version 1.6 book - Part 184 of 189
 
16. Java stacks and queues
16. Java stacks and queues16. Java stacks and queues
16. Java stacks and queues
 
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
 
Java_practical_handbook
Java_practical_handbookJava_practical_handbook
Java_practical_handbook
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paper
 
Java Performance Puzzlers
Java Performance PuzzlersJava Performance Puzzlers
Java Performance Puzzlers
 
Class method
Class methodClass method
Class method
 
Groovy 1.8の新機能について
Groovy 1.8の新機能についてGroovy 1.8の新機能について
Groovy 1.8の新機能について
 
Is java8 a true functional programming language
Is java8 a true functional programming languageIs java8 a true functional programming language
Is java8 a true functional programming language
 
Is java8a truefunctionallanguage
Is java8a truefunctionallanguageIs java8a truefunctionallanguage
Is java8a truefunctionallanguage
 
Easy Going Groovy 2nd season on DevLOVE
Easy Going Groovy 2nd season on DevLOVEEasy Going Groovy 2nd season on DevLOVE
Easy Going Groovy 2nd season on DevLOVE
 
Java practical(baca sem v)
Java practical(baca sem v)Java practical(baca sem v)
Java practical(baca sem v)
 
Java Generics
Java GenericsJava Generics
Java Generics
 

Similar to Extracting Executable Transformations from Distilled Code Changes

Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7
Paulo Morgado
 
New C# features
New C# featuresNew C# features
New C# features
Alexej Sommer
 
functions
functionsfunctions
functions
Makwana Bhavesh
 
An introduction to scala
An introduction to scalaAn introduction to scala
An introduction to scala
Mohsen Zainalpour
 
Functional programming basics
Functional programming basicsFunctional programming basics
Functional programming basics
openbala
 
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Codemotion
 
Querying the History of Software Projects using QwalKeko
Querying the History of Software Projects using QwalKekoQuerying the History of Software Projects using QwalKeko
Querying the History of Software Projects using QwalKeko
stevensreinout
 
Functional Programming You Already Know
Functional Programming You Already KnowFunctional Programming You Already Know
Functional Programming You Already Know
Kevlin Henney
 
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
James Titcumb
 
ICSM07.ppt
ICSM07.pptICSM07.ppt
ICSM07.ppt
Ptidej Team
 
QwalKeko, a History Querying Tool
QwalKeko, a History Querying ToolQwalKeko, a History Querying Tool
QwalKeko, a History Querying Tool
stevensreinout
 
Mixing functional and object oriented approaches to programming in C#
Mixing functional and object oriented approaches to programming in C#Mixing functional and object oriented approaches to programming in C#
Mixing functional and object oriented approaches to programming in C#
Mark Needham
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
HamletDRC
 
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
PROIDEA
 
New Functional Features of Java 8
New Functional Features of Java 8New Functional Features of Java 8
New Functional Features of Java 8
franciscoortin
 
.Net december 2017 updates - Tamir Dresher
.Net december 2017 updates - Tamir Dresher.Net december 2017 updates - Tamir Dresher
.Net december 2017 updates - Tamir Dresher
Tamir Dresher
 
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloading
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloadingRiga DevDays 2017 - The hitchhiker’s guide to Java class reloading
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloading
Anton Arhipov
 
EdSketch: Execution-Driven Sketching for Java
EdSketch: Execution-Driven Sketching for JavaEdSketch: Execution-Driven Sketching for Java
EdSketch: Execution-Driven Sketching for Java
Lisa Hua
 
Detecting Bugs in Binaries Using Decompilation and Data Flow Analysis
Detecting Bugs in Binaries Using Decompilation and Data Flow AnalysisDetecting Bugs in Binaries Using Decompilation and Data Flow Analysis
Detecting Bugs in Binaries Using Decompilation and Data Flow Analysis
Silvio Cesare
 
Object-oriented Basics
Object-oriented BasicsObject-oriented Basics
Object-oriented Basics
Jamie (Taka) Wang
 

Similar to Extracting Executable Transformations from Distilled Code Changes (20)

Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7
 
New C# features
New C# featuresNew C# features
New C# features
 
functions
functionsfunctions
functions
 
An introduction to scala
An introduction to scalaAn introduction to scala
An introduction to scala
 
Functional programming basics
Functional programming basicsFunctional programming basics
Functional programming basics
 
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
 
Querying the History of Software Projects using QwalKeko
Querying the History of Software Projects using QwalKekoQuerying the History of Software Projects using QwalKeko
Querying the History of Software Projects using QwalKeko
 
Functional Programming You Already Know
Functional Programming You Already KnowFunctional Programming You Already Know
Functional Programming You Already Know
 
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
 
ICSM07.ppt
ICSM07.pptICSM07.ppt
ICSM07.ppt
 
QwalKeko, a History Querying Tool
QwalKeko, a History Querying ToolQwalKeko, a History Querying Tool
QwalKeko, a History Querying Tool
 
Mixing functional and object oriented approaches to programming in C#
Mixing functional and object oriented approaches to programming in C#Mixing functional and object oriented approaches to programming in C#
Mixing functional and object oriented approaches to programming in C#
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
 
New Functional Features of Java 8
New Functional Features of Java 8New Functional Features of Java 8
New Functional Features of Java 8
 
.Net december 2017 updates - Tamir Dresher
.Net december 2017 updates - Tamir Dresher.Net december 2017 updates - Tamir Dresher
.Net december 2017 updates - Tamir Dresher
 
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloading
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloadingRiga DevDays 2017 - The hitchhiker’s guide to Java class reloading
Riga DevDays 2017 - The hitchhiker’s guide to Java class reloading
 
EdSketch: Execution-Driven Sketching for Java
EdSketch: Execution-Driven Sketching for JavaEdSketch: Execution-Driven Sketching for Java
EdSketch: Execution-Driven Sketching for Java
 
Detecting Bugs in Binaries Using Decompilation and Data Flow Analysis
Detecting Bugs in Binaries Using Decompilation and Data Flow AnalysisDetecting Bugs in Binaries Using Decompilation and Data Flow Analysis
Detecting Bugs in Binaries Using Decompilation and Data Flow Analysis
 
Object-oriented Basics
Object-oriented BasicsObject-oriented Basics
Object-oriented Basics
 

Recently uploaded

Tom tresser burning issue.pptx My Burning issue
Tom tresser burning issue.pptx My Burning issueTom tresser burning issue.pptx My Burning issue
Tom tresser burning issue.pptx My Burning issue
amekonnen
 
Pro-competitive Industrial Policy – OECD – June 2024 OECD discussion
Pro-competitive Industrial Policy – OECD – June 2024 OECD discussionPro-competitive Industrial Policy – OECD – June 2024 OECD discussion
Pro-competitive Industrial Policy – OECD – June 2024 OECD discussion
OECD Directorate for Financial and Enterprise Affairs
 
Artificial Intelligence, Data and Competition – LIM – June 2024 OECD discussion
Artificial Intelligence, Data and Competition – LIM – June 2024 OECD discussionArtificial Intelligence, Data and Competition – LIM – June 2024 OECD discussion
Artificial Intelligence, Data and Competition – LIM – June 2024 OECD discussion
OECD Directorate for Financial and Enterprise Affairs
 
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
OECD Directorate for Financial and Enterprise Affairs
 
Gregory Harris - Cycle 2 - Civics Presentation
Gregory Harris - Cycle 2 - Civics PresentationGregory Harris - Cycle 2 - Civics Presentation
Gregory Harris - Cycle 2 - Civics Presentation
gharris9
 
Competition and Regulation in Professions and Occupations – OECD – June 2024 ...
Competition and Regulation in Professions and Occupations – OECD – June 2024 ...Competition and Regulation in Professions and Occupations – OECD – June 2024 ...
Competition and Regulation in Professions and Occupations – OECD – June 2024 ...
OECD Directorate for Financial and Enterprise Affairs
 
Mastering the Concepts Tested in the Databricks Certified Data Engineer Assoc...
Mastering the Concepts Tested in the Databricks Certified Data Engineer Assoc...Mastering the Concepts Tested in the Databricks Certified Data Engineer Assoc...
Mastering the Concepts Tested in the Databricks Certified Data Engineer Assoc...
SkillCertProExams
 
Updated diagnosis. Cause and treatment of hypothyroidism
Updated diagnosis. Cause and treatment of hypothyroidismUpdated diagnosis. Cause and treatment of hypothyroidism
Updated diagnosis. Cause and treatment of hypothyroidism
Faculty of Medicine And Health Sciences
 
Pro-competitive Industrial Policy – LANE – June 2024 OECD discussion
Pro-competitive Industrial Policy – LANE – June 2024 OECD discussionPro-competitive Industrial Policy – LANE – June 2024 OECD discussion
Pro-competitive Industrial Policy – LANE – June 2024 OECD discussion
OECD Directorate for Financial and Enterprise Affairs
 
ASONAM2023_presection_slide_track-recommendation.pdf
ASONAM2023_presection_slide_track-recommendation.pdfASONAM2023_presection_slide_track-recommendation.pdf
ASONAM2023_presection_slide_track-recommendation.pdf
ToshihiroIto4
 
原版制作贝德福特大学毕业证(bedfordhire毕业证)硕士文凭原版一模一样
原版制作贝德福特大学毕业证(bedfordhire毕业证)硕士文凭原版一模一样原版制作贝德福特大学毕业证(bedfordhire毕业证)硕士文凭原版一模一样
原版制作贝德福特大学毕业证(bedfordhire毕业证)硕士文凭原版一模一样
gpww3sf4
 
Gregory Harris' Civics Presentation.pptx
Gregory Harris' Civics Presentation.pptxGregory Harris' Civics Presentation.pptx
Gregory Harris' Civics Presentation.pptx
gharris9
 
Artificial Intelligence, Data and Competition – OECD – June 2024 OECD discussion
Artificial Intelligence, Data and Competition – OECD – June 2024 OECD discussionArtificial Intelligence, Data and Competition – OECD – June 2024 OECD discussion
Artificial Intelligence, Data and Competition – OECD – June 2024 OECD discussion
OECD Directorate for Financial and Enterprise Affairs
 
Presentatie 8. Joost van der Linde & Daniel Anderton - Eliq 28 mei 2024
Presentatie 8. Joost van der Linde & Daniel Anderton - Eliq 28 mei 2024Presentatie 8. Joost van der Linde & Daniel Anderton - Eliq 28 mei 2024
Presentatie 8. Joost van der Linde & Daniel Anderton - Eliq 28 mei 2024
Dutch Power
 
Artificial Intelligence, Data and Competition – ČORBA – June 2024 OECD discus...
Artificial Intelligence, Data and Competition – ČORBA – June 2024 OECD discus...Artificial Intelligence, Data and Competition – ČORBA – June 2024 OECD discus...
Artificial Intelligence, Data and Competition – ČORBA – June 2024 OECD discus...
OECD Directorate for Financial and Enterprise Affairs
 
Collapsing Narratives: Exploring Non-Linearity • a micro report by Rosie Wells
Collapsing Narratives: Exploring Non-Linearity • a micro report by Rosie WellsCollapsing Narratives: Exploring Non-Linearity • a micro report by Rosie Wells
Collapsing Narratives: Exploring Non-Linearity • a micro report by Rosie Wells
Rosie Wells
 
Burning Issue Presentation By Kenmaryon.pdf
Burning Issue Presentation By Kenmaryon.pdfBurning Issue Presentation By Kenmaryon.pdf
Burning Issue Presentation By Kenmaryon.pdf
kkirkland2
 
Carrer goals.pptx and their importance in real life
Carrer goals.pptx  and their importance in real lifeCarrer goals.pptx  and their importance in real life
Carrer goals.pptx and their importance in real life
artemacademy2
 
XP 2024 presentation: A New Look to Leadership
XP 2024 presentation: A New Look to LeadershipXP 2024 presentation: A New Look to Leadership
XP 2024 presentation: A New Look to Leadership
samililja
 
Suzanne Lagerweij - Influence Without Power - Why Empathy is Your Best Friend...
Suzanne Lagerweij - Influence Without Power - Why Empathy is Your Best Friend...Suzanne Lagerweij - Influence Without Power - Why Empathy is Your Best Friend...
Suzanne Lagerweij - Influence Without Power - Why Empathy is Your Best Friend...
Suzanne Lagerweij
 

Recently uploaded (20)

Tom tresser burning issue.pptx My Burning issue
Tom tresser burning issue.pptx My Burning issueTom tresser burning issue.pptx My Burning issue
Tom tresser burning issue.pptx My Burning issue
 
Pro-competitive Industrial Policy – OECD – June 2024 OECD discussion
Pro-competitive Industrial Policy – OECD – June 2024 OECD discussionPro-competitive Industrial Policy – OECD – June 2024 OECD discussion
Pro-competitive Industrial Policy – OECD – June 2024 OECD discussion
 
Artificial Intelligence, Data and Competition – LIM – June 2024 OECD discussion
Artificial Intelligence, Data and Competition – LIM – June 2024 OECD discussionArtificial Intelligence, Data and Competition – LIM – June 2024 OECD discussion
Artificial Intelligence, Data and Competition – LIM – June 2024 OECD discussion
 
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
 
Gregory Harris - Cycle 2 - Civics Presentation
Gregory Harris - Cycle 2 - Civics PresentationGregory Harris - Cycle 2 - Civics Presentation
Gregory Harris - Cycle 2 - Civics Presentation
 
Competition and Regulation in Professions and Occupations – OECD – June 2024 ...
Competition and Regulation in Professions and Occupations – OECD – June 2024 ...Competition and Regulation in Professions and Occupations – OECD – June 2024 ...
Competition and Regulation in Professions and Occupations – OECD – June 2024 ...
 
Mastering the Concepts Tested in the Databricks Certified Data Engineer Assoc...
Mastering the Concepts Tested in the Databricks Certified Data Engineer Assoc...Mastering the Concepts Tested in the Databricks Certified Data Engineer Assoc...
Mastering the Concepts Tested in the Databricks Certified Data Engineer Assoc...
 
Updated diagnosis. Cause and treatment of hypothyroidism
Updated diagnosis. Cause and treatment of hypothyroidismUpdated diagnosis. Cause and treatment of hypothyroidism
Updated diagnosis. Cause and treatment of hypothyroidism
 
Pro-competitive Industrial Policy – LANE – June 2024 OECD discussion
Pro-competitive Industrial Policy – LANE – June 2024 OECD discussionPro-competitive Industrial Policy – LANE – June 2024 OECD discussion
Pro-competitive Industrial Policy – LANE – June 2024 OECD discussion
 
ASONAM2023_presection_slide_track-recommendation.pdf
ASONAM2023_presection_slide_track-recommendation.pdfASONAM2023_presection_slide_track-recommendation.pdf
ASONAM2023_presection_slide_track-recommendation.pdf
 
原版制作贝德福特大学毕业证(bedfordhire毕业证)硕士文凭原版一模一样
原版制作贝德福特大学毕业证(bedfordhire毕业证)硕士文凭原版一模一样原版制作贝德福特大学毕业证(bedfordhire毕业证)硕士文凭原版一模一样
原版制作贝德福特大学毕业证(bedfordhire毕业证)硕士文凭原版一模一样
 
Gregory Harris' Civics Presentation.pptx
Gregory Harris' Civics Presentation.pptxGregory Harris' Civics Presentation.pptx
Gregory Harris' Civics Presentation.pptx
 
Artificial Intelligence, Data and Competition – OECD – June 2024 OECD discussion
Artificial Intelligence, Data and Competition – OECD – June 2024 OECD discussionArtificial Intelligence, Data and Competition – OECD – June 2024 OECD discussion
Artificial Intelligence, Data and Competition – OECD – June 2024 OECD discussion
 
Presentatie 8. Joost van der Linde & Daniel Anderton - Eliq 28 mei 2024
Presentatie 8. Joost van der Linde & Daniel Anderton - Eliq 28 mei 2024Presentatie 8. Joost van der Linde & Daniel Anderton - Eliq 28 mei 2024
Presentatie 8. Joost van der Linde & Daniel Anderton - Eliq 28 mei 2024
 
Artificial Intelligence, Data and Competition – ČORBA – June 2024 OECD discus...
Artificial Intelligence, Data and Competition – ČORBA – June 2024 OECD discus...Artificial Intelligence, Data and Competition – ČORBA – June 2024 OECD discus...
Artificial Intelligence, Data and Competition – ČORBA – June 2024 OECD discus...
 
Collapsing Narratives: Exploring Non-Linearity • a micro report by Rosie Wells
Collapsing Narratives: Exploring Non-Linearity • a micro report by Rosie WellsCollapsing Narratives: Exploring Non-Linearity • a micro report by Rosie Wells
Collapsing Narratives: Exploring Non-Linearity • a micro report by Rosie Wells
 
Burning Issue Presentation By Kenmaryon.pdf
Burning Issue Presentation By Kenmaryon.pdfBurning Issue Presentation By Kenmaryon.pdf
Burning Issue Presentation By Kenmaryon.pdf
 
Carrer goals.pptx and their importance in real life
Carrer goals.pptx  and their importance in real lifeCarrer goals.pptx  and their importance in real life
Carrer goals.pptx and their importance in real life
 
XP 2024 presentation: A New Look to Leadership
XP 2024 presentation: A New Look to LeadershipXP 2024 presentation: A New Look to Leadership
XP 2024 presentation: A New Look to Leadership
 
Suzanne Lagerweij - Influence Without Power - Why Empathy is Your Best Friend...
Suzanne Lagerweij - Influence Without Power - Why Empathy is Your Best Friend...Suzanne Lagerweij - Influence Without Power - Why Empathy is Your Best Friend...
Suzanne Lagerweij - Influence Without Power - Why Empathy is Your Best Friend...
 

Extracting Executable Transformations from Distilled Code Changes

  • 1. Extracting Executable Transformations from Distilled Code Changes Reinout Stevens resteven@vub.ac.be @ReinoutStevens Coen De Roover cderoove@vub.ac.be @oniroi 1
  • 2. Context: Distilled Code Changes B. Fluri, M. Würsch, M. Pinzger, and H. C. Gall. Change distilling: Tree differencing for fine-grained source code change extraction. Transactions on Software Engineering, 2007. 2 1. update(0,1) 2. move(int y = 0;) 3. insert(public int foo()…) 4. delete(int z = 0;) Output: 00 public class Example { 01 public Integer run(Integer x) { 02 return x; 03 } 04 05 public void test() { 06 int x = 0; 07 int y = 0; 08 int z = 0; 09 run(x); 10 } 11 } 00 public class Example { 01 public Integer run(Integer x) { 02 int y = 0; 03 return x; 04 } 05 06 public int foo() { 07 return 42; 08 } 09 10 public void test() { 11 int x = 1; 12 run(x); 13 } 14 } Insert Delete Move Update 00 public class Example { 01 public Integer run(Integer x) { 02 return x; 03 } 04 05 public void test() { 06 int x = 0; 07 int y = 0; 08 int z = 0; 09 run(x); 10 } 11 } 00 public class Example { 01 public Integer run(Integer x) { 02 int y = 0; 03 return x; 04 } 05 06 public int foo() { 07 return 42; 08 } 09 10 public void test() { 11 int x = 1; 12 run(x); 13 } 14 } Revision 1 Revision 2
  • 3. Goal: Extracting Executable Transformations 3 Insert Insert Move Delete Update Insert Move Delete Delete Insert Insert Move Insert Delete Update Delete Update Move Insert Insert Update Update Move …
  • 4. Naive Approach: Logic Queries over Changes public class Example { int x = 0; } public class Example { int y = 0; } 1. update(“x”, “y”) 1 (defn rename-field [changes] 2 (run* [?update] 3 (member ?update changes) 4 (change|update ?update) 5 (change|update-original ?update ?val|source) 6 (ast :SimpleName ?val|source) 7 (ast-parent ?val|source ?parent|source) 8 (ast :VariableDeclarationFragment ?parent|source) 9 (update-newval ?update ?val|target) 0 (ast :SimpleName ?val|target) 1 (name-name|different ?val|source ?val|target)) 4 Revision 1 Revision 2 changes look for an update that modifies a field its name
  • 5. 1. delete(“int x = 0;”) 2. insert(“int aLongerName = 0;”) 1 (defn rename-field [changes] 2 (run* [?insert ?delete] 3 (fresh [?insert|source’ ?delete|original ?i-name ?d-name] 4 (member ?delete changes) 5 (member ?insert changes) 6 (== ?sequence (list ?insert ?delete)) 7 (change|insert ?insert) 8 (change|delete ?delete) 9 (insert-node ?insert ?insert|source’) 0 (ast :VariableDeclarationFragment ?insert|source’) 1 (delete-node ?delete ?delete|original) 2 (ast :VariableDeclarationFragment ?delete|source) 3 (has :name ?insert|source’ ?i-name) 4 (has :name ?delete|source ?d-name) 5 (name-name|different ?i-name ?d-name))) 5 public class Example { int x = 0; } public class Example { int aLongerName = 0; } changes Revision 1 Revision 2 look for a delete and insert that introduce a field and remove a field with a different name Naive Approach: Logic Queries over Changes
  • 6. Problem: Change Equivalence 1. update(“x”, “y”) 1. delete(“int x = 0;”) 2. insert(“int y = 0;”) 1. insert(“int y = 0;”) 2. delete(“int x = 0;”) Possible Changes Sequences public class Example { int x = 0; } Revision 1 public class Example { int y = 0; } Revision 2 6 One change distiller may produce different change sequences for the same source code transformation in different commits: • different change types • different length • different subjects of changes
  • 8. Problem Summary Multiple change sequences implement the same source code transformation It is not possible for a user to enumerate all the change sequences that implement a transformation in a query 8
  • 9. 9 initial state sought-after state 1 (defn field-rename [esg] 2 (run* [?es] 3 (query-changes esg ?es [?orig-ast ?field] 4 (in-current-es [es ast] 5 (== ?orig-ast ast) 6 (ast-field ast ?field)) 7 change->+ 8 (in-current-es [es ast] 9 (fresh [?renamed ?new-name] 0 (ast-field ast ?renamed) 1 (ast-field|absent ast ?field) 2 (ast-field|absent ?orig-ast ?renamed))))) public class Example { int x = 0; } public class Example { int y = 0; } Approach: Before&After AST Specification
  • 10. 10 public class Example { int x = 0; int y = 1; } public class Example { } Source AST Target AST 1 3 2 4 Regular Dependency List Dependency Change Dependency Graph 1. insert(int x, Example, Example, nil, :BodyDeclarations, 0) 2. insert(int y, Example, Example, nil, :BodyDeclarations, 1) 3. insert(0, nil, int x, nil, :Initializer, nil) 4. insert(1, nil, int y, nil, :Initializer, nil) Distilled Change Sequence public class Example { } public class Example { int x = 0; int y = 1; } public class Example { int x; } public class Example { int x = 0; } public class Example { int x = 0; int y; } public class Example { int x; int y; } public class Example { int x; int y = 1; } public class Example { int y; } public class Example { int y = 1; } 1 2 3 2 1 4 2 3 4 1 34 Evolution State Graph Implementation Overview
  • 11. 11 1 3 2 4 Regular Dependency List Dependency 1. insert(int x, Example, Example, nil, :BodyDeclarations, 0) 2. insert(int y, Example, Example, nil, :BodyDeclarations, 1) 3. insert(0, nil, int x, nil, :Initializer, nil) 4. insert(1, nil, int y, nil, :Initializer, nil) Solution: Change Dependency Graph Insert Dependency List Dependency Source SourceTarget Target Move Dependency Source Target α
  • 13. 13 1. insert(int x, Example, Example, nil, :BodyDeclarations, 0) 2. insert(int y, Example, Example, nil, :BodyDeclarations, 1) 3. insert(0, nil, int x, nil, :Initializer, nil) 4. insert(1, nil, int y, nil, :Initializer, nil) public class Example { } public class Example { int x = 0; int y = 1; } public class Example { int x; } public class Example { int x = 0; } public class Example { int x = 0; int y; } public class Example { int x; int y; } public class Example { int x; int y = 1; } public class Example { int y; } public class Example { int y = 1; } 1 2 3 2 1 4 2 3 4 1 34 Solution: Evolution State Graph
  • 14. • Detect instances of refactorings in open-source projects using a single evolution query per refactoring • Ensure returned change sequences are minimal and executable • Compare our approach with the naive approach K. Prete, N. Rachatasumrit, N. Sudan, and M. Kim, “Template-based reconstruction of complex refactorings,” in Proc. of the 2010 Int. Conf. on Software Maintenance (ICSM10) E. Murphy-Hill, C. Parnin, and A. P. Black, “How we refactor, and how we know it,” Transactions on Software Engineering, vol. 38, pp. 5–18, 2012. 14 Evaluation: Outline
  • 15. 15 ChangeNodes Distiller Known Refactorings Magic Constant Field Rename Unused Method public class Example { } public class Example { int x = 0; int y = 1; } public class Example { int x; } public class Example { int x = 0; } public class Example { int x = 0; int y; } public class Example { int x; int y; } public class Example { int x; int y = 1; } public class Example { int y; } public class Example { int y = 1; } 1 2 3 2 1 4 2 3 4 1 34 Evolution State Graph Change Dependency Graph 1 3 2 4 Regular Dependency List Dependency Evolution Query 1 (query-changes esg ?es 2 [?absent ?method …] 3 (in-current-es [es ast] 4 (== ast ?absent) 5 (ast-method ast ?method) 6 (child+ ?method ?literal) 7 (literal-value ?literal ?value)) 8 change->* 9 (in-current-es [es ast] 0 (ast-ast-field|introduced ?absent ast ?field) 1 (field-value|initialized ?field ?value) 2 (ast-method-method|corresponding …) 3 (child+ ?cmethod ?field-access) 4 (field-name|accessed ?field ?field-access))) Minimal Executable Code Transformation Insert Move Insert Code Rev1 Code Rev2 Insert Move … Evaluation: Outline
  • 16. 16 1 1 public class Jar extends Zip { 2 2 private static final String INDEX_NAME="META-INF/INDEX.LIST"; 3 + private static final String MANIFEST_NAME="META-INF/MANIFEST.MF"; 3 4 private Manifest configuredManifest; 4 5 private Manifest savedConfiguredManifest; 5 6 6 7 protected void zipFile( ) throws IOException { 7 - if ("META-INF/MANIFEST.MF".equalsIgnoreCase(vPath)) { 8 + if (MANIFEST_NAME.equalsIgnoreCase(vPath)) { 8 9 if (!doubleFilePass || (doubleFilePass && skipWriting)) { 9 10 filesetManifest(fromArchive,is); 10 11 } 11 12 } 12 13 else { 13 14 super.zipFile(is,zOut,vPath,lastModified,fromArchive,mode); 14 15 } 15 16 } 16 17 } Evaluation: Replace Magic Constant
  • 17. 17 1 (query-changes esg ?es 2 [?absent ?method ?literal value ?cmethod ?field ?field-access] 3 (in-current-es [es ast] 4 (== ast ?absent) 5 (ast-method ast ?method) 6 (child+ ?method ?literal) 7 (literal-value ?literal ?value)) 8 change->* 9 (in-current-es [es ast] 0 (ast-ast-field|introduced ?absent ast ?field) 1 (field-value|initialized ?field ?value) 2 (ast-method-method|corresponding ast ?method ?cmethod) 3 (child+ ?cmethod ?field-access) 4 (field-name|accessed ?field ?field-access))) protected void zipFile(…) { if (“META-INF/MANIFEST.MF” .equalsIgnoreCase(vPath)) { … private String MANIFEST_NAME = “META-INF/MANIFEST.MF"; … protected void zipFile(…) { if (MANIFEST_NAME .equalsIgnoreCase(vPath)) { … Evaluation: Replace Magic Constant
  • 18. 18 Legend insert delete move solution dependency update • Total Changes: 74 • Solution Length Our Approach: 4 • Solution Length Replaying Sequence: 23 Evaluation: Inspecting the Solution
  • 19. 19 Evaluation: Result Summary NumberofChanges 0 50 100 150 200 250 300 350 Refactoring Constant Constant Constant Constant Constant Constant Method Method Method Field Field Field Field 6 1513 3 39 12655 10 48 213 24 57 9 264 1214 118 199 1000 23 82 221 27 63 10 291 5 11 25 149 245 1244 74 202 Total Changes Solution Length Replaying Sequence Solution Length Our Approach
  • 20. Conclusion • The change equivalence problem renders specifying a sought-after code transformation in terms of changes difficult • Our approach supports specifying code transformations using before&after states in logic queries • Solutions to our queries are a minimal, executable subsequence of changes that implements the sought- after transformation 20
  • 21. Discussion Do ad-hoc solutions to the change equivalence problem invalidate existing MSR studies? 21