[Paper Review] Recommending Extract Method Refactoring Based on Confidence of Predicted Method Name
This paper proposes a novel approach to recommending Extract Method refactoring by leveraging the confidence score of method name predictions from code2seq, a state-of-the-art code-to-name model. By integrating this confidence metric with existing metrics in GEMS, the method significantly improves recommendation correctness, with code2seq confidence emerging as the most important feature, increasing F-measure and coverage over baseline techniques.
Refactoring is an important activity that is frequently performed in software development, and among them, Extract Method is known to be one of the most frequently performed refactorings. The existing techniques for recommending Extract Method refactoring calculate metrics from the source method and the code fragments to be extracted to order the recommendation candidates. This paper proposes a new technique for accurately recommending Extract Method refactoring by considering whether code fragments are semantically coherent chunks that can be given clear method names, in addition to the metrics used in previous studies. As a criterion for the semantic coherency, the proposed technique employs the probability (i.e. confidence) of the predicted method names for the code fragments output by code2seq, which is a state-of-the-art method name prediction technique. The evaluation experiment confirmed that the proposed technique has higher correctness of recommendation than the existing techniques.
Motivation & Objective
- To improve the accuracy of Extract Method refactoring recommendations by incorporating semantic coherence of code fragments.
- To address the limitation of existing techniques that ignore whether extracted code can be semantically named.
- To evaluate whether method name prediction confidence correlates with refactoring suitability.
- To extend the state-of-the-art GEMS framework with confidence-based filtering for better recommendation precision and recall.
Proposed method
- The proposed method uses code2seq to predict method names for candidate code fragments and extracts the confidence score of the top prediction.
- It integrates the confidence score as a new feature alongside traditional metrics (e.g., cohesion, complexity) used in GEMS.
- The model combines confidence with existing features such as TYPEDELE_COHESION, INVOCATION_COHESION, and RATIO_LOC to rank refactoring candidates.
- The technique is implemented as an extension of GEMS, using XGBoost for classification and feature importance analysis.
- Positive and negative examples are constructed from real refactoring data to train and evaluate the model.
- Feature importance is analyzed to assess the contribution of confidence relative to other metrics.
Experimental results
Research questions
- RQ1Does incorporating confidence from code2seq predictions improve the correctness of Extract Method refactoring recommendations?
- RQ2How does the confidence score of predicted method names correlate with the semantic coherence of code fragments?
- RQ3What is the relative contribution of confidence compared to traditional refactoring metrics in the recommendation model?
- RQ4Can confidence scores effectively distinguish between viable and non-viable refactoring candidates?
Key findings
- The proposed technique achieves higher F-measure than GEMS across all tolerance levels, confirming improved recommendation correctness.
- The confidence score from code2seq (CODE2SEQ_CONFIDENCE) became the most important feature, with an importance score of 0.30011, significantly outperforming the next most important feature.
- The mean confidence for positive (refactored) examples was 0.063695, higher than the 0.011233 mean for negative examples, indicating better semantic coherence in viable candidates.
- The median confidence for positive examples (0.0036578) was higher than for negative examples (0.00000049674), further supporting the discriminative power of confidence.
- The model's recall increased more than precision, indicating that confidence effectively expands the coverage of recommended refactoring targets.
- The confidence score contributed significantly to prediction, as shown by its dominance in feature importance rankings and consistent performance gains.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.