Search code examples
javaeclipsefindgreppackage

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". 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!


Solution

  • 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