void (@NotNull Project project, @Nullable Runnable runnable, List<? extends SmartPsiElementPointer<PsiElement>> elements, @NotNull Predicate<? super ProblemDescriptor> shouldApplyFix) { ApplicationManager.getApplication().invokeLater(() -> { List<PsiElement> psiElements = new ArrayList<>(); for (SmartPsiElementPointer<PsiElement> element : elements) { PsiElement psiElement = element.getElement(); if (psiElement != null && psiElement.isPhysical()) { psiElements.add(psiElement); } } if (psiElements.isEmpty()) { return; } GlobalInspectionContextBase globalContext = (GlobalInspectionContextBase)InspectionManager.getInstance(project).createNewGlobalContext(); InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getCurrentProfile(); AnalysisScope analysisScope = new AnalysisScope(new LocalSearchScope(psiElements.toArray(PsiElement.EMPTY_ARRAY)), project); globalContext.codeCleanup(analysisScope, profile, null, runnable, true, shouldApplyFix); }); }