code cleanup: get rid of redundant Project parameter
authorDmitry Batkovich <batya239@gmail.com>
Sat, 4 Jun 2016 05:35:54 +0000 (08:35 +0300)
committerDmitry Batkovich <batya239@gmail.com>
Sat, 4 Jun 2016 05:35:54 +0000 (08:35 +0300)
platform/analysis-impl/src/com/intellij/codeInspection/actions/CleanupIntention.java
platform/analysis-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextBase.java
platform/lang-impl/src/com/intellij/codeInspection/actions/CodeCleanupAction.java
platform/lang-impl/src/com/intellij/codeInspection/actions/RunInspectionAction.java
platform/lang-impl/src/com/intellij/codeInspection/actions/RunInspectionIntention.java
platform/lang-impl/src/com/intellij/codeInspection/ex/GlobalInspectionContextImpl.java

index d55671b4791370b247b24bc6f35130299a041494..dce11df2124c3d28df6e9c45143ed116ac96cd50 100644 (file)
@@ -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);
     }
   }
 
index 68c6d02153cdfc657e1494ba949833fc8f0dc041..a53fb7de796329a1a5d4dfa3c6505175b39b28c9 100644 (file)
@@ -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();
index 2073aec5ceefe6b3a5d494e9e1136095c11705e2..6d0d52bb2139510a4ef553c2aba8544bfc1845ae 100644 (file)
@@ -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
index 5a0e74b06359c90d4e9d80ceb656b0467c2fa2c3..6896fac160a8f840dc3eb826af5ccb83aa794f7d 100644 (file)
@@ -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);
             }
           });
index 05fcc4ed8bec8845a6625c78b4e5bfb4b6498edf..cbf00cafed63940855d598c7d964b7cf2097a162 100644 (file)
@@ -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<InspectionToolWrapper> allWrappers = new LinkedHashSet<InspectionToolWrapper>();
     allWrappers.add(toolWrapper);
index dd1d3c6fb90b0cfe8322a04749cc7e96bb06290e..3908b6366da33393ee135aab86bd3748ddf35978 100644 (file)
@@ -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<Tools> inspectionTools = ContainerUtil.filter(profile.getAllEnabledInspectionTools(project), tools -> {
+    final Iterable<Tools> 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<HighlightInfo> 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) {