run intentions under transaction (IDEA-CR-15393)
authorpeter <peter@jetbrains.com>
Mon, 7 Nov 2016 13:54:36 +0000 (14:54 +0100)
committerpeter <peter@jetbrains.com>
Mon, 7 Nov 2016 14:05:26 +0000 (15:05 +0100)
java/java-impl/src/com/intellij/codeInsight/intention/impl/BindFieldsFromParametersAction.java
platform/lang-impl/src/com/intellij/codeInsight/intention/impl/ShowIntentionActionsHandler.java
platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java

index 9b7c38453c68cbe1a2ab6006b97ca53c29529c30..0c0e6bde9a653c2b021bbc53ef5530f8fd986999 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2016 JetBrains s.r.o.
+ * Copyright 2000-2014 JetBrains s.r.o.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@ import com.intellij.codeInsight.intention.HighPriorityAction;
 import com.intellij.ide.util.MemberChooser;
 import com.intellij.lang.java.JavaLanguage;
 import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.application.TransactionGuard;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.fileEditor.ex.IdeDocumentHistory;
@@ -158,27 +157,25 @@ public class BindFieldsFromParametersAction extends BaseIntentionAction implemen
   private static void invoke(final Project project, Editor editor, PsiFile file, boolean isInteractive) {
     PsiParameter psiParameter = FieldFromParameterUtils.findParameterAtCursor(file, editor);
     if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;
-    TransactionGuard.getInstance().submitTransactionAndWait(() -> {
-      final PsiMethod method = psiParameter != null ? (PsiMethod)psiParameter.getDeclarationScope() : PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PsiMethod.class);
-      LOG.assertTrue(method != null);
-
-      final HashSet<String> usedNames = new HashSet<>();
-      final Iterable<PsiParameter> parameters = selectParameters(project, method, copyUnboundedParamsAndClearOriginal(method), isInteractive);
-      final MultiMap<PsiType, PsiParameter> types = new MultiMap<>();
-      for (PsiParameter parameter : parameters) {
-        types.putValue(parameter.getType(), parameter);
-      }
-      final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project);
-      final boolean preferLongerNames = settings.PREFER_LONGER_NAMES;
-      for (PsiParameter selected : parameters) {
-        try {
-          settings.PREFER_LONGER_NAMES = preferLongerNames || types.get(selected.getType()).size() > 1;
-          processParameter(project, selected, usedNames);
-        } finally {
-          settings.PREFER_LONGER_NAMES = preferLongerNames;
-        }
+    final PsiMethod method = psiParameter != null ? (PsiMethod)psiParameter.getDeclarationScope() : PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PsiMethod.class);
+    LOG.assertTrue(method != null);
+
+    final HashSet<String> usedNames = new HashSet<>();
+    final Iterable<PsiParameter> parameters = selectParameters(project, method, copyUnboundedParamsAndClearOriginal(method), isInteractive);
+    final MultiMap<PsiType, PsiParameter> types = new MultiMap<>();
+    for (PsiParameter parameter : parameters) {
+      types.putValue(parameter.getType(), parameter);
+    }
+    final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project);
+    final boolean preferLongerNames = settings.PREFER_LONGER_NAMES;
+    for (PsiParameter selected : parameters) {
+      try {
+        settings.PREFER_LONGER_NAMES = preferLongerNames || types.get(selected.getType()).size() > 1;
+        processParameter(project, selected, usedNames);
+      } finally {
+        settings.PREFER_LONGER_NAMES = preferLongerNames;
       }
-    });
+    }
   }
 
   @NotNull
index 504dc3dff075f2277c8d0cc33ec37432700e32b2..8a6d9d27854a846eef9d9d9c8aaeb30d9a71438e 100644 (file)
@@ -32,6 +32,7 @@ import com.intellij.featureStatistics.FeatureUsageTracker;
 import com.intellij.featureStatistics.FeatureUsageTrackerImpl;
 import com.intellij.injected.editor.EditorWindow;
 import com.intellij.lang.injection.InjectedLanguageManager;
+import com.intellij.openapi.application.TransactionGuard;
 import com.intellij.openapi.application.WriteAction;
 import com.intellij.openapi.command.CommandProcessor;
 import com.intellij.openapi.diagnostic.Logger;
@@ -182,7 +183,7 @@ public class ShowIntentionActionsHandler implements CodeInsightActionHandler {
                                                                                          (psiFile, editor) -> availableFor(psiFile, editor, action)) : Pair.<PsiFile, Editor>create(hostFile, null);
     if (pair == null) return false;
 
-    CommandProcessor.getInstance().executeCommand(project, () -> {
+    CommandProcessor.getInstance().executeCommand(project, () -> TransactionGuard.getInstance().submitTransactionAndWait(() -> {
       Runnable r = () -> action.invoke(project, pair.second, pair.first);
       try {
         if (action.startInWriteAction()) {
@@ -197,7 +198,7 @@ public class ShowIntentionActionsHandler implements CodeInsightActionHandler {
       if (hostEditor != null) {
         DaemonCodeAnalyzer.getInstance(project).updateVisibleHighlighters(hostEditor);
       }
-    }, text, null);
+    }), text, null);
     return true;
   }
 }
index 554d6cc6de7779c166b328c47c37235cf2670078..cdeb1b6ba4b27bb262797d6a1803cce138681d0c 100644 (file)
@@ -60,6 +60,7 @@ import com.intellij.openapi.actionSystem.*;
 import com.intellij.openapi.actionSystem.ex.ActionManagerEx;
 import com.intellij.openapi.application.ReadAction;
 import com.intellij.openapi.application.Result;
+import com.intellij.openapi.application.TransactionGuard;
 import com.intellij.openapi.application.WriteAction;
 import com.intellij.openapi.command.CommandProcessor;
 import com.intellij.openapi.command.WriteCommandAction;
@@ -551,7 +552,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
 
   @Override
   public void launchAction(@NotNull final IntentionAction action) {
-    ShowIntentionActionsHandler.chooseActionAndInvoke(getFile(), getEditor(), action, action.getText());
+    TransactionGuard.submitTransaction(getProject(), () -> ShowIntentionActionsHandler.chooseActionAndInvoke(getFile(), getEditor(), action, action.getText()));
     UIUtil.dispatchAllInvocationEvents();
   }