Automated pattern-directed refactoring for complex conditional statements
来源期刊:中南大学学报(英文版)2014年第5期
论文作者:刘伟 胡志刚 LIU Hong-tao(刘宏韬) YANG Liu(杨柳)
文章页码:1935 - 1945
Key words:refactoring; abstract syntax tree; complex conditional statements; design patterns; factory method pattern; strategy pattern
Abstract: Complex conditional statement is one of the bad code smells, which affects the quality of the code and design of software. In the proposed approach, two commonly-used design patterns for handling complex conditional statements are selected, and they are the factory method pattern and the strategy pattern. Two pattern-directed refactoring approaches based on the two design patterns are proposed. Each approach contains a refactoring opportunities identification algorithm and an automated refactoring algorithm. After parsing the abstract syntax tree generated from source code, the refactoring opportunities are identified effectively and automatically. Then, for candidate code, refactoring algorithms are executed automatically, which are used to simplify or remove complex conditional statements. By empirical analysis and quality assessment, the code after refactoring has better maintainability and extensibility, and the proposed approach for automated pattern-directed refactoring succeeds to reduce code size and complexity of classes.
LIU Wei(刘伟)1, HU Zhi-gang(胡志刚)1,2, LIU Hong-tao(刘宏韬)2, YANG Liu(杨柳)2
(1. School of Information Science and Engineering, Central South University, Changsha 410083, China;
2. School of Software, Central South University, Changsha 410075, China)
Abstract:Complex conditional statement is one of the bad code smells, which affects the quality of the code and design of software. In the proposed approach, two commonly-used design patterns for handling complex conditional statements are selected, and they are the factory method pattern and the strategy pattern. Two pattern-directed refactoring approaches based on the two design patterns are proposed. Each approach contains a refactoring opportunities identification algorithm and an automated refactoring algorithm. After parsing the abstract syntax tree generated from source code, the refactoring opportunities are identified effectively and automatically. Then, for candidate code, refactoring algorithms are executed automatically, which are used to simplify or remove complex conditional statements. By empirical analysis and quality assessment, the code after refactoring has better maintainability and extensibility, and the proposed approach for automated pattern-directed refactoring succeeds to reduce code size and complexity of classes.
Key words:refactoring; abstract syntax tree; complex conditional statements; design patterns; factory method pattern; strategy pattern