views:

68

answers:

4

I've got a class which overrides equals() and I want to see where this equals method is being used in the workspace. Using Eclipse, I generally do Ctrl-Shift-g which finds all references in the workspace. Unfortunately, for equals(), its pulling back every single reference of equals in my workspace from any type, not just the one where I've overridden it and its impossible to figure out which of the many results is pertinent to my search. Is what I want to do possible?

EDIT: To clarify. I have a class A which overrides the equals method. I have a class B (and others) which use class A but do not extend it. I want to find which classes in my workspace use Class A's equals method regardless of whether or not they belong to Class A's hierarchy such as Class B.

A: 

Right click on your equals method and select the option

References--> Hierarchy

Emil
If I have a class A which overrides the equals method, I'm looking for all places in the code base where A.equals() is getting called. The hierarchy of the overriding isn't what I'm after.
Chris Knight
@Emil: This method will find any use of the equals method in subclasses of Class A, but not any use in Class B which does not extend Class A and merely uses Class A instead.
Chris Knight
A: 

References-->Workspace or References-->Project

sweetfa
Thanks, but this is the same as the Ctrl-Shift-g shortcut above. It finds any reference to equals() in the workspace for any object, not just the object I'm interested in.
Chris Knight
A: 

Shift+Ctrl+H on method name (same as Refernces->Hierarchy). works for me!

ohadshai
@ohadshai as mentioned below, this will find references in ClassC for equals implemented in `ClassA` where `ClassC extends ClassA` but not `ClassB` which merely uses `ClassA`.
Chris Knight
+2  A: 

In general you can't do this as equals is on Object, take for example

mysession.getAttribute("someobject").equals(foo)

no way to detect that this object is your class type.

MeBigFatGuy
Good point. Hadn't considered this.
Chris Knight