Three Heads Are Better Than One: Suggesting Move Method Refactoring Opportunities with Inter-class Code Entity Dependency Enhanced Hybrid Hypergraph Neural Network
Methods implemented in incorrect classes will cause excessive reliance on other classes than their own, known as a typical code smell symptom: feature envy, which makes it difficult to maintain increased coupling between classes. Addressing this issue, several Move Method refactoring tools have been proposed, employing a two-phase process: identifying misplaced methods to move and appropriate classes to receive, and implementing the mechanics of refactoring. These tools traditionally use hard-coded metrics to measure correlations between movable methods and target classes and apply heuristic thresholds or trained classifiers to unearth refactoring opportunities. Yet, these approaches predominantly illuminate pairwise correlations between methods and classes while overlooking the complex and complicated dependencies binding multiple code entities within these methods/classes that are prevalent in real-world cases. This narrow focus can lead to refactoring suggestions that may diverge from developers' actual needs. To bridge this gap, our paper leverages the concept of inter-class code entity dependency hypergraph to model complicated dependency relationships involving multiple code entities within various methods/classes and proposes a hypergraph learning-based approach to suggest Move Method refactoring opportunities named HMove. We first construct inter-class code entity dependency hypergraphs from training samples and assign attributes to entities with a pre-trained code model. All the attributed hypergraphs are fed into a hybrid hypergraph neural network for training. Utilizing this trained neural network alongside a large language model, we construct a refactoring suggestion system. We trained HMove on a large-scale dataset and evaluated it on two real-world datasets. The results show that demonstrates an increase of 27.8% in precision, 2.5% in recall, and 18.5% in f1-measure compared to 9 state-of-the-art refactoring tools, which is more useful for 68% of participants. The results also unveil practical suggestions and new insights that benefit existing feature envy-related refactoring techniques.
- Research Article
- 10.3390/app15084270
- Apr 12, 2025
- Applied Sciences
Move method refactoring (MMR) is one of the most commonly used software maintenance techniques to improve feature envy. Existing works focus on how to identify and recommend MMR. However, little is known about how MMR impacts program performance. There is a gap in knowledge regarding MMR and its performance impact. To address this gap, this paper proposes MovePerf, a novel approach to predicting performance for MMR based on deep learning and feature interaction. On the one hand, MovePerfselects 32 features based on observations from real-world projects. Furthermore, MovePerf obtains the execution time for each project after MMR as the performance label by employing a performance profiling tool, JMH. On the other hand, MovePerf builds a hybrid model to learn features from low-order and high-order interactions by composing a deep feedforward neural network and a factor machine. With this model, it predicts the performance for these projects after MMR. We evaluate MovePerf on real-world projects including JUnit, LC-problems, Kevin, and Concurrency. The experimental results show that MovePerf obtains an average MRE of 7.69%, illustrating that the predicted value is close to the real value. Furthermore, MovePerf improves the MRE from 1.83% to 8.61% compared to existing approaches, including a CNN, DeepFM, DeepPerf, and HINNPerf, demonstrating its effectiveness.
- Conference Article
16
- 10.1109/saner.2017.7884658
- Feb 1, 2017
We propose, in this paper, a lightweight refactoring recommendation tool, namely c-JRefRec, to identify Move Method refactoring opportunities based on four heuristics using static and semantic program analysis. Our tool aims at identiying refactoring opportunities before a code change is committed to the codebase based on current code changes whenever the developer saves/compiles his code. We evaluate the efficiency of our approach in detecting Feature Envy smells and recommending Move Method refactorings to fix them on three Java open-source systems and 30 code changes. Results show that our approach achieves an average precision of 0.48 and 0.73 of recall and outperforms a state-of-the-art approach namely JDeodorant.
- Research Article
155
- 10.1109/tse.2013.60
- Jul 1, 2014
- IEEE Transactions on Software Engineering
During software maintenance and evolution the internal structure of the software system undergoes continuous changes. These modifications drift the source code away from its original design, thus deteriorating its quality, including cohesion and coupling of classes. Several refactoring methods have been proposed to overcome this problem. In this paper we propose a novel technique to identify Move Method refactoring opportunities and remove the Feature Envy bad smell from source code. Our approach, coined as Methodbook, is based on relational topic models (RTM), a probabilistic technique for representing and modeling topics, documents (in our case methods) and known relationships among these. Methodbook uses RTM to analyze both structural and textual information gleaned from software to better support move method refactoring. We evaluated Methodbook in two case studies. The first study has been executed on six software systems to analyze if the move method operations suggested by Methodbook help to improve the design quality of the systems as captured by quality metrics. The second study has been conducted with eighty developers that evaluated the refactoring recommendations produced by Methodbook. The achieved results indicate that Methodbook provides accurate and meaningful recommendations for move method refactoring operations.
- Conference Article
33
- 10.1145/3387940.3392191
- Jun 27, 2020
Software refactoring plays an important role in increasing code quality. One of the most popular refactoring types is the Move Method refactoring. It is usually applied when a method depends more on members of other classes than on its own original class. Several approaches have been proposed to recommend Move Method refactoring automatically. Most of them are based on heuristics and have certain limitations (e.g., they depend on the selection of metrics and manually-defined thresholds). In this paper, we propose an approach to recommend Move Method refactoring based on a path-based representation of code called code2vec that is able to capture the syntactic structure and semantic information of a code fragment. We use this code representation to train a machine learning classifier suggesting to move methods to more appropriate classes. We evaluate the approach on two publicly available datasets: a manually compiled dataset of well-known open-source projects and a synthetic dataset with automatically injected code smell instances. The results show that our approach is capable of recommending accurate refactoring opportunities and outperforms JDeodorant and JMove, which are state of the art tools in this field.
- Conference Article
19
- 10.1109/icsme55016.2022.00033
- Oct 1, 2022
Incorrect placement of methods within classes is a typical code smell called Feature Envy, which causes additional maintenance and cost during evolution. To remove this design flaw, several Move Method refactoring tools have been proposed. To the best of our knowledge, state-of-the-art related techniques can be broadly divided into two categories: the first line is non-machine-learning-based approaches built on software measurement, while the selection and thresholds of software metrics heavily rely on expert knowledge. The second line is machine learning-based approaches, which suggest Move Method refactoring by learning to extract features from code information. However, most approaches in this line treat different forms of code information identically, disregarding their significant variation on data analysis. In this paper, we propose an approach to recommend Move Method refactoring named RMove by automatically learning structural and semantic representation from code fragment respectively. We concatenate these representations together and further train the machine learning classifiers to guide the movement of method to suitable classes. We evaluate our approach on two publicly available datasets. The results show that our approach outperforms three state-of-the-art refactoring tools including PathMove, JDeodorant, and JMove in effectiveness and usefulness. The results also unveil useful findings and provide new insights that benefit other types of feature envy refactoring techniques.
- Conference Article
- 10.1145/3132498.3132511
- Sep 18, 2017
Similarity coefficients are used by several techniques to identify refactoring opportunities. As an example, it is expected that a method is located in a class that is structurally similar to it. However, the existing coefficients in Literature have not been designed for the structural analysis of software systems, which may not guarantee satisfactory accuracy. This paper, therefore, proposes new coefficients---based on genetic algorithms over a training set of ten systems---to improve the accuracy of the identification of Move Class, Move Method, and Extract Method refactoring opportunities. We conducted an empirical study comparing these proposed coefficients with other 18 coefficients in other 101 systems. The results indicate, in relation to the best analyzed coefficient, an improvement of 10.57% for the identification of Move Method refactoring opportunities, 3.17% for Move Class, and 0.30% for Extract Method. Moreover, we implemented a tool that relies on the proposed coefficients to recommend refactoring opportunities.
- Research Article
68
- 10.1016/j.jss.2017.11.073
- Dec 9, 2017
- Journal of Systems and Software
JMove: A novel heuristic and tool to detect move method refactoring opportunities
- Conference Article
6
- 10.1109/iwor.2019.00012
- May 1, 2019
Previous studies introduced various techniques for detecting Move Method refactoring opportunities. However, different authors have different evaluations, which leads to the fact that results reported by different papers do not correlate with each other and it is almost impossible to understand which algorithm works better in practice. In this paper, we provide an overview of existing evaluation approaches for Move Method refactoring recommendation algorithms, as well as discuss their advantages and disadvantages. We propose a tool that can be used for generating large synthetic datasets suitable for both algorithms evaluation and building complex machine learning models for Move Method refactoring recommendation.
- Conference Article
41
- 10.1145/1985793.1985913
- May 21, 2011
We propose a novel approach to identify Move Method refactoring opportunities and remove the Feature Envy bad smell from source code. The proposed approach analyzes both structural and conceptual relationships between methods and uses Relational Topic Models to identify sets of methods that share several responsabilities, i.e., 'friend methods'. The analysis of method friendships of a given method can be used to pinpoint the target class (envied class) where the method should be moved in. The results of a preliminary empirical evaluation indicate that the proposed approach provides meaningful refactoring opportunities.
- Research Article
- 10.1109/tla.2026.11369405
- Feb 1, 2026
- IEEE Latin America Transactions
The Move Method refactoring is crucial for mitigating the Feature Envy code smell, which enhances cohesion and reduces coupling by relocating methods to more suitable classes. Existing deep learning approaches often suffer from redundant features, limiting model generalization. To address this, this paper introduces GMove, a novel approach leveraging feature fusion and a hybrid deep learning architecture (Bi-LSTM and CNN branches) to recommend refactoring opportunities. By fusing semantic, structural, and metric features from a constructed 16,828-sample dataset, GMove effectively filters redundant information. Experimental results demonstrate that GMove achieves a high synthetic F1 score of 97.7% and significantly outperforms state-of-the-art refactoring tools, showing an average F1 improvement of 9.7% over the strongest modern baseline, affirming its effectiveness and novel fusion strategy.
- Research Article
347
- 10.1109/tse.2009.1
- May 1, 2009
- IEEE Transactions on Software Engineering
Placement of attributes/methods within classes in an object-oriented system is usually guided by conceptual criteria and aided by appropriate metrics. Moving state and behavior between classes can help reduce coupling and increase cohesion, but it is nontrivial to identify where such refactorings should be applied. In this paper, we propose a methodology for the identification of Move Method refactoring opportunities that constitute a way for solving many common feature envy bad smells. An algorithm that employs the notion of distance between system entities (attributes/methods) and classes extracts a list of behavior-preserving refactorings based on the examination of a set of preconditions. In practice, a software system may exhibit such problems in many different places. Therefore, our approach measures the effect of all refactoring suggestions based on a novel entity placement metric that quantifies how well entities have been placed in system classes. The proposed methodology can be regarded as a semi-automatic approach since the designer will eventually decide whether a suggested refactoring should be applied or not based on conceptual or other design quality criteria. The evaluation of the proposed approach has been performed considering qualitative, metric, conceptual, and efficiency aspects of the suggested refactorings in a number of open-source projects.
- Research Article
- 10.31891/2307-5732-2025-359-125
- Dec 19, 2025
- Herald of Khmelnytskyi National University. Technical sciences
The study introduces a method for decomposing monolithic information system architectures through clustering of node embeddings obtained from Graph Neural Networks (GNNs). The software is represented as a directed graph of code entities, where nodes correspond to business classes and edges capture import or invocation dependencies. A two-layer GraphSAGE model with mean aggregation generates embeddings that combine structural and contextual features. The resulting representations are clustered using k-means to delineate potential microservice boundaries. The method was evaluated on an open-source e-commerce monolith written in C#. The codebase comprises over 190 classes across five business domains: Products, Orders, Customers, Inventory, and Categories. Compared with a baseline that applies k-means to raw CodeBERT embeddings, the proposed approach achieved higher clustering quality, reaching a Silhouette score of 0.69 versus 0.24. Two additional metrics confirmed the results: Normalized Mutual Information (NMI = 0.74), reflecting the similarity between detected clusters and reference domains, and Adjusted Rand Index (ARI = 0.68), accounting for random agreement (averaged over ten independent runs). Both indicate stable and consistent alignment with functional areas of the system. Analysis of the resulting clusters shows that GNN-based embeddings capture not only syntactic but also semantic relations among program entities, producing interpretable partitions that correspond to domain modules. The method serves as a reproducible, data-driven aid for architectural refactoring and supports the transition of legacy monolithic systems toward microservice architectures. Future research aims to include dynamic call-graph data, version-history information, and community-detection algorithms to automate cluster number selection and improve scalability for large-scale projects.