[FIXED] Finding all uses of a Java class in reference equality in IntelliJ


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:

  1. Instances of this class and sub-classes

  2. That are used in reference equality

It is okay if it does not detect reference equality checks of instances of superclasses of this class.


The right way to do this is:

  1. Edit > Find > Search Structurally…

  2. Use the following template

$LHS$ == $RHS$
  1. Click the $LHS$ section and add a Filter on the right of Type set to your type fully-qualified (in my case roshan.model.Quantity) and select ‘Within Type Hierarchy’

  2. Repeat with the $RHS$ (you may optionally set the Type to model.Quantity|null if you want to include null-checks)

  3. 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.

Answered By – Roshan

Answer Checked By – David Marino (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published