Search in sources :

Example 11 with FileTemplateManager

use of com.intellij.ide.fileTemplates.FileTemplateManager in project android by JetBrains.

the class AndroidStudioInitializer method setUpNewProjectActions.

private static void setUpNewProjectActions() {
    replaceAction("NewClass", new CreateClassAction());
    // Update the text for the file creation templates.
    FileTemplateManager fileTemplateManager = FileTemplateManager.getDefaultInstance();
    fileTemplateManager.getTemplate("Singleton").setText(fileTemplateManager.getJ2eeTemplate("Singleton").getText());
    for (String templateName : new String[] { "Class", "Interface", "Enum", "AnnotationType" }) {
        FileTemplate template = fileTemplateManager.getInternalTemplate(templateName);
        template.setText(fileTemplateManager.getJ2eeTemplate(templateName).getText());
    }
}
Also used : CreateClassAction(com.android.tools.idea.actions.CreateClassAction) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) FileTemplateManager(com.intellij.ide.fileTemplates.FileTemplateManager)

Example 12 with FileTemplateManager

use of com.intellij.ide.fileTemplates.FileTemplateManager in project Aspose.Imaging-for-Java by aspose-imaging.

the class AsposeMavenUtil method runOrApplyFileTemplate.

private static void runOrApplyFileTemplate(Project project, VirtualFile file, String templateName, Properties properties) throws IOException {
    FileTemplateManager manager = FileTemplateManager.getInstance();
    FileTemplate fileTemplate = manager.getJ2eeTemplate(templateName);
    Properties allProperties = manager.getDefaultProperties(project);
    allProperties.putAll(properties);
    String text = fileTemplate.getText(allProperties);
    Pattern pattern = Pattern.compile("\\$\\{(.*)\\}");
    Matcher matcher = pattern.matcher(text);
    StringBuffer builder = new StringBuffer();
    while (matcher.find()) {
        matcher.appendReplacement(builder, "\\$" + matcher.group(1).toUpperCase() + "\\$");
    }
    matcher.appendTail(builder);
    text = builder.toString();
    TemplateImpl template = (TemplateImpl) TemplateManager.getInstance(project).createTemplate("", "", text);
    for (int i = 0; i < template.getSegmentsCount(); i++) {
        if (i == template.getEndSegmentNumber())
            continue;
        String name = template.getSegmentName(i);
        String value = "\"" + properties.getProperty(name, "") + "\"";
        template.addVariable(name, value, value, true);
    }
    VfsUtil.saveText(file, template.getTemplateText());
    PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
    if (psiFile != null) {
        new ReformatCodeProcessor(project, psiFile, null, false).run();
    }
}
Also used : TemplateImpl(com.intellij.codeInsight.template.impl.TemplateImpl) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) FileTemplateManager(com.intellij.ide.fileTemplates.FileTemplateManager) PsiFile(com.intellij.psi.PsiFile) ReformatCodeProcessor(com.intellij.codeInsight.actions.ReformatCodeProcessor) Properties(java.util.Properties)

Example 13 with FileTemplateManager

use of com.intellij.ide.fileTemplates.FileTemplateManager in project Aspose.BarCode-for-Java by aspose-barcode.

the class AsposeMavenUtil method runOrApplyFileTemplate.

private static void runOrApplyFileTemplate(Project project, VirtualFile file, String templateName, Properties properties) throws IOException {
    FileTemplateManager manager = FileTemplateManager.getInstance();
    FileTemplate fileTemplate = manager.getJ2eeTemplate(templateName);
    Properties allProperties = manager.getDefaultProperties(project);
    allProperties.putAll(properties);
    String text = fileTemplate.getText(allProperties);
    Pattern pattern = Pattern.compile("\\$\\{(.*)\\}");
    Matcher matcher = pattern.matcher(text);
    StringBuffer builder = new StringBuffer();
    while (matcher.find()) {
        matcher.appendReplacement(builder, "\\$" + matcher.group(1).toUpperCase() + "\\$");
    }
    matcher.appendTail(builder);
    text = builder.toString();
    TemplateImpl template = (TemplateImpl) TemplateManager.getInstance(project).createTemplate("", "", text);
    for (int i = 0; i < template.getSegmentsCount(); i++) {
        if (i == template.getEndSegmentNumber())
            continue;
        String name = template.getSegmentName(i);
        String value = "\"" + properties.getProperty(name, "") + "\"";
        template.addVariable(name, value, value, true);
    }
    VfsUtil.saveText(file, template.getTemplateText());
    PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
    if (psiFile != null) {
        new ReformatCodeProcessor(project, psiFile, null, false).run();
    }
}
Also used : TemplateImpl(com.intellij.codeInsight.template.impl.TemplateImpl) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) FileTemplateManager(com.intellij.ide.fileTemplates.FileTemplateManager) PsiFile(com.intellij.psi.PsiFile) ReformatCodeProcessor(com.intellij.codeInsight.actions.ReformatCodeProcessor) Properties(java.util.Properties)

Example 14 with FileTemplateManager

use of com.intellij.ide.fileTemplates.FileTemplateManager in project Aspose.OCR-for-Java by aspose-ocr.

the class AsposeMavenUtil method runOrApplyFileTemplate.

private static void runOrApplyFileTemplate(Project project, VirtualFile file, String templateName, Properties properties) throws IOException {
    FileTemplateManager manager = FileTemplateManager.getInstance();
    FileTemplate fileTemplate = manager.getJ2eeTemplate(templateName);
    Properties allProperties = manager.getDefaultProperties(project);
    allProperties.putAll(properties);
    String text = fileTemplate.getText(allProperties);
    Pattern pattern = Pattern.compile("\\$\\{(.*)\\}");
    Matcher matcher = pattern.matcher(text);
    StringBuffer builder = new StringBuffer();
    while (matcher.find()) {
        matcher.appendReplacement(builder, "\\$" + matcher.group(1).toUpperCase() + "\\$");
    }
    matcher.appendTail(builder);
    text = builder.toString();
    TemplateImpl template = (TemplateImpl) TemplateManager.getInstance(project).createTemplate("", "", text);
    for (int i = 0; i < template.getSegmentsCount(); i++) {
        if (i == template.getEndSegmentNumber())
            continue;
        String name = template.getSegmentName(i);
        String value = "\"" + properties.getProperty(name, "") + "\"";
        template.addVariable(name, value, value, true);
    }
    VfsUtil.saveText(file, template.getTemplateText());
    PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
    if (psiFile != null) {
        new ReformatCodeProcessor(project, psiFile, null, false).run();
    }
}
Also used : TemplateImpl(com.intellij.codeInsight.template.impl.TemplateImpl) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) FileTemplateManager(com.intellij.ide.fileTemplates.FileTemplateManager) PsiFile(com.intellij.psi.PsiFile) ReformatCodeProcessor(com.intellij.codeInsight.actions.ReformatCodeProcessor) Properties(java.util.Properties)

Example 15 with FileTemplateManager

use of com.intellij.ide.fileTemplates.FileTemplateManager in project Aspose.Cells-for-Java by aspose-cells.

the class AsposeMavenUtil method runOrApplyFileTemplate.

private static void runOrApplyFileTemplate(Project project, VirtualFile file, String templateName, Properties properties) throws IOException {
    FileTemplateManager manager = FileTemplateManager.getInstance();
    FileTemplate fileTemplate = manager.getJ2eeTemplate(templateName);
    Properties allProperties = manager.getDefaultProperties(project);
    allProperties.putAll(properties);
    String text = fileTemplate.getText(allProperties);
    Pattern pattern = Pattern.compile("\\$\\{(.*)\\}");
    Matcher matcher = pattern.matcher(text);
    StringBuffer builder = new StringBuffer();
    while (matcher.find()) {
        matcher.appendReplacement(builder, "\\$" + matcher.group(1).toUpperCase() + "\\$");
    }
    matcher.appendTail(builder);
    text = builder.toString();
    TemplateImpl template = (TemplateImpl) TemplateManager.getInstance(project).createTemplate("", "", text);
    for (int i = 0; i < template.getSegmentsCount(); i++) {
        if (i == template.getEndSegmentNumber())
            continue;
        String name = template.getSegmentName(i);
        String value = "\"" + properties.getProperty(name, "") + "\"";
        template.addVariable(name, value, value, true);
    }
    VfsUtil.saveText(file, template.getTemplateText());
    PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
    if (psiFile != null) {
        new ReformatCodeProcessor(project, psiFile, null, false).run();
    }
}
Also used : TemplateImpl(com.intellij.codeInsight.template.impl.TemplateImpl) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) FileTemplateManager(com.intellij.ide.fileTemplates.FileTemplateManager) PsiFile(com.intellij.psi.PsiFile) ReformatCodeProcessor(com.intellij.codeInsight.actions.ReformatCodeProcessor) Properties(java.util.Properties)

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