I am looking for a Java library (source code parser) that would help me extract unqualified names of all class names being used in the source code. For example for the given code example:
public class Example {
private ClassName1;
protected ClassName2 instance = new ClassName2();
public Example() {
ClassName3 test = new ClassName3();
}
public doSomething() {
//ClassName4 test = new ClassName4("SomeExampleString");
ClassName5 test = new ClassName5("ExampleString2");
}
}
I need to get the following list:
ClassName1, ClassName2, ClassName3, ClassName5
as this is the list of all names of classes that are being "used" in the source code.
So far I have tried to write a simple parser that would do this for me but is not robust enough to be used in the real world. I have looked into a few Java parsers too, but the problem is that I don't know how this problem would be called to look into their code for a solution, which I believe exists in the domain of existing Java parsers.
So what I am looking for is a Java source parser that would allow me to obtain a class name lists like the one in the example and a short example on how to achieve this or directions where to look for / how this problem is properly called.
NOTE: I am not looking for a method to detect all classes loaded by JVM nor classes in classpath, but a way to detect classes in textual sense by parsing original Java source code that is not compiled.