How create a VirtualFile if the package name and file name is known?
Hi!
I have a package name of a java class and the name of the class itself, like "com.mypackage.myapp.myclass.java". How can I create a VirtualFile that points to that java class?
Please sign in to leave a comment.
A package name can correspond to multiple directories (in different modules or different source roots of a module). In order to create a file, you need either to choose one of the directories yourself or offer that choice to your user. To get the list of directories corresponding to a package name, you can use PackageIndex.getDirectoriesByPackageName().
Once you have a specific directory, you can use VirtualFile.createChildData() or PsiDirectory.add() to create a file, as described in http://confluence.jetbrains.com/display/IDEADEV/IntelliJ+IDEA+Architectural+Overview