I want to identify all instances of reference equality for a particular class and replace them with equals
. Is there a technique or tool in IntelliJ that I can use for this? Can I filter Find Usages down to "usage in ==
" somehow?
Essentially, I would like this tool to list:
Instances of this class and sub-classes
That are used in reference equality
It is okay if it does not detect reference equality checks of instances of superclasses of this class.
CodePudding user response:
The right way to do this is:
Edit > Find > Search Structurally...
Use the following template
$LHS$ == $RHS$
Click the
$LHS$
section and add a Filter on the right ofType
set to your type fully-qualified (in my caseroshan.model.Quantity
) and select 'Within Type Hierarchy'Repeat with the
$RHS$
(you may optionally set theType
tomodel.Quantity|null
if you want to include null-checks)Run Find
This will find you exactly the set of reference equality checks of type LHS to type RHS including sub-classes on both sides. Ha! Amazing.