4 comments
Comment actions Permalink

Hello chandra,

The recommended way to register file templates is simply to store them as
files in the "fileTemplates/includes" directory of your plugin.

addPattern() from com.intellij.ide.fileTemplates.FileTemplateManager
is deleted in
http://git.jetbrains.org/?p=idea/community.git;a=commitdiff;h=b63986dc
e8a5c49dd6031cd066f3746074438d80. Is there any alternative to this?


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


0
Comment actions Permalink

I am using the following template for new class:

#parse("Copyright Header.java")
#if (${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
public class ${NAME} {
}

I have added 'Copyright Header' template using the following code snippet:

FileTemplateManager.addTemplate("Copyright Header", "java").setText(lines("// Copyright ${YEAR}  blah", ""));


Now, Copyright Header template is available under Templates tab.

I am getting the following exception during New Class creation:

[ 413556]  ERROR - fileTemplates.FileTemplateUtil - Error evaluating template:
#parse("Copyright Header.java")
#if (${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
public class ${NAME} {
}

org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'Copyright Header.java'
    at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:452)
    at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:335)
    at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1102)
    at org.apache.velocity.runtime.directive.Parse.render(Parse.java:177)
    at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:170)
    at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:318)
    at org.apache.velocity.app.Velocity.evaluate(Velocity.java:322)
    at org.apache.velocity.app.Velocity.evaluate(Velocity.java:195)
    at com.intellij.ide.fileTemplates.FileTemplateUtil.a(FileTemplateUtil.java:230)
    at com.intellij.ide.fileTemplates.FileTemplateUtil.mergeTemplate(FileTemplateUtil.java:224)
...

Does adding 'Copyright Header.java' file fileTemplates/includes solves this problem?

Adding this 'Copyright Header' template manually under Includes tab seems to work fine.

Thanks,
Chandra

0
Comment actions Permalink

Update: code snippet given below is working fine.

Initially, I tried putting 'Copyright Header.java' under fileTemplates/includes directory of a plugin. But, using spaces in file-names is not allowed in our code base. So, I tried placing 'CopyrightHeader.java' under fileTemplates/includes directory of one-of- my plugins. Still. I couldnt see 'CopyrightHeader' under Includes tab of File Templates. Another issue is: now, I have to update default template pattern of Class, Interface etc (as they are using 'Copyright Header.java' in their pattern).

Is there a way to override these patterns as part of Intellij 10 install packages? Or, is there another way of adding 'Copyright Header.java' to Includes of File Templates?

I tried to get the effect of FileTemplateManger.addPatern() using the following code [and it is working as intended].

      FileTemplate patternTemplates[] = templateManager.getAllPatterns();
      CustomFileTemplate copyRightTemplate = new CustomFileTemplate("Copyright Header", "java");
      copyRightTemplate.setText(lines(
          "// Copyright ${YEAR} blah ",
          ""
      ));
      List<FileTemplate> updatedPatternTemplates = new ArrayList<FileTemplate>(Arrays.asList(patternTemplates));
      updatedPatternTemplates.add(copyRightTemplate);
      templateManager.setTemplates(FileTemplateManager.INCLUDES_TEMPLATES_CATEGORY, updatedPatternTemplates);

Thanks,
Chandra

0
Comment actions Permalink

Try to add *.ft to compiler options in order to include ft files from fileTemplates/includes in the bundle. This helped me.

0

Please sign in to leave a comment.