Enumeration refactoring: a tool for automatically converting Java constants to enumerated types

Java 5 introduces several new features that offer significant improvements over older Java technology. We consider the new enum construct, which provides language support for enumerated types. Before Java 5, programmers needed to employ various patterns 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 demonstrate an automated refactoring tool called Convert Constants to Enum for transforming legacy Java code to use the new enumeration construct. An interprocedural type inferencing algorithm that tracks the flow of enumerated values drives the approach, and the tool is implemented as a seamless extension to existing refactoring support in Eclipse. The resulting code is semantically equivalent to the original, increasingly type-safe, easier to comprehend, less complex, and supports separate compilation.

[1]  Arun Lakhotia,et al.  Identifying enumeration types modeled with symbolic constants , 1996, Proceedings of WCRE '96: 4rd Working Conference on Reverse Engineering.

[2]  Benjamin C. Pierce,et al.  Types and programming languages: the next generation , 2003, 18th Annual IEEE Symposium of Logic in Computer Science, 2003. Proceedings..

[3]  Frank Tip,et al.  Aggregate structure identification and its application to program analysis , 1999, POPL '99.

[4]  Frank Tip,et al.  Refactoring for Parameterizing Java Classes , 2007, 29th International Conference on Software Engineering (ICSE'07).

[5]  Atanas Rountev,et al.  Automated Refactoring of Legacy Java Software to Enumerated Types , 2007, 2007 IEEE International Conference on Software Maintenance.

[6]  Eli Tilevich,et al.  Annotation refactoring: inferring upgrade transformations for legacy applications , 2008, OOPSLA.

[7]  Arie van Deursen,et al.  Understanding COBOL systems using inferred types , 1999, Proceedings Seventh International Workshop on Program Comprehension.

[8]  Arie van Deursen,et al.  Type inference for COBOL systems , 1998, Proceedings Fifth Working Conference on Reverse Engineering (Cat. No.98TB100261).

[9]  Joshua J. Bloch Effective Java : programming language guide , 2001 .

[10]  Joshua Kerievsky,et al.  Refactoring to Patterns , 2004, XP/Agile Universe.

[11]  Fritz Henglein,et al.  AnnoDomini: from type theory to Year 2000 conversion tool , 1999, POPL '99.

[12]  Frank Tip,et al.  Efficiently Refactoring Java Applications to Use Generic Libraries , 2005, ECOOP.