AntiCopyPaster 2.0: Whitebox just-in-time code duplicates extraction
Eman Abdullah AlOmar, Benjamin Knobloch, Thomas Kain, Christopher Kalish, Mohamed Wiem Mkaouer, Ali Ouni
TL;DR
Problem: Duplicate code hampers maintenance and comprehension, motivating proactive, just-in-time refactoring. Approach: extend AntiCopyPaster with a whitebox, rule-based detection framework that uses 78 metrics across keywords, coupling, complexity, and size, with percentile-based thresholds and a per-metric advanced settings interface, integrated into a four-stage pipeline (Duplicate Detector → Code Analyzer → Method Extractor → Refactoring Launcher). Contributions: configurable metrics, percentile sensitivity, multi-project support, and a transparent decision process that can reproduce prior refactorings. Findings: preliminary evaluation shows improved replication of refactorings and user-reported satisfaction with configurability, though some users desire better advanced guidance and multi-project support. Significance: enables tighter integration of refactoring into the developer workflow and customizable governance of when to extract methods.
Abstract
AntiCopyPaster is an IntelliJ IDEA plugin, implemented to detect and refactor duplicate code interactively as soon as a duplicate is introduced. The plugin only recommends the extraction of a duplicate when it is worth it. In contrast to current Extract Method refactoring approaches, our tool seamlessly integrates with the developer's workflow and actively provides recommendations for refactorings. This work extends our tool to allow developers to customize the detection rules, i.e., metrics, based on their needs and preferences. The plugin and its source code are publicly available on GitHub at https://github.com/refactorings/anti-copy-paster. The demonstration video can be found on YouTube: https://youtu.be/ Y1sbfpds2Ms.
