Generating source code in FacetTypeFrameworkSupportProvider

I have a FacetTypeFrameworkSupportProvider implementation and i would like to generate some classes when the facet is created.

So, i overrided the onFacetCreated method and implemented the generation logic there. Everything inside a StartupManager.runWhenProjectIsInitialized block.

For creating packages i'm using PackageUtil.findOrCreateDirectoryForPackage.
This fails, as a dialog shows up saying:

"No Source Roots configured for module xxx. Please use Settings | Paths to configure roots"

and then the project settings window shows up.

Any idea how i can do this ?

1 comment
Comment actions Permalink

When onFacetCreate is called the module isn't initialized yet.
StartupManager#runWhenProjectIsInitialized helps if you are creating new
project but if you are creating new module in the existent project the
runnable passed to runWhenProjectIsInitialized will be executed
immediately because project is already initialized.

You can use "rootModel" parameter of "onFacetCreated" method to access
root model of the module being created. E.g. you can use get source
roots by using rootModel.getSourceRoots(), when create directories using
VirtualFile#createChildDirectory, create java-file using
VirtualFile#createChildData and write text to that file using
VfsUtil.saveText.

I have a FacetTypeFrameworkSupportProvider implementation and i would like to generate some classes when the facet is created.

So, i overrided the onFacetCreated method and implemented the generation logic there. Everything inside a StartupManager.runWhenProjectIsInitialized block.

For creating packages i'm using PackageUtil.findOrCreateDirectoryForPackage.
This fails, as a dialog shows up saying:

"No Source Roots configured for module xxx. Please use Settings | Paths to configure roots"

and then the project settings window shows up.

Any idea how i can do this ?



--
Nikolay Chashnikov
Software Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

0

Please sign in to leave a comment.