@Override
  public CommonProblemDescriptor @Nullable [] checkElement(
    @NotNull RefEntity refEntity,
    @NotNull AnalysisScope analysisScope,
    @NotNull InspectionManager inspectionManager,
    @NotNull GlobalInspectionContext globalInspectionContext) {
    if (!(refEntity instanceof RefPackage refPackage)) {
      return null;
    }
    final Set<RefPackage> dependencies = DependencyUtils.calculateTransitiveDependenciesForPackage(refPackage);
    final Set<RefPackage> dependents = DependencyUtils.calculateTransitiveDependentsForPackage(refPackage);
    final Set<RefPackage> mutualDependents = new HashSet<>(dependencies);
    mutualDependents.retainAll(dependents);
    final int numMutualDependents = mutualDependents.size();
    if (numMutualDependents == 0) {
      return null;
    }
    final String packageName = refPackage.getQualifiedName();
    final String errorString;
    if (numMutualDependents == 1) {
      final RefPackage[] packages = mutualDependents.toArray(new RefPackage[1]);
      errorString = InspectionGadgetsBundle.message("cyclic.package.dependency.1.problem.descriptor",
                                                    packageName, packages[0].getQualifiedName());
    }
    else if (numMutualDependents == 2) {
      final RefPackage[] packages = mutualDependents.toArray(new RefPackage[2]);
      Arrays.sort(packages, RefEntityAlphabeticalComparator.getInstance());
      errorString = InspectionGadgetsBundle.message("cyclic.package.dependency.2.problem.descriptor",
                                                    packageName, packages[0].getQualifiedName(), packages[1].getQualifiedName());
    }
    else {
      errorString = InspectionGadgetsBundle.message("cyclic.package.dependency.problem.descriptor",
                                                    packageName, Integer.valueOf(numMutualDependents));
    }
    return new CommonProblemDescriptor[]{
      inspectionManager.createProblemDescriptor(errorString)
    };
  }
@Override
  public CommonProblemDescriptor @Nullable [] checkElement(
    @NotNull RefEntity refEntity,
    @NotNull AnalysisScope analysisScope,
    @NotNull InspectionManager inspectionManager,
    @NotNull GlobalInspectionContext globalInspectionContext)