• 中国计算机学会会刊
  • 中国科技核心期刊
  • 中文核心期刊

J4 ›› 2010, Vol. 32 ›› Issue (4): 71-74.doi: 10.3969/j.issn.1007130X.2010.

• 论文 • 上一篇    下一篇

相似代码检测工具及其案例分析

李卓,邓明荣   

  1. (浙江大学管理学院,浙江 杭州 310028)
  • 收稿日期:2009-06-25 修回日期:2009-10-12 出版日期:2010-03-28 发布日期:2010-03-28
  • 通讯作者: 李卓 E-mail:lizhuo@zju.edu.cn

A Code Similarity Detection Tool and Its Case Study

LI Zhuo,DENG Mingrong   

  1. (School of Management,Zhejiang University,Hangzhou 310028,China)
  • Received:2009-06-25 Revised:2009-10-12 Online:2010-03-28 Published:2010-03-28
  • Contact: LI Zhuo E-mail:lizhuo@zju.edu.cn

摘要: 软件系统中的相似代码给软件维护带来很大困难,也是最易见的重构对象。如何有效地检测相似代码是软件工程领域的一个重要研究课题。本文介绍了常见的基于文本匹配的相似代码检测算法,尤其是检测源文件之间相似代码的动态文本匹配算法和源文件内部相似代码的后缀树算法,并将这两种算法结合起来,实现一个相似代码检测工具。该工具提供了时空代价平衡的相似代码检测能力,提供了精确有效的相似代码检测手段,帮助开发人员锁定相似代码,提高了重构活动的效率。本文介绍了该工具的架构和内部处理流程,并应用该工具搜索了若干实际应用系统的重复代码,检验了工具的可用性。还简单讨论了该工具和其他一些相似代码检测工具的优劣。

关键词: 相似代码检测, 动态文本匹配, 后缀树, 重构

Abstract: Similar code detection is a common entry point of software refactoring activities. The paper firstly introduces texts mappingbased similar code detection algorithms like the dynamic text mapping algorithm and the suffix tree algorithm. Based on the combination of these two algorithms, a tool for automated similar code detection is implemented. This tool provides not only a capability to detect similar code both between and within the source files, for an improved accuracy, but also an automatic approach to help developers secure similar code candidates, hence improves the efficiency of software refactoring. Finally, the paper analyzes the experimental outputs of practical programs in a financial information system. Its practicality is shown.

Key words: similar code detection;dynamic text mapping;suffix tree;refactoring

中图分类号: