Search in sources :

Example 6 with FileTemplateManager

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()));
    }
}
Also used : ConfigurationException(com.intellij.openapi.options.ConfigurationException) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) FileTemplateManager(com.intellij.ide.fileTemplates.FileTemplateManager) IOException(java.io.IOException)

Example 7 with FileTemplateManager

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()));
    }
}
Also used : ConfigurationException(com.intellij.openapi.options.ConfigurationException) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) FileTemplateManager(com.intellij.ide.fileTemplates.FileTemplateManager) IOException(java.io.IOException)

Example 8 with FileTemplateManager

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);
}
Also used : FileTemplateManager(com.intellij.ide.fileTemplates.FileTemplateManager)

Example 9 with FileTemplateManager

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);
}
Also used : FileTemplateManager(com.intellij.ide.fileTemplates.FileTemplateManager) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with FileTemplateManager

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);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) PackageWrapper(com.intellij.refactoring.PackageWrapper) IncorrectOperationException(com.intellij.util.IncorrectOperationException) FileTemplateManager(com.intellij.ide.fileTemplates.FileTemplateManager) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Module(com.intellij.openapi.module.Module)

Aggregations

FileTemplateManager (com.intellij.ide.fileTemplates.FileTemplateManager)25 FileTemplate (com.intellij.ide.fileTemplates.FileTemplate)23 PsiFile (com.intellij.psi.PsiFile)7 Project (com.intellij.openapi.project.Project)6 Properties (java.util.Properties)6 ReformatCodeProcessor (com.intellij.codeInsight.actions.ReformatCodeProcessor)5 TemplateImpl (com.intellij.codeInsight.template.impl.TemplateImpl)5 Matcher (java.util.regex.Matcher)5 Pattern (java.util.regex.Pattern)5 IncorrectOperationException (com.intellij.util.IncorrectOperationException)4 IOException (java.io.IOException)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 File (java.io.File)3 NotNull (org.jetbrains.annotations.NotNull)3 Editor (com.intellij.openapi.editor.Editor)2 Module (com.intellij.openapi.module.Module)2 ConfigurationException (com.intellij.openapi.options.ConfigurationException)2 ArrayList (java.util.ArrayList)2 Nullable (org.jetbrains.annotations.Nullable)2 CreateClassAction (com.android.tools.idea.actions.CreateClassAction)1