private @NotNull String generateText(@NotNull PsiClass recordClass) {
    PsiField lastField =
      StreamEx.ofReversed(recordClass.getFields()).findFirst(field -> field.hasModifierProperty(PsiModifier.STATIC)).orElse(null);
    PsiMethod lastMethod =
      StreamEx.ofReversed(recordClass.getMethods()).findFirst(method -> !(method instanceof SyntheticElement)).orElse(null);
    PsiElement lBrace = recordClass.getLBrace();
    PsiElement insertFieldsAfter = lastField == null ? lBrace : lastField;
    PsiElement insertMethodsAfter = lastMethod == null ? insertFieldsAfter : lastMethod;
    StringBuilder result = new StringBuilder();
    for (PsiElement child = recordClass.getFirstChild(); child != null; child = child.getNextSibling()) {
      result.append(getChildText(recordClass, child));
      if (child == insertFieldsAfter) {
        insertFields(result, recordClass);
        insertConstructor(result, JavaPsiRecordUtil.findCanonicalConstructor(recordClass), recordClass);
      }
      if (child == insertMethodsAfter) {
        insertMethods(result, recordClass, recordClass.getRecordComponents());
      }
    }
    if (insertFieldsAfter == null) {
      result.append("{\n");
      insertFields(result, recordClass);
      insertConstructor(result, JavaPsiRecordUtil.findCanonicalConstructor(recordClass), recordClass);
      insertMethods(result, recordClass, recordClass.getRecordComponents());
      result.append("}");
    }
    return result.toString();
  }
private @NotNull String generateText(@NotNull PsiClass recordClass)