private void copyExtendsList(@NotNull PsiClass classToRemove,
                               @Nullable PsiReferenceList sourceExtendsList,
                               boolean targetExtends,
                               PsiElementFactory elementFactory) {
    if (sourceExtendsList != null) {
      final PsiClassType[] referenceTypes = sourceExtendsList.getReferencedTypes();
      final PsiReferenceList targetExtendsList = targetExtends ? myExtendingClass.getExtendsList() : myExtendingClass.getImplementsList();
      final PsiClassType[] existingRefTypes = targetExtendsList.getReferencedTypes();
      for (PsiClassType referenceType : referenceTypes) {
        if (ArrayUtilRt.find(existingRefTypes, referenceType) > -1) continue;
        PsiClassType classType = (PsiClassType)mySubstitutor.substitute(referenceType);
        PsiElement extendsRef = targetExtendsList.add(elementFactory.createReferenceElementByType(classType));
        PsiClass classToExtend = classType.resolve();
        if (classToExtend != null && classToExtend.hasModifierProperty(PsiModifier.SEALED)) {
          String extendingClassName = Objects.requireNonNull(myExtendingClass.getQualifiedName());
          if (classToExtend.getPermitsList() == null) {
            if (classToExtend.getContainingFile() != myExtendingClass.getContainingFile()) {
              Collection<String> missingInheritors = SealedUtils.findSameFileInheritors(classToExtend, classToRemove);
              missingInheritors.add(extendingClassName);
              SealedUtils.fillPermitsList(classToExtend, missingInheritors);
            }
          }
          else {
            SealedUtils.fillPermitsList(classToExtend, Collections.singleton(extendingClassName));
          }
        }
        CodeStyleManager.getInstance(myExtendingClass.getProject()).reformat(extendsRef);
      }
    }
  }
private void copyExtendsList(@NotNull PsiClass classToRemove,
                               @Nullable PsiReferenceList sourceExtendsList,
                               boolean targetExtends,
                               PsiElementFactory elementFactory)