arXiv:2608.23377cs.SEAug 2026

Manuscript Offprint

arXiv:2608.23377

Formalizing and Automating Fine-Grained Move Refactorings Across Methods

Kota Yasuhara, Shinpei Hayashi

Kota Yasuhara

School of Computing

Institute of Science Tokyo

Tokyo, Japan

yasuhara@se.comp.isct.ac.jp

Shinpei Hayashi

School of Computing

Institute of Science Tokyo

Tokyo, Japan

hayashi@comp.isct.ac.jp

Abstract—Developers use automated Move refactorings to improve the modular structure of source code and the assignment of responsibilities. Class- and method-level Move refactorings are automated in modern IDEs, but statement- and expression-level moves that adjust method boundaries remain largely unautomated. We formalize five variants of Move Statement refactoring as preconditions and steps grounded in four basic conditions covering data reachability, execution count, side effects, and syntactic constraints required for compilation, of which all but the side-effect condition are checked statically. Combined with existing techniques, this also yields finer-grained moves of expressions and partial expressions. We further refine the formalization iteratively against a real project, deriving twenty additional preconditions and steps that handle Java syntactic diversity in practice. We evaluate applicability and compilability on ten projects, and behavior preservation in a case study on one of them: Move Statement refactorings yield compilable code in 93.3–97.0% of applicable cases, and the case study shows that the observed behavioral changes stem from side-effect reordering left to developer judgment, not from defects in the statically checked conditions.

Index Terms—refactoring, software maintenance, automation

I. INTRODUCTION

Refactoring has been widely used to improve the internal design of programs and continually improve the quality of modularization [1]. Because maintenance dominates software development costs [2], [3] and program complexity tends to increase as development continues [4], improving the quality of modularization is essential to keep programs from becoming overly complex [5]. Refactoring remains a substantial part of everyday development: developers report spending about 10% of their working time on refactoring [6], and recent large-scale studies confirm that it is practiced routinely [7], [8].

The Move Method refactoring [1] improves the quality of modularization by adjusting class boundaries and assigning methods to appropriate classes [9], [10]. Refactoring tools in Integrated Development Environments (IDEs) can apply it automatically and safely [11]–[13], and several approaches recommend Move Method opportunities [14]–[18].

Finer-grained move refactorings, beyond the granularity of methods, can play a significant role in improving modular structure. Whereas method-level move refactorings are limited to adjusting class boundaries, refactorings that move statement- or expression-level responsibilities between methods allow developers to flexibly redefine method boundaries and achieve more balanced responsibility assignments. They are actively performed in real-world projects: the refactoring detection tool RefactoringMiner [19], [20] identifies a refactoring named Localize Parameter, which converts a parameter into a local variable inside the callee method by moving the corresponding statement or expression from the call site into the callee. A recent empirical study by Zhao et al. [8] reports that Localize Parameter is performed on average 31.56 times per project, suggesting that developers frequently perform fine-grained move refactorings in practice. Despite this demand, the foundations for formalizing and automating such refactorings remain insufficient.

Fowler defines several statement-level move refactorings [1], but his informal catalog entries lack the precise preconditions and steps needed for automated, behavior-preserving application. Sasaki et al. formalized the conditions for moving statements to different locations within the same method [21], but their approach cannot move statements to different methods. Moreover, refactoring techniques for moving expressions have not been systematically established. Extract Local Variable extracts an expression into a statement and Extract Parameter moves an expression or a variable declaration to the callers as a parameter, but no technique moves a computation into the callee by turning a parameter into a variable declaration.

In this paper, we propose a systematic and automated approach for fine-grained move refactorings, including Move Statement and Move Expression, as shown in Fig. 1. When moving statements across methods, four basic conditions must be satisfied to preserve program behavior: data references, execution counts, side effects and their ordering, and syntactic and structural constraints required for compilation. To enforce these conditions, we statically analyze control flow and data dependencies, and define and automate the preconditions and steps of refactorings: all conditions but the side-effect one are guaranteed statically, whereas changes caused by side-effect reordering are deliberately left to developer judgment.

This paper focuses on the mechanics of fine-grained move refactorings: deciding whether a given move satisfies the statically checked applicability conditions and performing the transformation automatically. Deciding which statements

© 2026 IEEE. Personal use of this material is permitted. Permission from IEEE must be obtained for all other uses, in any current or future media, including reprinting/republishing this material for advertising or promotional purposes, creating new collective works, for resale or redistribution to servers or lists, or reuse of any copyrighted component of this work in other works.

Figure

Fig. 1. Fine-grained move refactorings addressed in this paper.

should move where, a judgment that involves the conceptual cohesion of the code, is a complementary recommendation problem, just as an Extract Method engine leaves the choice of what to extract to its user. Statically checked and automated mechanics are a prerequisite for any such recommender: a recommended move is useless if applying it breaks the program.

The recent rise of large language model (LLM)-based coding assistants reinforces rather than diminishes the need for formalized refactoring automation. LLMs edit code probabilistically and offer no guarantee of behavior preservation, whereas a formalized engine checks explicit conditions statically by construction, runs locally at interactive speed, and explains a rejection in terms of the violated precondition. The two are complementary rather than competing: recent Move Method assistants already combine LLM-based judgment about where code should live with static analysis that applies the change safely [24], [25]. Our formalization supplies this statically checked execution layer at the statement and expression granularity, so that once an LLM or a developer decides that a statement belongs in a callee, the application can be delegated to a deterministic engine. This division of labor becomes more valuable as agentic workflows chain many small edits, where per-step static checks keep errors from compounding. Once automated with such guarantees, fine-grained moves can also be composed at scale: this work is thus a first step toward automating responsibility-assignment refactoring that optimizes the assignment of statements to methods across a system [26]–[28].

The main contributions of this paper are as follows.

• We formalize fine-grained move refactorings, including five Move Statement and three Move Expression variants, of which four and one are newly formalized, respectively, grounded in four basic conditions covering data reachability, execution count, side effects, and syntactic constraints required for compilation.

• We propose an iterative refinement methodology that adds preconditions or steps based on failures observed on a real project, yielding twenty additional rules.

• We empirically evaluate the formalization on ten projects, reporting applicability, compile success rates of 93.3–97.0%, a test-based case study, and a cross-operation taxonomy of compile failures.

References (38)