Skip to main content
Log in

Automated refactoring of legacy Java software to enumerated types

  • Published:
Automated Software Engineering Aims and scope Submit manuscript

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.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Subscribe and save

Springer+ Basic
$34.99 /Month
  • Get 10 units per month
  • Download Article/Chapter or eBook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
Subscribe now

Buy Now

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Fig. 1
Fig. 2
Fig. 3
Fig. 4
Fig. 5
Fig. 6
Fig. 7
Fig. 8
Fig. 9
Fig. 10
Fig. 11
Fig. 12
Fig. 13
Fig. 14
Fig. 15
Fig. 16
Fig. 17

Similar content being viewed by others

Explore related subjects

Discover the latest articles, news and stories from top researchers in related subjects.

Notes

  1. This example was inspired by one of the authors’ work at the Center for Automotive Research at the Ohio State University.

  2. A similar pattern called Type Codes is described in Fowler (1999) and Kerievsky (2004).

  3. We exclude boolean from this list for several reasons: (1) The type has only two values, true and false, thus any transformed enum type can only have two members and (2) our algorithm becomes simpler due to this exclusion.

  4. Although the focus of our tool is to refactor legacy Java software to utilize the new enum construct, we do not discriminate against current Java software (e.g., those written in Java \(\ge 5\)). In this case, uses of the enum identifier for the purpose of declaring language enumerated types is acceptable.

  5. Larger in terms of the maximum capacity held by values of the primitive type in bytes.

  6. http://github.com/khatchad/Constants-to-Enum-Eclipse-Plugin.

  7. http://code.google.com/soc.

  8. java5 denotes the package java. included in the Java 5 JDK.

  9. Excludes boolean types.

  10. The term interface is used here not to solely denote that of Java interfaces, but instead to denote the broader notion of interfaces which, in Java, would also include class declarations.

  11. inter-program or inter-module in the case of COBOL.

References

  • Bäumer, D., Gamma, E., Kiezun, A.: Integrating refactoring support into a Java development tool. In: OOPSLA’01 Companion (2001)

  • Bloch, J.: Effective Java Programming Language Guide. Prentice Hall PTR, Upper Saddle River (2001)

    Google Scholar 

  • 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)

  • 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)

  • 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

  • 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

  • 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

  • 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)

  • 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

  • Fowler, M.: Refactoring: Improving the Design of Existing Code. Addison-Wesley Professional, Reading (1999)

  • 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–96

  • Gamma, E., Helm, R., Johnson, R., Vlissides, J.: Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley, Boston (1995)

    MATH  Google Scholar 

  • Gosling, J., Joy, B., Steele, G., Bracha, G.: Java\(^{{\rm TM}}\) Language Specification, 3rd edn. Addison-Wesley, Boston (2005)

    Google Scholar 

  • 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)

  • Kerievsky, J.: Refactoring to Patterns. Pearson Higher Education, London (2004)

    Book  Google Scholar 

  • 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

  • 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

  • Kiezun, A., Ernst, M.D., Tip, F., Fuhrer, R.M. (2007) Refactoring for parameterizing Java classes. In: International Conference on Software Engineering

  • Knuth, D.E.: Semantics of context-free languages. Theory Comput. Syst. 2(2) (1967)

  • Kumar, A., Sutton, A., Stroustrup, B.: Rejuvenating C++ programs through demacrofication. In: International Conference on Software Maintenance, IEEE, pp. 98–107 (2012)

  • Oracle Corporation (2010) Java programming language: Enhancements in jdk 5. http://docs.oracle.com/javase/1.5.0/docs/guide/language

  • Oracle Corporation (2015) Typesafe enums. http://docs.oracle.com/javase/8/docs/technotes/guides/language/enums.html

  • Palsberg, J., Schwartzbach, M.I.: Object-Oriented Type Systems. Wiley, Chichester (1994)

    MATH  Google Scholar 

  • Pierce, B.C.: Types and Programming Languages. MIT Press, Cambridge (2002)

    MATH  Google Scholar 

  • 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

  • Steimann, F., Siberski, W., Kúhne, T.: Towards the systematic use of interfaces in java programming. In: PPPJ (2003)

  • Steimann, F., Mayer, P., Meißner, A.: Decoupling classes with inferred interfaces. In: ACM Symposium on Applied Computing, pp. 1404–1408 (2006)

  • 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)

  • 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)

  • 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)

  • 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)

  • von Dincklage, D., Diwan, A.: Converting Java classes to use generics. In: Object-Oriented Programming, Systems, Languages and Applications, pp. 1–14 (2004)

Download references

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.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Raffi Khatchadourian.

Additional information

A portion of this work was administered during his time at the Department of Computer Science and Engineering at Ohio State University and at the Department of Computer Systems Technology at New York City College of Technology, City University of New York.

This material is based upon work supported by the National Science Foundation under Grant CCF-0546040.

Rights and permissions

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Khatchadourian, R. Automated refactoring of legacy Java software to enumerated types. Autom Softw Eng 24, 757–787 (2017). https://doi.org/10.1007/s10515-016-0208-8

Download citation

  • Received:

  • Accepted:

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s10515-016-0208-8

Keywords