@Override
 public Object evaluate(EvaluationContextImpl context) throws EvaluateException {
   Object result =
       context.getSuspendContext().getDebugProcess().getVirtualMachineProxy().mirrorOfVoid();
   try {
     result = myBodyEvaluator.evaluate(context);
   } catch (EvaluateException e) {
     boolean catched = false;
     ObjectReference vmException = e.getExceptionFromTargetVM();
     if (vmException != null) {
       for (CatchEvaluator evaluator : myCatchBlockEvaluators) {
         if (evaluator != null
             && DebuggerUtils.instanceOf(vmException.type(), evaluator.getExceptionType())) {
           result = evaluator.evaluate(vmException, context);
           catched = true;
           break;
         }
       }
     }
     if (!catched) {
       throw e;
     }
   } finally {
     if (myFinallyEvaluator != null) {
       result = myFinallyEvaluator.evaluate(context);
     }
   }
   return result;
 }
示例#2
0
  @Override
  public void computeTypeSourcePosition(@NotNull final XNavigatable navigatable) {
    if (myEvaluationContext.getSuspendContext().isResumed()) return;
    DebugProcessImpl debugProcess = myEvaluationContext.getDebugProcess();
    debugProcess
        .getManagerThread()
        .schedule(
            new JumpToObjectAction.NavigateCommand(
                getDebuggerContext(), myValueDescriptor, debugProcess, null) {
              @Override
              public Priority getPriority() {
                return Priority.HIGH;
              }

              @Override
              protected void doAction(@Nullable final SourcePosition sourcePosition) {
                if (sourcePosition != null) {
                  ApplicationManager.getApplication()
                      .runReadAction(
                          new Runnable() {
                            @Override
                            public void run() {
                              navigatable.setSourcePosition(
                                  DebuggerUtilsEx.toXSourcePosition(sourcePosition));
                            }
                          });
                }
              }
            });
  }
示例#3
0
 public Object evaluate(EvaluationContextImpl context) throws EvaluateException {
   final Object result = myDelegate.evaluate(context);
   if (result instanceof ObjectReference) {
     context.getSuspendContext().keep((ObjectReference) result);
   }
   return result;
 }
示例#4
0
  @Override
  public void computeSourcePosition(@NotNull final XNavigatable navigatable) {
    if (navigatable instanceof XInlineSourcePosition
        && !(navigatable instanceof XNearestSourcePosition)
        && !(myValueDescriptor instanceof ThisDescriptorImpl
            || myValueDescriptor instanceof LocalVariableDescriptor)) {
      return;
    }
    myEvaluationContext
        .getManagerThread()
        .schedule(
            new SuspendContextCommandImpl(myEvaluationContext.getSuspendContext()) {
              @Override
              public Priority getPriority() {
                if (navigatable instanceof XInlineSourcePosition) {
                  return Priority.LOW;
                }
                return Priority.NORMAL;
              }

              @Override
              protected void commandCancelled() {
                navigatable.setSourcePosition(null);
              }

              @Override
              public void contextAction() throws Exception {
                ApplicationManager.getApplication()
                    .runReadAction(
                        new Runnable() {
                          @Override
                          public void run() {
                            final boolean nearest = navigatable instanceof XNearestSourcePosition;
                            SourcePosition position =
                                SourcePositionProvider.getSourcePosition(
                                    myValueDescriptor, getProject(), getDebuggerContext(), nearest);
                            if (position != null) {
                              navigatable.setSourcePosition(
                                  DebuggerUtilsEx.toXSourcePosition(position));
                            }
                          }
                        });
              }
            });
  }
示例#5
0
  private void computeSourcePosition(
      @NotNull final XNavigatable navigatable, final boolean inline) {
    myEvaluationContext
        .getManagerThread()
        .schedule(
            new SuspendContextCommandImpl(myEvaluationContext.getSuspendContext()) {
              @Override
              public Priority getPriority() {
                return inline ? Priority.LOWEST : Priority.NORMAL;
              }

              @Override
              protected void commandCancelled() {
                navigatable.setSourcePosition(null);
              }

              @Override
              public void contextAction() throws Exception {
                ApplicationManager.getApplication()
                    .runReadAction(
                        new Runnable() {
                          @Override
                          public void run() {
                            SourcePosition position =
                                SourcePositionProvider.getSourcePosition(
                                    myValueDescriptor, getProject(), getDebuggerContext(), false);
                            if (position != null) {
                              navigatable.setSourcePosition(
                                  DebuggerUtilsEx.toXSourcePosition(position));
                            }
                            if (inline) {
                              position =
                                  SourcePositionProvider.getSourcePosition(
                                      myValueDescriptor, getProject(), getDebuggerContext(), true);
                              if (position != null) {
                                navigatable.setSourcePosition(
                                    DebuggerUtilsEx.toXSourcePosition(position));
                              }
                            }
                          }
                        });
              }
            });
  }
示例#6
0
  @Nullable
  @Override
  public String getEvaluationExpression() {
    if (evaluationExpression == null) {
      // TODO: change API to allow to calculate it asynchronously
      myEvaluationContext
          .getManagerThread()
          .invokeAndWait(
              new SuspendContextCommandImpl(myEvaluationContext.getSuspendContext()) {
                @Override
                public Priority getPriority() {
                  return Priority.HIGH;
                }

                @Override
                public void contextAction() throws Exception {
                  evaluationExpression =
                      ApplicationManager.getApplication()
                          .runReadAction(
                              new Computable<String>() {
                                @Override
                                public String compute() {
                                  try {
                                    PsiExpression psiExpression =
                                        getDescriptor()
                                            .getTreeEvaluation(
                                                JavaValue.this, getDebuggerContext());
                                    if (psiExpression != null) {
                                      return new TextWithImportsImpl(psiExpression).getText();
                                    }
                                  } catch (EvaluateException e) {
                                    LOG.info(e);
                                  }
                                  return null;
                                }
                              });
                }
              });
    }
    return evaluationExpression;
  }
示例#7
0
    @Override
    public void startEvaluation(@NotNull final XFullValueEvaluationCallback callback) {
      if (callback.isObsolete()) return;
      myEvaluationContext
          .getManagerThread()
          .schedule(
              new SuspendContextCommandImpl(myEvaluationContext.getSuspendContext()) {
                @Override
                public Priority getPriority() {
                  return Priority.NORMAL;
                }

                @Override
                protected void commandCancelled() {
                  callback.errorOccurred(DebuggerBundle.message("error.context.has.changed"));
                }

                @Override
                public void contextAction() throws Exception {
                  if (callback.isObsolete()) return;
                  evaluate(callback);
                }
              });
    }
示例#8
0
  @NotNull
  @Override
  public Promise<XExpression> calculateEvaluationExpression() {
    if (evaluationExpression != null) {
      return Promise.resolve(evaluationExpression);
    } else {
      final AsyncPromise<XExpression> res = new AsyncPromise<XExpression>();
      myEvaluationContext
          .getManagerThread()
          .schedule(
              new SuspendContextCommandImpl(myEvaluationContext.getSuspendContext()) {
                @Override
                public Priority getPriority() {
                  return Priority.HIGH;
                }

                @Override
                public void contextAction() throws Exception {
                  evaluationExpression =
                      ApplicationManager.getApplication()
                          .runReadAction(
                              new Computable<XExpression>() {
                                @Override
                                public XExpression compute() {
                                  try {
                                    PsiElement psiExpression =
                                        getDescriptor()
                                            .getTreeEvaluation(
                                                JavaValue.this, getDebuggerContext());
                                    if (psiExpression != null) {
                                      XExpression res =
                                          TextWithImportsImpl.toXExpression(
                                              new TextWithImportsImpl(psiExpression));
                                      // add runtime imports if any
                                      Set<String> imports =
                                          psiExpression.getUserData(
                                              DebuggerTreeNodeExpression.ADDITIONAL_IMPORTS_KEY);
                                      if (imports != null && res != null) {
                                        if (res.getCustomInfo() != null) {
                                          imports.add(res.getCustomInfo());
                                        }
                                        res =
                                            new XExpressionImpl(
                                                res.getExpression(),
                                                res.getLanguage(),
                                                StringUtil.join(imports, ","),
                                                res.getMode());
                                      }
                                      return res;
                                    }
                                  } catch (EvaluateException e) {
                                    LOG.info(e);
                                  }
                                  return null;
                                }
                              });
                  res.setResult(evaluationExpression);
                }
              });
      return res;
    }
  }
示例#9
0
  @Override
  public void computeChildren(@NotNull final XCompositeNode node) {
    scheduleCommand(
        myEvaluationContext,
        node,
        new SuspendContextCommandImpl(myEvaluationContext.getSuspendContext()) {
          @Override
          public Priority getPriority() {
            return Priority.NORMAL;
          }

          @Override
          public void contextAction() throws Exception {
            final XValueChildrenList children = new XValueChildrenList();
            final NodeRenderer renderer =
                myValueDescriptor.getRenderer(myEvaluationContext.getDebugProcess());
            final Ref<Integer> remainingNum = new Ref<Integer>(0);
            renderer.buildChildren(
                myValueDescriptor.getValue(),
                new ChildrenBuilder() {
                  @Override
                  public NodeDescriptorFactory getDescriptorManager() {
                    return myNodeManager;
                  }

                  @Override
                  public NodeManager getNodeManager() {
                    return myNodeManager;
                  }

                  @Override
                  public ValueDescriptor getParentDescriptor() {
                    return myValueDescriptor;
                  }

                  @Override
                  public void setRemaining(int remaining) {
                    remainingNum.set(remaining);
                  }

                  @Override
                  public void initChildrenArrayRenderer(ArrayRenderer renderer) {
                    renderer.START_INDEX = myCurrentChildrenStart;
                    renderer.END_INDEX =
                        myCurrentChildrenStart + XCompositeNode.MAX_CHILDREN_TO_SHOW - 1;
                    myCurrentChildrenStart += XCompositeNode.MAX_CHILDREN_TO_SHOW;
                  }

                  @Override
                  public void setChildren(List<DebuggerTreeNode> nodes) {
                    for (DebuggerTreeNode node : nodes) {
                      final NodeDescriptor descriptor = node.getDescriptor();
                      if (descriptor instanceof ValueDescriptorImpl) {
                        // Value is calculated already in NodeManagerImpl
                        children.add(
                            create(
                                JavaValue.this,
                                (ValueDescriptorImpl) descriptor,
                                myEvaluationContext,
                                myNodeManager,
                                false));
                      } else if (descriptor instanceof MessageDescriptor) {
                        children.add(
                            new JavaStackFrame.DummyMessageValueNode(descriptor.getLabel(), null));
                      }
                    }
                  }
                },
                myEvaluationContext);
            node.addChildren(children, true);
            if (remainingNum.get() > 0) {
              node.tooManyChildren(remainingNum.get());
            }
          }
        });
  }
示例#10
0
  @Override
  public void computePresentation(@NotNull final XValueNode node, @NotNull XValuePlace place) {
    final SuspendContextImpl suspendContext = myEvaluationContext.getSuspendContext();
    myEvaluationContext
        .getManagerThread()
        .schedule(
            new SuspendContextCommandImpl(suspendContext) {
              @Override
              public Priority getPriority() {
                return Priority.NORMAL;
              }

              @Override
              protected void commandCancelled() {
                node.setPresentation(
                    null,
                    new XErrorValuePresentation(
                        DebuggerBundle.message("error.context.has.changed")),
                    false);
              }

              @Override
              public void contextAction() throws Exception {
                if (!myContextSet) {
                  myValueDescriptor.setContext(myEvaluationContext);
                }
                myValueDescriptor.updateRepresentation(
                    myEvaluationContext,
                    new DescriptorLabelListener() {
                      @Override
                      public void labelChanged() {
                        Icon nodeIcon = DebuggerTreeRenderer.getValueIcon(myValueDescriptor);
                        final String value = getValueString();
                        XValuePresentation presentation;
                        @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
                        EvaluateException exception = myValueDescriptor.getEvaluateException();
                        presentation =
                            new JavaValuePresentation(
                                value,
                                myValueDescriptor.getIdLabel(),
                                exception != null ? exception.getMessage() : null,
                                myValueDescriptor);

                        if (myValueDescriptor.getLastRenderer()
                            instanceof FullValueEvaluatorProvider) {
                          XFullValueEvaluator evaluator =
                              ((FullValueEvaluatorProvider) myValueDescriptor.getLastRenderer())
                                  .getFullValueEvaluator(myEvaluationContext, myValueDescriptor);
                          if (evaluator != null) {
                            node.setFullValueEvaluator(evaluator);
                          }
                        } else if (value.length() > XValueNode.MAX_VALUE_LENGTH) {
                          node.setFullValueEvaluator(
                              new JavaFullValueEvaluator(myEvaluationContext) {
                                @Override
                                public void evaluate(
                                    @NotNull final XFullValueEvaluationCallback callback) {
                                  final ValueDescriptorImpl fullValueDescriptor =
                                      myValueDescriptor.getFullValueDescriptor();
                                  fullValueDescriptor.updateRepresentation(
                                      myEvaluationContext,
                                      new DescriptorLabelListener() {
                                        @Override
                                        public void labelChanged() {
                                          callback.evaluated(fullValueDescriptor.getValueText());
                                        }
                                      });
                                }
                              });
                        }
                        node.setPresentation(
                            nodeIcon, presentation, myValueDescriptor.isExpandable());
                      }
                    });
              }
            });
  }