Java 如何找到在 Android Studio 中使用方法或变量的位置(快捷方式)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29000308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can i find where a method or a variable is used in Android Studio (shortcut)
提问by Omar BISTAMI
I know how to find the source by using ctrl+ left click on a method, for example, but what if I want to find where this method is used? I'm using Windows 7.
例如,我知道如何通过ctrl在方法上使用+ 左键单击来查找源,但是如果我想查找使用此方法的位置怎么办?我正在使用 Windows 7。
Let's suppose I have the following method:
假设我有以下方法:
class A {
public int sum(int a, int b) {
return a+b;
}
}
and I am using this method in
我正在使用这种方法
class B {
...
a.sum(c, d);
...
}
and I want to find where I used sum
while I was in class A
.
我想找到我sum
上课时用过的地方A
。
PS: I'm new to Android studio (started using it about a month ago).
PS:我是 Android Studio 的新手(大约一个月前开始使用它)。
采纳答案by John P.
In Android Studio, highlight the method and either right click > Find usages or use the Alt+F7shortcut.
在 Android Studio 中,突出显示该方法,然后右键单击 > 查找用法或使用Alt+F7快捷方式。
Edit: Ctrl+left clickon a method is useful for finding where that method was initially declared
编辑:Ctrl+ left clickon a 方法对于查找该方法最初声明的位置很有用
回答by Benyam Ephrem
Just click on the method or variable and any usages will be highlighted and on the scroll bar on the right side of your code you will see gray bars appear, those are the usages of the current highlighted (or clicked on) variable or method within your code.
只需单击方法或变量,任何用法都会突出显示,在代码右侧的滚动条上,您会看到灰色条出现,这些是当前突出显示(或单击)的变量或方法在您的代码中的用法代码。
回答by Andrey
For Ubuntu users:
对于 Ubuntu 用户:
For me Alt+F7has not worked, so I've solved the conflict by going to the
对我来说Alt+F7没有用,所以我通过去解决了冲突
Ubuntu System settings-> keyboard -> shortcuts
and changing Alt+F7in there with another combination.
并用另一种组合改变Alt+ F7。
And now it's working ))
现在它正在工作))
回答by SAURABH_12
To find all uses of a variable or method in Android Studio you can use
要在 Android Studio 中查找变量或方法的所有用途,您可以使用
- ctrl+shift+F7(window/Ubuntu)
- after that for navigation purpose you can use F3
- ctrl+shift+F7(窗口/Ubuntu)
- 之后出于导航目的,您可以使用 F3
回答by hBrent
Here are different key shortcuts for displaying method or variable usage. The keymaps with F14in them were added by me; the others are default. For Windows (and Linux?), replace the ⌘key with Ctrl(I think). Find Usages shows them in a dedicated window in Android Studio (the solution in other answers), while Show Usages puts them in a popup (second image below).
以下是用于显示方法或变量用法的不同快捷键。其中的键盘映射F14是我添加的;其他都是默认的。对于 Windows(和 Linux?),将⌘密钥替换为Ctrl(我认为)。Find Usages 将它们显示在 Android Studio 的专用窗口中(其他答案中的解决方案),而 Show Usages 将它们放在弹出窗口中(下图第二张)。
回答by Jason Escobar
use [Ctrl+b] or [Ctrl+Alt+b] to navigate to the origin of the method or variable declearation and implementation
使用 [Ctrl+b] 或 [Ctrl+Alt+b] 导航到方法的原点或变量的清除和实现