diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/actions/CleanupIntention.java b/platform/analysis-impl/src/com/intellij/codeInspection/actions/CleanupIntention.java index d55671b47913..dce11df2124c 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/actions/CleanupIntention.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/actions/CleanupIntention.java @@ -56,7 +56,7 @@ public abstract class CleanupIntention implements IntentionAction, LowPriorityAc final AnalysisScope scope = getScope(project, file); if (scope != null) { final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile(); - globalContext.codeCleanup(project, scope, profile, getText(), null, false); + globalContext.codeCleanup(scope, profile, getText(), null, false); } } 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 68c6d02153cd..a53fb7de7963 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextBase.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextBase.java @@ -379,8 +379,7 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G } } - public void codeCleanup(@NotNull Project project, - @NotNull AnalysisScope scope, + public void codeCleanup(@NotNull AnalysisScope scope, @NotNull InspectionProfile profile, @Nullable String commandName, @Nullable Runnable postRunnable, @@ -389,7 +388,7 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G public static void codeCleanup(@NotNull Project project, @NotNull AnalysisScope scope, @Nullable Runnable runnable) { GlobalInspectionContextBase globalContext = (GlobalInspectionContextBase)InspectionManager.getInstance(project).createNewGlobalContext(false); final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile(); - globalContext.codeCleanup(project, scope, profile, null, runnable, false); + globalContext.codeCleanup(scope, profile, null, runnable, false); } public static void cleanupElements(@NotNull final Project project, @Nullable final Runnable runnable, @NotNull PsiElement... scope) { @@ -419,7 +418,7 @@ public class GlobalInspectionContextBase extends UserDataHolderBase implements G GlobalInspectionContextBase globalContext = (GlobalInspectionContextBase)InspectionManager.getInstance(project).createNewGlobalContext(false); final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile(); AnalysisScope analysisScope = new AnalysisScope(new LocalSearchScope(psiElements.toArray(new PsiElement[psiElements.size()])), project); - globalContext.codeCleanup(project, analysisScope, profile, null, runnable, true); + globalContext.codeCleanup(analysisScope, profile, null, runnable, true); }; Application application = ApplicationManager.getApplication(); diff --git a/platform/lang-impl/src/com/intellij/codeInspection/actions/CodeCleanupAction.java b/platform/lang-impl/src/com/intellij/codeInspection/actions/CodeCleanupAction.java index 2073aec5ceef..6d0d52bb2139 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/actions/CodeCleanupAction.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/actions/CodeCleanupAction.java @@ -41,7 +41,7 @@ public class CodeCleanupAction extends CodeInspectionAction { final InspectionProfile profile = myExternalProfile != null ? myExternalProfile : InspectionProjectProfileManager.getInstance(project).getInspectionProfile(); final InspectionManager managerEx = InspectionManager.getInstance(project); final GlobalInspectionContextBase globalContext = (GlobalInspectionContextBase)managerEx.createNewGlobalContext(false); - globalContext.codeCleanup(project, scope, profile, getTemplatePresentation().getText(), null, false); + globalContext.codeCleanup(scope, profile, getTemplatePresentation().getText(), null, false); } @Override diff --git a/platform/lang-impl/src/com/intellij/codeInspection/actions/RunInspectionAction.java b/platform/lang-impl/src/com/intellij/codeInspection/actions/RunInspectionAction.java index 5a0e74b06359..6896fac160a8 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/actions/RunInspectionAction.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/actions/RunInspectionAction.java @@ -181,7 +181,7 @@ public class RunInspectionAction extends GotoActionBase { @Override public void actionPerformed(ActionEvent e) { managerEx.createNewGlobalContext(false) - .codeCleanup(project, getScope(), currentProfile, "Cleanup by " + toolWrapper.getDisplayName(), null, false); + .codeCleanup(getScope(), currentProfile, "Cleanup by " + toolWrapper.getDisplayName(), null, false); close(DialogWrapper.OK_EXIT_CODE); } }); diff --git a/platform/lang-impl/src/com/intellij/codeInspection/actions/RunInspectionIntention.java b/platform/lang-impl/src/com/intellij/codeInspection/actions/RunInspectionIntention.java index 05fcc4ed8bec..cbf00cafed63 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/actions/RunInspectionIntention.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/actions/RunInspectionIntention.java @@ -117,14 +117,14 @@ public class RunInspectionIntention implements IntentionAction, HighPriorityActi public static void rerunInspection(@NotNull InspectionToolWrapper toolWrapper, @NotNull InspectionManagerEx managerEx, @NotNull AnalysisScope scope, - PsiElement psiElement) { + @Nullable PsiElement psiElement) { GlobalInspectionContextImpl inspectionContext = createContext(toolWrapper, managerEx, psiElement); inspectionContext.doInspections(scope); } public static GlobalInspectionContextImpl createContext(@NotNull InspectionToolWrapper toolWrapper, @NotNull InspectionManagerEx managerEx, - PsiElement psiElement) { + @Nullable PsiElement psiElement) { final InspectionProfileImpl rootProfile = (InspectionProfileImpl)InspectionProfileManager.getInstance().getRootProfile(); LinkedHashSet allWrappers = new LinkedHashSet(); allWrappers.add(toolWrapper); diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java index dd1d3c6fb90b..3908b6366da3 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java @@ -846,21 +846,20 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp } @Override - public void codeCleanup(@NotNull final Project project, - @NotNull final AnalysisScope scope, + public void codeCleanup(@NotNull final AnalysisScope scope, @NotNull final InspectionProfile profile, @Nullable final String commandName, @Nullable final Runnable postRunnable, final boolean modal) { - Task task = modal ? new Task.Modal(project, "Inspect code...", true) { + Task task = modal ? new Task.Modal(getProject(), "Inspect code...", true) { @Override public void run(@NotNull ProgressIndicator indicator) { - cleanup(scope, profile, project, postRunnable, commandName); + cleanup(scope, profile, postRunnable, commandName); } - } : new Task.Backgroundable(project, "Inspect code...", true) { + } : new Task.Backgroundable(getProject(), "Inspect code...", true) { @Override public void run(@NotNull ProgressIndicator indicator) { - cleanup(scope, profile, project, postRunnable, commandName); + cleanup(scope, profile, postRunnable, commandName); } }; ProgressManager.getInstance().run(task); @@ -868,7 +867,6 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp private void cleanup(@NotNull final AnalysisScope scope, @NotNull InspectionProfile profile, - @NotNull final Project project, @Nullable final Runnable postRunnable, @Nullable final String commandName) { setCurrentScope(scope); @@ -892,7 +890,7 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp else { range = null; } - final Iterable inspectionTools = ContainerUtil.filter(profile.getAllEnabledInspectionTools(project), tools -> { + final Iterable inspectionTools = ContainerUtil.filter(profile.getAllEnabledInspectionTools(getProject()), tools -> { assert tools != null; return tools.getTool().getTool() instanceof CleanupLocalInspectionTool; }); @@ -913,10 +911,10 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp } if (!lTools.isEmpty()) { - final LocalInspectionsPass pass = new LocalInspectionsPass(file, PsiDocumentManager.getInstance(project).getDocument(file), range != null ? range.getStartOffset() : 0, + final LocalInspectionsPass pass = new LocalInspectionsPass(file, PsiDocumentManager.getInstance(getProject()).getDocument(file), range != null ? range.getStartOffset() : 0, range != null ? range.getEndOffset() : file.getTextLength(), LocalInspectionsPass.EMPTY_PRIORITY_RANGE, true, HighlightInfoProcessor.getEmpty()); - Runnable runnable = () -> pass.doInspectInBatch(GlobalInspectionContextImpl.this, InspectionManager.getInstance(project), lTools); + Runnable runnable = () -> pass.doInspectInBatch(GlobalInspectionContextImpl.this, InspectionManager.getInstance(getProject()), lTools); ApplicationManager.getApplication().runReadAction(runnable); final List infos = pass.getInfos(); if (searchScope instanceof LocalSearchScope) { @@ -950,12 +948,12 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp if (!FileModificationService.getInstance().preparePsiElementsForWrite(results.keySet())) return; final String title = "Code Cleanup"; - final SequentialModalProgressTask progressTask = new SequentialModalProgressTask(project, title, true); + final SequentialModalProgressTask progressTask = new SequentialModalProgressTask(getProject(), title, true); progressTask.setMinIterationTime(200); - progressTask.setTask(new SequentialCleanupTask(project, results, progressTask)); - CommandProcessor.getInstance().executeCommand(project, () -> { + progressTask.setTask(new SequentialCleanupTask(getProject(), results, progressTask)); + CommandProcessor.getInstance().executeCommand(getProject(), () -> { if (commandName != null) { - CommandProcessor.getInstance().markCurrentCommandAsGlobal(project); + CommandProcessor.getInstance().markCurrentCommandAsGlobal(getProject()); } ProgressManager.getInstance().run(progressTask); if (postRunnable != null) { @@ -963,7 +961,7 @@ public class GlobalInspectionContextImpl extends GlobalInspectionContextBase imp } }, title, null); }; - TransactionGuard.submitTransaction(project, runnable); + TransactionGuard.submitTransaction(getProject(), runnable); } private static boolean isBinary(@NotNull PsiFile file) {