code cleanup: run by name cleanup inspection must fix only this inspection problems
authorDmitry Batkovich <batya239@gmail.com>
Sat, 4 Jun 2016 05:52:15 +0000 (08:52 +0300)
committerDmitry Batkovich <batya239@gmail.com>
Sat, 4 Jun 2016 05:52:15 +0000 (08:52 +0300)
platform/lang-impl/src/com/intellij/codeInspection/actions/RunInspectionAction.java
platform/lang-impl/src/com/intellij/codeInspection/actions/RunInspectionIntention.java

index 6896fac160a8f840dc3eb826af5ccb83aa794f7d..653dfc2a8c63a199a78bc6a011d022ed32299c60 100644 (file)
@@ -25,6 +25,7 @@ import com.intellij.codeInspection.InspectionManager;
 import com.intellij.codeInspection.InspectionProfile;
 import com.intellij.codeInspection.InspectionsBundle;
 import com.intellij.codeInspection.ex.InspectionManagerEx;
+import com.intellij.codeInspection.ex.InspectionProfileImpl;
 import com.intellij.codeInspection.ex.InspectionToolWrapper;
 import com.intellij.featureStatistics.FeatureUsageTracker;
 import com.intellij.ide.IdeBundle;
@@ -180,8 +181,9 @@ public class RunInspectionAction extends GotoActionBase {
           actions.add(new AbstractAction("Fix All") {
             @Override
             public void actionPerformed(ActionEvent e) {
+              InspectionProfileImpl cleanupToolProfile = RunInspectionIntention.createProfile(toolWrapper, managerEx, element);
               managerEx.createNewGlobalContext(false)
-                .codeCleanup(getScope(), currentProfile, "Cleanup by " + toolWrapper.getDisplayName(), null, false);
+                .codeCleanup(getScope(), cleanupToolProfile, "Cleanup by " + toolWrapper.getDisplayName(), null, false);
               close(DialogWrapper.OK_EXIT_CODE);
             }
           });
index cbf00cafed63940855d598c7d964b7cf2097a162..f6f0682301800c1df081cc5fb5ef06e4a2c51134 100644 (file)
@@ -122,9 +122,20 @@ public class RunInspectionIntention implements IntentionAction, HighPriorityActi
     inspectionContext.doInspections(scope);
   }
 
+  @NotNull
   public static GlobalInspectionContextImpl createContext(@NotNull InspectionToolWrapper toolWrapper,
                                                           @NotNull InspectionManagerEx managerEx,
                                                           @Nullable PsiElement psiElement) {
+    final InspectionProfileImpl model = createProfile(toolWrapper, managerEx, psiElement);
+    final GlobalInspectionContextImpl inspectionContext = managerEx.createNewGlobalContext(false);
+    inspectionContext.setExternalProfile(model);
+    return inspectionContext;
+  }
+
+  @NotNull
+  public static InspectionProfileImpl createProfile(@NotNull InspectionToolWrapper toolWrapper,
+                                                    @NotNull InspectionManagerEx managerEx,
+                                                    @Nullable PsiElement psiElement) {
     final InspectionProfileImpl rootProfile = (InspectionProfileImpl)InspectionProfileManager.getInstance().getRootProfile();
     LinkedHashSet<InspectionToolWrapper> allWrappers = new LinkedHashSet<InspectionToolWrapper>();
     allWrappers.add(toolWrapper);
@@ -145,9 +156,7 @@ public class RunInspectionIntention implements IntentionAction, HighPriorityActi
     catch (InvalidDataException ignored) {
     }
     model.setSingleTool(toolWrapper.getShortName());
-    final GlobalInspectionContextImpl inspectionContext = managerEx.createNewGlobalContext(false);
-    inspectionContext.setExternalProfile(model);
-    return inspectionContext;
+    return model;
   }
 
   @Override