Search in sources :

Example 6 with FileTemplate

use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.

the class GroovyOverrideImplementUtil method generateMethodPrototype.

public static GrMethod generateMethodPrototype(GrTypeDefinition aClass, PsiMethod method, PsiSubstitutor substitutor) {
    final Project project = aClass.getProject();
    final boolean isAbstract = method.hasModifierProperty(PsiModifier.ABSTRACT);
    String templName = isAbstract ? JavaTemplateUtil.TEMPLATE_IMPLEMENTED_METHOD_BODY : JavaTemplateUtil.TEMPLATE_OVERRIDDEN_METHOD_BODY;
    final FileTemplate template = FileTemplateManager.getInstance(method.getProject()).getCodeTemplate(templName);
    final GrMethod result = (GrMethod) GenerateMembersUtil.substituteGenericMethod(method, substitutor, aClass);
    setupModifierList(result);
    setupOverridingMethodBody(project, method, result, template, substitutor);
    setupReturnType(result, method);
    setupAnnotations(aClass, method, result);
    GroovyChangeContextUtil.encodeContextInfo(result);
    return result;
}
Also used : Project(com.intellij.openapi.project.Project) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)

Example 7 with FileTemplate

use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.

the class CCNewSubtaskAction method createTaskDescriptionFile.

private static void createTaskDescriptionFile(Project project, VirtualFile taskDir, int index) {
    String taskDescriptionFileName = StudyUtils.getTaskDescriptionFileName(CCSettings.getInstance().useHtmlAsDefaultTaskFormat());
    FileTemplate taskTextTemplate = FileTemplateManager.getInstance(project).getInternalTemplate(taskDescriptionFileName);
    PsiDirectory taskPsiDir = PsiManager.getInstance(project).findDirectory(taskDir);
    if (taskTextTemplate != null && taskPsiDir != null) {
        String nextTaskTextName = FileUtil.getNameWithoutExtension(taskDescriptionFileName) + EduNames.SUBTASK_MARKER + index + "." + FileUtilRt.getExtension(taskDescriptionFileName);
        try {
            FileTemplateUtil.createFromTemplate(taskTextTemplate, nextTaskTextName, null, taskPsiDir);
        } catch (Exception e) {
            LOG.error(e);
        }
    }
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate)

Example 8 with FileTemplate

use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.

the class CreatePackageAction method createInitPy.

private static void createInitPy(PsiDirectory directory) {
    final FileTemplateManager fileTemplateManager = FileTemplateManager.getInstance(directory.getProject());
    final FileTemplate template = fileTemplateManager.getInternalTemplate("Python Script");
    if (directory.findFile(PyNames.INIT_DOT_PY) != null) {
        return;
    }
    if (template != null) {
        try {
            FileTemplateUtil.createFromTemplate(template, PyNames.INIT_DOT_PY, fileTemplateManager.getDefaultProperties(), directory);
        } catch (Exception e) {
            LOG.error(e);
        }
    } else {
        final PsiFile file = PsiFileFactory.getInstance(directory.getProject()).createFileFromText(PyNames.INIT_DOT_PY, "");
        directory.add(file);
    }
}
Also used : FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) FileTemplateManager(com.intellij.ide.fileTemplates.FileTemplateManager) PsiFile(com.intellij.psi.PsiFile)

Example 9 with FileTemplate

use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.

the class JavaI18nizeQuickFixDialog method getI18nizedText.

public String getI18nizedText() {
    String propertyKey = StringUtil.escapeStringCharacters(getKey());
    I18nizedTextGenerator textGenerator = myResourceBundleManager.getI18nizedTextGenerator();
    if (textGenerator != null) {
        return generateText(textGenerator, propertyKey, getPropertiesFile(), myLiteralExpression);
    }
    String templateName = getTemplateName();
    LOG.assertTrue(templateName != null);
    FileTemplate template = FileTemplateManager.getInstance(myProject).getCodeTemplate(templateName);
    Map<String, String> attributes = new THashMap<>();
    attributes.put(PROPERTY_KEY_OPTION_KEY, propertyKey);
    attributes.put(RESOURCE_BUNDLE_OPTION_KEY, getResourceBundleText());
    attributes.put(PROPERTY_VALUE_ATTR, StringUtil.escapeStringCharacters(myDefaultPropertyValue));
    addAdditionalAttributes(attributes);
    String text = null;
    try {
        text = template.getText(attributes);
    } catch (IOException e) {
        LOG.error(e);
    }
    return text;
}
Also used : I18nizedTextGenerator(com.intellij.lang.properties.psi.I18nizedTextGenerator) THashMap(gnu.trove.THashMap) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) IOException(java.io.IOException)

Example 10 with FileTemplate

use of com.intellij.ide.fileTemplates.FileTemplate in project intellij-community by JetBrains.

the class JavaI18nizeQuickFixDialog method suggestAvailableResourceBundleExpressions.

private void suggestAvailableResourceBundleExpressions() {
    String templateName = getTemplateName();
    if (templateName == null)
        return;
    if (myShowJavaCodeInfo) {
        FileTemplate template = FileTemplateManager.getInstance(myProject).getCodeTemplate(templateName);
        boolean showResourceBundleSuggester = template.getText().contains("${" + RESOURCE_BUNDLE_OPTION_KEY + "}");
        myJavaCodeInfoPanel.setVisible(showResourceBundleSuggester);
    }
    Set<String> result = JavaI18nUtil.suggestExpressionOfType(myResourceBundleType, myLiteralExpression);
    if (result.isEmpty()) {
        result.add(getResourceBundleText());
    }
    myRBEditorTextField.setHistory(ArrayUtil.toStringArray(result));
    SwingUtilities.invokeLater(() -> myRBEditorTextField.setSelectedIndex(0));
}
Also used : FileTemplate(com.intellij.ide.fileTemplates.FileTemplate)

Aggregations

FileTemplate (com.intellij.ide.fileTemplates.FileTemplate)66 FileTemplateManager (com.intellij.ide.fileTemplates.FileTemplateManager)20 Project (com.intellij.openapi.project.Project)13 IOException (java.io.IOException)12 PsiFile (com.intellij.psi.PsiFile)10 Properties (java.util.Properties)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 IncorrectOperationException (com.intellij.util.IncorrectOperationException)8 PsiDirectory (com.intellij.psi.PsiDirectory)7 NotNull (org.jetbrains.annotations.NotNull)7 PsiElement (com.intellij.psi.PsiElement)6 Module (com.intellij.openapi.module.Module)5 File (java.io.File)5 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)5 Nullable (org.jetbrains.annotations.Nullable)4 Editor (com.intellij.openapi.editor.Editor)3 ConfigurationException (com.intellij.openapi.options.ConfigurationException)3 ArrayList (java.util.ArrayList)3 Pattern (java.util.regex.Pattern)3 ReformatCodeProcessor (com.intellij.codeInsight.actions.ReformatCodeProcessor)2