Constants to Enum Eclipse Plugin
The Convert Constants to Enum refactoring for Eclipse provides an automated approach for transforming legacy Java code to use the new enumeration construct. This semantics-preserving tool increases type safety, produces code that is easier to comprehend, removes unnecessary complexity, and eliminates brittleness problems that normally prevent separate compilation.
The plugin refactors Java legacy code to make use of the new enum program construct which was introduced in Java 5. This construct, which provides language support for enumerated types, is one of many new features of Java that offer significant improvements over older Java technology. Prior to Java 5, programmers were required to employ various design patterns (e.g., static final int ...) 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.
There are several features currently lacking in the plugin which are obstacles to wide distribution including a robust graphical user interface, a full test suite with regression tests, and complete undo functionality.
In short, install the plugin via the update site, select a set of constants explicitly through the package explorer or outline view, and select the "Convert Constants to Enum" option from the context menu. A wizard will then display with further instructions and customizations. In future versions, we hope to have the command available at multiple levels (e.g., projects) and from the editor and drop down menu.
Go to the Outline View (Window -> Show View -> Outline), then in the Outline View select (using Ctrl + Click) all the constants you want to convert. Right click on them, and select Refactor -> Convert Constants to Enum... from the right-click menu.
Please feel free to post to the General Development Discussion list with any comments, questions, or concerns.
Note that this plugin depends on https://github.com/khatchad/edu.cuny.citytech.refactoring.common.
- Original Eclipse bugzilla page
- Original author's website
- ICSM '07 conference paper
- Full technical report
- Article on Eclipse refactoring
- API for refactoring wizards
- Update site