A light weight hybrid approach to detect code clones

Code cloning is the process of reusing the code portions of different parts of the same project or proven good portions of different projects. The harmfulness of code clones are presented by the literature of the code cloning. In this paper we are proposing a hybrid light weight approach to detect various types of clones. CLONE DETECTION PROCESS Several approaches are proposed by different people and organizations in code clone literature. In this paper the proposed clone detection process is discussed in detail. In other words this paper explains theoretical model of the proposed system. Clone Detection Process: Proposed Model In a system‟s source text, a clone detector locates pieces of code which are of high similarity. The major difficulty is that it is hard to make out beforehand about the code fragments that can be repeated multiple times. Hence, each possible fragment should be compared to every other possible fragment. This is an expensive comparison from the view of computational time. Many measures have been taken to reduce the comparison domain before the performance of the actual comparison. If the potential cloned fragments are located future analysis is taken up to identify the actual clones. In the proposed method, to make out all varieties of clones which are present in the source code, a hybrid technique is adapted. This approach is based on textual and metric analysis. Clone detection technique which is text based utilizes the transformation. This includes removal of comments and removal of whitespaces. It is considered as one of the fastest clone detection approaches. This is because the syntactical or semantical analysis of source is not performed by the text based technique. It deals easily with type I clones and type II clones with additional data transformation. Metric based technique follows a different method. Instead of making comparisons directly on the code, metric based technique gathers different metrics of code and makes the comparison of these metric values to detect clones. For detecting similar codes, various clone detection techniques use only metrics these days. The proposed method can be implemented to find clones in JAVA. The method which has system architecture is shown in Figure 3.1 Metric based and text based techniques are used by the proposed approach in order to detect clones. These clones are divided into two stages. For the selection of potential code metric based technique is used in the first stage. In the second stage, metric match is used to select potential clones. After the selection, the potential clones are processed further along with text based technique. The proposed research methodology aims to trace out clones with textual analysis using metrics. Clone detection process can be either textual or one that has metric analysis traditionally. The comparison is done line by line for potential clones in order to determine if two potential clones are truly clones of each other. Soon after the beginning of the process, the method developed examines the given input source code and recognizes the different methods which are present. SSRG International Journal of Mobile Computing & Application (SSRG-IJMCA) – volume 2 Issue 6 Nov to Dec 2015 ISSN: 2393 9141 www.internationaljournalssrg. org Page 27 Figure 3.1: Clone Detection Architecture (block diagram) There are many phases in clone detection process. These phases involve input and preprocessing, conversion of template, computation of metrics and lastly detection of clone types. If the pairs show similarity when textual comparison is done, those pairs are listed as clones. The developed method for detection does not use any external parsers. In comparison to the methods, it needs less overhead when it comes to complexity, and SSRG International Journal of Mobile Computing & Application (SSRG-IJMCA) – volume 2 Issue 6 Nov to Dec 2015 ISSN: 2393 9141 www.internationaljournalssrg. org Page 28 processing time in terms of precision and recall values. Preprocessing and Input Selection In this phase the source code which is uninteresting for the comparison phase is filtered. File integration, standardization of source code and source code normalization are included in this phase. The grouping of all the files of a project into one large single file for external examination is done in file integration. The concatenation of all the files which belong to the same project is transformed into one large file convenient for external parsing in file