Toward an Implementation of the “Form Template Method” Refactoring Nicolas Juillerat University of Fribourg Switzerland.

Slides:



Advertisements
Similar presentations
Computer Science 1620 Function Overloading. Review Question: suppose I have the following function: can I call this function with an integer? yes – compiler.
Advertisements

A Process Splitting Transformation for Kahn Process Networks Sjoerd Meijer.
Review What is a virtual function? What can be achieved with virtual functions? How to define a pure virtual function? What is an abstract class? Can a.
Compilation 2011 Static Analysis Johnni Winther Michael I. Schwartzbach Aarhus University.
CS412/413 Introduction to Compilers Radu Rugina Lecture 37: DU Chains and SSA Form 29 Apr 02.
Test-Driven Development and Refactoring CPSC 315 – Programming Studio.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Conditional statements and Boolean expressions. The if-statement in Java (1) The if-statement is a conditional statement The statement is executed only.
Reverse Engineering © SERG Code Cloning: Detection, Classification, and Refactoring.
Functions Quick Review What is a Function? A module of code that performs a specific job. Examples: Function that determines the maximum of two numbers.
16/11/2015 9:05 AM6/11/2015 9:05 AM6/11/2015 9:05 AMFunctions Functions A function consists of: Name Name Arguments (also called parameters) Arguments.
A Tool Support to Merge Similar Methods with a Cohesion Metric COB ○ Masakazu Ioka 1, Norihiro Yoshida 2, Tomoo Masai 1,Yoshiki Higo 1, Katsuro Inoue 1.
Refactoring Haskell Programs Huiqing Li Computing Lab, University of Kent
Analyzing Software Code and Execution – Plagiarism and Bug Detection Shoaib Jameel.
Maya: Multiple-Dispatch Syntax Extension in Java Jason Baker and Wilson C. Hsieh University of Utah.
JExample Extending JUnit with explicit dependencies Bachelor Project Lea Hänsenberger.
Templates. Objectives At the conclusion of this lesson, students should be able to Explain how function templates are used Correctly create a function.
Program Analysis Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
Refactoring Support Tool: Cancer Yoshiki Higo Osaka University.
Java Classes Introduction and Chapter 1 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 3 Lexical and Syntactic Analysis Syntactic.
INF5110: Mandatory Exercise 2 Eyvind W. Axelsen @eyvindwa Slides are partly based on.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
McLab Tutorial Part 6 – Introduction to the McLab Backends MATLAB-to-MATLAB MATLAB-to-Fortran90 (McFor) McVM with JIT 6/4/2011Backends-
A Review of Recursion Dr. Jicheng Fu Department of Computer Science University of Central Oklahoma.
2006/09/19AOAsia 21 Towards Locating a Functional Concern Based on a Program Slicing Technique Takashi Ishio 1,2, Ryusuke Niitani 2 and Katsuro Inoue 2.
COSC 1P03 Data Structures and Abstraction 4.1 Abstract Data Types The advantage of a bad memory is that one enjoys several times the same good things for.
{ Graphite Grigory Arashkovich, Anuj Khanna, Anirban Gangopadhyay, Michael D’Egidio, Laura Willson.
2002/12/11PROFES20021 On software maintenance process improvement based on code clone analysis Yoshiki Higo* , Yasushi Ueda* , Toshihiro Kamiya** , Shinji.
CHAPTER 3 Function Overloading. 2 Introduction The polymorphism refers to ‘one name having many forms’ ‘different behaviour of an instance depending upon.
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University Inoue Laboratory Eunjong Choi 1 Investigating Clone.
CS212: Object Oriented Analysis and Design Lecture 9: Function Overloading in C++
1 Evaluating Code Duplication Detection Techniques Filip Van Rysselberghe and Serge Demeyer Lab On Re-Engineering University Of Antwerp Towards a Taxonomy.
Static Methods. 2 Objectives Look at how to build static (class) methods Study use of methods calling, parameters, returning values Contrast reference.
Compiler Principles Fall Compiler Principles Lecture 0: Local Optimizations Roman Manevich Ben-Gurion University.
CPS 506 Comparative Programming Languages Syntax Specification.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
CASE/Re-factoring and program slicing
Chapter 14 Abstract Classes and Interfaces. Abstract Classes An abstract class extracts common features and functionality of a family of objects An abstract.
Lecture 9.4 Java Interfaces. © 2006 Pearson Addison-Wesley. All rights reserved Java does not support multiple inheritance. Interface Characteristics...
Scalable Clone Detection and Elimination for Erlang Programs Huiqing Li, Simon Thompson University of Kent Canterbury, UK.
Simple Functions Writing Reuseable Formulas. Problem Using OCD, design and implement a program that computes the area and circumference of an Australian.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
Chpater 3. Outline The definition of Syntax The Definition of Semantic Most Common Methods of Describing Syntax.
Interpreters and Higher-Order Functions CSE 413 Autumn 2008 Credit: CSE341 notes by Dan Grossman.
CS412/413 Introduction to Compilers Radu Rugina Lecture 11: Symbol Tables 13 Feb 02.
Java Classes Introduction. Contents Introduction Objects and Classes Using the Methods in a Java Class – References and Aliases Defining a Java Class.
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University A Metric-based Approach for Reconstructing Methods.
An Algorithm for Detecting and Removing Clones in Java Code Nicolas Juillerat & Béat Hirsbrunner Pervasive and Artificial Intelligence ( ) Research Group,
Copyright Prentice Hall Modified by Sana odeh, NYU
Programming what is C++
Introduction to Computers Computer Generations
Programming Languages 2nd edition Tucker and Noonan
Templates.
Constructing Precedence Table
Programming Languages Dan Grossman 2013
Functions CIS 40 – Introduction to Programming in Python
Basic Program Analysis: AST
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
Functions.
Refactoring Support Tool: Cancer
Data structures and algorithms
Programming Assignment 2A
Exception Handling.
Anatomy of a Java Program
Single-Result Functions & Modularity
Topic 25 - more array algorithms
Rudra Dutta CSC Spring 2007, Section 001
Matching Program Versions
Presentation transcript:

Toward an Implementation of the “Form Template Method” Refactoring Nicolas Juillerat University of Fribourg Switzerland

27/09/07SCAM'072 1.Problem definition public void rotateAt(Point center, double amount) { translate(mult(center, )); rotate(amount, center); translate(center); normalize(amount); } public void skewAt(Point center, double amount) { translate(mult(center, )); amount = skew(amount); translate(center); normalize(amount); } public void templateMethod( Point center, double amount) { translate(mult(center, d1())); amount = d2(amount, center); translate(center); normalize(amount); }

27/09/07SCAM' Challenges How to compare two code snippets? –Use clone detection techniques? –Yes, but… small differences The matching order is important Renamed variables are more difficult to handle

27/09/07SCAM' Challenges ABCDEABCDE ABDCEABDCE ABCDEABCDE Matching order Clone detection 4 clones

27/09/07SCAM' Challenges ABCDEABCDE ABDCEABDCE ABCDEABCDE ABDCEABDCE ABCDEABCDE ABDCEABDCE Matching order Template method (2 solutions)‏

27/09/07SCAM' Challenges Renamed variables int x = z * 2; print(x); store(x); int y = x - 4; return y; int y = z * 2 print(y); store(y); y++; return y; int x = z * 2; print(x); store(x); int y = x - 4; return y; int y = z * 2 print(y); store(y); y++; return y; x --- x, y --- y, z --- z 2 matches x --- y, y --- x, z --- z 3 matches

27/09/07SCAM' Challenges Renamed variables int x = z * 2; print(x); store(x); int y = x - 4; return y; int y = z * 2 print(y); store(y); y++; return y; int x = z * 2; print(x); store(x); int y = x - 4; return y; int y = z * 2 print(y); store(y); y++; return y; We need to know what variables are matched before we can match statements. But we need to know what statements are matched before we can match variables Reason: unlike with clone detection, variable matching must be the same for multiple matched statements

27/09/07SCAM' Challenges Method extraction –Known problem, but the template method can only be formed if all differences can be extracted AXDFHKLAXDFHKL BXCFMKPBXCFMKP e1 X e2 F e3 K e4 e1 X e2 F H/M K e4 Successfully extracted Failed to extract. No template method can be formed

27/09/07SCAM' Challenges Method extraction –Furthermore, we have to extract pairs of different methods AXDFHKLAXDFHKL BXCFMKPBXCFMKP e1 X e2 F e3 K e4 void D(int, String); float C(int, boolean); float e2(int, String, boolean);  Merging of arguments / results

27/09/07SCAM' Proposed solutions

27/09/07SCAM' Proposed solutions Variable matching (before matched statements are known)‏ –Based on Maximum Matching of Bipartite Graphs (Heuristic, used to supply a proposal)‏ Not in paper (ongoing work)‏ Statement comparison –Post-order AST traversal (  Tokens list)‏ –Longest Common Subsequence (LCM)‏ Or modified LZ77 (data compression algorithm)‏ –Common ancestor (tree)‏ And various other tree algorithms

27/09/07SCAM' Proposed solutions Method Extraction –If impossible, various tricks to make the extraction possible Divide the method to extract into multiple methods Extend a method with matched statements –Some duplications remains Control flow to dataflow conversion Etc –More freedom than with method extraction alone

27/09/07SCAM' Discussion/Conclusion

27/09/07SCAM' Discussion/Conclusion Algorithms: AST Traversal  List Longest Common SubsequenceLongest Common Subsequence Common Ancestor (tree)‏Common Ancestor (tree)‏ Maximum matching of bipartite graphsMaximum matching of bipartite graphs Control flow to data flow conversionControl flow to data flow conversion Data/Control flow analysis LZ77LZ77 … Existing techniques / abstractions: Graph transformations Graph rewriting languages AST Traversals/Rewriting Scripting languages Code queries … Questions: Are the existing techniques suitable for really complex refactorings? Isn’t a general purpose language (+ suitable library) more adequate?