public static PsiFile createFromTemplate(@NotNull final PsiDirectory directory,
@NotNull final String name,
@NotNull String fileName,
@NotNull String templateName,
@NonNls String... parameters) throws IncorrectOperationException {
final FileTemplate template = FileTemplateManager.getInstance().getInternalTemplate(templateName);
Properties properties = new Properties(FileTemplateManager.getInstance().getDefaultProperties());
JavaTemplateUtil.setPackageNameAttribute(properties, directory);
properties.setProperty(NAME_TEMPLATE_PROPERTY, name);
properties.setProperty(LOW_CASE_NAME_TEMPLATE_PROPERTY, name.substring(0, 1).toLowerCase() + name.substring(1));
for (int i = 0; i < parameters.length; i += 2) {
properties.setProperty(parameters[i], parameters[i + 1]);
}
String text;
try {
text = template.getText(properties);
} catch (Exception e) {
throw new RuntimeException("Unable to load template for " + FileTemplateManager.getInstance().internalTemplateToSubject(templateName),
e);
}