private static LookupElementBuilder createGenerateMethodElement(
      PsiMethod prototype,
      PsiSubstitutor substitutor,
      Icon icon,
      String typeText,
      InsertHandler<LookupElement> insertHandler) {
    String methodName = prototype.getName();

    String visibility = VisibilityUtil.getVisibilityModifier(prototype.getModifierList());
    String modifiers = (visibility == PsiModifier.PACKAGE_LOCAL ? "" : visibility + " ");

    PsiType type = substitutor.substitute(prototype.getReturnType());
    String signature =
        modifiers + (type == null ? "" : type.getPresentableText() + " ") + methodName;

    String parameters =
        PsiFormatUtil.formatMethod(
            prototype, substitutor, PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_NAME);

    String overrideSignature =
        " @Override "
            + signature; // leading space to make it a middle match, under all annotation
                         // suggestions
    LookupElementBuilder element =
        LookupElementBuilder.create(prototype, signature)
            .withLookupString(methodName)
            .withLookupString(signature)
            .withLookupString(overrideSignature)
            .withInsertHandler(insertHandler)
            .appendTailText(parameters, false)
            .appendTailText(" {...}", true)
            .withTypeText(typeText)
            .withIcon(icon);
    element.putUserData(GENERATE_ELEMENT, true);
    return element;
  }