🤖 AI Summary
Existing refactoring tools struggle to automatically identify opportunities to replace custom logic with equivalent API invocations, as they rely on predefined templates and fail to effectively model semantic equivalence across multiple statements. This work presents the first systematic characterization of the scope, categories, and patterns of API-replacement refactoring and introduces AKIRA, a hybrid recommendation framework that integrates static pattern matching with semantic reasoning, augmented by a refactoring-aware knowledge base. Evaluated through empirical analysis of 166,299 open-source Java commits and manual validation, AKIRA achieves 90% recall and 88% precision on an internal dataset and substantially improves performance on the external RETIWA dataset, increasing recall from 21% to 81% and precision from 40% to 78%, thereby significantly enhancing the accuracy and feasibility of identifying complex API-replacement refactorings.
📝 Abstract
Software refactoring is essential for maintaining code quality. However, API replacement refactoring, which replaces custom logic with API calls, remains underexplored. Existing refactoring tools provide limited support for detecting such opportunities because they rely on predefined templates and have difficulty capturing complex, multi-statement semantic equivalents. To address this limitation, we conduct the first empirical study of API replacement refactorings by mining 166,299 commits across six open-source Java projects and manually analyzing a curated subset of 1,800 commits, from which we identify 366 validated instances to characterize their scope, categories, and recurring patterns. Based on these insights, we propose AKIRA (Adaptive Knowledge Discovery and Retrieval), a hybrid framework that integrates pattern-deterministic heuristics with a refactoring-aware knowledge base to assess the practical feasibility of recommending API replacement refactorings. Our evaluation shows that AKIRA achieves 90% recall and 88% precision on a manually curated dataset. Furthermore, on the external RETIWA dataset, AKIRA significantly improves the state of the art by increasing recall from 21% to 81% and precision from 40% to 78%. These results demonstrate the effectiveness of combining static pattern matching with semantic reasoning to support the automation of recommending complex API replacement refactorings.