找出Java/Eclipse项目中使用特定包的类的位置
我有许多 Eclipse 项目,它们都使用特定包中的类,我们将其称为“gr.serafeim”。现在,我想找到所有源文件中 gr.serafeim 成员的使用位置(每个文件的哪些行号)。问题是我通常使用导入而不是类的完全限定名称,因此搜索“gr.serafeim”只会返回导入语句:(
我不想要任何东西,只是一个快速而肮脏的解决方案找出包含 gr.serafeim 包的类(一个 eclipse 插件?)的所有行。作为附加值,我不仅想要这些函数的声明,还想要这些函数的方法调用,
这是我真正想要的示例 。 :
// 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);
}
什么我希望从前一个文件中得到的返回结果是这样的
main.java: 5: Test t = new Test(5);
main.java: 7: t.add(i);
如果前一个文件无法完成,那么我也可以采用一种方法来大规模命名我的所有类,因此该语句
Test t = new Test(5);
将变为
gr.serafeim.Test t = new gr.serafeim.Test(5);
然后 。我只是 grep for gr.serafiem 。这当然不会帮助找到 t.add(i) 行,但这是一个很好的第一步,我可以从那里开始自己检查代码...
I have a number of Eclipse projects that are all using classes from a specific package, let's call it "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. 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 :(
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 ?). 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. 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 ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这里有一个技巧:
使用 package-info.java 文件将包标记为已弃用:
现在您应该在使用该包的任何地方看到编译器警告
Here's a hack:
Mark the package as deprecated using a package-info.java file:
Now you should see compiler warnings everywhere you use the package
右键->参考文献-> (无论你想要哪个)。对于工作区引用,请使用 Shift-Ctrl-G(无论如何,默认情况下)。
我认为默认结果列表是一棵树,可以更改为列表。不过,我不认为它会显示行号,至少在我使用的稍微过时的 Eclipse 版本中是这样。如果您专门寻找行号,我认为默认工具没有包含它们的导出。
您可以尝试 IntelliJ Community Edition;它的搜索确实显示行号,并且结果可以导出到文本文件(下面的片段)。
Right-click -> References -> (whichever you want). For workspace references, Shift-Ctrl-G (by default, anyway).
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. 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; its searches do show line numbers, and results are exportable to a text file (fragment below).
您可以选择类、构造函数、方法或字段,然后按“ctrl + alt+ h”。这将打开呼叫层次结构菜单。
You can select class, constructor, method or field and press "ctrl + alt+ h". This opens the call hierarchy menu.
只需从构建路径中删除该包,编译器就会在使用它的任何地方开始显示错误。
Simply remove the package from your build path and the compiler starts showing error wherever it is used.