From 6333616f4fbf36c05f57f6280f030debee5a0241 Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Mon, 19 Aug 2013 08:51:45 +0400 Subject: [PATCH] IDEA-112215 Do not include return keyword in generated code while implementing an interface --- .../code/New Method Body.groovy.ft | 1 + .../code/New Method Body.groovy.html | 43 +++++++++++++++++++ .../groovy/actions/GroovyTemplates.java | 26 ++++++----- .../intentions/base/IntentionUtils.java | 7 ++- .../testIntegration/GroovyTestFramework.java | 9 ++-- 5 files changed, 71 insertions(+), 15 deletions(-) create mode 100644 plugins/groovy/resources/fileTemplates/code/New Method Body.groovy.ft create mode 100644 plugins/groovy/resources/fileTemplates/code/New Method Body.groovy.html diff --git a/plugins/groovy/resources/fileTemplates/code/New Method Body.groovy.ft b/plugins/groovy/resources/fileTemplates/code/New Method Body.groovy.ft new file mode 100644 index 000000000000..51bce149b88a --- /dev/null +++ b/plugins/groovy/resources/fileTemplates/code/New Method Body.groovy.ft @@ -0,0 +1 @@ +#if ( $RETURN_TYPE != "void" )$DEFAULT_RETURN_VALUE#end \ No newline at end of file diff --git a/plugins/groovy/resources/fileTemplates/code/New Method Body.groovy.html b/plugins/groovy/resources/fileTemplates/code/New Method Body.groovy.html new file mode 100644 index 000000000000..3dc921054ed1 --- /dev/null +++ b/plugins/groovy/resources/fileTemplates/code/New Method Body.groovy.html @@ -0,0 +1,43 @@ + + + + + + +
This is a built-in template used for filling the body of a Groovy method + each time it is generated by the program, e.g. when using the Create Method from Usage intention action.
+ The template is editable. Along with Groovy expressions and comments, you can also use the predefined variables + that will be then expanded into the corresponding values.
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Predefined variables will take the following values:
${RETURN_TYPE} a return type of a created method
${DEFAULT_RETURN_VALUE} a value returned by the method by default
${METHOD_NAME} name of the created method
${CLASS_NAME} qualified name of the class where method is created
${SIMPLE_CLASS_NAME} non-qualified name of the class where method is implemented
+ + \ No newline at end of file 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 8f6d0876ee19..49875ced64b9 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/GroovyTemplates.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/actions/GroovyTemplates.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -15,16 +15,22 @@ */ package org.jetbrains.plugins.groovy.actions; +import org.jetbrains.annotations.NonNls; + /** * @author Max Medvedev */ -public class GroovyTemplates { - public static final String GROOVY_CLASS = "GroovyClass.groovy"; - public static final String GROOVY_INTERFACE = "GroovyInterface.groovy"; - public static final String GROOVY_ENUM = "GroovyEnum.groovy"; - public static final String GROOVY_ANNOTATION = "GroovyAnnotation.groovy"; - public static final String GROOVY_SCRIPT = "GroovyScript.groovy"; - public static final String GROOVY_DSL_SCRIPT = "GroovyDslScript.gdsl"; - public static final String GANT_SCRIPT = "GantScript.gant"; - public static final String GROOVY_SERVER_PAGE = "GroovyServerPage.gsp"; +public interface GroovyTemplates { + @NonNls String GROOVY_CLASS = "GroovyClass.groovy"; + @NonNls String GROOVY_INTERFACE = "GroovyInterface.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_FROM_USAGE_METHOD_BODY = "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"; + @NonNls String GROOVY_JUNIT_TEAR_DOWN_METHOD_GROOVY = "Groovy JUnit TearDown Method.groovy"; } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/base/IntentionUtils.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/base/IntentionUtils.java index f97bfeb29e1e..5c66f97ba6a0 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/base/IntentionUtils.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/base/IntentionUtils.java @@ -19,6 +19,8 @@ import com.intellij.codeInsight.CodeInsightUtilCore; import com.intellij.codeInsight.daemon.impl.quickfix.CreateFromUsageUtils; import com.intellij.codeInsight.daemon.impl.quickfix.CreateMethodFromUsageFix; import com.intellij.codeInsight.template.*; +import com.intellij.ide.fileTemplates.FileTemplate; +import com.intellij.ide.fileTemplates.FileTemplateManager; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; @@ -30,6 +32,7 @@ import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.GroovyFileType; +import org.jetbrains.plugins.groovy.actions.GroovyTemplates; import org.jetbrains.plugins.groovy.annotator.intentions.QuickfixUtil; import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement; @@ -140,7 +143,9 @@ public class IntentionUtils { ((GrMethod)method).setReturnType(PsiType.VOID); } if (method.getBody() != null) { - CreateFromUsageUtils.setupMethodBody(method); + FileTemplateManager templateManager = FileTemplateManager.getInstance(); + FileTemplate fileTemplate = templateManager.getCodeTemplate(GroovyTemplates.GROOVY_FROM_USAGE_METHOD_BODY); + CreateFromUsageUtils.setupMethodBody(method, method.getContainingClass(), fileTemplate); } if (hasNoReturnType) { ((GrMethod)method).setReturnType(null); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/testIntegration/GroovyTestFramework.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/testIntegration/GroovyTestFramework.java index 2aa715057c7a..3cdabe38a8e0 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/testIntegration/GroovyTestFramework.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/testIntegration/GroovyTestFramework.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2013 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. @@ -31,6 +31,7 @@ import com.intellij.util.IncorrectOperationException; import icons.JetgroovyIcons; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.GroovyFileType; +import org.jetbrains.plugins.groovy.actions.GroovyTemplates; import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory; import org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames; @@ -125,15 +126,15 @@ public class GroovyTestFramework extends JavaTestFramework { @Override public FileTemplateDescriptor getSetUpMethodFileTemplateDescriptor() { - return new FileTemplateDescriptor("Groovy JUnit SetUp Method.groovy"); + return new FileTemplateDescriptor(GroovyTemplates.GROOVY_JUNIT_SET_UP_METHOD_GROOVY); } public FileTemplateDescriptor getTearDownMethodFileTemplateDescriptor() { - return new FileTemplateDescriptor("Groovy JUnit TearDown Method.groovy"); + return new FileTemplateDescriptor(GroovyTemplates.GROOVY_JUNIT_TEAR_DOWN_METHOD_GROOVY); } public FileTemplateDescriptor getTestMethodFileTemplateDescriptor() { - return new FileTemplateDescriptor("Groovy JUnit Test Method.groovy"); + return new FileTemplateDescriptor(GroovyTemplates.GROOVY_JUNIT_TEST_METHOD_GROOVY); } @Override