Automating refactoring detection is an important goal in software engineering, with the potential to significantly reduce development time and costs. However, the complexity of refactoring tasks and the need for language-specific knowledge make the development of general-purpose solutions challenging. While machine learning models have proven effective in detecting refactorings in widely used languages like Java, their applicability to other languages–such as Kotlin–remains largely unexplored, especially due to the limited availability of labeled datasets. This study investigates the feasibility of zero-shot cross-language refactoring detection by applying machine learning models trained on Java to identify refactorings in Kotlin. We employ Random Forest classifiers, originally trained on Java code, to detect seven types of class-level refactorings in Kotlin projects. For evaluation, we use RefDetect–an established refactoring detection tool–to extract 2,540 class-level refactorings from approximately 30,000 commits across 10 open-source Kotlin repositories. The Java-trained models are then applied to these projects, and their predictions are compared against RefDetect’s results to assess accuracy and generalizability. Our evaluation shows that the Java-trained models achieve an average F-score of 71% in detecting class-level refactorings in Kotlin. The model demonstrates strong recall (84%), indicating its ability to detect most actual refactorings, but precision is more modest (66%), suggesting a higher rate of false positives. Our analysis shows that model performance is influenced by both the type of refactoring and the characteristics of individual repositories. Refactorings such as Move Class, Extract Interface, and Rename Class consistently yield high F-scores–often above 90%. In contrast, less frequent refactorings like Extract Subclass and Extract Superclass yield significantly lower F-scores, around 40%. Detection accuracy for individual refactoring types also differs between repositories, implying that project-specific factors (e.g., code structure and refactoring frequency) influence model predictions. This observed variability highlights the potential benefits of tailoring detection strategies to match the unique characteristics of each project and refactoring type.

错误:搜索内容不能为空,请输入英文关键词
错误:关键词超出字数限制,请精简
高级检索

Refactoring Detection Across Languages: Leveraging Java-Trained Models for Detecting Class-Level Refactorings in Kotlin

  • Mohammad Mehdi Afkhami,
  • Iman Hemati Moghadam,
  • Vadim Zaytsev,
  • Mohammad Hossein Ashoori,
  • Hossein Bazmandegan

摘要

Automating refactoring detection is an important goal in software engineering, with the potential to significantly reduce development time and costs. However, the complexity of refactoring tasks and the need for language-specific knowledge make the development of general-purpose solutions challenging. While machine learning models have proven effective in detecting refactorings in widely used languages like Java, their applicability to other languages–such as Kotlin–remains largely unexplored, especially due to the limited availability of labeled datasets. This study investigates the feasibility of zero-shot cross-language refactoring detection by applying machine learning models trained on Java to identify refactorings in Kotlin. We employ Random Forest classifiers, originally trained on Java code, to detect seven types of class-level refactorings in Kotlin projects. For evaluation, we use RefDetect–an established refactoring detection tool–to extract 2,540 class-level refactorings from approximately 30,000 commits across 10 open-source Kotlin repositories. The Java-trained models are then applied to these projects, and their predictions are compared against RefDetect’s results to assess accuracy and generalizability. Our evaluation shows that the Java-trained models achieve an average F-score of 71% in detecting class-level refactorings in Kotlin. The model demonstrates strong recall (84%), indicating its ability to detect most actual refactorings, but precision is more modest (66%), suggesting a higher rate of false positives. Our analysis shows that model performance is influenced by both the type of refactoring and the characteristics of individual repositories. Refactorings such as Move Class, Extract Interface, and Rename Class consistently yield high F-scores–often above 90%. In contrast, less frequent refactorings like Extract Subclass and Extract Superclass yield significantly lower F-scores, around 40%. Detection accuracy for individual refactoring types also differs between repositories, implying that project-specific factors (e.g., code structure and refactoring frequency) influence model predictions. This observed variability highlights the potential benefits of tailoring detection strategies to match the unique characteristics of each project and refactoring type.