AST-Based Automated Elimination of break and continue Statements in Java Code
Abstract
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.
Create a lesson
Metadata
- Comments
- 9 pages, 1 figure. Source code available at https://github.com/andyjuarez-dev/automated-refactoring-java-code.git
Related papers
Did the Finding Go Away? Evidence for Closing Automated Code Review Findings
Shared title terminologycs.SEXuechun Luo, Weicheng Wang
Which Link Should I Look At First?: Automated Link Ranking in Code Reviews
Shared title terminologycs.SEPanya Trakoolgerntong, Arus Thienmee, Patsathorn Chadbantern et al.
What Moves the Ceiling on Automated Audit: from General Code to Scientific Code, Results and Data
Shared title terminologycs.SEZhaohe Dong
EA-Ops: Git-Native Architecture as Code for Continuous Enterprise Architecture Governance
Shared title terminologycs.SEVahid Tavakkoli, Kabeh Mohsenzadegan, Kyandoghere Kyamakya
Reusing Battle-tested Code: A Systematic Literature Review of Automated Software Transplantation
Shared title terminologycs.SEThanatad Songpetchmongkol, Earl T. Barr, Mark Harman et al.
Bridging UVM and Tessent: An Automated Co-Verification Framework for MBIST Designs
Shared title terminologycs.SEDo Ngoc Tiep, Cao Ngoc Thanh Do, Luu Danh Minh et al.