Things Structural Clones Tell that Simple Clones Don’t

  • View
    27

  • Download
    0

Embed Size (px)

DESCRIPTION

Things Structural Clones Tell that Simple Clones Don’t. Hamid Abdul Basit. Software Clones. Simple clones the same or similar code fragments Structural clones higher-level , larger similarities Similarity of code and similarity of structure. Simple clones. Structural Clones. - PowerPoint PPT Presentation

Text of Things Structural Clones Tell that Simple Clones Don’t

Slide 1

Things Structural Clones Tell that Simple Clones DontHamid Abdul Basit

1

1Software ClonesSimple clones the same or similar code fragmentsStructural clones higher-level, larger similaritiesSimilarity of code and similarity of structure22Simple clones

334Structural Clones

4CreateTask.BLValidateTask()Task.DBAddTask()Task TableaccessesProject.DBAddProject()Project TableexecutesCreateProject.BLValidateProject()accessesexecutesvisualizesvisualizesUser InterfaceBusiness LogicDatabaseCreateTaskCreateProjectCreateTask.UICreateTask()CreateProject.UICreateProject()Collaborative structural cloneStructural Clones55When are structural clones useful?showing a bigger picture of similarity situation - the forest from the treesFinding refactoring opportunitiesArchitecture recovery, program understanding and maintenanceStructural clones often represent application domain or design conceptsRe-engineering for reuseThe bigger the clones the better for reuseSome benefits for plagiarism detection667A structure is a graphADCBxyzwEntities {A,B,C,D}Relationships {w,x,y,z}7EntitiesPhysically definedCode fragments, files , web pages, directoriesSemantically definedMethods, classes, packagesConceptually definedComponents, sub-systems88RelationshipsPhysical co-locationSame file, same directoryRuntimeMessage passingHyperlink between web pagesDesign levelInheritanceAssociationComposition

99e8be6bxwzxze7bxyze8dye6dye7dye8ce6ce7ce8aS8e6aS6e7aS7e4bxyze5bxyze4dye5dye4ce5ce4aS4e5aS5Structural Clones1010Higher level similarities are composed of lower level similaritiesCan be recovered by finding repeating configurations of lower level similarities11Observation11Detecting Structural Clones12Simple clones in filesclone patterns1987654321312141011151,4,8,10,11,121,4,7,8,10,11,122,5,9,13,1512animate colors Detecting Structural Clones13File Analysis1811101247135915213Detecting Structural Clones14Directory Analysis1811101247135915214Detecting Structural Clones15File Level Structural Clone Across Directories110487151392515a1b1c1a2b2c2F1F2Simple Clone Structure (SCS)Across Files16F1F2File Clone Class (FCC)17File Clone Structure (FCS) Across / Within Directories18F1X1Z2F2X2Y1Y2D1D2Z1STRUCTURAL CLONES DETECTED BY CLONE MINERSimple Clone Structures (SCS) Across MethodsSimple Clone Structures (SCS) Across FilesMethod Clone Classes (MCC)Method Clone Structures (MCS) Across FilesFile Clone Classes (FCC)File Clone Structures (FCS) Across DirectoriesFile Clone Structures (FCS) Within Directories19In earlier workWe hypothesized the benefits of structural clonesRe-engineering for reuse, architecture recovery, Defined structural clonesImplemented Clone Miner structural clone detectorDid initial empirical evaluation20In work presented hereHow frequent are the different types of structural clones?Are structural clones more meaningful for program understanding and design recovery than simple clones?What is the value added by structural clone detection in identifying refactoring opportunities?21Case Study Systems22Apache Ivy http://ant.apache.org/ivy/index.htmlApache Ant http://ant.apache.org/Columbahttp://sourceforge.net/projects/columba/Dnsjavahttp://www.dnsjava.org/Javax-Swinghttp://www.oracle.com/technetwork/java/javase/downloads/index.htmlJFreeCharthttp://www.jfree.org/jfreechart/ANTLR http://www.antlr.org/DrJava http://www.drjava.org/FreeColhttp://www.freecol.org/JEdithttp://www.jedit.org/JHotDrawhttp://www.jhotdraw.org/Apache -IvtApache-AntColumbaDnsJavaJavax-SwingJFreechartAntlrTokens 240711711914569676137019960906505448243461Files38611741549182620585258Lines Of Code542352246421570003008428916019835161414Methods415612849833420241525178423618AntlrDrJavaFreeColJEditJHotdrawAVERAGE TOTALTokens 2434616157395187955361731649294731614964060Files2586054885314846246476Lines Of Code61414140571128854157079633641367961450519Methods36187831589268734859723075373Systems Overview23AVERAGE TOTALSCC127513231SCC Instances412542924Average Length of SCC Instance48Methods Containing SCC153216198% Methods Containing SCC22Files Containing SCC3323476% Files Containing SCC53Directories Containing SCC51504% Directories Containing SCC83Simple Clone Classes (SCC)24% Methods Containing SCC25How frequent are the different types of structural clones?261Structural Clones are FrequentSimple clones tend to occur in groups56% of simple clones are within structural clonesThere are less structural clones than simple clones2727Simple Clone Classes (SCC) and Simple Clone Structures (SCS)28AVERAGE TOTALSCS7277257SCS Instances256725798Average Instances In SCS3Average Token Count (ATC) in SCS87Average % Cover(APC) in SCS9SCC Covered By SCS7037204% SCC Covered By SCS54Methods Containing SCS100910665% Methods Containing SCS14Files Containing SCS2983122% Files Containing SCS48Directories Containing SCS48467% Directories Containing SCS80Simple Clone Structures (SCS)Across Files29% SCC Covered By SCS Across Files30AVERAGE TOTALSCS3063229SCS Instances115812362Average Instances In SCS3SCC Covered By SCS6947278% SCC Covered By SCS55Methods Containing SCS105411093% Methods Containing SCS15Files Containing SCS2122216% Files Containing SCS36Directories Containing SCS41413% Directories Containing SCS72Simple Clone Structures (SCS)Within Files31% Files Containing SCS Within Files32AVERAGE TOTALSCS106710996SCS Instances378839398Average Instances In SCS3Average Token Count (ATC) in SCS55Average %Cover(APC) in SCS53SCC Covered By SCS108111168% SCC Covered By SCS86Methods Containing SCS330035666% Methods Containing SCS21Files Containing SCS3193344% Files Containing SCS52Directories Containing SCS50492% Directories Containing SCS82Simple Clone Structures (SCS) Across Methods33% SCC Covered By SCS Across Methods34Method Clone Classes (MCC) and Method Clone Structures (MCS)35AVERAGE TOTALMCC1651760MCC Instances4755068Average Instances In MCC2SCC Covered By MCC2963139% SCC Covered By MCC23Methods Covered By MCC4755068% Methods Covered By MCC7Files Containing MCC1962066% Files Containing MCC31Directories Containing MCC39385% Directories Containing MCC66Method Clone Classes (MCC)36AVERAGE TOTALMCS22230MCS Instances58612Average Instances In MCS2MCC Covered By MCS45484% MCC Covered By MCS4Methods Covered By MCS1621740% Methods Covered By MCS2Files Containing MCS36384% Files Containing MCS6Directories Containing MCS10106% Directories Containing MCS23Method Clone Structures (MCS) Across Files37File Clone Classes (FCC) and File Clone Structures (FCS)38AVERAGE TOTALFCC10112FCC Instances29314Average Instances In FCC3SCC Covered By FCC69755% SCC Covered By FCC5Files Containing FCC28307% Files Containing FCC4Directories Containing FCC10110% Directories Containing FCC23File Clone Classes (FCC)39AVERAGE TOTALFCS440FCS Instances1098Average Instances In FCS2FCC Covered By FCS438% FCC Covered By FCS40Files Containing FCS12116% Files Containing FCS2Directories Containing FCS764% Directories Containing FCS16File Clone Structures (FCS)Across Directories40AVERAGE TOTALFCS886FCS Instances25267Average Instances In FCS2FCC Covered By FCS883% FCC Covered By FCS66Files Covered By FCS20218% Files Covered By FCS3Directories Containing FCS664% Directories Containing FCS11File Clone Structures (FCS)Within Directories41Are structural clones more meaningful for program understanding and design recovery than simple clones?422Improved Program Understanding and Design RecoveryAnalysis is more qualitative than quantitativeanecdotal evidences of interesting examples of various types of structural clonesLarger program parts recovered as clones from a system are expected to be more meaningful than smaller onesHigh level structural clones like FCC and FCS appear to be a very useful tool for design recovery because of their size, highlighting the design level similarities between various parts of the system43FCC Examples from Apache-AntTCPCFTP.java458652%FTPTaskMirrorImpl.java457663% TarFileSetTest.java45190%ZipFileSetTest.java45190%44TCPCColonialAIPlayer.java513076%StandardAIPlayer.java508452% ReportCargoPanel.java68274%ReportNavalPanel.java68669%FCC examples from FreeCol45FCC examples from DrJava46File NamesTCPCBackSlashTest.java205084%SingleQuoteTest.java205088%FCC examples from JFreeChart47File NamesTCPCCombinedDomainCategoryPlot.java100850%CombinedDomainXYPlot.java100552%CombinedDomainXYPlot.java118261%CombinedRangeCategoryPlot.java118571%CombinedRangeXYPlot.java118263%FCC Example from Javax-Swing48File NamesTCPCMultiButtonUI.java64489 %MultiColorChooserUI.java64489 %MultiComboBoxUI.java79587 %MultiDesktopIconUI.java64489 %MultiDesktopPaneUI.java64489 %MultiFileChooserUI.java83375 %MultiInternalFrameUI.java64489 %MultiLabelUI.java64489 %MultiListUI.java70873 %MultiMenuBarUI.java64489 %MultiMenuItemUI.java64488 %MultiOptionPaneUI.java73787 %MultiPanelUI.java64489 %MultiPopupMenuUI.java70279 %MultiProgressBarUI.java64489 %FCC Example from Javax-Swing49File NamesTCPCMultiScrollBarUI.java64489 %MultiScrollPaneUI.java64489 %MultiSeparatorUI.java64489 %MultiSliderUI.java64489 %MultiSpinnerUI.java64489 %MultiSplitPaneUI.java86280 %MultiTabbedPaneUI.java70874 %MultiTableHeaderUI.java64489 %MultiTableUI.java64489 %MultiTextUI.java79853 %MultiToolBarUI.java64489 %MultiToolTipUI.java64489 %MultiTreeUI.java85961 %MultiViewportUI.java64489 %MultiRootPaneUI.java64489 %DirectoryTCPCFile Namerenderer/category/78651 %GradientBarPainter.javarenderer/xy/78651 %GradientXYBarPainter.javarenderer/category/5377 %BarPainter.javarenderer/xy/5376 %XYBarPainter.javaFCS Example from JFreeChart5051Clones77%,53 tokensClones51%,786 tokensClones77%,53 tokensClones51%,786 tokensGradientBarPainter.javaBarPainter.javaGradientXYBarPainter.javaXYBarPainter.javaImplementsImplementsFCS Example from JFreeChartGradientXYBarPainter is an implementation of theXYBarPainterinterface while GradientBarPainter is an implementation of theBarPainterin