A method for clone detection of java source code
A source code, java-like technology, applied in the computer field, can solve the problems of poor generality and accuracy of clone detection methods, and achieve the effects of low cost, improved efficiency, and efficient detection
- Summary
- Abstract
- Description
- Claims
- Application Information
AI Technical Summary
Problems solved by technology
Method used
Image
Examples
Embodiment 1
[0041] Such as figure 1 As shown, a method for cloning detection of Java source code of the present invention comprises the following steps: S1: extracting the class in the Java source code as the minimum extraction unit; S2: uniformly replacing the function name and the variable name in the Java class; S3: Compare the classes in the Java source code, and output the comparison result.
[0042] During the implementation of this embodiment, the class in the Java source code is extracted as the minimum extraction unit, and the function name and variable name in the Java class are uniformly replaced, so that when different codes are cloned and detected, even if the function name and variable name in the class are When the variable name is changed, the accurate comparison of the class can also be realized, and then the clone detection of the entire code through the class can effectively improve the accuracy of the clone detection. This method is aimed at the exact same reuse of the...
Embodiment 2
[0044] In this embodiment, on the basis of Embodiment 1, step S2 includes the following sub-steps: scan each Java class, and uniformly replace the terminator representing the variable name in the Java class with a literal value; define a tag type for extending or customizing field.
[0045] During the implementation of this embodiment, in order to shield the impact of the variable name in the java source program on the clone code detection, each java class is scanned, and the terminators [id], [number], [ stringlit] and other basic types are uniformly replaced by the literal x, and the comment content is uniformly replaced by [comment], and the custom [tokens] section is used to extend or customize token types.
Embodiment 3
[0047] In this embodiment, on the basis of Embodiment 1, step S1 includes the following sub-steps: define a root non-terminator of a class, and use the root non-terminal as the root node to establish a parse tree; the parent nodes in the parse tree are all composed of The parent node is composed of a plurality of sorted child nodes; the parent nodes of the parsing tree are all non-terminators; the leaf nodes of the parsing tree are all terminators; the root non-terminals are represented as all leaf nodes the sequence of.
[0048] During the implementation of this embodiment, in order to further detect the java source program code clones that change, increase or delete program statements, but most of the text content of the code is the same, the present invention parses the class file and generates a parsing tree, according to the above method It is equivalent to defining each non-terminal from top to bottom, until each non-terminal is expressed as a series of terminators. In ...
PUM
Login to View More Abstract
Description
Claims
Application Information
Login to View More 


