When done manually, refactoring legacy code in order to eliminate uses of deprecated APIs is an error-prone and time-consuming process. In this paper, we investigate to which degree refactorings for deprecated Java APIs can be automated, and quantify the benefit of Javadoc code hints for this task. To this end, we build a symbolic and a neural engine for the automatic refactoring of deprecated APIs. The former is based on type-directed and component-based program synthesis, whereas the latter uses LLMs. We applied our engines to refactor the deprecated methods in the Oracle JDK 15. Our experiments show that code hints are enabling for the automation of this task: even the worst engine correctly refactors 71% of the tasks with code hints, which drops to at best 14% on tasks without. Adding more code hints to Javadoc can hence boost the refactoring of code that uses deprecated APIs.
翻译:手动重构遗留代码以消除废弃API的使用是一个易出错且耗时的过程。本文研究了废弃Java API重构的自动化程度,并量化了Javadoc代码提示对此任务的益处。为此,我们构建了符号引擎和神经引擎以实现废弃API的自动重构:前者基于类型导向和组件化的程序合成技术,后者则利用大语言模型(LLMs)。我们将这些引擎应用于重构Oracle JDK 15中的废弃方法。实验表明,代码提示是实现该任务自动化的关键:即使在最差的引擎配置下,使用代码提示也能正确重构71%的任务;若无代码提示,最佳情况下的正确率也仅能达到14%。因此,在Javadoc中增加代码提示可显著促进使用废弃API的代码重构工作。