From 070546e3e189530af17a2c0748abbcfed98e776a Mon Sep 17 00:00:00 2001 From: Daniil Ovchinnikov Date: Thu, 10 Nov 2016 18:41:35 +0300 Subject: [PATCH] [groovy] organize file templates --- .../j2ee/GroovyServerPage.gsp.ft | 16 ------ .../j2ee/GroovyServerPage.gsp.html | 30 ---------- plugins/groovy/jetgroovy.iml | 1 + .../internal/Gant Script.gant.ft} | 0 .../internal/Gant Script.gant.html} | 0 .../internal/Groovy Annotation.groovy.ft} | 0 .../internal/Groovy Annotation.groovy.html} | 0 .../internal/Groovy Class.groovy.ft} | 0 .../internal/Groovy Class.groovy.html} | 0 .../internal/Groovy DSL Script.gdsl.ft} | 0 .../internal/Groovy DSL Script.gdsl.html} | 0 .../internal/Groovy Enum.groovy.ft} | 0 .../internal/Groovy Enum.groovy.html} | 0 .../internal/Groovy Interface.groovy.ft} | 0 .../internal/Groovy Interface.groovy.html} | 0 .../internal/Groovy Script.groovy.ft} | 0 .../internal/Groovy Script.groovy.html} | 0 .../internal/Groovy Trait.groovy.ft} | 0 .../internal/Groovy Trait.groovy.html} | 0 .../groovy/src/META-INF/groovy-templates.xml | 14 +++++ plugins/groovy/src/META-INF/plugin.xml | 6 +- .../groovy/actions/GroovyTemplates.java | 20 ++++--- .../actions/GroovyTemplatesFactory.java | 57 +++---------------- .../plugins/groovy/gant/GantLoader.java | 44 -------------- 24 files changed, 35 insertions(+), 153 deletions(-) delete mode 100644 plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyServerPage.gsp.ft delete mode 100644 plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyServerPage.gsp.html rename plugins/groovy/{groovy-psi/resources/fileTemplates/j2ee/GantScript.gant.ft => resources/fileTemplates/internal/Gant Script.gant.ft} (100%) rename plugins/groovy/{groovy-psi/resources/fileTemplates/j2ee/GantScript.gant.html => resources/fileTemplates/internal/Gant Script.gant.html} (100%) rename plugins/groovy/{groovy-psi/resources/fileTemplates/j2ee/GroovyAnnotation.groovy.ft => resources/fileTemplates/internal/Groovy Annotation.groovy.ft} (100%) rename plugins/groovy/{groovy-psi/resources/fileTemplates/j2ee/GroovyAnnotation.groovy.html => resources/fileTemplates/internal/Groovy Annotation.groovy.html} (100%) rename plugins/groovy/{groovy-psi/resources/fileTemplates/j2ee/GroovyClass.groovy.ft => resources/fileTemplates/internal/Groovy Class.groovy.ft} (100%) rename plugins/groovy/{groovy-psi/resources/fileTemplates/j2ee/GroovyClass.groovy.html => resources/fileTemplates/internal/Groovy Class.groovy.html} (100%) rename plugins/groovy/{groovy-psi/resources/fileTemplates/j2ee/GroovyDslScript.gdsl.ft => resources/fileTemplates/internal/Groovy DSL Script.gdsl.ft} (100%) rename plugins/groovy/{groovy-psi/resources/fileTemplates/j2ee/GroovyDslScript.gdsl.html => resources/fileTemplates/internal/Groovy DSL Script.gdsl.html} (100%) rename plugins/groovy/{groovy-psi/resources/fileTemplates/j2ee/GroovyEnum.groovy.ft => resources/fileTemplates/internal/Groovy Enum.groovy.ft} (100%) rename plugins/groovy/{groovy-psi/resources/fileTemplates/j2ee/GroovyEnum.groovy.html => resources/fileTemplates/internal/Groovy Enum.groovy.html} (100%) rename plugins/groovy/{groovy-psi/resources/fileTemplates/j2ee/GroovyInterface.groovy.ft => resources/fileTemplates/internal/Groovy Interface.groovy.ft} (100%) rename plugins/groovy/{groovy-psi/resources/fileTemplates/j2ee/GroovyInterface.groovy.html => resources/fileTemplates/internal/Groovy Interface.groovy.html} (100%) rename plugins/groovy/{groovy-psi/resources/fileTemplates/j2ee/GroovyScript.groovy.ft => resources/fileTemplates/internal/Groovy Script.groovy.ft} (100%) rename plugins/groovy/{groovy-psi/resources/fileTemplates/j2ee/GroovyScript.groovy.html => resources/fileTemplates/internal/Groovy Script.groovy.html} (100%) rename plugins/groovy/{groovy-psi/resources/fileTemplates/j2ee/GroovyTrait.groovy.ft => resources/fileTemplates/internal/Groovy Trait.groovy.ft} (100%) rename plugins/groovy/{groovy-psi/resources/fileTemplates/j2ee/GroovyTrait.groovy.html => resources/fileTemplates/internal/Groovy Trait.groovy.html} (100%) create mode 100644 plugins/groovy/src/META-INF/groovy-templates.xml delete mode 100644 plugins/groovy/src/org/jetbrains/plugins/groovy/gant/GantLoader.java diff --git a/plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyServerPage.gsp.ft b/plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyServerPage.gsp.ft deleted file mode 100644 index 2f59b5eb9ade..000000000000 --- a/plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyServerPage.gsp.ft +++ /dev/null @@ -1,16 +0,0 @@ -<%-- - Created by IntelliJ IDEA. - User: ${USER} - Date: ${DATE} - Time: ${TIME} ---%> - -<%@ page contentType="text/html;charset=UTF-8" %> - - - - - - - - \ No newline at end of file diff --git a/plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyServerPage.gsp.html b/plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyServerPage.gsp.html deleted file mode 100644 index 3afe747a5d92..000000000000 --- a/plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyServerPage.gsp.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - -
- - This is a built-in template used each time you create new - Groovy Server Page - -
- - \ No newline at end of file diff --git a/plugins/groovy/jetgroovy.iml b/plugins/groovy/jetgroovy.iml index ebecd0542410..47aef70ed7a2 100644 --- a/plugins/groovy/jetgroovy.iml +++ b/plugins/groovy/jetgroovy.iml @@ -5,6 +5,7 @@ + diff --git a/plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GantScript.gant.ft b/plugins/groovy/resources/fileTemplates/internal/Gant Script.gant.ft similarity index 100% rename from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GantScript.gant.ft rename to plugins/groovy/resources/fileTemplates/internal/Gant Script.gant.ft diff --git a/plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GantScript.gant.html b/plugins/groovy/resources/fileTemplates/internal/Gant Script.gant.html similarity index 100% rename from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GantScript.gant.html rename to plugins/groovy/resources/fileTemplates/internal/Gant Script.gant.html diff --git a/plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyAnnotation.groovy.ft b/plugins/groovy/resources/fileTemplates/internal/Groovy Annotation.groovy.ft similarity index 100% rename from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyAnnotation.groovy.ft rename to plugins/groovy/resources/fileTemplates/internal/Groovy Annotation.groovy.ft diff --git a/plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyAnnotation.groovy.html b/plugins/groovy/resources/fileTemplates/internal/Groovy Annotation.groovy.html similarity index 100% rename from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyAnnotation.groovy.html rename to plugins/groovy/resources/fileTemplates/internal/Groovy Annotation.groovy.html diff --git a/plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyClass.groovy.ft b/plugins/groovy/resources/fileTemplates/internal/Groovy Class.groovy.ft similarity index 100% rename from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyClass.groovy.ft rename to plugins/groovy/resources/fileTemplates/internal/Groovy Class.groovy.ft diff --git a/plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyClass.groovy.html b/plugins/groovy/resources/fileTemplates/internal/Groovy Class.groovy.html similarity index 100% rename from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyClass.groovy.html rename to plugins/groovy/resources/fileTemplates/internal/Groovy Class.groovy.html diff --git a/plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyDslScript.gdsl.ft b/plugins/groovy/resources/fileTemplates/internal/Groovy DSL Script.gdsl.ft similarity index 100% rename from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyDslScript.gdsl.ft rename to plugins/groovy/resources/fileTemplates/internal/Groovy DSL Script.gdsl.ft diff --git a/plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyDslScript.gdsl.html b/plugins/groovy/resources/fileTemplates/internal/Groovy DSL Script.gdsl.html similarity index 100% rename from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyDslScript.gdsl.html rename to plugins/groovy/resources/fileTemplates/internal/Groovy DSL Script.gdsl.html diff --git a/plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyEnum.groovy.ft b/plugins/groovy/resources/fileTemplates/internal/Groovy Enum.groovy.ft similarity index 100% rename from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyEnum.groovy.ft rename to plugins/groovy/resources/fileTemplates/internal/Groovy Enum.groovy.ft diff --git a/plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyEnum.groovy.html b/plugins/groovy/resources/fileTemplates/internal/Groovy Enum.groovy.html similarity index 100% rename from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyEnum.groovy.html rename to plugins/groovy/resources/fileTemplates/internal/Groovy Enum.groovy.html diff --git a/plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyInterface.groovy.ft b/plugins/groovy/resources/fileTemplates/internal/Groovy Interface.groovy.ft similarity index 100% rename from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyInterface.groovy.ft rename to plugins/groovy/resources/fileTemplates/internal/Groovy Interface.groovy.ft diff --git a/plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyInterface.groovy.html b/plugins/groovy/resources/fileTemplates/internal/Groovy Interface.groovy.html similarity index 100% rename from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyInterface.groovy.html rename to plugins/groovy/resources/fileTemplates/internal/Groovy Interface.groovy.html diff --git a/plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyScript.groovy.ft b/plugins/groovy/resources/fileTemplates/internal/Groovy Script.groovy.ft similarity index 100% rename from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyScript.groovy.ft rename to plugins/groovy/resources/fileTemplates/internal/Groovy Script.groovy.ft diff --git a/plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyScript.groovy.html b/plugins/groovy/resources/fileTemplates/internal/Groovy Script.groovy.html similarity index 100% rename from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyScript.groovy.html rename to plugins/groovy/resources/fileTemplates/internal/Groovy Script.groovy.html diff --git a/plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyTrait.groovy.ft b/plugins/groovy/resources/fileTemplates/internal/Groovy Trait.groovy.ft similarity index 100% rename from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyTrait.groovy.ft rename to plugins/groovy/resources/fileTemplates/internal/Groovy Trait.groovy.ft diff --git a/plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyTrait.groovy.html b/plugins/groovy/resources/fileTemplates/internal/Groovy Trait.groovy.html similarity index 100% rename from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyTrait.groovy.html rename to plugins/groovy/resources/fileTemplates/internal/Groovy Trait.groovy.html diff --git a/plugins/groovy/src/META-INF/groovy-templates.xml b/plugins/groovy/src/META-INF/groovy-templates.xml new file mode 100644 index 000000000000..772a769f45da --- /dev/null +++ b/plugins/groovy/src/META-INF/groovy-templates.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/groovy/src/META-INF/plugin.xml b/plugins/groovy/src/META-INF/plugin.xml index a1d2009df337..8af4657b1f95 100644 --- a/plugins/groovy/src/META-INF/plugin.xml +++ b/plugins/groovy/src/META-INF/plugin.xml @@ -568,8 +568,6 @@ - - @@ -1778,9 +1776,6 @@ - - org.jetbrains.plugins.groovy.gant.GantLoader - org.jetbrains.plugins.groovy.mvc.MvcPathMacros @@ -1808,6 +1803,7 @@ + diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/GroovyTemplates.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/GroovyTemplates.java index 1c28c2a54213..4da74a803f7f 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/GroovyTemplates.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/GroovyTemplates.java @@ -21,15 +21,17 @@ import org.jetbrains.annotations.NonNls; * @author Max Medvedev */ public interface GroovyTemplates { - @NonNls String GROOVY_CLASS = "GroovyClass.groovy"; - @NonNls String GROOVY_INTERFACE = "GroovyInterface.groovy"; - @NonNls String GROOVY_TRAIT = "GroovyTrait.groovy"; - @NonNls String GROOVY_ENUM = "GroovyEnum.groovy"; - @NonNls String GROOVY_ANNOTATION = "GroovyAnnotation.groovy"; - @NonNls String GROOVY_SCRIPT = "GroovyScript.groovy"; - @NonNls String GROOVY_DSL_SCRIPT = "GroovyDslScript.gdsl"; - @NonNls String GANT_SCRIPT = "GantScript.gant"; - @NonNls String GROOVY_SERVER_PAGE = "GroovyServerPage.gsp"; + @NonNls String GROOVY_CLASS = "Groovy Class.groovy"; + @NonNls String GROOVY_INTERFACE = "Groovy Interface.groovy"; + @NonNls String GROOVY_TRAIT = "Groovy Trait.groovy"; + @NonNls String GROOVY_ENUM = "Groovy Enum.groovy"; + @NonNls String GROOVY_ANNOTATION = "Groovy Annotation.groovy"; + + @NonNls String GROOVY_SCRIPT = "Groovy Script.groovy"; + @NonNls String GROOVY_DSL_SCRIPT = "Groovy DSL Script.gdsl"; + + @NonNls String GANT_SCRIPT = "Gant Script.gant"; + @NonNls String GROOVY_FROM_USAGE_METHOD_BODY = "Groovy New Method Body.groovy"; @NonNls String GROOVY_JUNIT_TEST_METHOD_GROOVY = "Groovy JUnit Test Method.groovy"; @NonNls String GROOVY_JUNIT_SET_UP_METHOD_GROOVY = "Groovy JUnit SetUp Method.groovy"; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/GroovyTemplatesFactory.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/GroovyTemplatesFactory.java index 47116c9cf95b..f9d2e811adaf 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/GroovyTemplatesFactory.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/GroovyTemplatesFactory.java @@ -17,65 +17,27 @@ package org.jetbrains.plugins.groovy.actions; import com.intellij.codeInsight.actions.ReformatCodeProcessor; -import com.intellij.ide.fileTemplates.*; -import com.intellij.openapi.fileTypes.FileTypeManager; +import com.intellij.ide.fileTemplates.FileTemplate; +import com.intellij.ide.fileTemplates.FileTemplateManager; +import com.intellij.ide.fileTemplates.JavaTemplateUtil; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFileFactory; -import com.intellij.util.ArrayUtil; import com.intellij.util.IncorrectOperationException; -import icons.JetgroovyIcons; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; -import org.jetbrains.plugins.groovy.GroovyBundle; import org.jetbrains.plugins.groovy.GroovyFileType; -import java.util.ArrayList; -import java.util.Collections; import java.util.Properties; -public class GroovyTemplatesFactory implements FileTemplateGroupDescriptorFactory { - @NonNls - public static final String[] TEMPLATES = {GroovyTemplates.GROOVY_CLASS, GroovyTemplates.GROOVY_SCRIPT}; - - public void registerCustromTemplates(String... templates) { - Collections.addAll(myCustomTemplates, templates); - } - - private static class GroovyTemplatesFactoryHolder { - private static final GroovyTemplatesFactory myInstance = new GroovyTemplatesFactory(); - } - - public static GroovyTemplatesFactory getInstance() { - return GroovyTemplatesFactoryHolder.myInstance; - } - - private final ArrayList myCustomTemplates = new ArrayList<>(); +public class GroovyTemplatesFactory { @NonNls static final String NAME_TEMPLATE_PROPERTY = "NAME"; static final String LOW_CASE_NAME_TEMPLATE_PROPERTY = "lowCaseName"; - @Override - public FileTemplateGroupDescriptor getFileTemplatesDescriptor() { - final FileTemplateGroupDescriptor group = new FileTemplateGroupDescriptor(GroovyBundle.message("file.template.group.title.groovy"), JetgroovyIcons.Groovy.Groovy_16x16); - final FileTypeManager fileTypeManager = FileTypeManager.getInstance(); - for (String template : TEMPLATES) { - group.addTemplate(new FileTemplateDescriptor(template, fileTypeManager.getFileTypeByFileName(template).getIcon())); - } - //add GSP Template - group.addTemplate(new FileTemplateDescriptor( - GroovyTemplates.GROOVY_SERVER_PAGE, fileTypeManager.getFileTypeByFileName(GroovyTemplates.GROOVY_SERVER_PAGE).getIcon())); - - // register custom templates - for (String template : getInstance().getCustomTemplates()) { - group.addTemplate(new FileTemplateDescriptor(template, fileTypeManager.getFileTypeByFileName(template).getIcon())); - } - return group; - } - - public static PsiFile createFromTemplate(@NotNull final PsiDirectory directory, @NotNull final String name, @NotNull String fileName, @@ -89,7 +51,7 @@ public class GroovyTemplatesFactory implements FileTemplateGroupDescriptorFactor Properties properties = new Properties(FileTemplateManager.getInstance(project).getDefaultProperties()); JavaTemplateUtil.setPackageNameAttribute(properties, directory); properties.setProperty(NAME_TEMPLATE_PROPERTY, name); - properties.setProperty(LOW_CASE_NAME_TEMPLATE_PROPERTY, name.substring(0, 1).toLowerCase() + name.substring(1)); + properties.setProperty(LOW_CASE_NAME_TEMPLATE_PROPERTY, StringUtil.decapitalize(name)); for (int i = 0; i < parameters.length; i += 2) { properties.setProperty(parameters[i], parameters[i + 1]); } @@ -98,7 +60,8 @@ public class GroovyTemplatesFactory implements FileTemplateGroupDescriptorFactor text = template.getText(properties); } catch (Exception e) { - throw new RuntimeException("Unable to load template for " + FileTemplateManager.getInstance(project).internalTemplateToSubject(templateName), e); + String message = "Unable to load template for " + FileTemplateManager.getInstance(project).internalTemplateToSubject(templateName); + throw new RuntimeException(message, e); } final PsiFileFactory factory = PsiFileFactory.getInstance(project); @@ -112,8 +75,4 @@ public class GroovyTemplatesFactory implements FileTemplateGroupDescriptorFactor return file; } - - public String[] getCustomTemplates() { - return ArrayUtil.toStringArray(myCustomTemplates); - } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/GantLoader.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/GantLoader.java deleted file mode 100644 index 60e0393bbbc6..000000000000 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/gant/GantLoader.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2000-2014 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jetbrains.plugins.groovy.gant; - -import com.intellij.openapi.components.ApplicationComponent; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.plugins.groovy.actions.GroovyTemplates; -import org.jetbrains.plugins.groovy.actions.GroovyTemplatesFactory; - -/** - * @author ilyas - */ -public class GantLoader implements ApplicationComponent { - - @Override - @NonNls - @NotNull - public String getComponentName() { - return "Gant loader"; - } - - @Override - public void initComponent() { - GroovyTemplatesFactory.getInstance().registerCustromTemplates(GroovyTemplates.GANT_SCRIPT); - } - - @Override - public void disposeComponent() { - } -}