arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2305.03428cs.SE
收藏

通过自动化提取方法重构支持单一职责

Supporting single responsibility through automated extract method refactoring

Alireza Ardalani, Saeed Parsa, Morteza Zakeri-Nasrabadi, Alexander Chatzigeorgiou

AI总结:

本文提出一种基于后向切片的自动化提取方法重构算法,将长方法分解为切片并提取为独立方法以实现单一职责,在GEMS基准和真实项目中显著提升了重构精确率与召回率,并改善了方法内聚度。

摘要:

方法/函数的职责是执行某些期望的计算,并通过各种交付物(包括对象字段和输出指令中的变量)将结果传递给其调用者。基于这一定义,本文提出了一种新算法,将长方法重构为具有单一职责的方法。我们提出了一种后向切片算法,将长方法分解为略微重叠的切片。切片针对每个输出指令计算,代表委托给该方法的职责结果。如果切片标准针对同一输出变量,则切片将不重叠。这些切片进一步被提取为独立方法,在满足特定行为保持条件时由原方法调用。所提方法在 GEMS 提取方法重构基准和三个真实世界项目上进行了评估。平均而言,实验表明,与最先进方法相比,在发现重构机会方面,精确率至少提高 29.6%,召回率提高 12.1%。此外,重构后工具将方法级内聚度指标平均提高 20%。实验结果证实了所提方法在提取单一职责方法中的适用性。

英文摘要:

The responsibility of a method/function is to perform some desired computations and disseminate the results to its caller through various deliverables, including object fields and variables in output instructions. Based on this definition of responsibility, this paper offers a new algorithm to refactor long methods to those with a single responsibility. We propose a backward slicing algorithm to decompose a long method into slightly overlapping slices. The slices are computed for each output instruction, representing the outcome of a responsibility delegated to the method. The slices will be non-overlapping if the slicing criteria address the same output variable. The slices are further extracted as independent methods, invoked by the original method if certain behavioral preservations are made. The proposed method has been evaluated on the GEMS extract method refactoring benchmark and three real-world projects. On average, our experiments demonstrate at least a 29.6% improvement in precision and a 12.1% improvement in the recall of uncovering refactoring opportunities compared to the state-of-the-art approaches. Furthermore, our tool improves method-level cohesion metrics by an average of 20% after refactoring. Experimental results confirm the applicability of the proposed approach in extracting methods with a single responsibility.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑