Skip to main navigation Skip to search Skip to main content

Extracting Conditional Expressions as Local Variables: Frequency, Motivation, and Automated Recommendation

  • Bridget Nyirongo
  • , Yanjie Jiang*
  • , Yuxia Zhang
  • , Hui Liu
  • *Corresponding author for this work
  • Beijing Institute of Technology
  • Tianjin University

Research output: Contribution to journalArticlepeer-review

Abstract

Software refactoring is essential for improving code readability and maintainability while reducing technical debt. Applying the extract local variable refactoring to condition expressions can simplify complex logic, enhance clarity, and reduce control-flow complexity. However, despite these benefits, mainstream IDEs and recent tool enhancements lack targeted, context-aware recommendations for this specific transformation. Understanding the patterns and contextual factors driving such extractions is necessary to augment existing tools with heuristics that promote meaningful and maintainable changes. To address this gap, this paper presents the first empirical study of extract local variable refactorings applied to conditional expressions, analyzing 984 instances across ten popular open-source Java projects. Our analysis shows that approximately 10.1% of extract local variable refactorings target condition expressions, highlighting their non-trivial presence in real-world projects. Through a two-round questionnaire survey, we identify and prioritize seven key motivations for applying extract variable to condition expressions, offering insight into developer intent. We further identify and validate twenty recurring features of such expressions, informing a set of practical heuristics that provide structural signals for suggesting this refactoring. Building on these findings, we introduce ConExtractor, a hybrid recommendation prototype combining heuristics with LLM evaluation. Across multiple LLM configurations, the hybrid approach achieves precision up to 96.7% and recall up to 88%, demonstrating its potential to provide selective and developer-aligned refactoring suggestions in practice.

Original languageEnglish
JournalIEEE Transactions on Software Engineering
DOIs
Publication statusAccepted/In press - 2026
Externally publishedYes

Keywords

  • Extract Condition
  • Extract Local Variable
  • IDE
  • Recommendation
  • Software Refactoring

Fingerprint

Dive into the research topics of 'Extracting Conditional Expressions as Local Variables: Frequency, Motivation, and Automated Recommendation'. Together they form a unique fingerprint.

Cite this