How create a VirtualFile if the package name and file name is known?


I have a package name of a java class and the name of the class itself, like "". How can I create a VirtualFile that points to that java class?

1 comment
Comment actions Permalink

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


Please sign in to leave a comment.