Let’s say I have an interface:
public interface Foo{
String bar(int baz);
}
Now in some Java code I have an anonymous implementation of that interface:
Foo foo = new Foo(){
public String bar(int baz){
return String.valueOf(baz);
}
};
Is there a way (in Eclipse) to refactor this to the enum singleton pattern (Effective Java, Item 3), like this:
// further up in the same Compilation Unit:
enum StandardFoo implements Foo{
INSTANCE{
public String bar(int baz){
return String.valueOf(baz);
}
}
}
// ...
Foo foo = StandardFoo.INSTANCE;
This refactoring is tedious to do by hand and I do it all the time. Is there any plugin that does that? Or a secret JDT trick I don’t know about (I’m using Indigo)?
BTW: do Idea or NetBeans support this refactoring?
IDEA supports Structural Search and Replace (Tutorial), which I believe could speed this up for you.