public static @NotNull @Unmodifiable List<ProblemDescriptor> runInspectionOnFile(@NotNull PsiFile psiFile,
                                                                                   @NotNull InspectionToolWrapper<?, ?> toolWrapper,
                                                                                   @NotNull GlobalInspectionContext inspectionContext) {
    InspectionManager inspectionManager = InspectionManager.getInstance(psiFile.getProject());
    toolWrapper.initialize(inspectionContext);
    RefManagerImpl refManager = (RefManagerImpl)inspectionContext.getRefManager();
    List<ProblemDescriptor> result = new ArrayList<>();
    refManager.runInsideInspectionReadAction(() -> {
      try {
        if (toolWrapper instanceof LocalInspectionToolWrapper) {
          Map<LocalInspectionToolWrapper, List<ProblemDescriptor>> problemDescriptors =
            inspectEx(Collections.singletonList((LocalInspectionToolWrapper)toolWrapper), psiFile, psiFile.getTextRange(), psiFile.getTextRange(),
                      false,
                      false, true, new EmptyProgressIndicator(), PairProcessor.alwaysTrue());

          for (List<ProblemDescriptor> group : problemDescriptors.values()) {
            result.addAll(group);
          }
        }
        else if (toolWrapper instanceof GlobalInspectionToolWrapper) {
          GlobalInspectionTool globalTool = ((GlobalInspectionToolWrapper)toolWrapper).getTool();
          if (globalTool.isGlobalSimpleInspectionTool()) {
            ProblemsHolder problemsHolder = new ProblemsHolder(inspectionManager, psiFile, false);
            ProblemDescriptionsProcessor collectProcessor = new ProblemDescriptionsProcessor() {
              @Override
              public CommonProblemDescriptor[] getDescriptions(@NotNull RefEntity refEntity) {
                return result.toArray(CommonProblemDescriptor.EMPTY_ARRAY);
              }

              @Override
              public void ignoreElement(@NotNull RefEntity refEntity) {
                throw new UnsupportedOperationException();
              }

              @Override
              public void resolveProblem(@NotNull CommonProblemDescriptor descriptor) {
                throw new UnsupportedOperationException();
              }

              @Override
              public void addProblemElement(@Nullable RefEntity refEntity, CommonProblemDescriptor @NotNull ... commonProblemDescriptors) {
                if (!(refEntity instanceof RefElement)) return;
                PsiElement element = ((RefElement)refEntity).getPsiElement();
                convertToProblemDescriptors(element, commonProblemDescriptors, result);
              }

              @Override
              public RefEntity getElement(@NotNull CommonProblemDescriptor descriptor) {
                throw new RuntimeException();
              }
            };
            globalTool.checkFile(psiFile, inspectionManager, problemsHolder, inspectionContext, collectProcessor);
          }
          else {
            RefElement fileRef = refManager.getReference(psiFile);
            AnalysisScope scope = new AnalysisScope(psiFile);
            assert fileRef != null;
            fileRef.accept(new RefVisitor() {
              @Override
              public void visitElement(@NotNull RefEntity elem) {
                CommonProblemDescriptor[] elemDescriptors = globalTool.checkElement(elem, scope, inspectionManager, inspectionContext);
                if (elemDescriptors != null) {
                  convertToProblemDescriptors(psiFile, elemDescriptors, result);
                }

                for (RefEntity child : elem.getChildren()) {
                  child.accept(this);
                }
              }
            });
          }
        }
      }
      finally {
        toolWrapper.cleanup(psiFile.getProject());
        inspectionContext.cleanup();
      }
    });
    return result;
  }
public static @NotNull @Unmodifiable List<ProblemDescriptor> runInspectionOnFile(@NotNull PsiFile psiFile,
                                                                                   @NotNull InspectionToolWrapper<?, ?> toolWrapper,
                                                                                   @NotNull GlobalInspectionContext inspectionContext)