Reputation: 1872
I am using IntelliJ IDEA and I have problem with method usage finding.
Suppose I have interface Worker.
public interface Worker {
void startWork();
void endWork();
}
And I have two implementations.
public class Develper implements Worker {
@Override
public void startWork() {
System.out.println("Developer Start Working");
}
@Override
public void endWork() {
}
}
public class Qa implements Worker {
@Override
public void startWork() {
System.out.println("QA start Work");
}
@Override
public void endWork() {
}
}
I open the Developer class and trying to find usages of startWork()
.
I want only to view usage of the Developer.startWork()
implemented method.
But when I find usages it shows both Developer and Qa.startWork()
method usages. How can I avoid Qa.startWork()
method usage when finding Developer.startWork()
usages?
Upvotes: 20
Views: 4645
Reputation: 4022
After reading the answer from @JimHawkins, I think the elephant is still in the room :) The question is, do you want to see where Developer.startWork()
is actually called, or do you want to see where it is statically referenced?
Eg:
Developer developer = new Developer();
developer.startWork(); // you want to find only this?
Worker worker = developer;
worker.startWork(); // ..or this as well?
The find usages method can only tell, where a given method is statically referenced, but not where it is actually used (that is determined runtime via the mechanism of polymorphism).
Upvotes: 1
Reputation: 191
Using Ctrl+Shift+Alt+F7 (⌘+⇧+⌥+F7 for Mac) should show the prompt from Jim Hawkins answer.
See: https://www.jetbrains.com/help/idea/find-usages-method-options.html
When you search for usages of a method implementation with this dialog Ctrl+Shift+Alt+F7, IntelliJ IDEA will ask whether or not you want to search for the base method. With any other find usages actions such as Alt+F7 or Ctrl+Alt+F7, the base method will be included in the search results automatically.
Upvotes: 18
Reputation: 4994
I'm using IntelliJ IDEA 15.0.1 .
I think what you see when using the "find usages" functionality depends from the context.
If you place the cursor in method name Developer.startWork
and invoke find usages
, you should see a small dialog. You are asked "Do you want to find usages of the base method?" .
If you say "No", and in your sources you did only call the method via the base class or interface (Worker.start()
in your example), IDEA doesn't show you any hits. Thats correct.
If you call the overridden method via Developer.startWork()
, and press "No" in the dialog, then you will see the usages of the specific implementation.
Upvotes: 6