Search method occurrencies in java methods

76 Views Asked by At

I have a task to implement IDE's find usages analog, using Java. The idea is that to find a some string, distinguish where it contains(in method, static block, field and etc.) and recursively find a methods which contain this found methods, fields and etc(build call tree from the bottom level to top). What is the best method to find usages of field, method in another method?(i can use regexp for that, but it'll be so slow). Some examples below:

public class A { 
    public String fieldToSearch = "someSearchPattern";
}

public class B {
    public void methodWhichContainsCallOfFieldToSearch() {
        A a = new A();
        sout(a.fieldToSearch);
    }
}

or

public class B {
    public void methodWhichContainsCallOfFieldToSearch(A a) {
        sout(a.fieldToSearch);
    }
}

The idea is to find method "methodWhichContainsCallOfFieldToSearch" that it really calls field "fieldToSearch" from class A. All tips, tricks or literature will be appreciated.

0

There are 0 best solutions below