private static String @NotNull [] addExtendsImplements(PsiElement context) {
    if (context.getParent() == null) {
      return ArrayUtilRt.EMPTY_STRING_ARRAY;
    }

    PsiElement elem = context.getParent();
    boolean ext = !(elem instanceof GrExtendsClause);
    boolean impl = !(elem instanceof GrImplementsClause);
    boolean permits = !(elem instanceof GrPermitsClause);

    if (elem instanceof GrTypeDefinitionBody) { //inner class
      elem = PsiUtil.skipWhitespacesAndComments(context.getPrevSibling(), false);
    }
    else {
      if (elem instanceof GrReferenceExpression && PsiUtil.skipWhitespacesAndComments(elem.getPrevSibling(), false) instanceof GrTypeDefinition) {
        elem = PsiUtil.skipWhitespacesAndComments(elem.getPrevSibling(), false);
      }
      else {
        PsiElement parent = elem.getParent();
        if (parent != null) {
          if (parent instanceof PsiFile) {
            elem = null;
          }
          else {
            elem = PsiUtil.skipWhitespacesAndComments(parent.getPrevSibling(), false);
          }
        }
      }
    }

    ext &= elem instanceof GrInterfaceDefinition || elem instanceof GrClassDefinition || elem instanceof GrTraitTypeDefinition;
    impl &= elem instanceof GrEnumTypeDefinition || elem instanceof GrClassDefinition || elem instanceof GrTraitTypeDefinition || elem instanceof GrRecordDefinition;
    permits &= elem instanceof GrInterfaceDefinition || elem instanceof GrClassDefinition || elem instanceof GrTraitTypeDefinition;
    if (!ext && !impl && !permits) return ArrayUtilRt.EMPTY_STRING_ARRAY;

    PsiElement[] children = elem.getChildren();
    for (PsiElement child : children) {
      ext &= !(child instanceof GrExtendsClause && ((GrExtendsClause)child).getKeyword() != null);
      impl &= !(child instanceof GrImplementsClause && ((GrImplementsClause)child).getKeyword() != null);
      if (child instanceof GrPermitsClause && ((GrPermitsClause)child).getKeyword() != null || child instanceof GrTypeDefinitionBody) {
        return ArrayUtilRt.EMPTY_STRING_ARRAY;
      }
    }
    List<String> keywords = new ArrayList<>();
    if (ext) {
      keywords.add(PsiKeyword.EXTENDS);
    }
    if (impl) {
      keywords.add(PsiKeyword.IMPLEMENTS);
    }
    if (permits && GroovyConfigUtils.isAtLeastGroovy40(context)) {
      keywords.add(PsiKeyword.PERMITS);
    }

    return ArrayUtil.toStringArray(keywords);
  }
private static String @NotNull [] addExtendsImplements(PsiElement context)