摘要
在软件开发过程中,克隆代码已经成为引起软件缺陷的一个重要因素。针对现有的方法不能很好地处理内聚度低、功能交叉的克隆代码的问题,提出了一种基于K-最近邻的克隆代码重构方法。首先,对克隆代码进行静态分析,搜集控制依赖信息和数据流信息,再经过K-最近邻聚类方法,形成便于提取、功能独立的代码片段,然后对代码片段进行过程提取,使之成为一个独立的过程,并用过程调用替代原来的克隆代码。实验结果表明,该方法能够对克隆代码进行有效组织,并对功能独立的部分进行提取。
In the development of software, code clones have been one of important causes for software defects. To solve the problem that the existing methods can not effectively handle low-cohesion and cross-functional code clones, this paper proposes a code clone restructuring approach based on k-nearest neighbor algorithm. Firstly, code clones are statically analyzed, and thereby the control dependency information and data flow information are collected. Then, k-nearest neighbor clustering algorithm is performed to form extractable or functional-independence code fragments. After that, a procedure extraction algorithm is performed on these code fragments to extract independent procedures. Finally, original code clones are replaced by the invocations of their corresponding procedures. Experiment results show that this method can effectively reorganize the structure of code clones and perform the extraction on functional independent code fragments.
作者
冯江辉
王甜甜
苏小红
马培军
FENG Jianghui, WANG Tiantian, SU Xiaohong, MA Peijun (School of Computer Science & Technology, Harbin Institute of Technology, HarDin, Heilongjiang, 150001)
出处
《智能计算机与应用》
2011年第1X期47-50,共4页
Intelligent Computer and Applications
基金
国家自然科学基金(61073052)
高等学校博士学科点专项科研基金(20092302110040).
关键词
重构
K-最近邻聚类算法
过程提取
静态分析
Restructuring
K-nearest Neighbor Clustering Algorithm
Procedure Extraction
Static Analysis