Download presentation
Presentation is loading. Please wait.
Published byBertha Turner Modified over 8 years ago
1
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 1/29 On The Detection of Code Clone With Concern Analysis Paiva, Alexandre; Alves, Johnatan; Figueiredo, Eduardo Software Engineering Lab (LabSoft) – Federal University of Minas Gerais (UFMG) Belo Horizonte – MG – Brazil {ampaiva, johnatan, figueiredo}@dcc.ufmg.br
2
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 2/29 Code Clone Definition Copy and Paste [2] Similarity (not necessarily identical) is clone [3]
3
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 3/29 Research Importance Software Engineering Software quality, complexity, architecture, refactoring, evolution, licensing, plagiarism, and so on. Workshops http://softwareclones.org/iwsc2014/ http://iwsc2015.usask.ca/
4
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 4/29 IWSC2014
5
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 5/29 IWSC2015
6
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 6/29 Example of Code Clone Type 1
7
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 7/29 Detection Tools Text based Token based Tree based Graph based (PDG) Metrics based Hybrid techinique
8
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 8/29 Concern Metrics Quantify properties of concerns Scattering Tangling CandidateDate Statistics Log Persistence Exception Handling
9
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 9/29 Motivation Code clones should be avoided Concern scattering should be avoided Concern scattering as key for locating code clones Concern scattering differs from PDG when ignores local variables and statements
10
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 10/29 Sonar (PurchaseOrderEJB.java x SupplierOrderEJB.java)
11
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 11/29 Type 4 Semantic is the same int foo1(List clones){ int total = 0; for (int i = 0; i < clones.size(); i++) { Clone clone = clones.get(i); if (!clone.isAvailable()) continue; total++; } return total; } int foo2(List list) { int count = 1, clones = 0; while (count <= list.size()) { if (list.get(count-1).isAvailable()) { clones = clones+1; } count = count+1; } return clones; }
12
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 12/29 Type 4 Semantic is the same int foo1(List clones){ int total = 0; for (int i = 0; i < clones.size(); i++) { Clone clone = clones.get(i); if (!clone.isAvailable()) continue; total++; } return total; } int foo2(List list) { int count = 1, clones = 0; while (count <= list.size()) { if (list.get(count-1).isAvailable()) { clones = clones+1; } count = count+1; } return clones; }
13
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 13/29 I I String name List calls String name List calls name: health.data.UnitRDB.getPartial calls: java.util.ArrayList.ArrayList lib.util.Iterator.Iterator java.util.List.add java.sql.ResultSet.next List of Methods II String call List methods (position) String call List methods (position) call: java.util.List.add methods: health.data.UnitRDB.getPartial 2 health.view.Address.mount 3 health.data.Employee.save 6 Hash of Calls PROPOSAL APPROACH Project Sources... java xmlpngjava Duplications GitHub BitBucket Other GitHub BitBucket Other ConcernsComparision.java
14
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 14/29 Systems Analyzed System Calls TotalDistinct Restaurantr399230 Telestrada688304 Learn Engh920381 Mobile Media1419449 Ecommerce 211706561 Health Watcher2301491 Ecommerce 259871982 PetStore61052352 Junit82212932 Facebook Android127734428 Restaurant Open194165616 Maven312679543 ArgoUML8243523582 JBoss16004051755
15
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 15/29 Sequence Concept 3 calls in sequence int foo1(List clones){ int total = 0; for (int i = 0; i < clones.size(); i++) { Clone clone = clones.get(i); if (!clone.isAvailable()) continue; total++; } return total; } int foo2(List list) { int count = 1, clones = 0; while (count <= list.size()) { if (list.get(count-1).isAvailable()) { clones = clones+1; } count = count+1; } return clones; }
16
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 16/29 Clones per Sequence System CallsSequences of Calls TotalDistinct3456789101112131415 Restaurantr3992301 11 Telestrada68830425122 Learn Engh920381503178655653211 Mobile Media1419449101604716563331 Ecommerce 21170656161730810668777369677025313 Health Watcher2301491373207154135302975 710853 Ecommerce 259871982292184104776246 384128313326 PetStore610523528672661651044933341378343 Junit822129328952911901608563623224161311 Facebook Android1277344281041361210153887156452916151810 Restaurant Open1941656163105222514601041893142138894230311814 Maven31267954343621924189484788948862727734414414210475 ArgoUML82435235821872681593771218916464413383009173544527 JBoss16004051755463331898673784308255418151414866664561405347253
17
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 17/29 public Page getCategories(int start, int count, Locale locale) throws CatalogDAOSysExce ption { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; try { connection = getDataSource().getConnection(); String[] parameterValues = new String[] { locale.toString() }; if (TRACE) { printSQLStatement(sqlStatements, XML_GET_CATEGORIES, parameterValues); } statement = buildSQLStatement(connection, sqlStatements, XML_GET_CATEGORIES, pa rameterValues); resultSet = statement.executeQuery(); if (start >= 0 && resultSet.absolute(start + 1)) { boolean hasNext = false; List categories = new ArrayList(); do { categories.add(new Category(resultSet.getString(1).trim(), resultSet.ge tString(2), resultSet.getString(3))); } while ((hasNext = resultSet.next()) && (--count > 0)); return new Page(categories, start, hasNext); } return Page.EMPTY_PAGE;... Clone Detected – Petstore - getCategories
18
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 18/29 Clone Detected – Petstore – getItems public Page getItems(String productID, int start, int count, Locale locale) throws Cata logDAOSysException { Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; try { connection = getDataSource().getConnection(); String[] parameterValues = new String[] { locale.toString(), productID }; if (TRACE) { printSQLStatement(sqlStatements, XML_GET_ITEMS, parameterValues); } statement = buildSQLStatement(connection, sqlStatements, XML_GET_ITEMS, paramet erValues); resultSet = statement.executeQuery(); if (start >= 0 && resultSet.absolute(start + 1)) { boolean hasNext = false; List items = new ArrayList(); do { int i = 1; items.add(new Item(...)); } while ((hasNext = resultSet.next()) && (--count > 0)); return new Page(items, start, hasNext); } return Page.EMPTY_PAGE;...
19
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 19/29 Comparison with Other Detectors CloneDR http://www.semanticdesigns.com/Products/Clone iClones http://www.softwareclones.org
20
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 20/29 Exercise Goal 12 snippets To decide: Is code clone?
21
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 21/29 Exercise Example
22
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 22/29 Expected answers Code is similar, but is not cloned. The sequence below should NOT be moved to a common method void foo1() { System.out.println("fileName: "+fileName+", orderId="+invoiceXDE.getOrderId()+", lineItemIds="+invoiceCDE.getLineItemIds()); System.exit(0); } void foo2() { System.out.println("Name: " + name); System.out.println("Age: " + age); System.out.println("Address: " + address); System.exit(0); }
23
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 23/29 Expected answers Code is clone. The sequence below should be moved to a common method void foo1() { System.out.println("fileName: "+fileName+", orderId="+invoiceXDE.getOrderId()+", lineItemIds="+invoiceCDE.getLineItemIds()); System.exit(0); } void foo2() { System.out.println("Name: " + name); System.out.println("Age: " + age); System.out.println("Address: " + address); System.exit(0); }
24
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 24/29 Final Tips The code clone is not the entire method Code clone is just a piece of code, maybe three or more lines
25
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 25/29 Exercise Survey http://esurv.org/?u=iscodeclone http://esurv.org/?u=iscodeclone
26
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 26/29 Survey Results
27
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 27/29 Threats of Validation Cases were randomically analysed This approach can be already covered by another detection method Survey was not representative Few subjects Bad cases Background
28
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 28/29 Conclusions Potential tool for Type 4 clone detection Found clones which were not found by other tools Performance was not focus, but large system was analysed Tool can be improved Hybrid solution may be an option
29
Software Engineering Lab (LabSoft) http://labsoft.dcc.ufmg.br/ 29/29 Thanks! This work was partially supported by CNPq (grant Universal 485907/2013-5) and FAPEMIG (grants APQ-02532-12 and PPM-00382-14)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.