Search in sources :

Example 1 with FileTemplate

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

the class GroovyGenerateMethodMissingHandler method generateMemberPrototypes.

@NotNull
@Override
protected List<? extends GenerationInfo> generateMemberPrototypes(PsiClass aClass, ClassMember[] members) throws IncorrectOperationException {
    final String templName = JavaTemplateUtil.TEMPLATE_FROM_USAGE_METHOD_BODY;
    final FileTemplate template = FileTemplateManager.getInstance(aClass.getProject()).getCodeTemplate(templName);
    final GrMethod method = genMethod(aClass, template);
    return method != null ? Collections.singletonList(new GroovyGenerationInfo<>(method, true)) : Collections.<GenerationInfo>emptyList();
}
Also used : FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) GroovyGenerationInfo(org.jetbrains.plugins.groovy.actions.generate.GroovyGenerationInfo) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with FileTemplate

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

the class CCUtils method createTaskContent.

public static void createTaskContent(@NotNull Project project, @Nullable IdeView view, @NotNull Course course, PsiDirectory taskDirectory) {
    CCLanguageManager manager = getStudyLanguageManager(course);
    if (manager == null) {
        return;
    }
    createFromTemplate(taskDirectory, manager.getTestsTemplate(project), view, false);
    createFromTemplate(taskDirectory, FileTemplateManager.getInstance(project).getInternalTemplate(StudyUtils.getTaskDescriptionFileName(CCSettings.getInstance().useHtmlAsDefaultTaskFormat())), view, false);
    String defaultExtension = manager.getDefaultTaskFileExtension();
    if (defaultExtension != null) {
        FileTemplate taskFileTemplate = manager.getTaskFileTemplateForExtension(project, defaultExtension);
        createFromTemplate(taskDirectory, taskFileTemplate, view, true);
    }
}
Also used : FileTemplate(com.intellij.ide.fileTemplates.FileTemplate)

Example 3 with FileTemplate

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

the class PyMoveTest method testTemplateAttributesExpansionInCreatedDestinationModule.

// PY-14979
public void testTemplateAttributesExpansionInCreatedDestinationModule() {
    final FileTemplateManager instance = FileTemplateManager.getInstance(myFixture.getProject());
    final FileTemplate template = instance.getInternalTemplate("Python Script");
    assertNotNull(template);
    final String oldTemplateContent = template.getText();
    try {
        template.setText("NAME = '${NAME}'");
        doMoveSymbolTest("C", "b.py");
    } finally {
        template.setText(oldTemplateContent);
    }
}
Also used : FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) FileTemplateManager(com.intellij.ide.fileTemplates.FileTemplateManager)

Example 4 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 5 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)74 FileTemplateManager (com.intellij.ide.fileTemplates.FileTemplateManager)24 PsiFile (com.intellij.psi.PsiFile)15 IOException (java.io.IOException)15 Properties (java.util.Properties)14 Project (com.intellij.openapi.project.Project)13 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 PsiDirectory (com.intellij.psi.PsiDirectory)9 IncorrectOperationException (com.intellij.util.IncorrectOperationException)8 Pattern (java.util.regex.Pattern)7 NotNull (org.jetbrains.annotations.NotNull)7 ReformatCodeProcessor (com.intellij.codeInsight.actions.ReformatCodeProcessor)6 PsiElement (com.intellij.psi.PsiElement)6 File (java.io.File)6 Matcher (java.util.regex.Matcher)6 TemplateImpl (com.intellij.codeInsight.template.impl.TemplateImpl)5 Module (com.intellij.openapi.module.Module)5 Nullable (org.jetbrains.annotations.Nullable)5 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)5 Editor (com.intellij.openapi.editor.Editor)3