Refactoring Clones: A New Perspective Nikolaos Tsantalis and Giri Panamoottil Krishnan Computer Science & Software Engineering.

Slides:



Advertisements
Similar presentations
Classes and Objects. What is Design? The parts of the software including – what information each part holds – what things each part can do – how the various.
Advertisements

Methods Java 5.1 A quick overview of methods
Unification and Refactoring of Clones Giri Panamoottil Krishnan and Nikolaos Tsantalis Department of Computer Science & Software Engineering Clone images.
CSE Lecture 3 – Algorithms I
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Pointer Analysis – Part I Mayur Naik Intel Research, Berkeley CS294 Lecture March 17, 2009.
SUMMARY: abstract classes and interfaces 1 Make a class abstract so instances of it cannot be created. Make a method abstract so it must be overridden.
Approximations of points and polygonal chains
An Exact Algorithm for the Vehicle Routing Problem with Backhauls
Reverse Engineering © SERG Code Cloning: Detection, Classification, and Refactoring.
Improving the Unification of Software Clones Using Tree & Graph Matching Algorithms Giri Panamoottil Krishnan Supervisor: Dr. Nikolaos Tsantalis
1 Abstract Classes & Inheritance Hierarchies. 2 Abstract classes & methods Keyword abstract applied to a class guarantees that subclass must be constructed.
Object Detection by Matching Longin Jan Latecki. Contour-based object detection Database shapes: …..
Preventive Software Maintenance: The Past, the Present, the Future Nikolaos Tsantalis Computer Science & Software Engineering Consortium for Software Engineering.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
CSE 222 Systems Programming Graph Theory Basics Dr. Jim Holten.
CSE 421 Algorithms Richard Anderson Lecture 16 Dynamic Programming.
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
Templates. Objectives At the conclusion of this lesson, students should be able to Explain how function templates are used Correctly create a function.
Application of Graph Theory to OO Software Engineering Alexander Chatzigeorgiou, Nikolaos Tsantalis, George Stephanides Department of Applied Informatics.
Software Testing and QA Theory and Practice (Chapter 4: Control Flow Testing) © Naik & Tripathy 1 Software Testing and Quality Assurance Theory and Practice.
Introduction SWE 619. Why Is Building Good Software Hard? Large software systems enormously complex  Millions of “moving parts” People expect software.
Language Evaluation Criteria
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Methods Chapter 6. 2 Program Modules in Java What we call "functions" in C++ are called "methods" in Java Purpose Reuse code Modularize the program This.
Complex objects How might you design a class called NestedRects of graphical objects that look like this? Requirements for the constructor: –Like many.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand design concepts for fixed-length and variable- length strings ❏
CS 106 Introduction to Computer Science I 03 / 19 / 2007 Instructor: Michael Eckmann.
Mining and Analysis of Control Structure Variant Clones Guo Qiao.
CS 61B Data Structures and Programming Methodology July 15, 2008 David Sun.
1 Object Oriented Programming Lecture IX Some notes on Java Performance with aspects on execution time and memory consumption.
1 Optimal Cycle Vida Movahedi Elder Lab, January 2008.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington ArraySet and Binary Search.
Pebble game extensions- Detecting relevant regions, protein hinge motions, allostery … Adnan Sljoka, York University Work with Walter Whiteley.
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University Inoue Laboratory Eunjong Choi 1 Investigating Clone.
Topic 25 - more array algorithms 1 "To excel in Java, or any computer language, you want to build skill in both the "large" and "small". By "large" I mean.
Toward an Implementation of the “Form Template Method” Refactoring Nicolas Juillerat University of Fribourg Switzerland.
CSC 212 – Data Structures Lecture 37: Course Review.
Computer Science and Engineering Parallelizing Defect Detection and Categorization Using FREERIDE Leonid Glimcher P. 1 ipdps’05 Scaling and Parallelizing.
Game Playing. Introduction One of the earliest areas in artificial intelligence is game playing. Two-person zero-sum game. Games for which the state space.
EVENTS Wiring together objects, code, and actions.
1 Object Oriented Programming Lecture XI An abstract function plotter, using the Template and the Strategy design patterns.
1 CSC/ECE 517 Fall 2010 Lec. 3 Overview of Eclipse Lectures Lecture 2 “Lecture 0” Lecture 3 1.Overview 2.Installing and Running 3.Building and Running.
Refactoring 2. Admin Blackboard Quiz Acknowledgements Material in this presentation was drawn from Martin Fowler, Refactoring: Improving the Design of.
Interfaces, Classes, Collections School of Engineering and Computer Science, Victoria University of Wellington COMP T2 Lecture 3 Thomas Kuehne.
Software Engineering Research Group, Graduate School of Engineering Science, Osaka University A Slicing Method for Object-Oriented Programs Using Lightweight.
ICOM 4035 – Data Structures Lecture 4 – Set ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel.
Software Construction and Evolution - CSSE 375 Making Method Calls Simpler Shawn and Steve Below – “Be the character!” The late acting teacher Lee Strasberg.
Spatial Indexing Techniques Introduction to Spatial Computing CSE 5ISC Some slides adapted from Spatial Databases: A Tour by Shashi Shekhar Prentice Hall.
March 1, 2004CS WPI1 CS 509 Design of Software Systems Lecture #6 Monday, March 1, 2004.
CSSE 375 Organizing Data – Part 1 Shawn and Steve Q1.
Visual C# 2005 Using Arrays. Visual C# Objectives Declare an array and assign values to array elements Initialize an array Use subscripts to access.
Games: Efficiency Andrea Danyluk September 23, 2013.
Module Road Map Refactoring Why Refactoring? Examples
Templates.
Methods Chapter 6.
A Refactoring Technique for Large Groups of Software Clones
CMSC201 Computer Science I for Majors Lecture 11 – Program Design
Clone Refactoring with Lambda Expressions
ME 521 Computer Aided Design 15-Optimization
Data Structures and Algorithms
Incremental Placement Algorithm for Field Programmable Gate Arrays
Inheritance "Question: What is the object oriented way of getting rich? Answer: Inheritance.“ “Inheritance is new code that reuses old code. Polymorphism.
A Boolean Paradigm in Multi-Valued Logic Synthesis
Overview of Eclipse Lectures
: Clone Refactoring Davood Mazinanian Nikolaos Tsantalis Raphael Stein
Assessing the Refactorability of Software Clones
A Primal-Dual Solution to Minimal Test Generation Problem
Search Exercise Search Tree? Solution (Breadth First Search)?
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Presentation transcript:

Refactoring Clones: A New Perspective Nikolaos Tsantalis and Giri Panamoottil Krishnan Computer Science & Software Engineering

Motivation A study by Tairas & Gray [2012] on the clones detected in 9 open-source projects revealed: – only 10.6% of them could be refactored by Eclipse – CeDAR was able to refactor 18.7% of them 7th International Workshop on Software Clones2

#1 Intelligent parameterization of differences 7th International Workshop on Software Clones3 Rectangle2D rect = null; if (orientation == HORIZONTAL) { low = Math.max(low, dataArea.getMinY()); high = Math.min(high, dataArea.getMaxY()); rect = new Rectangle2D.Double( dataArea.getMinX(), low, dataArea.getWidth(), high - low); } Rectangle2D rect = null; if (orientation == HORIZONTAL) { low = Math.max(low, dataArea.getMinX()); high = Math.min(high, dataArea.getMaxX()); rect = new Rectangle2D.Double( low, dataArea.getMinY(), high - low, dataArea.getHeight()); } Clone #1 Clone #2 Problem: Current solutions can parameterize only a small subset of differences in clones. – variable identifiers, literals – method calls

#1 Intelligent parameterization of differences Solution: Any expression returning a value of a given type can be replaced with an expression returning the same type – Method call: dataArea.getMinX() – Literals: "value" – Class instance creation: new LegendItem() – Field access: this.dataset – Qualified name: Node.WORKSTATION – Array access: a[index] – Infix expression: area.getY() + 4 – Cast: (MeterInterval)iterator.next() 7th International Workshop on Software Clones4

#2 Optimal matching of duplicated code Problem: Current approaches may return non- optimal matching solutions. Reason: They do not explore the entire search space of possible matches. In case of multiple possible matches, they select the “first” or “best” match. 7th International Workshop on Software Clones5

if (orientation == VERTICAL) { Line2D line = new Line2D.Double(); double y0 = dataArea.getMinY(); double y1 = dataArea.getMaxY(); g2.setPaint(im.getOutlinePaint()); g2.setStroke(im.getOutlineStroke()); if (range.contains(start)) { line.setLine(start2d, y0, start2d, y1); g2.draw(line); } if (range.contains(end)) { line.setLine(end2d, y0, end2d, y1); g2.draw(line); } else if (orientation == HORIZONTAL) { Line2D line = new Line2D.Double(); double x0 = dataArea.getMinX(); double x1 = dataArea.getMaxX(); g2.setPaint(im.getOutlinePaint()); g2.setStroke(im.getOutlineStroke()); if (range.contains(start)) { line.setLine(x0, start2d, x1, start2d); g2.draw(line); } if (range.contains(end)) { line.setLine(x0, end2d, x1, end2d); g2.draw(line); } if (orientation == VERTICAL) { Line2D line = new Line2D.Double(); double x0 = dataArea.getMinX(); double x1 = dataArea.getMaxX(); g2.setPaint(im.getOutlinePaint()); g2.setStroke(im.getOutlineStroke()); if (range.contains(start)) { line.setLine(x0, start2d, x1, start2d); g2.draw(line); } if (range.contains(end)) { line.setLine(x0, end2d, x1, end2d); g2.draw(line); } else if (orientation == HORIZONTAL) { Line2D line = new Line2D.Double(); double y0 = dataArea.getMinY(); double y1 = dataArea.getMaxY(); g2.setPaint(im.getOutlinePaint()); g2.setStroke(im.getOutlineStroke()); if (range.contains(start)) { line.setLine(start2d, y0, start2d, y1); g2.draw(line); } if (range.contains(end)) { line.setLine(end2d, y0, end2d, y1); g2.draw(line); } 7th International Workshop on Software Clones Clone #1 Clone #2 NOT APPROVED 6

else if (orientation == HORIZONTAL) { } if (orientation == VERTICAL) { } if (orientation == VERTICAL) { Line2D line = new Line2D.Double(); double y0 = dataArea.getMinY(); double y1 = dataArea.getMaxY(); g2.setPaint(im.getOutlinePaint()); g2.setStroke(im.getOutlineStroke()); if (range.contains(start)) { line.setLine(start2d, y0, start2d, y1); g2.draw(line); } if (range.contains(end)) { line.setLine(end2d, y0, end2d, y1); g2.draw(line); } else if (orientation == HORIZONTAL) { Line2D line = new Line2D.Double(); double x0 = dataArea.getMinX(); double x1 = dataArea.getMaxX(); g2.setPaint(im.getOutlinePaint()); g2.setStroke(im.getOutlineStroke()); if (range.contains(start)) { line.setLine(x0, start2d, x1, start2d); g2.draw(line); } if (range.contains(end)) { line.setLine(x0, end2d, x1, end2d); g2.draw(line); } Line2D line = new Line2D.Double(); double x0 = dataArea.getMinX(); double x1 = dataArea.getMaxX(); g2.setPaint(im.getOutlinePaint()); g2.setStroke(im.getOutlineStroke()); if (range.contains(start)) { line.setLine(x0, start2d, x1, start2d); g2.draw(line); } if (range.contains(end)) { line.setLine(x0, end2d, x1, end2d); g2.draw(line); } Line2D line = new Line2D.Double(); double y0 = dataArea.getMinY(); double y1 = dataArea.getMaxY(); g2.setPaint(im.getOutlinePaint()); g2.setStroke(im.getOutlineStroke()); if (range.contains(start)) { line.setLine(start2d, y0, start2d, y1); g2.draw(line); } if (range.contains(end)) { line.setLine(end2d, y0, end2d, y1); g2.draw(line); } 7th International Workshop on Software Clones Clone #1 Clone #2 7

if (orientation == HORIZONTAL) { Line2D line = new Line2D.Double(); double y0 = dataArea.getMinY(); double y1 = dataArea.getMaxY(); g2.setPaint(im.getOutlinePaint()); g2.setStroke(im.getOutlineStroke()); if (range.contains(start)) { line.setLine(start2d, y0, start2d, y1); g2.draw(line); } if (range.contains(end)) { line.setLine(end2d, y0, end2d, y1); g2.draw(line); } else if (orientation == VERTICAL) { Line2D line = new Line2D.Double(); double x0 = dataArea.getMinX(); double x1 = dataArea.getMaxX(); g2.setPaint(im.getOutlinePaint()); g2.setStroke(im.getOutlineStroke()); if (range.contains(start)) { line.setLine(x0, start2d, x1, start2d); g2.draw(line); } if (range.contains(end)) { line.setLine(x0, end2d, x1, end2d); g2.draw(line); } if (orientation == VERTICAL) { Line2D line = new Line2D.Double(); double y0 = dataArea.getMinY(); double y1 = dataArea.getMaxY(); g2.setPaint(im.getOutlinePaint()); g2.setStroke(im.getOutlineStroke()); if (range.contains(start)) { line.setLine(start2d, y0, start2d, y1); g2.draw(line); } if (range.contains(end)) { line.setLine(end2d, y0, end2d, y1); g2.draw(line); } else if (orientation == HORIZONTAL) { Line2D line = new Line2D.Double(); double x0 = dataArea.getMinX(); double x1 = dataArea.getMaxX(); g2.setPaint(im.getOutlinePaint()); g2.setStroke(im.getOutlineStroke()); if (range.contains(start)) { line.setLine(x0, start2d, x1, start2d); g2.draw(line); } if (range.contains(end)) { line.setLine(x0, end2d, x1, end2d); g2.draw(line); } 7th International Workshop on Software Clones Clone #1 Clone #2 APPROVED 8

#2 Optimal matching of duplicated code The minimization of differences plays a critical role in the refactoring of clones. Objectives: – Maximize the number of matched statements – Minimize the number of differences between them Solution: Adaptation of the Maximum Common Subgraph (MCS) algorithm for PDG mapping. 7th International Workshop on Software Clones9

#3 Refactoring sub-clones 7th International Workshop on Software Clones double jmin = 0.0; double jmax = 0.0; if (RectangleEdge.isTopOrBottom(edge)) { jmin = dataArea.getMinX(); jmax = dataArea.getMaxX(); } else if (RectangleEdge.isLeftOrRight(edge)) { jmin = dataArea.getMaxY(); jmax = dataArea.getMinY(); } double jmin = 0.0; double jmax = 0.0; if (RectangleEdge.isTopOrBottom(edge)) { jmin = dataArea.getMinX(); jmax = dataArea.getMaxX(); } else if (RectangleEdge.isLeftOrRight(edge)) { jmax = dataArea.getMinY(); jmin = dataArea.getMaxY(); } Clone #1 Clone #2 10

#3 Refactoring sub-clones Solution: Find sub-clones that can be extracted in separate methods. Sub-clones should implement a distinct functionality: – Compute a single variable – Affect the state of an object 7th International Workshop on Software Clones11 N. Tsantalis and A. Chatzigeorgiou, “Identification of extract method refactoring opportunities for the decomposition of methods,” J. Syst. Softw., vol. 84, no. 10, pp. 1757–1782, Oct

7th International Workshop on Software Clones double jmin = 0.0; double jmax = 0.0; if (RectangleEdge.isTopOrBottom(edge)) { jmin = dataArea.getMinX(); jmax = dataArea.getMaxX(); } else if (RectangleEdge.isLeftOrRight(edge)) { jmin = dataArea.getMaxY(); jmax = dataArea.getMinY(); } double jmin = 0.0; double jmax = 0.0; if (RectangleEdge.isTopOrBottom(edge)) { jmin = dataArea.getMinX(); jmax = dataArea.getMaxX(); } else if (RectangleEdge.isLeftOrRight(edge)) { jmax = dataArea.getMinY(); jmin = dataArea.getMaxY(); } Clone #1 Clone #2 Before After private void jmin(Rectangle2D dataArea, RectangleEdge edge) { double jmin = 0.0; if (RectangleEdge.isTopOrBottom(edge)) { jmin = dataArea.getMinX(); } else if (RectangleEdge.isLeftOrRight(edge)) { jmin = dataArea.getMaxY(); } return jmin; } private void jmax(Rectangle2D dataArea, RectangleEdge edge) { double jmax = 0.0; if (RectangleEdge.isTopOrBottom(edge)) { jmax = dataArea.getMaxX(); } else if (RectangleEdge.isLeftOrRight(edge)) { jmax = dataArea.getMinY(); } return jmax; } Clone #1 Clone #2 12 double jmin = jmin(dataArea, edge); double jmax = jmax(dataArea, edge); double jmin = jmin(dataArea, edge); double jmax = jmax(dataArea, edge);

Refactoring of the Clones 7th International Workshop on Software Clones13