Rator: detecting fine-grained semantic code clones using tree encoding based on node degrees of freedom

Abstract Code clone detection has garnered significant attention across various fields, including code refactoring, plagiarism detection, and software maintenance. Numerous methods have been proposed for detecting code clones; however, while text-based and token-based approaches are scalable, they often fail to consider code semantics and are unable to effectively handle semantic code clones. Although tree-based methods perform well in semantic code clone detection, they are limited by the complex structure of trees, making it challenging to apply to large-scale clone detection. Moreover, these methods struggle to achieve fine-grained semantic code clone detection, lacking the ability to pinpoint specific code blocks within semantic clones. In this paper, we propose Rator , a tree-based code clone detector that combines scalability and fine-grained analysis capabilities while effectively detecting semantic clones. Specifically, we design a tree encoding method based on node degrees of freedom, which can transform complex tree structures into simple vector representations while preserving the structural details of the tree. In this way, we can encode all the subtrees of the abstract syntax tree into separate sets of vectors and derive similar features by calculating the similarity between these vectors. The derived similar features serve dual purposes: firstly, they are employed to train a machine learning-based code clone detector, and then, by analyzing the subtree types corresponding to the feature values, specific clone code blocks can be precisely located, thus achieving fine-grained code clone detection. Experimental results show that Rator outperforms nine state-of-the-art code clone detectors with F1 scores of 0.99 and 0.91 on BigCloneBench and Google Code Jam datasets, respectively. As for scalability, Rator is about 93 times faster than ASTNN , another state-of-the-art tree-based semantic clone detector. Regarding fine-grained detection, Rator correctly identifies the concrete clone block with a Top-3 ranked list. Furthermore, the accuracy of fine-grained detection on the Google Code Jam dataset is up to 100% with a Top-2 ranked list.

Authors

Institutions

Publication Details

Journal
Cybersecurity
Published
2026-02-03
DOI
https://doi.org/10.1186/s42400-025-00456-4
Primary Topic
Software Engineering Research
Type
article
Field-Weighted Citation Impact
0.00
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

Rator: detecting fine-grained semantic code clones using tree encoding based on node degrees of freedom

Rui Lou, Yutao Hu, Bing Sun, Huanwei Wang et al.
Cybersecurity
Software Engineering Research
article

Rator: detecting fine-grained semantic code clones using tree encoding based on node degrees of freedom

Rui Lou, Yutao Hu, Bing Sun, Huanwei Wang, Yu Zhang, Weiyu Dong
article en

Abstract

Abstract Code clone detection has garnered significant attention across various fields, including code refactoring, plagiarism detection, and software maintenance. Numerous methods have been proposed for detecting code clones; however, while text-based and token-based approaches are scalable, they often fail to consider code semantics and are unable to effectively handle semantic code clones. Although tree-based methods perform well in semantic code clone detection, they are limited by the complex structure of trees, making it challenging to apply to large-scale clone detection. Moreover, these methods struggle to achieve fine-grained semantic code clone detection, lacking the ability to pinpoint specific code blocks within semantic clones. In this paper, we propose Rator , a tree-based code clone detector that combines scalability and fine-grained analysis capabilities while effectively detecting semantic clones. Specifically, we design a tree encoding method based on node degrees of freedom, which can transform complex tree structures into simple vector representations while preserving the structural details of the tree. In this way, we can encode all the subtrees of the abstract syntax tree into separate sets of vectors and derive similar features by calculating the similarity between these vectors. The derived similar features serve dual purposes: firstly, they are employed to train a machine learning-based code clone detector, and then, by analyzing the subtree types corresponding to the feature values, specific clone code blocks can be precisely located, thus achieving fine-grained code clone detection. Experimental results show that Rator outperforms nine state-of-the-art code clone detectors with F1 scores of 0.99 and 0.91 on BigCloneBench and Google Code Jam datasets, respectively. As for scalability, Rator is about 93 times faster than ASTNN , another state-of-the-art tree-based semantic clone detector. Regarding fine-grained detection, Rator correctly identifies the concrete clone block with a Top-3 ranked list. Furthermore, the accuracy of fine-grained detection on the Google Code Jam dataset is up to 100% with a Top-2 ranked list.

CybersecurityVol. 9(1)
PLA Information Engineering University (CN), Jiangyin Traffic Planning Survey & Design Institute (China) (CN), Huazhong University of Science and Technology (CN)
Peace, Justice and strong institutions
Openalex Percentile: Top 79%
Software Engineering Research
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.