diff --git a/platform/analysis-impl/api-dump-unreviewed.txt b/platform/analysis-impl/api-dump-unreviewed.txt index b97522e70414..7e49fda05c51 100644 --- a/platform/analysis-impl/api-dump-unreviewed.txt +++ b/platform/analysis-impl/api-dump-unreviewed.txt @@ -2621,6 +2621,7 @@ c:com.intellij.codeInspection.ex.GlobalInspectionContextBase - p:canceled():V - p:classifyTool(java.util.List,java.util.List,java.util.List,com.intellij.codeInspection.ex.Tools,com.intellij.codeInspection.ex.InspectionToolWrapper):V - cleanup():V +- s:cleanupElements(com.intellij.openapi.project.Project,java.lang.Runnable,java.util.function.Predicate,com.intellij.codeInspection.InspectionProfile,com.intellij.psi.PsiElement[]):V - s:cleanupElements(com.intellij.openapi.project.Project,java.lang.Runnable,java.util.function.Predicate,com.intellij.psi.PsiElement[]):V - s:cleanupElements(com.intellij.openapi.project.Project,java.lang.Runnable,com.intellij.psi.PsiElement[]):V - close(Z):V diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextBase.java b/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextBase.java index 517fe14269e3..fb25e6dc55a5 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextBase.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextBase.java @@ -465,6 +465,28 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G cleanupElements(project, runnable, Predicates.alwaysTrue(), scope); } + /** + * Runs code cleanup on the specified scope with the specified profile + * + * @param project project from which to use the inspection profile + * @param runnable will be run after completion of the cleanup + * @param shouldApplyFix predicate to filter out fixes + * @param profile inspection profile to use + * @param scope the elements to clean up + */ + public static void cleanupElements(@NotNull Project project, + @Nullable Runnable runnable, + Predicate shouldApplyFix, + @NotNull InspectionProfile profile, + PsiElement @NotNull ... scope) { + List psiElements = Stream.of(scope).filter(e -> e != null && e.isPhysical()).toList(); + if (psiElements.isEmpty()) return; + GlobalInspectionContextBase globalContext = + (GlobalInspectionContextBase)InspectionManager.getInstance(project).createNewGlobalContext(); + AnalysisScope analysisScope = new AnalysisScope(new LocalSearchScope(psiElements.toArray(PsiElement.EMPTY_ARRAY)), project); + globalContext.codeCleanup(analysisScope, profile, null, runnable, false, shouldApplyFix); + } + /** * Runs code cleanup on the specified scope * @@ -477,13 +499,7 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G @Nullable Runnable runnable, Predicate shouldApplyFix, PsiElement @NotNull ... scope) { - List psiElements = Stream.of(scope).filter(e -> e != null && e.isPhysical()).toList(); - 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, false, shouldApplyFix); + cleanupElements(project, runnable, shouldApplyFix, InspectionProjectProfileManager.getInstance(project).getCurrentProfile(), scope); } public void close(boolean noSuspiciousCodeFound) {