provide PLAIN_CALL_SUPER variable to ease custom template creation

This commit is contained in:
Anna Kozlova
2017-06-14 16:37:34 +03:00
parent 363c7fd4ea
commit 79b15d7356
3 changed files with 14 additions and 1 deletions

View File

@@ -301,8 +301,13 @@ public class OverrideImplementUtil extends OverrideImplementExploreUtil {
@NotNull
public static String callSuper(PsiMethod superMethod, PsiMethod overriding) {
return callSuper(superMethod, overriding, true);
}
@NotNull
private static String callSuper(PsiMethod superMethod, PsiMethod overriding, boolean prependReturn) {
@NonNls StringBuilder buffer = new StringBuilder();
if (!superMethod.isConstructor() && !PsiType.VOID.equals(superMethod.getReturnType())) {
if (prependReturn && !superMethod.isConstructor() && !PsiType.VOID.equals(superMethod.getReturnType())) {
buffer.append("return ");
}
buffer.append("super");
@@ -350,6 +355,7 @@ public class OverrideImplementUtil extends OverrideImplementExploreUtil {
properties.setProperty(FileTemplate.ATTRIBUTE_RETURN_TYPE, returnType.getPresentableText());
properties.setProperty(FileTemplate.ATTRIBUTE_DEFAULT_RETURN_VALUE, PsiTypesUtil.getDefaultValueOfType(returnType));
properties.setProperty(FileTemplate.ATTRIBUTE_CALL_SUPER, callSuper(originalMethod, result));
properties.setProperty(FileTemplate.ATTRIBUTE_PLAIN_CALL_SUPER, callSuper(originalMethod, result, false));
JavaTemplateUtil.setClassAndMethodNameProperties(properties, targetClass, result);
JVMElementFactory factory = JVMElementFactories.getFactory(targetClass.getLanguage(), originalMethod.getProject());

View File

@@ -42,6 +42,7 @@ public interface FileTemplate extends Cloneable {
String ATTRIBUTE_RETURN_TYPE = "RETURN_TYPE";
String ATTRIBUTE_DEFAULT_RETURN_VALUE = "DEFAULT_RETURN_VALUE";
String ATTRIBUTE_CALL_SUPER = "CALL_SUPER";
String ATTRIBUTE_PLAIN_CALL_SUPER = "PLAIN_CALL_SUPER";
String ATTRIBUTE_CLASS_NAME = "CLASS_NAME";
String ATTRIBUTE_SIMPLE_CLASS_NAME = "SIMPLE_CLASS_NAME";

View File

@@ -21,6 +21,12 @@
for other methods - <code><b>return</b> <b>super</b>.<i>method_name</i>();</code> with or without parameters
</font></td>
</tr>
<tr>
<td valign="top"><nobr><font face="verdana" size="-2"><b>${PLAIN_CALL_SUPER}</b></font></nobr></td>
<td width="10">&nbsp;</td>
<td width="100%" valign="top"><font face="verdana" size="-1">a super method call, <code><b>super</b>.<i>method_name</i>();</code> with or without parameters;
</font></td>
</tr>
<tr>
<td valign="top"><nobr><font face="verdana" size="-2"><b>${RETURN_TYPE}</b></font></nobr></td>
<td width="10">&nbsp;</td>