How to refactor thousands of lines of Java code? Is there any tool available?
In our application we have two or three classes which contains the entire Java Swing application logic. These two or three classes contain around 7k lines of code.
Now I have been assigned the task to refactor this Java code.
How do I start? Is there any tool available that will do the refactoring or at least guide us?
I assume that you are trying to break up these large classes into smaller ones. The most common way to do this is with the Extract Class refactoring. It just happens that this is a major topic in my PhD thesis work.
One of the hard parts is deciding what goes into the new classes. There are two publicly available tools that I know of that help - ExtC (my tool) and JDeodorant. Both are Eclipse plug-ins, and I would classify both as being prototypes. If you want to try to use my tool, I'll be glad to help.
Once you decide what should go into the new class, you have to do the actual work of separating the class into others. Eclipse's Extract Class refactoring is misnamed and isn't really helpful. IntelliJ's IDEA is much better, but still has some bugs. JDeodorant can also perform the split, but it also has some bugs.
I'd recommend Eclipse - the brilliant Java IDE for the editing and refactoring. It has several tools for refactoring. An excellent tutorial on how to do it with Eclipse is located at:
There's a brililant article on the power of refactoring with Eclipse, if you're not yet convinced, at:
And finally another article on how to refactor in Eclipse, including techniques and tools, is available at:
There's also another stackoverflow question on strategies for refactoring Java code that you may be interested in:
Hope that helps, good luck!