1 / 29

On The Detection of Code Clone With Concern Analysis

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. Code Clone.

dvelazquez
Download Presentation

On The Detection of Code Clone With Concern Analysis

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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. Code Clone • Definition • Copyand Paste [2] • Similarity (notnecessarilyidentical) is clone [3]

  3. ResearchImportance • Software Engineering • Software quality, complexity, architecture, refactoring, evolution, licensing, plagiarism, and so on. • Workshops • http://softwareclones.org/iwsc2014/ • http://iwsc2015.usask.ca/

  4. IWSC2014

  5. IWSC2015

  6. Example ofCode Clone Type 1

  7. Detection Tools • Textbased • Token based • Treebased • Graphbased (PDG) • Metricsbased • Hybridtechinique

  8. ConcernMetrics • Quantify properties of concerns • Scattering • Tangling Statistics Candidate Date Log Persistence ExceptionHandling

  9. Motivation • Code clones shouldbeavoided • Concernscatteringshouldbeavoided • Concernscattering as key for locatingcode clones • Concernscatteringdiffersfrom PDG when ignores local variablesandstatements

  10. Sonar (PurchaseOrderEJB.java x SupplierOrderEJB.java)

  11. Type 4 • Semanticisthesame intfoo1(List<Clone> clones){ inttotal = 0; for(inti = 0; i < clones.size(); i++) { Clone clone = clones.get(i); if(!clone.isAvailable()) continue; total++; } returntotal; } int foo2(List<Clone> list) { intcount = 1, clones = 0; while(count <= list.size()) { if (list.get(count-1).isAvailable()) { clones= clones+1; } count= count+1; } returnclones; }

  12. Type 4 • Semanticisthesame intfoo1(List<Clone> clones){ inttotal = 0; for(inti = 0; i < clones.size(); i++) { Clone clone = clones.get(i); if(!clone.isAvailable()) continue; total++; } returntotal; } int foo2(List<Clone> list) { intcount = 1, clones = 0; while(count <= list.size()) { if (list.get(count-1).isAvailable()) { clones= clones+1; } count= count+1; } returnclones; }

  13. PROPOSAL APPROACH I GitHub BitBucket Other HashofCalls ListofMethods Stringname Listcalls Stringcall Listmethods (position) .java Comparision Concerns II call: java.util.List.add methods: health.data.UnitRDB.getPartial 2 health.view.Address.mount 3 health.data.Employee.save 6 name: health.data.UnitRDB.getPartial calls: java.util.ArrayList.ArrayList lib.util.Iterator.Iterator java.util.List.add java.sql.ResultSet.next • Duplications

  14. Systems Analyzed

  15. SequenceConcept • 3 calls in sequence intfoo1(List<Clone> clones){ inttotal = 0; for(inti = 0; i < clones.size(); i++) { Clone clone = clones.get(i); if(!clone.isAvailable()) continue; total++; } returntotal; } int foo2(List<Clone> list) { intcount = 1, clones = 0; while(count <= list.size()) { if (list.get(count-1).isAvailable()) { clones= clones+1; } count= count+1; } returnclones; }

  16. Clones per Sequence

  17. Clone Detected – Petstore - getCategories public Page getCategories(int start, intcount, Localelocale) throwsCatalogDAOSysException {     Connection connection = null; PreparedStatementstatement = null; ResultSetresultSet = null; try {         connection = getDataSource().getConnection(); String[] parameterValues = newString[] { locale.toString() }; if (TRACE) { printSQLStatement(sqlStatements, XML_GET_CATEGORIES, parameterValues);         } statement = buildSQLStatement(connection, sqlStatements, XML_GET_CATEGORIES, parameterValues); resultSet = statement.executeQuery(); if (start >= 0 && resultSet.absolute(start + 1)) { booleanhasNext = false; Listcategories = newArrayList(); do { categories.add(newCategory(resultSet.getString(1).trim(), resultSet.getString(2), resultSet.getString(3)));            } while ((hasNext = resultSet.next()) && (--count > 0)); returnnew Page(categories, start, hasNext);         } returnPage.EMPTY_PAGE; ...

  18. Clone Detected – Petstore – getItems public Page getItems(StringproductID, int start, intcount, Localelocale) throwsCatalogDAOSysException {     Connection connection = null; PreparedStatementstatement = null; ResultSetresultSet = null; try {         connection = getDataSource().getConnection(); String[] parameterValues = newString[] { locale.toString(), productID }; if (TRACE) { printSQLStatement(sqlStatements, XML_GET_ITEMS, parameterValues);         } statement = buildSQLStatement(connection, sqlStatements, XML_GET_ITEMS, parameterValues); resultSet = statement.executeQuery(); if (start >= 0 && resultSet.absolute(start + 1)) { booleanhasNext = false; Listitems = newArrayList(); do { int i = 1; items.add(new Item(...));            } while ((hasNext = resultSet.next()) && (--count > 0)); returnnew Page(items, start, hasNext);         } returnPage.EMPTY_PAGE; ...

  19. ComparisonwithOtherDetectors • CloneDR • http://www.semanticdesigns.com/Products/Clone • iClones • http://www.softwareclones.org

  20. ExerciseGoal • 12 snippets • To decide: Iscode clone?

  21. ExerciseExample

  22. Expectedanswers • Codeis similar, butisnotcloned. • The sequencebelowshould NOT bemovedto a common method void foo1() { System.out.println("fileName: "+fileName+", orderId="+invoiceXDE.getOrderId()+", lineItemIds="+invoiceCDE.getLineItemIds()); System.exit(0); } voidfoo2() { System.out.println("Name: " + name); System.out.println("Age: " + age); System.out.println("Address: " + address); System.exit(0); }

  23. Expectedanswers • Codeis clone. • The sequencebelowshouldbemovedto a common method void foo1() { System.out.println("fileName: "+fileName+", orderId="+invoiceXDE.getOrderId()+", lineItemIds="+invoiceCDE.getLineItemIds()); System.exit(0); } voidfoo2() { System.out.println("Name: " + name); System.out.println("Age: " + age); System.out.println("Address: " + address); System.exit(0); }

  24. Final Tips • The code clone isnottheentiremethod • Code clone isjust a pieceofcode, maybethreeor more lines

  25. ExerciseSurvey • http://esurv.org/?u=iscodeclone

  26. SurveyResults

  27. ThreatsofValidation • Cases wererandomicallyanalysed • This approach canbealreadycoveredbyanotherdetectionmethod • Surveywasnotrepresentative • Fewsubjects • Bad cases • Background

  28. Conclusions • Potential tool for Type 4 clone detection • Found clones whichwerenotfoundbyother tools • Performance wasnotfocus, butlarge system wasanalysed • Tool canbeimproved • Hybridsolutionmaybeanoption

  29. Thanks! This work was partially supported by CNPq (grant Universal 485907/2013-5) and FAPEMIG (grants APQ-02532-12 and PPM-00382-14)

More Related