[go: up one dir, main page]
More Web Proxy on the site http://driver.im/ skip to main content
research-article

An automated extract method refactoring approach to correct the long method code smell

Published: 01 May 2022 Publication History

Abstract

Long Method is amongst the most common code smells in software systems. Despite various attempts to detect the long method code smell, few automated approaches are presented to refactor this smell. Extract Method refactoring is mainly applied to eliminate the Long Method smell. However, current approaches still face serious problems such as insufficient accuracy in detecting refactoring opportunities, limitations on correction types, the need for human intervention in the refactoring process, and lack of attention to object-oriented principles, mainly single responsibility and cohesion–coupling principles. This paper aims to automatically identify and refactor the long method smells in Java codes using advanced graph analysis techniques, addressing the aforementioned difficulties. First, a graph representing project entities is created. Then, long method smells are detected, considering the methods’ dependencies and sizes. All possible refactorings are then extracted and ranked by a modularity metric, emphasizing high cohesion and low coupling classes for the detected methods. Finally, a proper name is assigned to the extracted method based on its responsibility. Subsequently, the best destination class is determined such that design modularity is maximized. Experts’ opinion is used to evaluate the proposed approach on five different Java projects. The results show the applicability of the proposed method in establishing the single responsibility principle with a 21% improvement compared to the state-of-the-art extract method refactoring approaches.

Highlights

Long Method is amongst the most common code smells in software systems.
The aim is to refactor long method smells using advanced graph analysis techniques.
A graph denoting project entities is created in which long method smells are detected.
All possible refactorings are then extracted and ranked by a modularity metric.
Results show a 21% improvement compared to the state-of-the-art approaches.

References

[1]
Agnihotri M., Chug A., A systematic literature survey of software metrics, code smells and refactoring techniques, J. Inf. Process. Syst. 16 (4) (2020) 915–934.
[2]
Aho A.V., Lam M.S., Sethi R., Ullman J.D., Compilers: Principles, Techniques, and Tools (2nd Edition), Addison-Wesley Longman Publishing Co., Inc., USA, 2006.
[3]
Al Dallal J., Measuring the discriminative power of object-oriented class cohesion metrics, IEEE Trans. Softw. Eng. 37 (6) (2011) 788–804,.
[4]
Alon U., Zilberstein M., Levy O., Yahav E., Code2vec: learning distributed representations of code, Proc. ACM Program. Lang. 3 (POPL) (2019) 1–29,.
[5]
Anon U., Javaparser: analyze, transform and generate your java codebase, 2019, https://javaparser.org/ (accessed May 18, 2021).
[6]
Arcelli Fontana F., Mäntylä M.V., Zanoni M., Marino A., Comparing and experimenting machine learning techniques for code smell detection, Empir. Softw. Eng. 21 (3) (2016) 1143–1191,.
[7]
Baqais A.A.B., Alshayeb M., Automatic software refactoring: A systematic literature review, Softw. Qual. J. 28 (2) (2020) 459–502,.
[8]
Bibiano, A.C., et al., A quantitative study on characteristics and effect of batch refactoring on code smells, in: Proceedings of the 2019 ACM/IEEE International Symposium on Empirical Software Engineering and Measurement (ESEM), Sep. 2019, 1–11, https://doi.org/10.1109/ESEM.2019.8870183.
[9]
Bloch J., Effective Java, Pearson Education, 2017.
[10]
Caram F.L., Rodrigues B.R.D.O., Campanelli A.S., Parreiras F.S., Machine learning techniques for code smells detection: A systematic mapping study, Int. J. Softw. Eng. Knowl. Eng. 29 (02) (2019) 285–316,.
[11]
Cedrim, D., et al., Understanding the impact of refactoring on smells: A longitudinal study of 23 software projects, in: Proceedings of the 2017 11th Joint Meeting on Foundations of Software Engineering, Aug. 2017, 465–475, https://doi.org/10.1145/3106237.3106259.
[12]
Charalampidou S., Ampatzoglou A., Chatzigeorgiou A., Gkortzis A., Avgeriou P., Identifying extract method refactoring opportunities based on functional relevance, IEEE Trans. Softw. Eng. 43 (10) (2017) 954–974,.
[13]
Di Nucci, D., Palomba, F., Tamburri, D.A., Serebrenik, A., De Lucia, A., Detecting code smells using machine learning techniques: Are we there yet?, in: Proceedings of the IEEE 25th International Conference on Software Analysis, Evolution and Reengineering (SANER), Mar. 2018, 612–621, https://doi.org/10.1109/SANER.2018.8330266.
[14]
Fontana, F.A., Ferme, V., Zanoni, M., Roveda, R., Towards a prioritization of code debt: A code smell Intensity Index, in: Proceedings of the IEEE 7th International Workshop on Managing Technical Debt (MTD), Oct. 2015, 16–24, https://doi.org/10.1109/MTD.2015.7332620.
[15]
Fortunato S., Community detection in graphs, Phys. Rep. 486 (3–5) (2010) 75–174,.
[16]
Fowler M., Beck K., Refactoring: Improving the Design of Existing Code, Second Edi, Addison-Wesley, 2018.
[17]
Gilbert D., JFreeChart, 2020, http://www.jfree.org/jfreechart/ (accessed Sep. 30, 2020).
[18]
Gousios G., Vergne M., Laaber C., Java-callgraph, 2018, https://github.com/gousiosg/java-callgraph (accessed May 18, 2021).
[19]
Gu A., Zhou X., Li Z., Li Q., Li L., Measuring object-oriented class cohesion based on complex networks, Arab. J. Sci. Eng. 42 (8) (2017) 3551–3561,.
[20]
Hubert J., Implementation of an Automatic Extract Method Refactoring, University of Stuttgart, 2019.
[21]
Jász, J., Siket, I., Pengő, E., Ságodi, Z., Ferenc, R., Systematic comparison of six open-source Java call graph construction tools, in: Proceedings of the 14th International Conference on Software Technologies, 2019, 117–128, https://doi.org/10.5220/0007929201170128.
[22]
Jiang, L., Liu, H., Jiang, H., Machine learning-based recommendation of method names: how far are we, in: Proceedings of the 34th IEEE/ACM International Conference on Automated Software Engineering (ASE), Nov. 2019, 602–614, https://doi.org/10.1109/ASE.2019.00062.
[23]
jVLT - a vocabulary learning tool, http://jvlt.sourceforge.net/ (accessed Sep. 15, 2021).
[24]
Kaur S., Singh P., How does object-oriented code refactoring influence software quality? research landscape and challenges, J. Syst. Softw. 157 (2019),.
[25]
Khomh F., Di Penta M., Guéhéneuc Y.G., Antoniol G., An Exploratory Study of the Impact of Antipatterns on Class Change- and Fault-Proneness 17 (3) (2012) 243–275,.
[26]
Lacerda G., Petrillo F., Pimenta M., Guéhéneuc Y.G., Code smells and refactoring: A tertiary systematic review of challenges and observations, J. Syst. Softw. 167 (2020),.
[27]
Lanza M., Marinescu R., Object-Oriented Metrics in Practice: Using Software Metrics To Characterize, Evaluate, and Improve the Design of Object-Oriented Systems, 1st Ed., Springer Publishing Company, Incorporated, 2006.
[28]
Leicht E.A., Newman M.E.J., Community structure in directed networks, Phys. Rev. Lett. 100 (11) (2008),.
[29]
Lozano, A., Mens, K., Portugal, J., Analyzing code evolution to uncover relations, in: Proceedings of the IEEE 2nd International Workshop on Patterns Promotion and Anti-patterns Prevention (PPAP), Mar. 2015, 1–4. https://doi.org/10.1109/PPAP.2015.7076847.
[30]
Mansoor U., Kessentini M., Wimmer M., Deb K., Multi-view refactoring of class and activity diagrams using a multi-objective evolutionary algorithm, Softw. Qual. J. 25 (2) (2017) 473–501,.
[31]
Mariani T., Vergilio S.R., A systematic review on search-based refactoring, Inf. Softw. Technol. 83 (2017) 14–34,.
[32]
Martin R.C., Clean Code: A Handbook of Agile Software Craftsmanship, Prentice-Hall, 2009.
[33]
Wiley & Sons Martin Lippert S.R., Refactoring in Large Software Projects: Performing Complex Restructurings Successfully, 1st Ed, 2006.
[34]
Maruyama K., Automated method-extraction refactoring by using block-based slicing, ACM SIGSOFT Softw. Eng. Notes 26 (3) (2001) 31–40,.
[35]
Mens T., Tourwe T., A survey of software refactoring, IEEE Trans. Softw. Eng. 30 (2) (2004) 126–139,.
[36]
Mkaouer M.W., Kessentini M., Bechikh S., Cinnéide M.Ó., Deb K., On the use of many quality attributes for software refactoring: a many-objective search-based software engineering approach, Empir. Softw. Eng. 21 (6) (2016) 2503–2545,.
[37]
Mohan M., Greer D., Using a many-objective approach to investigate automated refactoring, Inf. Softw. Technol. 112 (2019) 83–101,.
[38]
Mongiovi M., Gheyi R., Soares G., Ribeiro M., Borba P., Teixeira L., Detecting overly strong preconditions in refactoring engines, IEEE Trans. Softw. Eng. 44 (5) (2018) 429–452,.
[39]
Müller J., Freemind - free mind mapping software, 2021, http://freemind.sourceforge.net/wiki/, (accessed Apr. 28, 2021).
[40]
NetworkX, NetworkX. https://networkx.github.io/ (accessed Apr. 26, 2019).
[41]
Newman M., Networks: An Introduction, OUP Oxford, 2010.
[42]
Newman M.E.J., Girvan M., Finding and evaluating community structure in networks, Phys. Rev. E 69 (2) (2004),.
[43]
Palomba F., Bavota G., Di Penta M., Fasano F., Oliveto R., De Lucia A., On the diffuseness and the impact on the maintainability of code smells: a large scale empirical investigation, Empir. Softw. Eng 23 (3) (2018) 1188–1221,.
[44]
Palomba, F., Panichella, A., De Lucia, A., Oliveto, R., Zaidman, A., A textual-based technique for Smell Detection, in: Proceedings of the IEEE 24th International Conference on Program Comprehension (ICPC), 2016, 1–10. https://doi.org/10.1109/ICPC.2016.7503704.
[45]
Pecorelli F., Di Nucci D., De Roover C., De Lucia A., A large empirical assessment of the role of data balancing in machine-learning-based code smell detection, J. Syst. Softw. 169 (2020),.
[46]
Pestov S., Jedit - programmer’s text editor, 2021, http://www.jedit.org/ (accessed Apr. 28, 2021).
[47]
Robbins J.E., Argouml, 2021, https://argouml.en.softonic.com/ (accessed Apr. 28, 2021).
[48]
Savić M., Ivanović M., Radovanović M., Analysis of high structural class coupling in object-oriented software systems, Computing 99 (11) (2017) 1055–1079,.
[49]
Sharma T., Spinellis D., A survey on software smells, J. Syst. Softw. 138 (2018) 158–173,.
[50]
Silva, D., Terra, R., Valente, M.T., Recommending automated extract method refactorings, in Proceedings of the 22nd International Conference on Program Comprehension - ICPC 2014, 2014, 146–156, https://doi.org/10.1145/2597008.2597141.
[51]
Sobrinho E.V.de P., De Lucia A., de A. Maia M., A systematic literature review on bad smells–5 w’s: which, when, what, who, where, IEEE Trans. Softw. Eng. 47 (1) (2021) 17–66,.
[52]
Steidl, D., Eder, S., Prioritizing maintainability defects based on refactoring recommendations, in: Proceedings of the 22nd International Conference on Program Comprehension - ICPC 2014, 2014, 168–176, https://doi.org/10.1145/2597008.2597805.
[53]
Subramaniam H., Zulzalil H., Software quality assessment using flexibility: a systematic literature review, Int. Rev. Comput. Softw. 7 (5) (2012).
[54]
Taibi D., Janes A., Lenarduzzi V., How developers perceive smells in source code: A replicated study, Inf. Softw. Technol. 92 (2017) 223–235,.
[55]
Tsantalis, N., Chaikalis, T., Chatzigeorgiou, A., Ten years of JDeodorant: lessons learned from the hunt for smells, in: Proceedings of the IEEE 25th International Conference on Software Analysis, Evolution and Reengineering (SANER), Mar. 2018, 4–14. https://doi.org/10.1109/SANER.2018.8330192.
[56]
Tsantalis N., Chatzigeorgiou A., Identification of extract method refactoring opportunities for the decomposition of methods, J. Syst. Softw. 84 (10) (2011) 1757–1782,.
[57]
Tufano M., et al., When and why your code starts to smell bad (and whether the smells go away), IEEE Trans. Softw. Eng. 43 (11) (2017) 1063–1088,.
[58]
Wang, X., Pollock, L., Vijay-Shanker, K., Automatic segmentation of method code into meaningful blocks to improve readability, in: Proceedings of the 18th Working Conference on Reverse Engineering, Oct. 2011, 35–44, https://doi.org/10.1109/WCRE.2011.15.
[59]
Yamashita, A., Moonen, L., Do code smells reflect important maintainability aspects?, in: Proceedings of the 28th IEEE International Conference on Software Maintenance (ICSM), Sep. 2012, pp. 306–315 https://doi.org/10.1109/ICSM.2012.6405287.
[60]
Yamashita, A., Moonen, L., Do developers care about code smells? an exploratory survey, in:Proceedings of the 20th Working Conference on Reverse Engineering (WCRE), Oct. 2013, 242–251, https://doi.org/10.1109/WCRE.2013.6671299.
[61]
Zaitsev, O., Ducasse, S., Bergel, A., Eveillard, M., Suggesting Descriptive Method Names: An Exploratory Study of Two Machine Learning Approaches, in: Proceedings of the International Conference on the Quality of Information and Communications Technology, 2020, 93–106, https://doi.org/10.1007/978-3-030-58793-2_8.

Cited By

View all

Recommendations

Comments

Please enable JavaScript to view thecomments powered by Disqus.

Information & Contributors

Information

Published In

cover image Journal of Systems and Software
Journal of Systems and Software  Volume 187, Issue C
May 2022
270 pages

Publisher

Elsevier Science Inc.

United States

Publication History

Published: 01 May 2022

Author Tags

  1. Software refactoring
  2. Extract method
  3. Long method
  4. Code smell
  5. Graph analysis

Qualifiers

  • Research-article

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)0
  • Downloads (Last 6 weeks)0
Reflects downloads up to 18 Jan 2025

Other Metrics

Citations

Cited By

View all
  • (2025)Testability-driven developmentComputer Standards & Interfaces10.1016/j.csi.2024.10387791:COnline publication date: 1-Jan-2025
  • (2025)Efficient feature envy detection and refactoring based on graph neural networkAutomated Software Engineering10.1007/s10515-024-00476-332:1Online publication date: 1-Jun-2025
  • (2023)A Systematic Literature Review on the Code Smells Datasets and Validation MechanismsACM Computing Surveys10.1145/359690855:13s(1-48)Online publication date: 13-Jul-2023
  • (2023)Supporting single responsibility through automated extract method refactoringEmpirical Software Engineering10.1007/s10664-023-10427-329:1Online publication date: 22-Dec-2023
  • (2023)Code smell prioritization in object‐oriented software systemsJournal of Software: Evolution and Process10.1002/smr.253635:12Online publication date: 29-Jan-2023

View Options

View options

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media