🤖 AI Summary
This work addresses the challenge of automating code clone refactoring in C#, particularly the absence of behavior parameterization—a feature commonly supported in Java but lacking in non-Java languages. We propose the first language-specific “Extract Method” refactoring technique for C# that leverages lambda expressions. Our approach integrates clone detection (using NiCad), static analysis, lambda abstraction modeling, and semantic equivalence verification to achieve clone merging and behavior parameterization. Evaluated on 22 open-source C# projects comprising 2,217 clone pairs, our method safely refactors 35.0% of clones, with 28.9% successfully undergoing end-to-end automated refactoring. This work breaks from the Java-centric paradigm in clone refactoring research and pioneers lambda-driven behavior parameterization for C# clone consolidation. By jointly considering C#-specific syntactic features and rigorous refactoring feasibility assessment, it establishes a novel, multi-language–aware pathway for clone governance.
📝 Abstract
"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.