cleanup
authorVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Wed, 28 Jan 2015 16:49:05 +0000 (17:49 +0100)
committerVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Thu, 29 Jan 2015 07:21:26 +0000 (08:21 +0100)
platform/core-api/src/org/jetbrains/concurrency/Obsolescent.java
platform/script-debugger/backend/src/org/jetbrains/concurrency/AsyncPromise.java
platform/script-debugger/backend/src/org/jetbrains/concurrency/ObsolescentConsumer.java [deleted file]
platform/script-debugger/backend/src/org/jetbrains/concurrency/RejectedPromise.java
platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/FunctionScopesValueGroup.java
platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/ObsolescentConsumer.java [new file with mode: 0644]
platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/ScopeVariablesGroup.java
platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/ValueNodeConsumer.java [deleted file]
platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/VariableView.java

index 716a31efddde3e52e3341db84c8054aed4918f72..0cddccabd93879a1f936ecf632dffdaa35cb1961 100644 (file)
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2000-2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.jetbrains.concurrency;
 
 public interface Obsolescent {
@@ -5,4 +20,8 @@ public interface Obsolescent {
    * @return <code>true</code> if result of computation won't be used so computation may be interrupted
    */
   boolean isObsolete();
+
+  @SuppressWarnings("ClassNameSameAsAncestorName")
+  interface Consumer<T> extends com.intellij.util.Consumer<T>, Obsolescent {
+  }
 }
index 30e81a7bef212f84c663fa6627d508f330e18973..f8377a13c8e02a56094bc919818cf004f294ed68 100644 (file)
@@ -51,6 +51,10 @@ public class AsyncPromise<T> extends Promise<T> implements Getter<T> {
   @NotNull
   @Override
   public Promise<T> rejected(@NotNull Consumer<Throwable> rejected) {
+    if (isObsolete(rejected)) {
+      return this;
+    }
+
     switch (state) {
       case PENDING:
         break;
@@ -307,7 +311,9 @@ public class AsyncPromise<T> extends Promise<T> implements Getter<T> {
     Consumer<Throwable> rejected = this.rejected;
     clearHandlers();
     if (rejected != null) {
-      rejected.consume(error);
+      if (!isObsolete(rejected)) {
+        rejected.consume(error);
+      }
     }
     else if (!(error instanceof MessageError)) {
       LOG.error(error);
diff --git a/platform/script-debugger/backend/src/org/jetbrains/concurrency/ObsolescentConsumer.java b/platform/script-debugger/backend/src/org/jetbrains/concurrency/ObsolescentConsumer.java
deleted file mode 100644 (file)
index 18f7dd3..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-package org.jetbrains.concurrency;
-
-import com.intellij.util.Consumer;
-
-public interface ObsolescentConsumer<T> extends Consumer<T>, Obsolescent {
-}
index d08ae2025218168f0bd967ec5ef34a68870f04e8..3aa74089267c74091e36916857b603f17900944d 100644 (file)
@@ -27,7 +27,9 @@ class RejectedPromise<T> extends Promise<T> {
   @NotNull
   @Override
   public Promise<T> rejected(@NotNull Consumer<Throwable> rejected) {
-    rejected.consume(error);
+    if (!AsyncPromise.isObsolete(rejected)) {
+      rejected.consume(error);
+    }
     return this;
   }
 
index dc4d12b51705216b4a07f1e0121cb7a42fb3c9b8..240a600b90b7bac0482e376a4022c78871f32978 100644 (file)
@@ -27,7 +27,7 @@ class FunctionScopesValueGroup extends XValueGroup {
     node.setAlreadySorted(true);
 
     value.resolve()
-      .done(new ValueNodeConsumer<FunctionValue>(node) {
+      .done(new ObsolescentConsumer<FunctionValue>(node) {
       @Override
       public void consume(FunctionValue value) {
         Scope[] scopes = value.getScopes();
diff --git a/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/ObsolescentConsumer.java b/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/ObsolescentConsumer.java
new file mode 100644 (file)
index 0000000..4e06d29
--- /dev/null
@@ -0,0 +1,17 @@
+package org.jetbrains.debugger;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.concurrency.Obsolescent;
+
+public abstract class ObsolescentConsumer<T> implements Obsolescent.Consumer<T> {
+  private final Obsolescent obsolescent;
+
+  protected ObsolescentConsumer(@NotNull Obsolescent obsolescent) {
+    this.obsolescent = obsolescent;
+  }
+
+  @Override
+  public final boolean isObsolete() {
+    return obsolescent.isObsolete();
+  }
+}
\ No newline at end of file
index 5753cf1e6090c47cc9f791957dde1b53407d4eb2..617972888bb947afea5648d78f687c3162ef65cc 100644 (file)
@@ -1,6 +1,5 @@
 package org.jetbrains.debugger;
 
-import com.intellij.util.Consumer;
 import com.intellij.xdebugger.XDebuggerBundle;
 import com.intellij.xdebugger.frame.XCompositeNode;
 import com.intellij.xdebugger.frame.XValueChildrenList;
@@ -93,22 +92,20 @@ public class ScopeVariablesGroup extends XValueGroup {
   public void computeChildren(final @NotNull XCompositeNode node) {
     Promise<Void> promise = Variables.processScopeVariables(scope, node, context, callFrame == null);
     if (callFrame != null) {
-      promise.done(new ValueNodeConsumer<Void>(node) {
+      promise.done(new ObsolescentConsumer<Void>(node) {
         @Override
         public void consume(Void ignored) {
           callFrame.getReceiverVariable()
-            .done(new Consumer<Variable>() {
+            .done(new ObsolescentConsumer<Variable>(node) {
               @Override
               public void consume(Variable variable) {
                 node.addChildren(variable == null ? XValueChildrenList.EMPTY : XValueChildrenList.singleton(new VariableView(variable, context)), true);
               }
             })
-            .rejected(new Consumer<Throwable>() {
+            .rejected(new ObsolescentConsumer<Throwable>(node) {
               @Override
               public void consume(@Nullable Throwable error) {
-                if (!node.isObsolete()) {
-                  node.addChildren(XValueChildrenList.EMPTY, true);
-                }
+                node.addChildren(XValueChildrenList.EMPTY, true);
               }
             });
         }
diff --git a/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/ValueNodeConsumer.java b/platform/script-debugger/debugger-ui/src/org/jetbrains/debugger/ValueNodeConsumer.java
deleted file mode 100644 (file)
index 481ed13..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-package org.jetbrains.debugger;
-
-import com.intellij.xdebugger.Obsolescent;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.concurrency.ObsolescentConsumer;
-
-public abstract class ValueNodeConsumer<T> implements ObsolescentConsumer<T> {
-  private final Obsolescent node;
-
-  protected ValueNodeConsumer(@NotNull Obsolescent node) {
-    this.node = node;
-  }
-
-  @Override
-  public final boolean isObsolete() {
-    return node.isObsolete();
-  }
-}
index e8a5f0ecba73cb3d198522ff748a5111e0cf5a0c..2ffbcb15da129376e25b0816c478f55b57812f19 100644 (file)
@@ -165,7 +165,7 @@ public final class VariableView extends XNamedValue implements VariableContext {
     if (!(variable instanceof ObjectProperty) || ((ObjectProperty)variable).getGetter() == null) {
       // it is "used" expression (WEB-6779 Debugger/Variables: Automatically show used variables)
       getEvaluateContext().evaluate(variable.getName())
-        .done(new ValueNodeConsumer<EvaluateResult>(node) {
+        .done(new ObsolescentConsumer<EvaluateResult>(node) {
           @Override
           public void consume(EvaluateResult result) {
             if (result.wasThrown) {
@@ -199,15 +199,14 @@ public final class VariableView extends XNamedValue implements VariableContext {
       public void startEvaluation(@NotNull final XFullValueEvaluationCallback callback) {
         ValueModifier valueModifier = variable.getValueModifier();
         assert valueModifier != null;
-        valueModifier.evaluateGet(variable, getEvaluateContext()).done(new Consumer<Value>() {
-          @Override
-          public void consume(Value value) {
-            if (!node.isObsolete()) {
+        valueModifier.evaluateGet(variable, getEvaluateContext())
+          .done(new ObsolescentConsumer<Value>(node) {
+            @Override
+            public void consume(Value value) {
               callback.evaluated("");
               setEvaluatedValue(value, null, node);
             }
-          }
-        });
+          });
       }
     }.setShowValuePopup(false));
   }