use of com.intellij.ide.fileTemplates.FileTemplateManager in project intellij-community by JetBrains.
the class GradleModuleBuilder method saveFile.
private static void saveFile(@NotNull VirtualFile file, @NotNull String templateName, @Nullable Map templateAttributes) throws ConfigurationException {
FileTemplateManager manager = FileTemplateManager.getDefaultInstance();
FileTemplate template = manager.getInternalTemplate(templateName);
try {
appendToFile(file, templateAttributes != null ? template.getText(templateAttributes) : template.getText());
} catch (IOException e) {
LOG.warn(String.format("Unexpected exception on applying template %s config", GradleConstants.SYSTEM_ID.getReadableName()), e);
throw new ConfigurationException(e.getMessage(), String.format("Can't apply %s template config text", GradleConstants.SYSTEM_ID.getReadableName()));
}
}
use of com.intellij.ide.fileTemplates.FileTemplateManager in project intellij-community by JetBrains.
the class GradleModuleBuilder method appendToFile.
private static void appendToFile(@NotNull VirtualFile file, @NotNull String templateName, @Nullable Map templateAttributes) throws ConfigurationException {
FileTemplateManager manager = FileTemplateManager.getDefaultInstance();
FileTemplate template = manager.getInternalTemplate(templateName);
try {
appendToFile(file, templateAttributes != null ? template.getText(templateAttributes) : template.getText());
} catch (IOException e) {
LOG.warn(String.format("Unexpected exception on appending template %s config", GradleConstants.SYSTEM_ID.getReadableName()), e);
throw new ConfigurationException(e.getMessage(), String.format("Can't append %s template config text", GradleConstants.SYSTEM_ID.getReadableName()));
}
}
use of com.intellij.ide.fileTemplates.FileTemplateManager in project intellij-community by JetBrains.
the class TraverseUIStarter method processFileTemplates.
private static void processFileTemplates(Element configurableElement) {
SearchableOptionsRegistrar optionsRegistrar = SearchableOptionsRegistrar.getInstance();
Set<OptionDescription> options = new TreeSet<>();
FileTemplateManager fileTemplateManager = FileTemplateManager.getDefaultInstance();
processTemplates(optionsRegistrar, options, fileTemplateManager.getAllTemplates());
processTemplates(optionsRegistrar, options, fileTemplateManager.getAllPatterns());
processTemplates(optionsRegistrar, options, fileTemplateManager.getAllCodeTemplates());
processTemplates(optionsRegistrar, options, fileTemplateManager.getAllJ2eeTemplates());
writeOptions(configurableElement, options);
}
use of com.intellij.ide.fileTemplates.FileTemplateManager in project intellij-plugins by JetBrains.
the class StrutsFileTemplateProvider method determineFileTemplate.
@NotNull
public FileTemplate determineFileTemplate(Project project) {
String template;
if (isNewerThan("2.5")) {
template = StrutsFileTemplateGroupDescriptorFactory.STRUTS_2_5_XML;
} else if (isNewerThan("2.3")) {
template = StrutsFileTemplateGroupDescriptorFactory.STRUTS_2_3_XML;
} else if (my21orNewer) {
template = isNewerThan("2.1.7") ? StrutsFileTemplateGroupDescriptorFactory.STRUTS_2_1_7_XML : StrutsFileTemplateGroupDescriptorFactory.STRUTS_2_1_XML;
} else {
template = StrutsFileTemplateGroupDescriptorFactory.STRUTS_2_0_XML;
}
final FileTemplateManager fileTemplateManager = FileTemplateManager.getInstance(project);
return fileTemplateManager.getJ2eeTemplate(template);
}
use of com.intellij.ide.fileTemplates.FileTemplateManager in project intellij-plugins by JetBrains.
the class CreateValidationXmlIntention method createValidationXml.
private static void createValidationXml(final Project project, final PsiClass actionClass, @Nullable final String path) {
final PsiManager manager = PsiManager.getInstance(project);
final String actionClassQualifiedName = actionClass.getQualifiedName();
assert actionClassQualifiedName != null;
final PackageWrapper targetPackage = new PackageWrapper(manager, StringUtil.getPackageName(actionClassQualifiedName));
final Module module = ModuleUtilCore.findModuleForPsiElement(actionClass);
assert module != null;
final List<VirtualFile> sourceRoots = ModuleRootManager.getInstance(module).getSourceRoots(JavaModuleSourceRootTypes.PRODUCTION);
final VirtualFile sourceRoot = sourceRoots.size() == 1 ? sourceRoots.get(0) : MoveClassesOrPackagesUtil.chooseSourceRoot(targetPackage, sourceRoots, manager.findDirectory(sourceRoots.get(0)));
if (sourceRoot == null) {
return;
}
final PsiDirectory directory = manager.findDirectory(sourceRoot);
assert directory != null : sourceRoot.getPresentableUrl();
final FileTemplateManager templateManager = FileTemplateManager.getInstance(project);
final FileTemplate validationTemplate = templateManager.getJ2eeTemplate(StrutsFileTemplateGroupDescriptorFactory.VALIDATION_XML);
final PsiDirectory packageDirectoryInSourceRoot = RefactoringUtil.createPackageDirectoryInSourceRoot(targetPackage, sourceRoot);
try {
final String filename = path == null ? actionClass.getName() + "-validation.xml" : actionClass.getName() + "-" + path + "-validation.xml";
final PsiElement psiElement = FileTemplateUtil.createFromTemplate(validationTemplate, filename, null, packageDirectoryInSourceRoot);
NavigationUtil.activateFileWithPsiElement(psiElement, true);
} catch (Exception e) {
throw new IncorrectOperationException("error creating validation.xml", (Throwable) e);
}
}
Aggregations