private static void addNewClause(@NotNull GrTypeDefinition typeDef,
                                   @NotNull Collection<String> elements,
                                   @NotNull Collection<String> additional,
                                   @NotNull Project project,
                                   boolean isExtends) throws IncorrectOperationException {
    if (elements.isEmpty() && additional.isEmpty()) return;

    @NlsSafe StringBuilder classText = new StringBuilder();
    classText.append("class A ");
    classText.append(isExtends ? "extends " : "implements ");

    for (String str : elements) {
      classText.append(str);
      classText.append(", ");
    }

    for (String str : additional) {
      classText.append(str);
      classText.append(", ");
    }

    classText.delete(classText.length() - 2, classText.length());

    classText.append(" {}");

    final GrTypeDefinition definition = GroovyPsiElementFactory.getInstance(project).createTypeDefinition(classText.toString());
    GroovyPsiElement clause = isExtends ? definition.getExtendsClause() : definition.getImplementsClause();
    assert clause != null;

    PsiElement addedClause = typeDef.addBefore(clause, typeDef.getBody());
    JavaCodeStyleManager.getInstance(project).shortenClassReferences(addedClause);
  }
private static void addNewClause(@NotNull GrTypeDefinition typeDef,
                                   @NotNull Collection<String> elements,
                                   @NotNull Collection<String> additional,
                                   @NotNull Project project,
                                   boolean isExtends)