摘要
代码克隆侦测对于代码重构以及可复用资产抽取都有着重要的作用.现有的克隆侦测方法及工具以相似代码片段为单位,给进一步的克隆分析以及代码重构带来困难.针对这一问题,本文提出了一种基于相似性度量的面向对象程序方法级克隆侦测方法,即以方法为单位进行克隆代码侦测.该方法综合利用代码中的注释、签名以及语法相似性来度量方法代码之间的克隆程度.在此基础上合并子类中的相似方法并提取到父类中,从而实现进一步的代码重构.本文通过对JDK包中代码的实验分析验证了本文所提出方法的有效性.初步的实验结果表明,本文方法能够准确、有效地辅助开发者实现方法级的克隆代码侦测.
Code clone detection is important for refactoring and extraction of reusable assets. The present code clone detec- tion method is on the basis of detection of similar code segments, which brings difficulty for further clone analysis and refactoring. Aiming at this problem, this paper offers a method level clone detection method for object-oriented program based on similarity measurement, which detects method level cloned code. Our method utilizes comments of the code, method signature and syntactic similarity to measure the degree of the clone. Based on the method mentioned above, further refactoring can be realized by combin- ing similar methods of sub-classes into one method and pulling it up into super-class. Our method' s effectiveness has been verified by analyzing the result of the experiment on the code of JDK. The initial experiment result shows that our method can help develop- er detect method level code clone both accurately and effectively.
出处
《电子学报》
EI
CAS
CSCD
北大核心
2010年第B02期174-181,共8页
Acta Electronica Sinica
基金
国家863高技术研究发展计划(No.2007AA01Z125,2009AA010307)
国家自然科学基金(No.60703092,60903013)
上海市科学技术委员会项目(No.08DZ2271800,09DZ2272800)
关键词
面向对象
代码克隆
克隆侦测
逆向工程
重构
object- oriented
code clone
clone detection
reverse engineering
refactoring