Replace variables in file/live template programatically


I have such simple code (shortened to just one template)

public class CreateOMIFileFromTemplateAction extends CreateFileFromTemplateAction {

private static final String ENTITY_TEMPLATE = "Entity";

public CreateOMIFileFromTemplateAction() {
super("OMI", "Create new OMI file", null);

protected void buildDialog(Project project, PsiDirectory directory, CreateFileFromTemplateDialog.Builder builder) {
builder.setTitle("New OMI file");
builder.addKind("Entity ", null, ENTITY_TEMPLATE);

protected String getActionName(PsiDirectory directory, String name, String template) {
return "Creating new OMI file";

protected PsiFile createFile(String name, String templateName, PsiDirectory dir) {
final FileTemplate template = FileTemplateManager.getInstance(dir.getProject()).getInternalTemplate(templateName);
String templateText = template.getText().replace("#[[ENTITY_NAME]]", "entity name here build from modified file path");
return createFileFromTemplate(name, template, dir);


I don't know if this is recommend way to do it, but it works OK. But in case I call template directly from Add->New Entity, not Wrapper dialog I am done. I can not override ActionPerformed because is final.

Is there any way to do that?

Thank you.




Please sign in to leave a comment.