[英]Find out where classes of a specific package are used in Java/Eclipse project
I have a number of Eclipse projects that are all using classes from a specific package, let's call it "gr.serafeim". 我有许多Eclipse项目都使用来自特定包的类,我们称之为“gr.serafeim”。 Now, I want to find where (which line numbers of each file) in all my source files are the members of gr.serafeim are used.
现在,我想查找所有源文件中使用gr.serafeim成员的位置(每个文件的行号)。 The problem is that I am usually using imports and not the fully qualified names of classes, so searching for "gr.serafeim" will only return me the import statements :(
问题是我通常使用导入而不是类的完全限定名称,因此搜索“gr.serafeim”只会返回import语句:(
I don't want anything fance, just a quick and dirty solution to find out all the lines containing classes of the gr.serafeim package (an eclipse plugin ?). 我不想要任何东西,只是一个快速而肮脏的解决方案,找出包含gr.serafeim包类的所有行(一个eclipse插件?)。 As an added value, I don't want only the declarations but also the method calls of these function.
作为附加值,我不仅需要声明,还需要这些函数的方法调用。
Here's an example of what I actually wanted: 这是我实际想要的示例:
// File main.java
import gr.serafeim.*;
public static void main(String args[]) {
// Test is a member of gr.serafeim !
Test t = new Test(5);
int i=3;
t.add(i);
}
What I'd like to get as a return from the previous file would be something like this 我想从前一个文件返回的内容是这样的
main.java: 5: Test t = new Test(5);
main.java: 7: t.add(i);
If the previous can't be done, then I could also go with a way to massively name qualify all my classes. 如果以前不能完成,那么我也可以采用一种方法来大规模命名我的所有课程。 So the statement
所以声明
Test t = new Test(5);
would become 会成为
gr.serafeim.Test t = new gr.serafeim.Test(5);
and then I'd just grep for gr.serafiem. 然后我只需要grep来获取gr.serafiem。 This of course won't help in finding the t.add(i) line but would be a good first step and I could go from there checking the code myself ...
这当然不会找到t.add(i)行,但这将是一个很好的第一步,我可以自己去检查代码...
You can select class, constructor, method or field and press "ctrl + alt+ h". 您可以选择类,构造函数,方法或字段,然后按“ctrl + alt + h”。 This opens the call hierarchy menu.
这将打开调用层次结构菜单。
Right-click -> References -> (whichever you want). 右键单击 - >引用 - >(根据需要)。 For workspace references, Shift-Ctrl-G (by default, anyway).
对于工作空间引用,请按Shift-Ctrl-G(无论如何,默认情况下)。
I think the default results list is a tree, that can be changed to a list. 我认为默认结果列表是一棵树,可以将其更改为列表。 I don't think it shows line numbers, however, at least in the slightly-dated version of Eclipse I'm using.
我不认为它显示行号,但是,至少在我使用的Eclipse的较早版本中。 If you're specifically looking for line numbers, I don't think the default tools have an export that includes them.
如果您正在专门寻找行号,那么我认为默认工具不会包含该行。
You might try the IntelliJ Community Edition; 您可以尝试IntelliJ Community Edition; its searches do show line numbers, and results are exportable to a text file (fragment below).
它的搜索确实显示行号,结果可导出到文本文件(下面的片段)。
Class
server.UDPServer
Found usages (44 usages)
StartThread.java (6 usages)
(12: 19) private final UDPServer myserv;
(14: 17) StartThread(UDPServer server){
(18: 16) myserv.button1.setEnabled(false);
(19: 16) myserv.button2.setEnabled(true);
(30: 32) myserv.area.append("Server is started\n");
(37: 36) myserv.area.append(" Received "
Here's a hack: 这是一个hack:
Mark the package as deprecated using a package-info.java file: 使用package-info.java文件将包标记为已弃用:
@Deprecated
package com.yourcompany.yourpackage;
Now you should see compiler warnings everywhere you use the package 现在,您应该在使用该软件包的任何地方看到编译器警告
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.