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.
Similar content being viewed by others
References
FOWLER M, BECK K. Refactoring-Improving the design of existing code [M]. Massachusetts: Addison-Wesley, 1999: 63–71.
VAKILIAN M, CHEN N, NEGARA S, RAJKUMAR A B, BAILEY P B, JOHNSON E R. Use, disuse, and misuse of automated refactorings [C]// Proceedings of the 34th International Conference on Software Engineering (ICSE). Zurich, 2012: 233–243.
MURPHY-HILL E, PARNIN C, BLACK A P. How we refactor, and how we know It [J]. IEEE Transaction on Software Engineering, 2012, 38(1): 5–18.
DALLAL J A. Constructing models for predicting extract subclass refactoring opportunities using object-oriented quality metrics [J]. Information and Software Technology, 2012, 54(10): 1125–1141.
TSANTALIS N, CHATZIGEORGIOU A. Identification of move method refactoring opportunities [J]. IEEE Transaction on Software Engineering, 2009, 35(3): 347–367.
TSANTALIS N, CHATZIGEORGIOU A. Identification of extract method refactoring opportunities [C]// Proceedings of the 13th European Conference on Software Maintenance and Reengineering (CSMR’09). Kaiserslautern, 2009: 119–128.
TSANTALIS N, CHATZIGEORGIOU A. Identification of extract method refactoring opportunities for the decomposition of methods [J]. Journal of Systems and Software, 2011, 84(10): 1757–1782.
TSANTALIS N, CHATZIGEORGIOU A. Identification of refactoring opportunities introducing polymorphism [J]. Journal of Systems and Software, 2010, 83(3): 391–404.
FOKAEFS M, TSANTALIS N, STROULIA E, CHATZIGEORGIOU A. Identification and application of extract class refactorings in object-oriented systems [J]. Journal of Systems and Software, 2012, 85(10): 2241–2260.
BAVOTA G, De LUCIA A, OLIVETO R. Identifying extract class refactoring opportunities using structural and semantic cohesion measures [J]. Journal of Systems and Software, 2011, 84(3): 397–414.
LIU Hui, NIU Zhen-dong, MA Zhi-yi, SHAO Wei-zhong. Identification of generalization refactoring opportunities [J]. Automated Software Engineering, 2013, 20(1): 81–110.
HIGO Y, KUSUMOTO S, INOUE K. A metric-based approach to identifying refactoring opportunities for merging code clones in a Java software system [J]. Journal of Software Maintenance and Evolution: Research and Practice, 2008, 20(6): 435–461.
KOMONDOOR R, HORWITZ S. Using slicing to identify duplication in source code [C]// Proceedings of the 8th International Symposium on Static Analysis. Paris, 2001: 40–56.
KERIEVSKY J. Refactoring to patterns [M]. Massachusetts: Addison-Wesley, 2004: 52–54.
GAMMA E, HELM R, JOHNSON R, VLISSIDES J. Design patterns: Elements of reusable object-oriented software [M]. Massachusetts: Addison-Wesley, 1995: 8–9.
CHRISTOPOULOU A, GIAKOUMAKIS E A, ZAFEIRIS V E, SOUKARA V. Automated refactoring to the Strategy design pattern [J]. Information and Software Technology, 2012, 54(11): 1202–1214.
JEBELEAN C, CHIRILA C B, CRETU V. A logic based approach to locate composite refactoring opportunities in object-oriented code [C]// Proceedings of the 2010 IEEE International Conference on Automation Quality and Testing Robotics (AQTR). Cluj-Napoca, 2010: 1–6.
JEON S U, LEE J S, BAE D H. An automated refactoring approach to design pattern-based program transformations in java programs [C]// Proceedings of the 9th Asia-Pacific Software Engineering Conference (APSEC). Queensland, 2002: 337–345.
JUILLERAT N, HIRSBRUNNER B. Toward an Implementation of the “Form Template Method” [C]// Proceedings of the 7th IEEE International Working Conference on Source Code Analysis and Manipulation (SCAM 2007). Paris, 2007: 81–90.
KUHN T, THOMANN O. Eclipse corner article abstract syntax tree [EB/OL]. [2006-11-20]. http://www.eclipse.org/articles/Article-JavaCodeManipulationAST/index.html.
Eclipse-The Eclipse Foundation open source community website. [EB/OL]. [2013-04-16]. http://www.eclipse.org/.
Author information
Authors and Affiliations
Corresponding author
Rights and permissions
About this article
Cite this article
Liu, W., Hu, Zg., Liu, Ht. et al. Automated pattern-directed refactoring for complex conditional statements. J. Cent. South Univ. 21, 1935–1945 (2014). https://doi.org/10.1007/s11771-014-2140-z
Received:
Accepted:
Published:
Issue Date:
DOI: https://doi.org/10.1007/s11771-014-2140-z