VirtualFile from class name

Hi!

I am searching for a way to get a VirtualFile from a class name.

Could someone please give me a hint how to do that?

The class name can be a name of a class in a dependency or a class of my project.

Is there an easy way, or do I have to iterate through all the modules and dependencies?

Thanks!
Ciao,
Mario

4 comments
Comment actions Permalink

JavaPsiFacade#findClass().getContainingFile().getVirtualFile()

0
Comment actions Permalink

Thanks, this kinda works, but I should have been more clear. This gets me the .java file in case of a project class. What I need is the compiled class.

0
Comment actions Permalink

You may take the module output path from
ModuleRootManager.getModuleExtension(CompilerModuleExtension) and find
by a relative path there. But what do you need it for? The project may
be not compiled or out-of-date.

0
Comment actions Permalink

Yes, I am already experimenting with this thing. And it seems to start working.

I am implementing a plugin which runs as an after-compile task to enhance the generated classes to make them Ebean entity beans. Ebean is sort of a JPA implementation.
Basically, the plugin calls the Ebean class weaver with all the class files from the last compile run - much like how the aspectj plugin works, but in contrast to the aspectj plugin, the ebean weaver needs to lookup the class hierarchy. This is, where the findClass() stuff comes into play.

At the moment, if findClass() returns a non PsiCompiledElement, I use the "harder approach" by scanning through the project-output directory and all the module-output directories.

Since it is an after-compile task, I think it should always see a clean compiled project, no?

0

Please sign in to leave a comment.