CleanupProblems (@NotNull AnalysisScope scope, @NotNull InspectionProfile profile, @NotNull ProgressIndicator progressIndicator, @NotNull Predicate<? super ProblemDescriptor> shouldApplyFix) { if (LOG.isDebugEnabled()) { LOG.debug("Code cleanup: searching for problems in code"); } setCurrentScope(scope); int fileCount = scope.getFileCount(); progressIndicator.setIndeterminate(false); SearchScope searchScope = ReadAction.compute(scope::toSearchScope); TextRange range; if (searchScope instanceof LocalSearchScope) { PsiElement[] elements = ((LocalSearchScope)searchScope).getScope(); range = elements.length == 1 ? ReadAction.compute(elements[0]::getTextRange) : null; } else { range = null; } Iterable<Tools> inspectionTools = ContainerUtil.filter(profile.getAllEnabledInspectionTools(getProject()), tools -> { assert tools != null; return tools.getTool().isCleanupTool(); }); boolean includeDoNotShow = includeDoNotShow(profile); List<ProblemDescriptor> descriptors = new ArrayList<>(); Set<PsiFile> files = new HashSet<>(); ((RefManagerImpl)getRefManager()).runInsideInspectionReadAction(() -> scope.accept(new PsiElementVisitor() { private int myCount; @Override public void visitFile(@NotNull PsiFile file) { if (LOG.isDebugEnabled()) { LOG.debug("Code cleanup: searching for problems in file " + file); } progressIndicator.setText(AbstractLayoutCodeProcessor.getPresentablePath(getProject(), file)); progressIndicator.setFraction((double)++myCount / fileCount); if (isBinary(file)) return; List<LocalInspectionToolWrapper> lTools = new ArrayList<>(); for (Tools tools : inspectionTools) { InspectionToolWrapper<?, ?> tool = tools.getEnabledTool(file, includeDoNotShow); if (tool != null && profile instanceof InspectionProfileImpl profileImpl) { @NotNull Set<InspectionToolWrapper<?, ?>> other = new HashSet<>(); profileImpl.collectDependentInspections(tool, other, getProject()); for (InspectionToolWrapper<?, ?> wrapper : other) { if (wrapper instanceof LocalInspectionToolWrapper) { lTools.add((LocalInspectionToolWrapper)wrapper); wrapper.initialize(GlobalInspectionContextImpl.this); } } } if (tool instanceof GlobalInspectionToolWrapper) { tool = ((GlobalInspectionToolWrapper)tool).getSharedLocalInspectionToolWrapper(); } if (tool != null) { lTools.add((LocalInspectionToolWrapper)tool); tool.initialize(GlobalInspectionContextImpl.this); } } if (!lTools.isEmpty()) { InspectionProfileWrapper.runWithCustomInspectionWrapper(file, p -> new InspectionProfileWrapper(profile, ((InspectionProfileImpl)p).getProfileManager()), () -> findProblemsInFile(file, lTools, range, searchScope, descriptors, files, shouldApplyFix)); } } })); return new CleanupProblems(files, descriptors, searchScope instanceof GlobalSearchScope); }