1

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!

Community
  • 1
  • 1
Serafeim
  • 14,962
  • 14
  • 91
  • 133

4 Answers4

1

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

mdanaci
  • 96
  • 4
1

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 "
Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • 1
    @SeanPatrickFloyd Oh, I see. In that case, I don't think there's a great option without pulling from byte code. – Dave Newton Oct 19 '11 at 15:25
1

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

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
  • This seems really nice, I didn't actually know about the package-info.java file ! – Serafeim Oct 20 '11 at 07:41
  • Actually, I see now that you need to put the package-info.java file inside the source code of the package. My problem is that I do not have the sources of the library I am using !!! So what could I do now ? – Serafeim Oct 20 '11 at 08:00
  • @Serafeim remove the library from your build path. Now compiler errors will show up everywhere you use the library's classes. – Sean Patrick Floyd Oct 20 '11 at 08:16
0

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

Hamza Safdar
  • 113
  • 5