Merge remote-tracking branch 'origin/master' into amakeev/debugger clion/162.282
authorAnton Makeev <Anton.Makeev@jetbrains.com>
Wed, 18 May 2016 10:45:50 +0000 (12:45 +0200)
committerAnton Makeev <Anton.Makeev@jetbrains.com>
Wed, 18 May 2016 10:45:50 +0000 (12:45 +0200)
1  2 
platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestUtil.java

index c95b952fecb6a9a33e1754cce3f362f75fc44a44,00b8ba027381562fbe0e6a212166f91503f21425..286cdfe43606d21a64ce5a346f0a4ef04f6870bb
@@@ -28,7 -28,6 +28,7 @@@ import com.intellij.openapi.util.Ref
  import com.intellij.openapi.util.text.StringUtil;
  import com.intellij.openapi.vfs.VirtualFile;
  import com.intellij.testFramework.UsefulTestCase;
 +import com.intellij.util.concurrency.FutureResult;
  import com.intellij.util.ui.TextTransferable;
  import com.intellij.util.ui.UIUtil;
  import com.intellij.xdebugger.breakpoints.*;
@@@ -110,16 -109,6 +110,16 @@@ public class XDebuggerTestUtil 
      return session.getSuspendContext().getActiveExecutionStack();
    }
  
 +  public static List<XExecutionStack> collectThreads(@NotNull XDebugSession session) throws InterruptedException {
 +    return collectThreadsWithErrors(session).first;
 +  }
 +
 +  public static Pair<List<XExecutionStack>, String> collectThreadsWithErrors(@NotNull XDebugSession session) throws InterruptedException {
 +    XTestExecutionStackContainer container = new XTestExecutionStackContainer();
 +    session.getSuspendContext().computeExecutionStacks(container);
 +    return container.waitFor(TIMEOUT);
 +  }
 +
    public static List<XStackFrame> collectFrames(@NotNull XDebugSession session) throws InterruptedException {
      return collectFrames(null, session);
    }
    }
  
    public static List<XStackFrame> collectStacks(XExecutionStack thread, long timeout) throws InterruptedException {
 +    return collectStacksWithError(thread, timeout).first;
 +  }
 +
 +  public static Pair<List<XStackFrame>, String> collectStacksWithError(XExecutionStack thread, long timeout) throws InterruptedException {
      XTestStackFrameContainer container = new XTestStackFrameContainer();
      thread.computeStackFrames(0, container);
 -    return container.waitFor(timeout).first;
 +    return container.waitFor(timeout);
    }
  
    public static List<XValue> collectVariables(XStackFrame frame) throws InterruptedException {
    public static void waitForSwing() throws InterruptedException, InvocationTargetException {
      final com.intellij.util.concurrency.Semaphore s = new com.intellij.util.concurrency.Semaphore();
      s.down();
-     ApplicationManager.getApplication().invokeLater(new Runnable() {
-       public void run() {
-         s.up();
-       }
-     });
+     ApplicationManager.getApplication().invokeLater(() -> s.up());
      s.waitForUnsafe();
      UIUtil.invokeAndWaitIfNeeded(new Runnable() {
        public void run() {
      assertVariableValueMatches(findVar(vars, name), name, valuePattern);
    }
  
 +  public static void assertVariableValueMatches(@NotNull Collection<XValue> vars,
 +                                                @Nullable String name,
 +                                                @Nullable String type,
 +                                                @Nullable @Language("RegExp") String valuePattern) throws InterruptedException {
 +    assertVariableValueMatches(findVar(vars, name), name, type, valuePattern);
 +  }
 +
 +  public static void assertVariableValueMatches(@NotNull Collection<XValue> vars,
 +                                                @Nullable String name,
 +                                                @Nullable String type,
 +                                                @Nullable @Language("RegExp") String valuePattern,
 +                                                @Nullable Boolean hasChildren) throws InterruptedException {
 +    assertVariableValueMatches(findVar(vars, name), name, type, valuePattern, hasChildren);
 +  }
 +
    public static void assertVariableValueMatches(@NotNull XValue var,
                                                  @Nullable String name,
                                                  @Nullable @Language("RegExp") String valuePattern) throws InterruptedException {
                                                  @Nullable String name,
                                                  @Nullable String type,
                                                  @Nullable @Language("RegExp") String valuePattern) throws InterruptedException {
 +    assertVariableValueMatches(var, name, type, valuePattern, null);
 +  }
 +
 +  public static void assertVariableValueMatches(@NotNull XValue var,
 +                                                @Nullable String name,
 +                                                @Nullable String type,
 +                                                @Nullable @Language("RegExp") String valuePattern,
 +                                                @Nullable Boolean hasChildren) throws InterruptedException {
      XTestValueNode node = computePresentation(var);
      if (name != null) assertEquals(name, node.myName);
      if (type != null) assertEquals(type, node.myType);
      if (valuePattern != null) {
 -      assertTrue("Expected value" + valuePattern + " Actual value: " + node.myValue, node.myValue.matches(valuePattern));
 +      assertTrue("Expected value" + valuePattern + " Actual value: " + node.myValue, node.myValue.matches(valuePattern));
      }
 +    if (hasChildren != null) assertEquals(hasChildren, node.myHasChildren);
    }
  
    public static void assertVariableTypeMatches(@NotNull Collection<XValue> vars,
    }
  
    public static void assertVariableFullValue(@NotNull XValue var,
 -                                             @Nullable String value) throws InterruptedException {
 +                                             @Nullable String value) throws Exception {
      XTestValueNode node = computePresentation(var);
 -    final String[] result = new String[1];
  
 -    node.myFullValueEvaluator.startEvaluation(new XFullValueEvaluator.XFullValueEvaluationCallback() {
 -      @Override
 -      public void evaluated(@NotNull String fullValue) {
 -        result[0] = fullValue;
 -      }
 +    if (value == null) {
 +      assertNull("full value evaluator should be null", node.myFullValueEvaluator);
 +    }
 +    else {
 +      final FutureResult<String> result = new FutureResult<>();
 +      node.myFullValueEvaluator.startEvaluation(new XFullValueEvaluator.XFullValueEvaluationCallback() {
 +        @Override
 +        public void evaluated(@NotNull String fullValue) {
 +          result.set(fullValue);
 +        }
  
 -      @Override
 -      public void evaluated(@NotNull String fullValue, @Nullable Font font) {
 -        result[0] = fullValue;
 -      }
 +        @Override
 +        public void evaluated(@NotNull String fullValue, @Nullable Font font) {
 +          result.set(fullValue);
 +        }
  
 -      @Override
 -      public void errorOccurred(@NotNull String errorMessage) {
 -        result[0] = errorMessage;
 -      }
 +        @Override
 +        public void errorOccurred(@NotNull String errorMessage) {
 +          result.set(errorMessage);
 +        }
  
 -      @Override
 -      public boolean isObsolete() {
 -        return false;
 -      }
 -    });
 +        @Override
 +        public boolean isObsolete() {
 +          return false;
 +        }
 +      });
  
 -    assertEquals(value, result[0]);
 +      assertEquals(value, result.get(TIMEOUT, TimeUnit.MILLISECONDS));
 +    }
    }
  
    public static void assertVariableFullValue(Collection<XValue> vars, @Nullable String name, @Nullable String value)
 -    throws InterruptedException {
 +    throws Exception {
      assertVariableFullValue(findVar(vars, name), value);
    }
  
  
    public static void assertSourcePosition(final XValue value, VirtualFile file, int offset) {
      final XTestNavigatable n = new XTestNavigatable();
-     ApplicationManager.getApplication().runReadAction(new Runnable() {
-       @Override
-       public void run() {
-         value.computeSourcePosition(n);
-       }
+     ApplicationManager.getApplication().runReadAction(() -> {
+       value.computeSourcePosition(n);
      });
      assertNotNull(n.myPosition);
      assertEquals(file, n.myPosition.getFile());
      assertEquals(expectedExpression, expression);
      return expression;
    }
 +  
 +  public static class XTestExecutionStackContainer extends XTestContainer<XExecutionStack> implements XSuspendContext.XExecutionStackContainer {
 +    @Override
 +    public void errorOccurred(@NotNull String errorMessage) {
 +      setErrorMessage(errorMessage);
 +    }
 +
 +    @Override
 +    public void addExecutionStack(@NotNull List<? extends XExecutionStack> executionStacks, boolean last) {
 +      addChildren(executionStacks, last);
 +    }
 +  } 
  
    public static class XTestStackFrameContainer extends XTestContainer<XStackFrame> implements XExecutionStack.XStackFrameContainer {
      public void addStackFrames(@NotNull List<? extends XStackFrame> stackFrames, boolean last) {