Search in sources :

Example 1 with CustomFileTemplate

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

the class EmbeddedLiveTemplatesTest method doTest.

protected void doTest(String text, String result) {
    CustomFileTemplate template = new CustomFileTemplate("foo", "txt");
    template.setText(text);
    template.setLiveTemplateEnabled(true);
    myFixture.testAction(new TestAction(template));
    VirtualFile[] files = FileEditorManager.getInstance(getProject()).getSelectedFiles();
    myFixture.openFileInEditor(files[0]);
    myFixture.checkResult(result);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CustomFileTemplate(com.intellij.ide.fileTemplates.impl.CustomFileTemplate)

Example 2 with CustomFileTemplate

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

the class FileTemplateUtil method createTemplate.

@NotNull
public static FileTemplate createTemplate(@NotNull String prefName, @NotNull String extension, @NotNull String content, FileTemplate[] templates) {
    final Set<String> names = new HashSet<>();
    for (FileTemplate template : templates) {
        names.add(template.getName());
    }
    String name = prefName;
    int i = 0;
    while (names.contains(name)) {
        name = prefName + " (" + ++i + ")";
    }
    final FileTemplate newTemplate = new CustomFileTemplate(name, extension);
    newTemplate.setText(content);
    return newTemplate;
}
Also used : CustomFileTemplate(com.intellij.ide.fileTemplates.impl.CustomFileTemplate) CustomFileTemplate(com.intellij.ide.fileTemplates.impl.CustomFileTemplate) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with CustomFileTemplate

use of com.intellij.ide.fileTemplates.impl.CustomFileTemplate in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoCreateFileActionTest method doTest.

private static void doTest(@NotNull PsiDirectory dir, @NotNull String newFileName, @NotNull String expectedPackage, @NotNull String expectedPackageWithTestSuffix) {
    CustomFileTemplate template = new CustomFileTemplate("testTemplate", "go");
    template.setText("package ${GO_PACKAGE_NAME}");
    CustomFileTemplate templateWithSuffix = new CustomFileTemplate("testTemplate", "go");
    templateWithSuffix.setText("package ${GO_PACKAGE_NAME_WITH_TEST_SUFFIX}");
    doTemplateTest(dir, newFileName, expectedPackage, template);
    doTemplateTest(dir, newFileName, expectedPackageWithTestSuffix, templateWithSuffix);
}
Also used : CustomFileTemplate(com.intellij.ide.fileTemplates.impl.CustomFileTemplate)

Aggregations

CustomFileTemplate (com.intellij.ide.fileTemplates.impl.CustomFileTemplate)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 NotNull (org.jetbrains.annotations.NotNull)1