Mark
Mark

Reputation: 19977

IntelliJ IDEA find usages of overriding method without finding sibling methods

I have a parent class P with subclasses A and B.

I would like to find all usages of a method f of A.

So either p.f() or a.f() but not b.f(), because an instance B b cannot call A.f.

I know I can find

I know there are always going to be false positives using only compile-time information, but there could be fewer.

Upvotes: 17

Views: 5939

Answers (2)

starkm
starkm

Reputation: 1029

Now it's possible to search usages in more depth. Just hit Ctrl+Shift+Alt+F7 (for Mac Cmd+Shift+Alt+F7) instead of Alt+F7 and check what you want to search for. In your case, uncheck 'Search for base method usages'.

For more information check out the official site: https://www.jetbrains.com/help/idea/find-usages-method-options.html

Upvotes: 12

Bas Leijdekkers
Bas Leijdekkers

Reputation: 26522

You could use Structural Search (Edit | Find | Search Structurally...) for this. Use a query like:

$x$.f()

with expression type filter A|P. This will find all calls to f() on expressions of a type of either A or P. If you have any more classes in the hierarchy between A and P, you will need to add these to the expression type filter also.

Upvotes: 14

Related Questions