Search in sources :

Example 6 with FileTemplateDescriptor

use of com.intellij.ide.fileTemplates.FileTemplateDescriptor in project intellij-plugins by JetBrains.

the class StrutsFileTemplateGroupDescriptorFactory method getFileTemplatesDescriptor.

public FileTemplateGroupDescriptor getFileTemplatesDescriptor() {
    final FileTemplateGroupDescriptor group = new FileTemplateGroupDescriptor(StrutsBundle.message("struts2"), Struts2Icons.Action);
    group.addTemplate(new FileTemplateDescriptor(STRUTS_2_0_XML, StrutsIcons.STRUTS_CONFIG_FILE));
    group.addTemplate(new FileTemplateDescriptor(STRUTS_2_1_XML, StrutsIcons.STRUTS_CONFIG_FILE));
    group.addTemplate(new FileTemplateDescriptor(STRUTS_2_1_7_XML, StrutsIcons.STRUTS_CONFIG_FILE));
    group.addTemplate(new FileTemplateDescriptor(STRUTS_2_3_XML, StrutsIcons.STRUTS_CONFIG_FILE));
    group.addTemplate(new FileTemplateDescriptor(STRUTS_2_5_XML, StrutsIcons.STRUTS_CONFIG_FILE));
    group.addTemplate(new FileTemplateDescriptor(VALIDATION_XML, StrutsIcons.VALIDATION_CONFIG_FILE));
    return group;
}
Also used : FileTemplateDescriptor(com.intellij.ide.fileTemplates.FileTemplateDescriptor) FileTemplateGroupDescriptor(com.intellij.ide.fileTemplates.FileTemplateGroupDescriptor)

Example 7 with FileTemplateDescriptor

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

the class TestIntegrationUtils method createTestMethodTemplate.

public static Template createTestMethodTemplate(@NotNull MethodKind methodKind, TestFramework descriptor, @NotNull PsiClass targetClass, @Nullable PsiClass sourceClass, @Nullable String name, boolean automatic, Set<String> existingNames) {
    FileTemplateDescriptor templateDesc = methodKind.getFileTemplateDescriptor(descriptor);
    String templateName = templateDesc.getFileName();
    FileTemplate fileTemplate = FileTemplateManager.getInstance(targetClass.getProject()).getCodeTemplate(templateName);
    Template template = TemplateManager.getInstance(targetClass.getProject()).createTemplate("", "");
    String templateText;
    try {
        Properties properties = new Properties();
        if (sourceClass != null && sourceClass.isValid()) {
            properties.setProperty(FileTemplate.ATTRIBUTE_CLASS_NAME, sourceClass.getQualifiedName());
        }
        templateText = fileTemplate.getText(properties);
    } catch (IOException e) {
        LOG.warn(e);
        templateText = fileTemplate.getText();
    }
    if (name == null)
        name = methodKind.getDefaultName();
    if (existingNames != null && !existingNames.add(name)) {
        int idx = 1;
        while (existingNames.contains(name)) {
            final String newName = name + (idx++);
            if (existingNames.add(newName)) {
                name = newName;
                break;
            }
        }
    }
    templateText = StringUtil.replace(templateText, "${BODY}\n", "");
    int from = 0;
    while (true) {
        int index = templateText.indexOf("${NAME}", from);
        if (index == -1)
            break;
        template.addTextSegment(templateText.substring(from, index));
        if (index > 0 && !Character.isWhitespace(templateText.charAt(index - 1))) {
            name = StringUtil.capitalize(name);
        } else {
            name = StringUtil.decapitalize(name);
        }
        if (from == 0) {
            Expression nameExpr = new ConstantNode(name);
            template.addVariable("name", nameExpr, nameExpr, !automatic);
        } else {
            template.addVariableSegment("name");
        }
        from = index + "${NAME}".length();
    }
    template.addTextSegment(templateText.substring(from, templateText.length()));
    template.setToIndent(true);
    template.setToReformat(true);
    template.setToShortenLongNames(true);
    return template;
}
Also used : ConstantNode(com.intellij.codeInsight.template.impl.ConstantNode) FileTemplateDescriptor(com.intellij.ide.fileTemplates.FileTemplateDescriptor) Expression(com.intellij.codeInsight.template.Expression) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) IOException(java.io.IOException) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) Template(com.intellij.codeInsight.template.Template)

Example 8 with FileTemplateDescriptor

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

the class TestNGDataProviderInspection method createMethodFix.

private static CreateMethodQuickFix createMethodFix(PsiAnnotationMemberValue provider, @NotNull PsiClass providerClass, PsiClass topLevelClass) {
    final String name = StringUtil.unquoteString(provider.getText());
    FileTemplateDescriptor templateDesc = new TestNGFramework().getParametersMethodFileTemplateDescriptor();
    assert templateDesc != null;
    final FileTemplate fileTemplate = FileTemplateManager.getInstance(provider.getProject()).getCodeTemplate(templateDesc.getFileName());
    String body = "";
    try {
        final Properties attributes = new Properties();
        attributes.put(FileTemplate.ATTRIBUTE_NAME, name);
        body = fileTemplate.getText(attributes);
        body = body.replace("${BODY}\n", "");
        final PsiMethod methodFromTemplate = JavaPsiFacade.getElementFactory(providerClass.getProject()).createMethodFromText(body, providerClass);
        final PsiCodeBlock methodBody = methodFromTemplate.getBody();
        if (methodBody != null) {
            body = StringUtil.trimEnd(StringUtil.trimStart(methodBody.getText(), "{"), "}");
        } else {
            body = "";
        }
    } catch (Exception ignored) {
    }
    if (StringUtil.isEmptyOrSpaces(body)) {
        body = "return new Object[][]{};";
    }
    String signature = "@" + DataProvider.class.getName() + " public ";
    if (providerClass == topLevelClass) {
        signature += "static ";
    }
    signature += "Object[][] " + name + "()";
    return CreateMethodQuickFix.createFix(providerClass, signature, body);
}
Also used : TestNGFramework(com.theoryinpractice.testng.TestNGFramework) FileTemplateDescriptor(com.intellij.ide.fileTemplates.FileTemplateDescriptor) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) Properties(java.util.Properties) IOException(java.io.IOException)

Example 9 with FileTemplateDescriptor

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

the class AppEngineTemplateGroupDescriptorFactory method getFileTemplatesDescriptor.

public FileTemplateGroupDescriptor getFileTemplatesDescriptor() {
    final FileTemplateDescriptor appEngineXml = new FileTemplateDescriptor(APP_ENGINE_WEB_XML_TEMPLATE, StdFileTypes.XML.getIcon());
    final FileTemplateDescriptor appEngineApplicationXml = new FileTemplateDescriptor(APP_ENGINE_APPLICATION_XML_TEMPLATE, StdFileTypes.XML.getIcon());
    final FileTemplateDescriptor jdoConfigXml = new FileTemplateDescriptor(APP_ENGINE_JDO_CONFIG_TEMPLATE, StdFileTypes.XML.getIcon());
    final FileTemplateDescriptor jpaConfigXml = new FileTemplateDescriptor(APP_ENGINE_JPA_CONFIG_TEMPLATE, StdFileTypes.XML.getIcon());
    return new FileTemplateGroupDescriptor("Google App Engine", GoogleAppEngineIcons.AppEngine, appEngineXml, appEngineApplicationXml, jdoConfigXml, jpaConfigXml);
}
Also used : FileTemplateDescriptor(com.intellij.ide.fileTemplates.FileTemplateDescriptor) FileTemplateGroupDescriptor(com.intellij.ide.fileTemplates.FileTemplateGroupDescriptor)

Example 10 with FileTemplateDescriptor

use of com.intellij.ide.fileTemplates.FileTemplateDescriptor in project Intellij-Plugin by getgauge.

the class SpecificationLiveTemplate method getFileTemplatesDescriptor.

@Override
public FileTemplateGroupDescriptor getFileTemplatesDescriptor() {
    FileTemplateGroupDescriptor descriptor = new FileTemplateGroupDescriptor("Specification", GaugeIcon.GAUGE_SPEC_FILE_ICON);
    descriptor.addTemplate(new FileTemplateDescriptor("Specification.spec", SpecFileType.INSTANCE.getIcon()));
    descriptor.addTemplate(new FileTemplateDescriptor("Concept.cpt", ConceptFileType.INSTANCE.getIcon()));
    return descriptor;
}
Also used : FileTemplateDescriptor(com.intellij.ide.fileTemplates.FileTemplateDescriptor) FileTemplateGroupDescriptor(com.intellij.ide.fileTemplates.FileTemplateGroupDescriptor)

Aggregations

FileTemplateDescriptor (com.intellij.ide.fileTemplates.FileTemplateDescriptor)10 FileTemplateGroupDescriptor (com.intellij.ide.fileTemplates.FileTemplateGroupDescriptor)6 FileTemplate (com.intellij.ide.fileTemplates.FileTemplate)2 IOException (java.io.IOException)2 Nullable (org.jetbrains.annotations.Nullable)2 Expression (com.intellij.codeInsight.template.Expression)1 Template (com.intellij.codeInsight.template.Template)1 ConstantNode (com.intellij.codeInsight.template.impl.ConstantNode)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 Editor (com.intellij.openapi.editor.Editor)1 FileTypeManager (com.intellij.openapi.fileTypes.FileTypeManager)1 Project (com.intellij.openapi.project.Project)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 TestFramework (com.intellij.testIntegration.TestFramework)1 TestNGFramework (com.theoryinpractice.testng.TestNGFramework)1 Properties (java.util.Properties)1 NonNls (org.jetbrains.annotations.NonNls)1