[英]Find Method usages only for specified class in Intelij-Idea
I am using Intelijidea and I have problem with method usage finding.我正在使用 Intelijidea,但在查找方法用法时遇到问题。
Suppose I have interface Worker.假设我有接口 Worker。
public interface Worker {
void startWork();
void endWork();
}
And I have two implementation.我有两个实现。
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 Developer class and trying to find usage of startWork.我打开 Developer 类并尝试查找 startWork 的用法。 I want only to view usage of Developer.startWork implemented method.
我只想查看 Developer.startWork 实现方法的使用情况。
but when i find usage it shows both Developer and Qa startWork method usages.但是当我找到用法时,它会同时显示 Developer 和 Qa startWork 方法的用法。 how can i avoid Qa.startWork method usage when finding Developer.startWork usages.
在查找 Developer.startWork 用法时如何避免 Qa.startWork 方法的使用。
Please advice.请指教。
Using Ctrl + Shift + Alt + F7 ( ⌘ + ⇧ + ⌥ + F7 for Mac) should show the prompt from Jim Hawkins answer.使用Ctrl + Shift + Alt + F7 (对于 Mac 为⌘ + ⇧ + ⌥ + F7 )应该会显示 Jim Hawkins 回答的提示。
See: https://www.jetbrains.com/help/idea/find-usages-method-options.html请参阅: 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.
当您使用此对话框 Ctrl+Shift+Alt+F7 搜索方法实现的用法时,IntelliJ IDEA 将询问您是否要搜索基本方法。 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.
对于任何其他查找用法操作,例如 Alt+F7 或 Ctrl+Alt+F7,基本方法将自动包含在搜索结果中。
I'm using IntelliJ IDEA 15.0.1 .我正在使用 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.如果您将光标放在方法名称
Developer.startWork
并调用find usages
,您应该会看到一个小对话框。 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.如果您说“不”,并且在您的来源中您只通过基类或接口(在您的示例中为
Worker.start()
调用了该方法,则 IDEA 不会向您显示任何命中。 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.如果您通过
Developer.startWork()
调用覆盖的方法,并在对话框中按“否”,那么您将看到具体实现的用法。
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?在阅读@JimHawkins 的答案后,我认为大象还在房间里:) 问题是,您是想查看 Developer#startWork 的实际调用位置,还是想查看它静态引用的位置?
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 ). find usages 方法只能告诉,给定的方法在哪里被静态引用,但不能告诉它实际使用的位置(这是通过多态机制确定的运行时)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.