Automated Software Engineering

, Volume 24, Issue 4, pp 757–787 | Cite as

Automated refactoring of legacy Java software to enumerated types

Article

Abstract

Modern Java languages introduce several new features that offer significant improvements over older Java technology. In this article we consider the new enum construct, which provides language support for enumerated types. Prior to recent Java languages, programmers needed to employ various patterns (e.g., the weak enum pattern) to compensate for the absence of enumerated types in Java. Unfortunately, these compensation patterns lack several highly-desirable properties of the enum construct, most notably, type safety. We present a novel fully-automated approach for transforming legacy Java code to use the new enumeration construct. This semantics-preserving approach increases type safety, produces code that is easier to comprehend, removes unnecessary complexity, and eliminates brittleness problems due to separate compilation. At the core of the proposed approach is an interprocedural type inferencing algorithm which tracks the flow of enumerated values. The algorithm was implemented as an open source, publicly available Eclipse plug-in and evaluated experimentally on 17 large Java benchmarks. Our results indicate that analysis cost is practical and the algorithm can successfully refactor a substantial number of fields to enumerated types. This work is a significant step towards providing automated tool support for migrating legacy Java software to modern Java technologies.

Keywords

Software environments Software maintenance Software tools Enumerated types Java Automated refactoring 

Notes

Acknowledgements

We would like to thank Jason Sawin, Atanas Rountev, and Frank Tip for answers to our technical questions and for referring us to related work.

References

  1. Bäumer, D., Gamma, E., Kiezun, A.: Integrating refactoring support into a Java development tool. In: OOPSLA’01 Companion (2001)Google Scholar
  2. Bloch, J.: Effective Java Programming Language Guide. Prentice Hall PTR, Upper Saddle River (2001)Google Scholar
  3. Bracha, G., Cohen, N., Kemper, C., Odersky, M., Stoutamire, D., Thorup, K., Wadler, P.: Adding generics to the Java programming language: public draft specification, version 2.0. Tech. Rep. JSR 014, Java Community Process (2003)Google Scholar
  4. Dean, J., Grove, D., Chambers, C.: Optimization of object-oriented programs using static class hierarchy analysis. In: European Conference on Object-Oriented Programming, pp. 77–101 (1995)Google Scholar
  5. Deursen, A.V., Moonen, L.: Type inference for COBOL systems. In: Working Conference on Reverse Engineering, IEEE Computer Society, Washington, DC, USA, pp. 220–230 (1998). doi:10.1109/WCRE.1998.723192
  6. Deursen, A.V., Moonen, L.: Understanding cobol systems using inferred types. In: International Workshop on Program Comprehension, IEEE Computer Society, Washington, DC, pp. 74–81 (1999). doi:10.1109/WPC.1999.777746
  7. Dig, D., Marrero, J., Ernst, M.D. (2009) Refactoring sequential java code for concurrency via concurrent libraries. In: International Conference on Software Engineering, IEEE Computer Society, Washington, DC, ICSE ’09, pp. 397–407. doi:10.1109/ICSE.2009.5070539
  8. Donovan, A., Kiezun, A., Tschantz, M.S., Ernst, M.D.: Converting Java programs to use generic libraries. In: Object-Oriented Programming, Systems, Languages and Applications, pp. 15–34 (2004)Google Scholar
  9. Eidorff, P.H., Henglein, F., Mossin, C., Niss, H., Sørensen, M.H., Tofte, M.: Annodomini: from type theory to year 2000 conversion tool. In: ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 1–14. ACM Press, New York, NY (1999). doi:10.1145/292540.292543
  10. Fowler, M.: Refactoring: Improving the Design of Existing Code. Addison-Wesley Professional, Reading (1999)Google Scholar
  11. Fuhrer, R., Tip, F., Kiezun, A., Dolby, J., Keller, M.: Efficiently refactoring Java applications to use generic libraries. In: European Conference on (2005) Object-Oriented Programming, pp. 71–96Google Scholar
  12. Gamma, E., Helm, R., Johnson, R., Vlissides, J.: Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, Boston (1995)MATHGoogle Scholar
  13. Gosling, J., Joy, B., Steele, G., Bracha, G.: Java\(^{{\rm TM}}\) Language Specification, 3rd edn. Addison-Wesley, Boston (2005)Google Scholar
  14. Gravley, J.M., Lakhotia, A.: Identifying enumeration types modeled with symbolic constants. In: Working Conference on Reverse Engineering, IEEE Computer Society, Washington, DC, p. 227 (1996)Google Scholar
  15. Kerievsky, J.: Refactoring to Patterns. Pearson Higher Education, London (2004)CrossRefGoogle Scholar
  16. Khatchadourian, R., Muskalla, B.: Enumeration refactoring: a tool for automatically converting java constants to enumerated types. In: International Conference on Automated Software Engineering, ACM, New York, NY, ASE ’10, pp. 181–182 (2010). doi:10.1145/1858996.1859036
  17. Khatchadourian, R., Sawin, J., Rountev, A.: Automated refactoring of legacy Java software to enumerated types. In: International Conference on Software Maintenance, IEEE, ICSM 2007, pp. 224–233 (2007). doi:10.1109/ICSM.2007.4362635
  18. Kiezun, A., Ernst, M.D., Tip, F., Fuhrer, R.M. (2007) Refactoring for parameterizing Java classes. In: International Conference on Software EngineeringGoogle Scholar
  19. Knuth, D.E.: Semantics of context-free languages. Theory Comput. Syst. 2(2) (1967)Google Scholar
  20. Kumar, A., Sutton, A., Stroustrup, B.: Rejuvenating C++ programs through demacrofication. In: International Conference on Software Maintenance, IEEE, pp. 98–107 (2012)Google Scholar
  21. Oracle Corporation (2010) Java programming language: Enhancements in jdk 5. http://docs.oracle.com/javase/1.5.0/docs/guide/language
  22. Palsberg, J., Schwartzbach, M.I.: Object-Oriented Type Systems. Wiley, Chichester (1994)MATHGoogle Scholar
  23. Pierce, B.C.: Types and Programming Languages. MIT Press, Cambridge (2002)MATHGoogle Scholar
  24. Ramalingam, G., Field, J., Tip, F.: Aggregate structure identification and its application to program analysis. In: ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, ACM Press, New York, NY, pp. 119–132 (1999). doi:10.1145/292540.292553
  25. Steimann, F., Siberski, W., Kúhne, T.: Towards the systematic use of interfaces in java programming. In: PPPJ (2003)Google Scholar
  26. Steimann, F., Mayer, P., Meißner, A.: Decoupling classes with inferred interfaces. In: ACM Symposium on Applied Computing, pp. 1404–1408 (2006)Google Scholar
  27. Sutter, B.D., Tip, F., Dolby, J.: Customization of java library classes using type constraints and profile information. In: European Conference on Object-Oriented Programming, pp. 585–610 (2004)Google Scholar
  28. Tip, F., Kiezun, A., Bäumer, D.: Refactoring for generalization using type constraints. In: Object-Oriented Programming, Systems, Languages and Applications, pp. 13–26 (2003)Google Scholar
  29. Tip, F., Fuhrer, R., Dolby, J., Kiezun, A.: Refactoring techniques for migrating applications to generic Java container classes. Tech. Rep. RC 23238, IBM T.J. Watson Research Center (2004)Google Scholar
  30. Vallée-Rai, R., et al.: Optimizing Java bytecode using the Soot framework: is it feasible? International Conference on Compiler Construction, LNCS, Vol. 1781, pp. 18–34 (2000)Google Scholar
  31. von Dincklage, D., Diwan, A.: Converting Java classes to use generics. In: Object-Oriented Programming, Systems, Languages and Applications, pp. 1–14 (2004)Google Scholar

Copyright information

© Springer Science+Business Media New York 2016

Authors and Affiliations

  1. 1.Department of Computer Science, Hunter CollegeCity University of New YorkNew YorkUSA

Personalised recommendations