void (@NotNull Project project, @NotNull PsiElement methodName, @NotNull ModPsiUpdater updater) { final PsiMethod method = (PsiMethod)methodName.getParent(); assert method != null; final PsiCodeBlock body = method.getBody(); if (body == null) { return; } final PsiType returnType = method.getReturnType(); final @NonNls StringBuilder statementText = new StringBuilder(); final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); if (returnType != null && !PsiTypes.voidType().equals(returnType)) { if (JavaCodeStyleSettings.getInstance(method.getContainingFile()).GENERATE_FINAL_LOCALS) { statementText.append("final "); } statementText.append(returnType.getCanonicalText()).append(' '); final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project); final SuggestedNameInfo baseNameInfo = codeStyleManager.suggestVariableName(VariableKind.LOCAL_VARIABLE, null, null, returnType); final SuggestedNameInfo nameInfo = codeStyleManager.suggestUniqueVariableName(baseNameInfo, body, true); statementText.append(nameInfo.names.length > 0 ? nameInfo.names[0] : "result"); statementText.append('='); final MethodSignatureBackedByPsiMethod superMethodSignature = MethodUtils.getSuperMethodSignature(method); if (superMethodSignature == null) { return; } final PsiMethod superMethod = superMethodSignature.getMethod(); final PsiType superReturnType = superMethod.getReturnType(); final PsiType substitutedType = superMethodSignature.getSubstitutor().substitute(superReturnType); if (superReturnType != null && !returnType.isAssignableFrom(substitutedType)) { statementText.append('(').append(returnType.getCanonicalText()).append(')'); } } statementText.append("super.").append(methodName.getText()).append('('); boolean comma = false; for (PsiParameter parameter : method.getParameterList().getParameters()) { if (comma) statementText.append(','); else comma = true; statementText.append(parameter.getName()); } statementText.append(");"); final PsiStatement newStatement = factory.createStatementFromText(statementText.toString(), null); final CodeStyleManager styleManager = CodeStyleManager.getInstance(project); final PsiJavaToken brace = body.getLBrace(); final PsiElement element = body.addAfter(newStatement, brace); final PsiElement element1 = styleManager.reformat(element); final PsiElement element2 = JavaCodeStyleManager.getInstance(project).shortenClassReferences(element1); updater.highlight(element2); if (element2 instanceof PsiDeclarationStatement declarationStatement) { final PsiLocalVariable variable = (PsiLocalVariable)declarationStatement.getDeclaredElements()[0]; List<String> nameSuggestions = new VariableNameGenerator(variable, VariableKind.LOCAL_VARIABLE) .byExpression(variable.getInitializer()) .byType(variable.getType()) .byName("original", "superResult") .generateAll(true); updater.rename(variable, nameSuggestions); } }