Matt Raible has changed BaseObject in the upcoming version of AppFuse so that equals() and hashCode() are abstract, meaning that all your AppFuse model classes will have to implement these methods. Matt suggests using Commonclipse to automatically generate these methods. It certainly beats creating them all by hand!
It's easy enough to add Commonclipse to Eclipse 3 by doing Help > Software Updates > Find and Install > Search for new features to install > Next > New Remote Site. Put Commonclipse in the Name and http://commonclipse.sourceforge.net in the URL. Click OK. Click Next.
Once Commonclipse is installed and Eclipse has restarted, do the following to get it working for AppFuse:
Window > Preferences > Java > Commonclipse. Select the General tab. Uncheck the second and third checkboxes, which are to Append super in hashCode() and Append super in equals(). Click Apply (if you like) and OK.
The body of BaseObject in AppFuse 1.5 contains actual implementations. To delegate these methods to their subclasses, change BaseObject and the methods to abstract, as in the following:
public abstract class BaseObject implements Serializable {
public abstract String toString();
public abstract boolean equals(Object o);
public abstract int hashCode();
}Now you are ready to use Commonclipse to generate the implementations for these abstract methods in your model classes. In Eclipse, open each class that is derived from BaseObject. You can have Eclipse find them all for you by clicking on the word BaseObject in the editor window and hitting the F4 key. This will open the Hierarchy view and show you all the classes that have BaseObject as a superclass.
Open each class by double-clicking it in the Hierarchy window. In the editor, right-click, go down to the Commonclipse menu item, and select the method you want generated. Unfortunately, Commonclipse makes you repeat this task for each method, and I am not aware of a keyboard shortcut, although I longed for one.
Take note of two quirks I came across with Commonclipse
- A couple of times, it actually modified BaseObject, rather than the class I was editing.
- More frequently, it would not do anything after I selected the generate menu item. There was no error message, but the method was not generated.
I think both these problems might have something to do with focus of the editor window. I think the key is to left-click in the editor window to ensure that the file you can see is also the one that has focus. (Make sure the insertion point in the editor window is flashing.) One thing I noticed is that you can single-click a class in the Hierarchy window, if the file is already open in the editor. When you do that, the editor window for that file comes to the front, but the focus is actually still in the Hierarchy window.
I'm not positive that's the root cause of the problem, but closing and reopening the file and doing any kind of editing in the file seemed to get past the do-nothing generate task.