发表机构
University of Málaga(马拉加大学)
机构由 AI 辅助整理,请以论文原文为准。AI 中文总结
该研究开发了一个基于Eclipse JDT API的Java自动重构工具,通过引入辅助布尔变量重写抽象语法树,消除循环中的break和continue语句,保持语义等价,并经测试和开源项目验证,支持后续提取方法等重构。
AI 中文摘要
本工作介绍了一个基于Eclipse JDT API构建的Java代码自动重构工具的开发。所提出的方法将不同类型循环中包含break和continue语句的控制结构转换为语义等价的构造,从而避免显式使用这些语句。为此,引入辅助布尔变量来重构控制流,同时保持原始程序行为不变。该转换的主要目标是改善代码结构,并支持后续自动化重构的应用,特别是基于提取方法操作的重构,这些操作通常受到跳转语句存在的限制。实现依赖于对抽象语法树(AST)的分析和重写,确保在所有处理场景中保持语义等价。该工具通过54个手动设计的测试用例和151个单元测试进行了验证,所有测试均产生了令人满意的结果。此外,它被应用于来自七个开源项目的139个方法,生成的代码无编译错误,并通过项目的测试套件验证了原始行为的保持。结果表明,所提出的方法能够安全地自动化重构包含break和continue语句的代码,促进进一步的代码演化和结构分析。
英文摘要
This work presents the development of an automatic refactoring tool for Java code built on top of the Eclipse JDT API. The proposed approach transforms control structures containing break and continue statements within different types of loops into semantically equivalent constructs that avoid their explicit use. To achieve this, auxiliary boolean variables are introduced to restructure the control flow while preserving the original program behavior. The main objective of this transformation is to improve code structure and enable the application of subsequent automated refactorings, particularly those based on the Extract Method operation, which are typically restricted by the presence of jump statements. The implementation relies on the analysis and rewriting of the Abstract Syntax Tree (AST), ensuring semantic equivalence in all addressed scenarios. The tool was validated through 54 manually designed test cases and 151 units tests, all of which produced satisfactory results. In addition, it was applied to 139 methods from seven open-source projects, generating code without compilation errors and preserving the original behavior as verified by the projects' test suites. The results demonstrate that the proposed approach safely automates the restructuring of code containing break and continue statements, facilitating further evolution and structural analysis.
Comments9 pages, 1 figure. Source code available at https://github.com/andyjuarez-dev/automated-refactoring-java-code.git