Friday, September 25, 2009

Subclipse handles file renaming (refactoring) of Java classes properly

I started playing with CollabNet desktop and particularly Subclipse within Eclipse. Some things I liked.

Refactoring

Subclipse DOES handle refactoring of classes. That is, if you rename a class, it will create subversion events to delete the old class and add the new class. For example, renaming A.java to B.java shows a "Add B.java with copy-from path of A.java." This means that it preserves the version history over time.

To refactor without the subclipse plugin, I had to do the following:
  • Use "Rename" to rename the class. This fixes all the code and simply renames the existing file as the new file. (OldClass --> NewClass)
  • Do a SVN "Update" to get the old file back in the directory (OldClass.java)
  • Delete that OldClass.java file and rename the NewClass.java back to OldClass.java. SVN should show you that the file has been locally modified.
  • Do a SVN Rename to rename OldClass.java back to NewClass.java.
  • SVN "Check for Modifications" (status) should show you a "delete" of OldClass.java and a "add" of NewClass.java with a copy-from path of OldClass.java
Definately a hassle. It's nice that Subclipse makes it all work properly.

I also noticed that Subclipse and Tortoise SVN seem to "play nice" with checked out versions of code. That is, you can alternate back and forth between using Subclipse and Tortoise to operate on files.

No comments:

Post a Comment