节点文献
重复代码检测技术的研究
Research on Detection Technology of Duplicated Code
【作者】 李建忠;
【导师】 刘建宾;
【作者基本信息】 汕头大学 , 计算机软件与理论, 2005, 硕士
【摘要】 软件会随着时间变得越来越难以理解,越来越难以维护。重构是在保持程序外部可观察行为不变情况下,对软件的内部结构进行重新改造和组织的技术,是获得软件质量的一项关键技术。然而“在哪使用哪种重构方法”始终是重构技术需解决的主要问题之一。 重复代码是程序中最常见的代码“坏味道”,Kontogiannis度量是检测重复代码的一种量化方法。然而,由于该度量方法所用的McCabe度量技术不能区分IF语句与循环语句的控制流复杂性,另外此方法不对两个比较函数的返回类型进行判断,因而在度量重复代码时会产生错误匹配。通过引入两个新的度量变量对其进行改进,提高该检测方法的准确性,并减少匹配错误。并通过引入过程蓝图改进它的检测过程,避免了要将源代码转换为抽象语法树这一复杂费时的工作,提高检测过程的效率。同时给出一种基于过程蓝图的程序环路复杂性度量实现方法,简化度量过程和实现,提高度量处理的效率。 Kontogiannis度量方法主要从代码的结构相似性识别重复代码,能识别出方法级的重复代码。Baker提出的参数化匹配方法能检测出方法级以下的重复代码,但它的空间复杂度要求过高,限制其能解决问题的范围。为此,我们引入过程蓝图改进该方法,降低程序的空间复杂度,并避免将源代码变换为后缀树这一复杂过程。 将两种方法有机地统一在同一语境下,避免在传统方法中须将它们分开处理的过程,即对相同的代码既要构造抽象语法树又要构造后缀树的过程,这样能更有效和更精确地检测出重复代码这种“坏味道”,为重构的自动定位和软件的自动重构提供一定的实现技术。
【Abstract】 Software continuously becomes more and more difficult to understand and maintain with time elapsing. Refactoring is a key technique to acquire software quality, which is to restructure and reorganize software without changing its external observable behaviour. However, "Where did Refactoring Come From" is one key issue to refactoring.Duplicated code is the worst "bad smells". Kontogiannis metrics is a technique of detecting the duplicated code. However, false matches will be taken place on account of two reasons, when this technique is used to detect the duplicated code. The first is that the complexity of the control flow between if statement and loops statement cannot be distinguished by the McCabe metrics, which is used by the Kontogiannis metrics. The second is that the Kontogiannis metrics doesn’t make judgement of the types of the returns of the two compared methods. In this paper. Kontogiannis metrics is improved by introducing two new variables so that the accuracy of detecting the duplicated code is raised and the false matches are reduced. And a technique based-on process blueprint is proposed, which measures the software cyclomatic complexity. This technique simplifies the process of the measuring and easy to implement. It is more efficient than the traditional method.Kontogiannis metrics search for duplicates using the knowledge that two clones have similar structural and functional properties, so it can recongnize the similar functions. The parameterized string matching method proposed by Baker can detect duplicated blocks. However, its ability to solve problem is limited for the space complexity. In order to reduce the space complexity of the arithmetic and avoid transforming the source code to p-suffix tree, the method is improved based-on process blueprint.Duplicated code can be detected accurately by integrating two different techniques organically in the same context. Based on process blueprint, we can avoid transforming the source code to not only abstract syntax tree but also p-suffix tree. So that more effective technology is provided for the localization of automatic refactoring.
- 【网络出版投稿人】 汕头大学 【网络出版年期】2005年 07期
- 【分类号】TP311.52
- 【被引频次】12
- 【下载频次】293