找出Java/Eclipse项目中使用特定包的类的位置

发布于 2024-12-10 12:48:49 字数 999 浏览 0 评论 0原文

我有许多 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 ...

This is not the same with this question!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

少女情怀诗 2024-12-17 12:48:49

这里有一个技巧:

使用 package-info.java 文件将包标记为已弃用:

@Deprecated
package com.yourcompany.yourpackage;

现在您应该在使用该包的任何地方看到编译器警告

Here's a hack:

Mark the package as deprecated using a package-info.java file:

@Deprecated
package com.yourcompany.yourpackage;

Now you should see compiler warnings everywhere you use the package

梦断已成空 2024-12-17 12:48:49

右键->参考文献-> (无论你想要哪个)。对于工作区引用,请使用 Shift-Ctrl-G(无论如何,默认情况下)。

我认为默认结果列表是一棵树,可以更改为列表。不过,我认为它会显示行号,至少在我使用的稍微过时的 Eclipse 版本中是这样。如果您专门寻找行号,我认为默认工具没有包含它们的导出。

您可以尝试 IntelliJ Community Edition;它的搜索确实显示行号,并且结果可以导出到文本文件(下面的片段)。

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 "

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).

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 "
心安伴我暖 2024-12-17 12:48:49

您可以选择类、构造函数、方法或字段,然后按“ctrl + alt+ h”。这将打开呼叫层次结构菜单。

You can select class, constructor, method or field and press "ctrl + alt+ h". This opens the call hierarchy menu.

昔梦 2024-12-17 12:48:49

只需从构建路径中删除该包,编译器就会在使用它的任何地方开始显示错误。

Simply remove the package from your build path and the compiler starts showing error wherever it is used.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文