IDEA-130959 (indicator passing reverted - causes premature task end)
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>
Wed, 12 Nov 2014 17:42:35 +0000 (18:42 +0100)
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>
Wed, 12 Nov 2014 17:42:35 +0000 (18:42 +0100)
platform/core-impl/src/com/intellij/openapi/application/ex/ApplicationUtil.java
platform/core-impl/src/com/intellij/openapi/fileEditor/impl/LoadTextUtil.java
plugins/java-decompiler/plugin/test/org/jetbrains/java/decompiler/IdeaDecompilerTest.java

index a864652c503ba44d701b344b7030b90ba405b827..c7cf4a8da64cf276e19a90670c306982563f962a 100644 (file)
@@ -17,7 +17,6 @@ package com.intellij.openapi.application.ex;
 
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.progress.ProcessCanceledException;
-import com.intellij.openapi.progress.ProgressIndicator;
 import com.intellij.openapi.progress.ProgressManager;
 import com.intellij.openapi.util.Computable;
 import com.intellij.openapi.util.Ref;
@@ -54,30 +53,25 @@ public class ApplicationUtil {
    * Allows to interrupt a process which does not performs checkCancelled() calls by itself.
    * Note that the process may continue to run in background indefinitely - so <b>avoid using this method unless absolutely needed</b>.
    */
-  public static <T> T runWithCheckCanceled(@NotNull final Callable<T> callable, @NotNull final ProgressIndicator indicator) throws Exception {
+  public static <T> T runWithCheckCanceled(@NotNull final Callable<T> callable) throws Exception {
     final Ref<Throwable> error = Ref.create();
 
     Future<T> future = ApplicationManager.getApplication().executeOnPooledThread(new Callable<T>() {
       @Override
       public T call() throws Exception {
-        return ProgressManager.getInstance().runProcess(new Computable<T>() {
-          @Override
-          public T compute() {
-            try {
-              return callable.call();
-            }
-            catch (Throwable t) {
-              error.set(t);
-              return null;
-            }
-          }
-        }, indicator);
+        try {
+          return callable.call();
+        }
+        catch (Throwable t) {
+          error.set(t);
+          return null;
+        }
       }
     });
 
     while (true) {
       try {
-        indicator.checkCanceled();
+        ProgressManager.checkCanceled();
       }
       catch (ProcessCanceledException e) {
         future.cancel(true);
index 6f1d24e4a8c310c703c2fca490c53e8f60f77958..ca194dd5ce65dc981caf748a11936b341aa0416d 100644 (file)
@@ -390,7 +390,7 @@ public final class LoadTextUtil {
                   public CharSequence call() {
                     return decompiler.decompile(file);
                   }
-                }, indicator));
+                }));
               }
               catch (Throwable t) {
                 error.set(t);
index ac7d270573484abb06bf0565ac6e58cc378870b8..81df4dd8285910ba3f2b408b94de1f1f03946b82 100644 (file)
@@ -18,12 +18,8 @@ package org.jetbrains.java.decompiler;
 import com.intellij.codeInsight.daemon.impl.IdentifierHighlighterPassFactory;
 import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction;
 import com.intellij.debugger.PositionManager;
-import com.intellij.openapi.application.ModalityState;
 import com.intellij.openapi.application.PluginPathManager;
-import com.intellij.openapi.fileEditor.FileDocumentManager;
 import com.intellij.openapi.fileTypes.StdFileTypes;
-import com.intellij.openapi.progress.ProcessCanceledException;
-import com.intellij.openapi.progress.ProgressIndicator;
 import com.intellij.openapi.util.SystemInfo;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.util.registry.Registry;
@@ -32,11 +28,9 @@ import com.intellij.openapi.vfs.*;
 import com.intellij.pom.Navigatable;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiFile;
-import com.intellij.psi.compiled.ClassFileDecompilers;
 import com.intellij.psi.impl.compiled.ClsFileImpl;
 import com.intellij.testFramework.PlatformTestUtil;
 import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
-import com.intellij.util.Alarm;
 import com.intellij.util.ThrowableRunnable;
 import com.intellij.util.containers.ContainerUtil;
 import com.intellij.util.io.URLUtil;
@@ -175,31 +169,4 @@ public class IdeaDecompilerTest extends LightCodeInsightFixtureTestCase {
       }
     }).cpuBound().assertTiming();
   }
-
-  public void testCancellation() {
-    VirtualFile file = getTestFile(PlatformTestUtil.getRtJarPath() + "!/javax/swing/JTable.class");
-
-    final IdeaDecompiler decompiler = (IdeaDecompiler)ClassFileDecompilers.find(file);
-    assertNotNull(decompiler);
-
-    final Alarm alarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD, getProject());
-    alarm.addRequest(new Runnable() {
-      @Override
-      public void run() {
-        ProgressIndicator progress = decompiler.getProgress();
-        if (progress != null) {
-          progress.cancel();
-        }
-        else {
-          alarm.addRequest(this, 200, ModalityState.any());
-        }
-      }
-    }, 750, ModalityState.any());
-
-    try {
-      FileDocumentManager.getInstance().getDocument(file);
-      fail("should have been cancelled");
-    }
-    catch (ProcessCanceledException ignored) { }
-  }
 }