Priority
Normal
Type
Feature 
State
Submitted 
Assignee
Anna Kozlova 
Subsystem
Refactoring 
Affected versions
Fix for
Build
6148
Severity
0
  • Submitted by   Dave Yost
    3 years ago (25 Jan 2007 04:42)
  • Updated by Dave Yost
    14 months ago (21 Nov 2008 19:06)
  • Jira: IDEA-11228
    (history, comments)

IDEA-11228

Refactor strings into enum members

2
If you select multiple initialized string declarations, IDEA should offer an intention to make them all members of an enum.

static final String FOO = "foo"; static final String BAR = "bar"; ... baz(FOO);

would become

enum Whatever { foo, bar }; ... baz(Whatever.foo.name());

The intention dialog could also offer to push the use of the enum down into methods, so the code instead could become

baz(Whatever.foo);
Comments (4)
 
History (0)
 
Links
 
Dave Yost
  Dave Yost
12 May 2007 11:19
(2 years ago)
#permalink
I've made a web page that talks about this.
http://yost.com/computers/java/java-spaghetti/
Dave Yost
  Dave Yost
05 Oct 2008 21:55
(16 months ago)
#permalink
Anything happening with this?
Anna Kozlova
  Anna Kozlova
06 Oct 2008 12:37
(16 months ago)
#permalink
It is possible to move your constants to enum as enum constants. Is it a solution?
Thank you
Raffi Khatchadourian
  Raffi Khatchadourian
15 Oct 2008 00:28
(15 months ago)
#permalink
I have a working implementation of refactoring non-string (e.g., int, bool, short) constants to enums in Eclipse. However, it does not currently have a GUI. You're welcome to have a look at it: https://bugs.eclipse.org/bugs/show_bug.cgi?id=200152