private static void addSuperClass(
    @NotNull final PsiClass aClass,
    @NotNull final PsiClass oldSuperClass,
    @NotNull final PsiClass newSuperClass
  ) {
    JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(aClass.getProject());
    PsiElementFactory factory = psiFacade.getElementFactory();
    PsiElement ref;
    if (aClass instanceof PsiAnonymousClass) {
      ref = ((PsiAnonymousClass)aClass).getBaseClassReference().replace(factory.createClassReferenceElement(newSuperClass));
    }
    else {
      PsiReferenceList extendsList = Objects.requireNonNull(aClass.getExtendsList());
      PsiJavaCodeReferenceElement[] refElements =
        ArrayUtil.mergeArrays(getReferences(extendsList), getReferences(aClass.getImplementsList()));
      for (PsiJavaCodeReferenceElement refElement : refElements) {
        if (refElement.isReferenceTo(oldSuperClass)) {
          refElement.delete();
        }
      }

      PsiReferenceList list;
      if (newSuperClass.isInterface() && !aClass.isInterface()) {
        list = aClass.getImplementsList();
      }
      else {
        list = extendsList;
        PsiJavaCodeReferenceElement[] elements = list.getReferenceElements();
        if (elements.length == 1) {
          PsiClass objectClass = psiFacade.findClass(CommonClassNames.JAVA_LANG_OBJECT, aClass.getResolveScope());
          if (objectClass != null && elements[0].isReferenceTo(objectClass)) {
            elements[0].delete();
          }
        }
      }
      assert list != null;
      ref = list.add(factory.createClassReferenceElement(newSuperClass));
    }
    JavaCodeStyleManager.getInstance(aClass.getProject()).shortenClassReferences(ref);
  }
private static void addSuperClass(
    @NotNull final PsiClass aClass,
    @NotNull final PsiClass oldSuperClass,
    @NotNull final PsiClass newSuperClass
  )