IDEA-112215 Do not include return keyword in generated code while implementing an interface

This commit is contained in:
Max Medvedev
2013-08-19 11:58:00 +04:00
parent c902566721
commit 6333616f4f
5 changed files with 71 additions and 15 deletions
@@ -0,0 +1 @@
#if ( $RETURN_TYPE != "void" )$DEFAULT_RETURN_VALUE#end
@@ -0,0 +1,43 @@
<html>
<body>
<table border="0" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td colspan="3"><font face="verdana" size="-1">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 <b>Create Method from Usage</b> intention action.<br>
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.</font>
</td>
</tr>
</table>
<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td colspan="3"><font face="verdana" size="-1">Predefined variables will take the following values:</font></td>
</tr>
<tr>
<td valign="top"><nobr><font face="verdana" size="-2" color="#7F0000"><b><i>${RETURN_TYPE}</i></b></font></nobr></td>
<td width="10">&nbsp;</td>
<td valign="top"><font face="verdana" size="-1">a return type of a created method</font></td>
</tr>
<tr>
<td valign="top"><nobr><font face="verdana" size="-2" color="#7F0000"><b><i>${DEFAULT_RETURN_VALUE}</i></b></font></nobr></td>
<td width="10">&nbsp;</td>
<td valign="top"><font face="verdana" size="-1">a value returned by the method by default</font></td>
</tr>
<tr>
<td valign="top"><nobr><font face="verdana" size="-2" color="#7F0000"><b><i>${METHOD_NAME}</i></b></font></nobr></td>
<td width="10">&nbsp;</td>
<td valign="top"><font face="verdana" size="-1">name of the created method</font></td>
</tr>
<tr>
<td valign="top"><nobr><font face="verdana" size="-2" color="#7F0000"><b><i>${CLASS_NAME}</i></b></font></nobr></td>
<td width="10">&nbsp;</td>
<td valign="top"><font face="verdana" size="-1">qualified name of the class where method is created</font></td>
</tr>
<tr>
<td valign="top"><nobr><font face="verdana" size="-2" color="#7F0000"><b><i>${SIMPLE_CLASS_NAME}</i></b></font></nobr></td>
<td width="10">&nbsp;</td>
<td valign="top"><font face="verdana" size="-1">non-qualified name of the class where method is implemented</font></td>
</tr>
</table>
</body>
</html>
@@ -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";
}
@@ -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);
@@ -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