In my custom Eclipse plugin, I have the fully qualified class name of a Java class as a String, and want to know its actual file path. In fact, I want to know the name of the source folder it resides in.
The class could be from any of the Java projects in the Workspace. The source folder names are arbitrary.
I use Eclipse 3.6.
Thanks!
You will have to use the search engine API. See org.eclipse.jdt.core.search.SearchEngine
.
You can see that there are various static functions you can call, each with their own options. You will need to create an appropriate org.eclipse.jdt.core.search.SearchPattern
and then pass it to the search engine along with a scope (the workspace) and a requestor (something that gathers all of the results).
Typically, you will get a bunch of stuff back, like IType
s, which are the public API for accessing types in the Java model. You can call IType.getResource().getLocation()
to get the filesystem location of any type. The getResource method may return null, so you need to check for that.
You will need to use the JDT API stuff to get to the IResource
of the Java class. From there you can use the Resource API to get the containing folders and whatever else you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With