EA-91810 - assert: NoSwingUnderWriteAction.lambda$watchForEvents$
authorAnna.Kozlova <anna.kozlova@jetbrains.com>
Wed, 16 Nov 2016 14:25:38 +0000 (15:25 +0100)
committerAnna.Kozlova <anna.kozlova@jetbrains.com>
Wed, 16 Nov 2016 15:02:34 +0000 (16:02 +0100)
push write access to utility to avoid dialogs from write actions

platform/core-impl/src/com/intellij/psi/impl/file/PsiFileImplUtil.java
platform/lang-impl/src/com/intellij/refactoring/copy/CopyFilesOrDirectoriesHandler.java
platform/lang-impl/src/com/intellij/refactoring/move/moveFilesOrDirectories/MoveFilesOrDirectoriesUtil.java
platform/lang-impl/src/com/intellij/refactoring/rename/RenameProcessor.java

index aa5e498e2082b66460095fdbe7e1ad20dbb3425a..db5a8e7cf50a87928c8156866109837d1ab1db80 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -16,7 +16,6 @@
 
 package com.intellij.psi.impl.file;
 
-import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.fileEditor.FileDocumentManager;
 import com.intellij.openapi.fileTypes.FileType;
@@ -59,7 +58,6 @@ public class PsiFileImplUtil {
   }
 
   public static void checkSetName(@NotNull PsiFile file, @NotNull String name) throws IncorrectOperationException {
-    ApplicationManager.getApplication().assertWriteAccessAllowed();
     VirtualFile vFile = file.getVirtualFile();
     VirtualFile parentFile = vFile.getParent();
     if (parentFile == null) return;
index 4d7704a953b203b14537268069145f6d878e3621..089df084fb100f5ef843c9a76ce2f93df8094b37 100644 (file)
@@ -21,6 +21,7 @@ import com.intellij.ide.util.EditorHelper;
 import com.intellij.ide.util.PlatformPackageUtil;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.application.Result;
+import com.intellij.openapi.application.WriteAction;
 import com.intellij.openapi.command.WriteCommandAction;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.project.Project;
@@ -331,7 +332,7 @@ public class CopyFilesOrDirectoriesHandler extends CopyHandlerDelegateBase {
       }
 
       if (selection == 0 && file != existing) {
-        existing.delete();
+        WriteAction.run(() -> existing.delete());
       }
       else {
         return true;
index fb1e9471fe6d4b4b8c6448d3a1447bf51163d2f8..9ffdc237f2b2c1668ad3bffa3ca8dc495cf217fd 100644 (file)
@@ -22,7 +22,6 @@ import com.intellij.openapi.command.CommandProcessor;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.DialogWrapper;
-import com.intellij.openapi.util.Computable;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.psi.*;
 import com.intellij.refactoring.RefactoringBundle;
@@ -153,13 +152,7 @@ public class MoveFilesOrDirectoriesUtil {
             for (final PsiElement psiElement : newElements) {
               if (psiElement instanceof PsiFile) {
                 final PsiFile file = (PsiFile)psiElement;
-                final boolean fileExist = ApplicationManager.getApplication().runWriteAction(new Computable<Boolean>() {
-                  @Override
-                  public Boolean compute() {
-                    return CopyFilesOrDirectoriesHandler.checkFileExist(targetDirectory1, choice, file, file.getName(), "Move");
-                  }
-                });
-                if (fileExist) continue;
+                if (CopyFilesOrDirectoriesHandler.checkFileExist(targetDirectory1, choice, file, file.getName(), "Move")) continue;
               }
               checkMove(psiElement, targetDirectory1);
               els.add(psiElement);
index 8c438ab4442ea408b4573b7a67526eb39aa7c0c5..63c3065f4b749c3f4bfe1e94525ebfb477923b11 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2015 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -200,6 +200,31 @@ public class RenameProcessor extends BaseRefactoringProcessor {
       }
     }
 
+    final int[] choice = myAllRenames.size() > 1 ? new int[]{-1} : null;
+    String message = null;
+    try {
+      for (Iterator<Map.Entry<PsiElement, String>> iterator = myAllRenames.entrySet().iterator(); iterator.hasNext(); ) {
+        Map.Entry<PsiElement, String> entry = iterator.next();
+        if (entry.getKey() instanceof PsiFile) {
+          final PsiFile file = (PsiFile)entry.getKey();
+          final PsiDirectory containingDirectory = file.getContainingDirectory();
+          if (CopyFilesOrDirectoriesHandler.checkFileExist(containingDirectory, choice, file, entry.getValue(), "Rename")) {
+            iterator.remove();
+            continue;
+          }
+        }
+        RenameUtil.checkRename(entry.getKey(), entry.getValue());
+      }
+    }
+    catch (IncorrectOperationException e) {
+      message = e.getMessage();
+    }
+
+    if (message != null) {
+      CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("rename.title"), message, getHelpID(), myProject);
+      return false;
+    }
+
     final Set<UsageInfo> usagesSet = ContainerUtil.newLinkedHashSet(usagesIn);
     usagesSet.addAll(variableUsages);
     final List<UnresolvableCollisionUsageInfo> conflictUsages = RenameUtil.removeConflictUsages(usagesSet);
@@ -350,31 +375,6 @@ public class RenameProcessor extends BaseRefactoringProcessor {
 
   @Override
   public void performRefactoring(@NotNull UsageInfo[] usages) {
-    final int[] choice = myAllRenames.size() > 1 ? new int[]{-1} : null;
-    String message = null;
-    try {
-      for (Iterator<Map.Entry<PsiElement, String>> iterator = myAllRenames.entrySet().iterator(); iterator.hasNext(); ) {
-        Map.Entry<PsiElement, String> entry = iterator.next();
-        if (entry.getKey() instanceof PsiFile) {
-          final PsiFile file = (PsiFile)entry.getKey();
-          final PsiDirectory containingDirectory = file.getContainingDirectory();
-          if (CopyFilesOrDirectoriesHandler.checkFileExist(containingDirectory, choice, file, entry.getValue(), "Rename")) {
-            iterator.remove();
-            continue;
-          }
-        }
-        RenameUtil.checkRename(entry.getKey(), entry.getValue());
-      }
-    }
-    catch (IncorrectOperationException e) {
-      message = e.getMessage();
-    }
-
-    if (message != null) {
-      CommonRefactoringUtil.showErrorMessage(RefactoringBundle.message("rename.title"), message, getHelpID(), myProject);
-      return;
-    }
-
     List<Runnable> postRenameCallbacks = new ArrayList<>();
 
     final MultiMap<PsiElement, UsageInfo> classified = classifyUsages(myAllRenames.keySet(), usages);