static HighlightInfo.Builder checkIntersectionInTypeCast(@NotNull PsiTypeCastExpression expression,
                                                   @NotNull LanguageLevel languageLevel,
                                                   @NotNull PsiFile file) {
    PsiTypeElement castTypeElement = expression.getCastType();
    if (castTypeElement == null || !isIntersection(castTypeElement, castTypeElement.getType())) {
      return null;
    }
    HighlightInfo.Builder info = checkFeature(expression, JavaFeature.INTERSECTION_CASTS, languageLevel, file);
    if (info != null) return info;

    PsiTypeElement[] conjuncts = PsiTreeUtil.getChildrenOfType(castTypeElement, PsiTypeElement.class);
    if (conjuncts != null) {
      Set<PsiType> erasures = new HashSet<>(conjuncts.length);
      erasures.add(TypeConversionUtil.erasure(conjuncts[0].getType()));
      List<PsiTypeElement> conjList = new ArrayList<>(Arrays.asList(conjuncts));
      for (int i = 1; i < conjuncts.length; i++) {
        PsiTypeElement conjunct = conjuncts[i];
        PsiType conjType = conjunct.getType();
        if (conjType instanceof PsiClassType) {
          PsiClass aClass = ((PsiClassType)conjType).resolve();
          if (aClass != null && !aClass.isInterface()) {
            HighlightInfo.Builder errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
              .range(conjunct)
              .descriptionAndTooltip(JavaErrorBundle.message("interface.expected"));
            var action = new FlipIntersectionSidesFix(aClass.getName(), conjunct, castTypeElement);
            errorResult.registerFix(action, null, HighlightDisplayKey.getDisplayNameByKey(null), null, null);
            return errorResult;
          }
        }
        else {
          return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
            .range(conjunct)
            .descriptionAndTooltip(JavaErrorBundle.message("unexpected.type.class.expected"));
        }
        if (!erasures.add(TypeConversionUtil.erasure(conjType))) {
          HighlightInfo.Builder highlightInfo = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
            .range(conjunct)
            .descriptionAndTooltip(JavaErrorBundle.message("repeated.interface"));
          var action = new DeleteRepeatedInterfaceFix(conjunct);
          highlightInfo.registerFix(action, null, HighlightDisplayKey.getDisplayNameByKey(null), null, null);
          return highlightInfo;
        }
      }

      List<PsiType> typeList = ContainerUtil.map(conjList, PsiTypeElement::getType);
      Ref<@Nls String> differentArgumentsMessage = new Ref<>();
      PsiClass sameGenericParameterization =
        InferenceSession.findParameterizationOfTheSameGenericClass(typeList, pair -> {
          if (!TypesDistinctProver.provablyDistinct(pair.first, pair.second)) {
            return true;
          }
          differentArgumentsMessage.set(IdeBundle.message("x.and.y", pair.first.getPresentableText(),
                                                          pair.second.getPresentableText()));
          return false;
        });
      if (sameGenericParameterization != null) {
        String message = JavaErrorBundle
          .message("class.cannot.be.inherited.with.different.arguments", formatClass(sameGenericParameterization),
                   differentArgumentsMessage.get());
        return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
          .range(expression)
          .descriptionAndTooltip(message);
      }
    }

    return null;
  }
static HighlightInfo.Builder checkIntersectionInTypeCast(@NotNull PsiTypeCastExpression expression,
                                                   @NotNull LanguageLevel languageLevel,
                                                   @NotNull PsiFile file)