[groovy] organize file templates
authorDaniil Ovchinnikov <daniil.ovchinnikov@jetbrains.com>
Thu, 10 Nov 2016 15:41:35 +0000 (18:41 +0300)
committerDaniil Ovchinnikov <daniil.ovchinnikov@jetbrains.com>
Thu, 10 Nov 2016 16:03:22 +0000 (19:03 +0300)
24 files changed:
plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyServerPage.gsp.ft [deleted file]
plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyServerPage.gsp.html [deleted file]
plugins/groovy/jetgroovy.iml
plugins/groovy/resources/fileTemplates/internal/Gant Script.gant.ft [moved from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GantScript.gant.ft with 100% similarity]
plugins/groovy/resources/fileTemplates/internal/Gant Script.gant.html [moved from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GantScript.gant.html with 100% similarity]
plugins/groovy/resources/fileTemplates/internal/Groovy Annotation.groovy.ft [moved from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyAnnotation.groovy.ft with 100% similarity]
plugins/groovy/resources/fileTemplates/internal/Groovy Annotation.groovy.html [moved from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyAnnotation.groovy.html with 100% similarity]
plugins/groovy/resources/fileTemplates/internal/Groovy Class.groovy.ft [moved from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyClass.groovy.ft with 100% similarity]
plugins/groovy/resources/fileTemplates/internal/Groovy Class.groovy.html [moved from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyClass.groovy.html with 100% similarity]
plugins/groovy/resources/fileTemplates/internal/Groovy DSL Script.gdsl.ft [moved from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyDslScript.gdsl.ft with 100% similarity]
plugins/groovy/resources/fileTemplates/internal/Groovy DSL Script.gdsl.html [moved from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyDslScript.gdsl.html with 100% similarity]
plugins/groovy/resources/fileTemplates/internal/Groovy Enum.groovy.ft [moved from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyEnum.groovy.ft with 100% similarity]
plugins/groovy/resources/fileTemplates/internal/Groovy Enum.groovy.html [moved from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyEnum.groovy.html with 100% similarity]
plugins/groovy/resources/fileTemplates/internal/Groovy Interface.groovy.ft [moved from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyInterface.groovy.ft with 100% similarity]
plugins/groovy/resources/fileTemplates/internal/Groovy Interface.groovy.html [moved from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyInterface.groovy.html with 100% similarity]
plugins/groovy/resources/fileTemplates/internal/Groovy Script.groovy.ft [moved from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyScript.groovy.ft with 100% similarity]
plugins/groovy/resources/fileTemplates/internal/Groovy Script.groovy.html [moved from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyScript.groovy.html with 100% similarity]
plugins/groovy/resources/fileTemplates/internal/Groovy Trait.groovy.ft [moved from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyTrait.groovy.ft with 100% similarity]
plugins/groovy/resources/fileTemplates/internal/Groovy Trait.groovy.html [moved from plugins/groovy/groovy-psi/resources/fileTemplates/j2ee/GroovyTrait.groovy.html with 100% similarity]
plugins/groovy/src/META-INF/groovy-templates.xml [new file with mode: 0644]
plugins/groovy/src/META-INF/plugin.xml
plugins/groovy/src/org/jetbrains/plugins/groovy/actions/GroovyTemplates.java
plugins/groovy/src/org/jetbrains/plugins/groovy/actions/GroovyTemplatesFactory.java
plugins/groovy/src/org/jetbrains/plugins/groovy/gant/GantLoader.java [deleted file]

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 (file)
index 2f59b5e..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-<%--
-  Created by IntelliJ IDEA.
-  User: ${USER}
-  Date: ${DATE}
-  Time: ${TIME}
---%>
-
-<%@ page contentType="text/html;charset=UTF-8" %>
-<html>
-<head>
-  <title></title>
-</head>
-<body>
-
-</body>
-</html>
\ 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 (file)
index 3afe747..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<!--
-  ~  Copyright 2000-2007 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.
-  ~
-  -->
-
-<html>
-<body>
-<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
-  <tr>
-    <td colspan="3">
-      <font face="verdana" size="-1">
-        This is a built-in template used each time you create new
-        Groovy Server Page
-      </font>
-    </td>
-  </tr>
-</table>
-</body>
-</html>
\ No newline at end of file
index ebecd054241019b2ca1d0c0c82fbfc4a195cb958..47aef70ed7a2a4b6f2e86f787d3e9e8a4d203638 100644 (file)
@@ -5,6 +5,7 @@
     <content url="file://$MODULE_DIR$">
       <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
       <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
     </content>
     <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />
diff --git a/plugins/groovy/src/META-INF/groovy-templates.xml b/plugins/groovy/src/META-INF/groovy-templates.xml
new file mode 100644 (file)
index 0000000..772a769
--- /dev/null
@@ -0,0 +1,14 @@
+<idea-plugin>
+  <extensions defaultExtensionNs="com.intellij">
+    <internalFileTemplate name="Groovy Class"/>
+    <internalFileTemplate name="Groovy Interface"/>
+    <internalFileTemplate name="Groovy Trait"/>
+    <internalFileTemplate name="Groovy Enum"/>
+    <internalFileTemplate name="Groovy Annotation"/>
+
+    <internalFileTemplate name="Groovy Script"/>
+    <internalFileTemplate name="Groovy DSL Script"/>
+
+    <internalFileTemplate name="Gant Script"/>
+  </extensions>
+</idea-plugin>
\ No newline at end of file
index a1d2009df337c79b0d5a8a362ae5f85607b475e2..8af4657b1f95872631f8d31084e2d55d090c5896 100644 (file)
     <targetElementEvaluator language="Groovy"
                             implementationClass="org.jetbrains.plugins.groovy.lang.psi.impl.GroovyTargetElementEvaluator"/>
 
-    <fileTemplateGroup implementation="org.jetbrains.plugins.groovy.actions.GroovyTemplatesFactory"/>
-
     <projectConfigurable instance="org.jetbrains.plugins.groovy.compiler.GroovyCompilerConfigurable" id="Groovy compiler"
                          displayName="Groovy Compiler" parentId="project.propCompiler"/>
     <java.compiler implementation="org.jetbrains.plugins.groovy.compiler.GreclipseIdeaCompiler"/>
   </actions>
 
   <application-components>
-    <component>
-      <implementation-class>org.jetbrains.plugins.groovy.gant.GantLoader</implementation-class>
-    </component>
     <component>
       <implementation-class>org.jetbrains.plugins.groovy.mvc.MvcPathMacros</implementation-class>
     </component>
     </component>
   </project-components>
 
+  <xi:include href="groovy-templates.xml" xpointer="xpointer(/idea-plugin/*)"/>
   <xi:include href="groovy-indexed-property-support.xml" xpointer="xpointer(/idea-plugin/*)"/>
   <xi:include href="groovy-logback-support.xml" xpointer="xpointer(/idea-plugin/*)"/>
 </idea-plugin>
index 1c28c2a54213973f75deccc52c9cfad485c80b81..4da74a803f7f323aa8159bee57789f97d2e9249c 100644 (file)
@@ -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";
index 47116c9cf95b7670f2cb10bddcd7d7b5dcc04852..f9d2e811adaf7531d79a9b357ef3f82fde0d3b71 100644 (file)
 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<String> 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 (file)
index 60e0393..0000000
+++ /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() {
-  }
-}