Ruben Laguna's blog

Aug 18, 2007 - 2 minute read - code comments compare decided eclipse formatting ignore java revisions whitespace

Eclipse Compare. Ignoring java formatting changes not only whitespace.

I met some difficulties dealing with the default eclipse java compare. I got involved on a project where everybody likes to commit code to CVS formatted their way, so comparing between CVS revisions is almost impossible.

So I decided to start investigating about Eclipse plugin development to make a Java Compare Viewer that not only ignores whitespace but also all java formatting changes. The result is the following

*Before *ignore java formatting plugin:

After ignore java formatting plugin:

The plugin honors the text font preferences set in General -> Appearance -> Colors and fonts -> Text Compare -> Java compare text font. Also honors the Java Formatter preferences in Java -> Code Style -> Formatter

You can download the plugin and source code tested in Eclipse 3.3 Europa release from here.

Or you can use Update Manager:

To activate/deactivate the plugin all you have to do is press the new icon in the java compare view

UPDATE: Depending on your current set of plugins this plugin may or may not work. There is an issue in Eclipse when it comes to registering contentMergeViewers, It seems that when you register more that one contentMergeViewer for a particular file extension (in this case the Eclipse JDT registers and my plugin registers com.rubenlaguna.eclipse.javacompare.JavaContentViewerCreator) then the CompareUIPlugin.registerExtensions() will only record the last one. I’m trying to figure out how can I force my plugin to register last because right now depending on your configuration my plugin can register before JDT and then JDT will override my contentMergeViewer with his own. I have filed a bug report on eclipse bugzilla about this issue