@NotNull
      static Stream<PsiDocTag> getRelatedJavadocThrows(@NotNull final PsiJavaCodeReferenceElement currentThrowsRef,
                                                       @Nullable final PsiDocComment comment) {
        if (comment == null) return Stream.empty();

        final PsiElement maybeThrowsList = currentThrowsRef.getParent();
        if (!(maybeThrowsList instanceof PsiReferenceList throwsList)) return Stream.empty();

        // return all @throws declarations from javadoc if the last throws declaration in the throws list is getting eliminated.
        if (throwsList.getReferenceElements().length == 1) {
          return StreamEx.of(comment.getTags())
            .filterBy(PsiDocTag::getName, "throws");
        }

        final PsiElement maybeClass = currentThrowsRef.resolve();
        if (!(maybeClass instanceof PsiClass reference)) return Stream.empty();

        final List<PsiClassType> throwsListWithoutCurrent = getThrowsListWithoutCurrent(throwsList, currentThrowsRef);

        final PsiClassType referenceType = PsiTypesUtil.getClassType(reference);
        if (throwsListWithoutCurrent.contains(referenceType)) return Stream.empty();

        final PsiManager manager = reference.getManager();

        final Predicate<PsiDocTag> isTagRelatedToCurrentThrowsRef = tag -> {
          final PsiClass throwsClass = JavaDocUtil.resolveClassInTagValue(tag.getValueElement());
          if (throwsClass == null) return false;
          // either the tag's class is exactly the current throws reference
          // or it's a inheritor of the throws declaration and there are no other parents in the throws list
          return manager.areElementsEquivalent(throwsClass, reference) ||
                 (throwsClass.isInheritor(reference, true) && !isParentInThrowsListPresent(throwsClass, throwsListWithoutCurrent));
        };

        return StreamEx.of(comment.getTags())
          .filterBy(PsiDocTag::getName, "throws")
          .filter(isTagRelatedToCurrentThrowsRef);
      }
@NotNull
      static Stream<PsiDocTag> getRelatedJavadocThrows(@NotNull final PsiJavaCodeReferenceElement currentThrowsRef,
                                                       @Nullable final PsiDocComment comment)