use of org.apache.velocity.runtime.parser.ParseException in project intellij-community by JetBrains.
the class CreateFileFromTemplateAction method createFileFromTemplate.
@Nullable
public static PsiFile createFileFromTemplate(@Nullable String name, @NotNull FileTemplate template, @NotNull PsiDirectory dir, @Nullable String defaultTemplateProperty, boolean openFile, @NotNull Map<String, String> liveTemplateDefaultValues) {
if (name != null) {
CreateFileAction.MkDirs mkdirs = new CreateFileAction.MkDirs(name, dir);
name = mkdirs.newName;
dir = mkdirs.directory;
}
PsiElement element;
Project project = dir.getProject();
try {
element = FileTemplateUtil.createFromTemplate(template, name, FileTemplateManager.getInstance(dir.getProject()).getDefaultProperties(), dir);
final PsiFile psiFile = element.getContainingFile();
final VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile != null) {
if (openFile) {
if (template.isLiveTemplateEnabled()) {
CreateFromTemplateActionBase.startLiveTemplate(psiFile, liveTemplateDefaultValues);
} else {
FileEditorManager.getInstance(project).openFile(virtualFile, true);
}
}
if (defaultTemplateProperty != null) {
PropertiesComponent.getInstance(project).setValue(defaultTemplateProperty, template.getName());
}
return psiFile;
}
} catch (ParseException e) {
throw new IncorrectOperationException("Error parsing Velocity template: " + e.getMessage(), (Throwable) e);
} catch (IncorrectOperationException e) {
throw e;
} catch (Exception e) {
LOG.error(e);
}
return null;
}
use of org.apache.velocity.runtime.parser.ParseException in project intellij-plugins by JetBrains.
the class FlexMainStep method commit.
@Override
public void commit(final CommitType commitType) throws CommitStepException {
super.commit(commitType);
// let's replace parent component only if template contains 'Superclass' macro
final FileTemplate template;
try {
template = ClassLoaderUtil.runWithClassLoader(ActionScriptCreateClassOrInterfaceFix.class.getClassLoader(), new ThrowableComputable<FileTemplate, IOException>() {
@Override
public FileTemplate compute() throws IOException {
return FileTemplateManager.getDefaultInstance().getInternalTemplate(myModel.getTemplateName());
}
});
String[] attributes = FileTemplateUtil.calculateAttributes(template.getText(), new Properties(), true, myProject);
if (ArrayUtil.contains(ActionScriptCreateClassOrInterfaceFix.SUPERCLASS, attributes)) {
myModel.setSuperclassFqn(getSuperclassFqn());
}
} catch (IOException e) {
// ignore as the action will not succeed
} catch (ParseException e) {
// ignore as the action will not succeed
}
}
Aggregations