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?

Answers


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:

http://www.cs.umanitoba.ca/~eclipse/13-Refactoring.pdf

There's a brililant article on the power of refactoring with Eclipse, if you're not yet convinced, at:

http://www.eclipse.org/articles/article.php?file=Article-Unleashing-the-Power-of-Refactoring/index.html

And finally another article on how to refactor in Eclipse, including techniques and tools, is available at:

http://www.ibm.com/developerworks/opensource/library/os-ecref/

There's also another stackoverflow question on strategies for refactoring Java code that you may be interested in:

What are the best code refactoring strategies ?

Hope that helps, good luck!


Need Your Help

cannot execute binary file - Executable Jar file

java terminal makefile executable

I'm having trouble trying to run an executable jar file using a makefile. Any help appreciated.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.