"Extract Method" refactoring is a technique for consolidating code clones. Parameterization approaches are used to extract a single method from multiple code clones that contain differences. This approach parameterizes expressions and behaviors within a method. In particular, behavior parameterization has been extensively studied in Java programs, but little research has been conducted on other programming languages. Lambda expressions can be used to parameterize behaviors, but the specifications of each programming language significantly affect the applicability of this technique. Therefore, the optimal "Extract Method" approach may vary depending on the programming language. In this study, we propose a C#-specific technique that uses lambda expressions to analyze and consolidate code clones. We evaluated our proposed method by applying it to code clones detected by the NiCad clone detector and measuring how many of them could be successfully consolidated. In total, 2,217 clone pairs from 22 projects were included in our evaluation. For the clone pairs determined to be refactorable, we also attempted refactoring actually. The proposed approach determined that 35.0% of all clone pairs were suitable for refactoring. Among these, 28.9% were successfully refactored.
翻译:"提取方法"重构是一种用于整合代码克隆的技术。参数化方法被用于从包含差异的多个代码克隆中提取单一方法。该方法对方法内的表达式和行为进行参数化。特别是在Java程序中,行为参数化已得到广泛研究,但针对其他编程语言的研究却很少。Lambda表达式可用于参数化行为,但各编程语言的规范会显著影响该技术的适用性。因此,最优的"提取方法"策略可能因编程语言而异。在本研究中,我们提出了一种针对C#的特定技术,该技术利用Lambda表达式分析和整合代码克隆。我们通过将所提方法应用于NiCad克隆检测器发现的代码克隆,并测量其成功整合的比例来进行评估。评估共包含来自22个项目的2,217个克隆对。对于被判定为可重构的克隆对,我们还实际尝试了重构操作。所提出的方法判定全部克隆对中35.0%适合进行重构,其中28.9%成功完成了重构。