Adding and accessing File Templates

My plugin generates classes. Now I am putting the finishing touches on it and I'd like the plugin to follow the Idea look and feel and thus I want my class to automatically use the File Header template, and ideally I would even like the layout of my class to be configurable by adding an additional File Template to the list of existing templates. Is this supported by the Open API and how?

Thanks!

3 comments

FileTemplateManager and FileTemplateUtil come in handy here.

something like the following should create a document from a template :

private void createFileFromTemplate(final ModifiableRootModel
rootModel, final String templateName) throws Exception {
final Module module = rootModel.getModule();
final Project project = module.getProject();
final PsiDirectory directory =
PsiManager.getInstance(project).findDirectory(rootModel.getSourceRoots()[0]);
FileTemplate template =
FileTemplateManager.getInstance().getJ2eeTemplate(templateName);
FileTemplateUtil.createFromTemplate(new PsiElement[1], template,
templateName, new Properties(), project, directory);
}

0

Sounds reasonable, however, "my" OpenAPI doesn't seem to have a FileTemplateManager :-/ Gonna check if there is a newer version of the devkit...

0

Hello daniel,

Sounds reasonable, however, "my" OpenAPI doesn't seem to have a
FileTemplateManager :-/ Gonna check if there is a newer version of the
devkit...


You need to add idea.jar to the classpath of your IDEA JDK.

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Please sign in to leave a comment.