@Override public void invoke(@NotNull Project project, @NotNull PsiFile file, @Nullable("is null when called from inspection") Editor editor, @NotNull PsiElement startElement, @NotNull PsiElement endElement) { if (editor == null) { LOG.error("Cannot run quick fix without editor: " + getClass().getSimpleName(), AttachmentFactory.createAttachment(file.getVirtualFile())); return; } if (!(startElement instanceof GoCallExpr)) return; GoCallExpr call = (GoCallExpr)startElement; List<GoExpression> args = call.getArgumentList().getExpressionList(); GoType resultType = ContainerUtil.getFirstItem(GoTypeUtil.getExpectedTypes(call)); PsiElement anchor = PsiTreeUtil.findPrevParent(file, call); Template template = TemplateManager.getInstance(project).createTemplate("", ""); template.addTextSegment("\nfunc " + myName); setupFunctionParameters(template, args, file); setupFunctionResult(template, resultType); template.addTextSegment(" {\n\t"); template.addEndVariable(); template.addTextSegment("\n}"); int offset = anchor.getTextRange().getEndOffset(); editor.getCaretModel().moveToOffset(offset); startTemplate(editor, template, project); }