摘要
单个软件系统中以及若干个相似系统之间的代码克隆给软件维护增加了很大困难.本文针对运用克隆侦测发现的相似代码片断,提出一种基于抽象语法树和静态分析的代码自动重构方法.该方法首先为克隆代码分别构造抽象语法树,然后运用语句差异度指标建立起语法树之间流程控制语句的对应关系.在此基础上,该方法根据控制流程和基本语句块两个层次上的差异性分析,最终通过代码可变点提取实现克隆代码的自动合并.针对Java代码开发了克隆代码重构支持工具原型,并分别针对JDK1.5和一个业务系统进行了自动重构实验.初步的结果表明,该方法能够准确、有效地辅助开发者实现克隆代码的自动重构.
Code clone in single software system or several similar systems makes software maintenance very difficult. This paper offers an automatic refactoring method of detected cloned code based on abstract syntax tree and static analysis. At first, this method builds abstract syntax trees for cloned code separately. Then the difference between statements is used to establish the relationship between flow control statements in abstract syntax trees. Based on these steps, this method analyses the difference between flow control statements and the difference between simple statement blocks, and finally combines the cloned code through extracting the variation points in source code. We have developed a prototype tool which supports refatoring of cloned code of Java. And experiments on automatic refactoring are taken on JDK1.5 and a business system. The initial result shows that this method can assist developer achieve the goal of automatically refatoring of cloned code both accurately and effectively.
出处
《小型微型计算机系统》
CSCD
北大核心
2009年第9期1752-1760,共9页
Journal of Chinese Computer Systems
基金
国家自然科学基金项目(60703092)资助
国家"八六三"高技术研究发展计划项目(2006AA01Z189
2007AA01Z125)资助
关键词
可变点提取
代码克隆
抽象语法树
再工程
逆向工程
variation point extraction
code clone
abstract syntax tree
reengineering
reverse engineering