public boolean evaluateCondition(EvaluationContextImpl context, LocatableEvent event)
     throws EvaluateException {
   if (CLASS_FILTERS_ENABLED) {
     String className = null;
     final ObjectReference thisObject = (ObjectReference) context.getThisObject();
     if (thisObject != null) {
       className = thisObject.referenceType().name();
     } else {
       final StackFrameProxyImpl frame = context.getFrameProxy();
       if (frame != null) {
         className = frame.location().declaringType().name();
       }
     }
     if (className != null) {
       boolean matches = false;
       for (ClassFilter classFilter : getClassFilters()) {
         if (classFilter.isEnabled() && classFilter.matches(className)) {
           matches = true;
           break;
         }
       }
       if (!matches) {
         return false;
       }
       for (ClassFilter classFilter : getClassExclusionFilters()) {
         if (classFilter.isEnabled() && classFilter.matches(className)) {
           return false;
         }
       }
     }
   }
   return super.evaluateCondition(context, event);
 }
Example #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));
                            }
                          });
                }
              }
            });
  }
  @Nullable
  private static Value createScaledBitmap(
      @NotNull EvaluationContextImpl context,
      @NotNull ObjectReference bitmap,
      @NotNull Dimension currentDimensions)
      throws EvaluateException {
    DebugProcessImpl debugProcess = context.getDebugProcess();
    Method createScaledBitmapMethod =
        DebuggerUtils.findMethod(
            bitmap.referenceType(),
            "createScaledBitmap",
            "(Landroid/graphics/Bitmap;IIZ)Landroid/graphics/Bitmap;");
    if (createScaledBitmapMethod == null) {
      return null;
    }

    double s =
        Math.max(currentDimensions.getHeight(), currentDimensions.getWidth()) / MAX_DIMENSION;

    VirtualMachineProxyImpl vm = context.getDebugProcess().getVirtualMachineProxy();
    Value dstWidth =
        DebuggerUtilsEx.createValue(vm, "int", (int) (currentDimensions.getWidth() / s));
    Value dstHeight =
        DebuggerUtilsEx.createValue(vm, "int", (int) (currentDimensions.getHeight() / s));
    Value filter = DebuggerUtilsEx.createValue(vm, "boolean", Boolean.FALSE);
    return debugProcess.invokeMethod(
        context,
        bitmap,
        createScaledBitmapMethod,
        Arrays.asList(bitmap, dstWidth, dstHeight, filter));
  }
 private ReferenceType loadClass(final String className) {
   final EvaluationContextImpl eContext = myDebuggerContext.createEvaluationContext();
   try {
     return myDebugProcess.loadClass(eContext, className, eContext.getClassLoader());
   } catch (Throwable ignored) {
   }
   return null;
 }
 @Override
 protected String calculateEventClass(EvaluationContextImpl context, LocatableEvent event)
     throws EvaluateException {
   String className = null;
   final ObjectReference thisObject = (ObjectReference) context.getThisObject();
   if (thisObject != null) {
     className = thisObject.referenceType().name();
   } else {
     final StackFrameProxyImpl frame = context.getFrameProxy();
     if (frame != null) {
       className = frame.location().declaringType().name();
     }
   }
   return className;
 }
 @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;
 }
  private static Value convertToWrapper(
      EvaluationContextImpl context, PrimitiveValue value, String wrapperTypeName)
      throws EvaluateException {
    final DebugProcessImpl process = context.getDebugProcess();
    final ClassType wrapperClass = (ClassType) process.findClass(context, wrapperTypeName, null);
    final String methodSignature =
        "("
            + JVMNameUtil.getPrimitiveSignature(value.type().name())
            + ")L"
            + wrapperTypeName.replace('.', '/')
            + ";";

    List<Method> methods = wrapperClass.methodsByName("valueOf", methodSignature);
    if (methods.size() == 0) { // older JDK version
      methods = wrapperClass.methodsByName(JVMNameUtil.CONSTRUCTOR_NAME, methodSignature);
    }
    if (methods.size() == 0) {
      throw new EvaluateException(
          "Cannot construct wrapper object for value of type "
              + value.type()
              + ": Unable to find either valueOf() or constructor method");
    }

    return process.invokeMethod(
        context, wrapperClass, methods.get(0), Collections.singletonList(value));
  }
Example #8
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;
 }
  @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));
                            }
                          }
                        });
              }
            });
  }
Example #10
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));
                              }
                            }
                          }
                        });
              }
            });
  }
Example #11
0
  @Override
  public Value evaluate(final EvaluationContext evaluationContext) throws EvaluateException {
    DebugProcess process = evaluationContext.getDebugProcess();

    ClassLoaderReference classLoader;
    try {
      classLoader = getClassLoader(evaluationContext, process);
    } catch (Exception e) {
      throw new EvaluateException("Error creating evaluation class loader: " + e, e);
    }

    String version = ((VirtualMachineProxyImpl) process.getVirtualMachineProxy()).version();
    JavaSdkVersion sdkVersion = JdkVersionUtil.getVersion(version);
    Collection<OutputFileObject> classes =
        compile(sdkVersion != null ? sdkVersion.getDescription() : null);

    try {
      defineClasses(classes, evaluationContext, process, classLoader);
    } catch (Exception e) {
      throw new EvaluateException("Error during classes definition " + e, e);
    }

    try {
      // invoke base evaluator on call code
      final Project project =
          ApplicationManager.getApplication()
              .runReadAction(
                  new Computable<Project>() {
                    @Override
                    public Project compute() {
                      return myPsiContext.getProject();
                    }
                  });
      ExpressionEvaluator evaluator =
          DebuggerInvocationUtil.commitAndRunReadAction(
              project,
              new EvaluatingComputable<ExpressionEvaluator>() {
                @Override
                public ExpressionEvaluator compute() throws EvaluateException {
                  final TextWithImports callCode = getCallCode();
                  PsiElement copyContext = myData.getAnchor();
                  final CodeFragmentFactory factory =
                      DebuggerUtilsEx.findAppropriateCodeFragmentFactory(callCode, copyContext);
                  return factory
                      .getEvaluatorBuilder()
                      .build(
                          factory.createCodeFragment(callCode, copyContext, project),
                          ContextUtil.getSourcePosition(evaluationContext));
                }
              });
      ((EvaluationContextImpl) evaluationContext).setClassLoader(classLoader);
      return evaluator.evaluate(evaluationContext);
    } catch (Exception e) {
      throw new EvaluateException("Error during generated code invocation " + e, e);
    }
  }
  @Nullable
  private static Dimension getDimension(
      @NotNull EvaluationContextImpl context, @NotNull Value bitmap) throws EvaluateException {
    DebugProcessImpl debugProcess = context.getDebugProcess();

    Integer w = getImageDimension(context, (ObjectReference) bitmap, debugProcess, "getWidth");
    Integer h = getImageDimension(context, (ObjectReference) bitmap, debugProcess, "getHeight");

    return (w != null & h != null) ? new Dimension(w, h) : null;
  }
Example #13
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;
  }
 @Nullable
 private static Value getBitmapConfig(EvaluationContextImpl context, ObjectReference bitmap)
     throws EvaluateException {
   DebugProcessImpl debugProcess = context.getDebugProcess();
   Method getConfig =
       DebuggerUtils.findMethod(
           bitmap.referenceType(), "getConfig", "()Landroid/graphics/Bitmap$Config;");
   if (getConfig == null) {
     return null;
   }
   return debugProcess.invokeMethod(context, bitmap, getConfig, Collections.emptyList());
 }
  private void runAction(final EvaluationContextImpl context, LocatableEvent event) {
    if (LOG_ENABLED || LOG_EXPRESSION_ENABLED) {
      final StringBuilder buf = StringBuilderSpinAllocator.alloc();
      try {
        if (LOG_ENABLED) {
          buf.append(getEventMessage(event));
          buf.append("\n");
        }
        final DebugProcessImpl debugProcess = context.getDebugProcess();
        final TextWithImports expressionToEvaluate = getLogMessage();
        if (LOG_EXPRESSION_ENABLED
            && expressionToEvaluate != null
            && !"".equals(expressionToEvaluate.getText())) {
          if (!debugProcess.isAttached()) {
            return;
          }

          try {
            ExpressionEvaluator evaluator =
                DebuggerInvocationUtil.commitAndRunReadAction(
                    getProject(),
                    new EvaluatingComputable<ExpressionEvaluator>() {
                      public ExpressionEvaluator compute() throws EvaluateException {
                        return EvaluatorBuilderImpl.build(
                            expressionToEvaluate,
                            ContextUtil.getContextElement(context),
                            ContextUtil.getSourcePosition(context));
                      }
                    });
            final Value eval = evaluator.evaluate(context);
            final String result =
                eval instanceof VoidValue ? "void" : DebuggerUtils.getValueAsString(context, eval);
            buf.append(result);
          } catch (EvaluateException e) {
            buf.append(DebuggerBundle.message("error.unable.to.evaluate.expression"));
            buf.append(" \"");
            buf.append(expressionToEvaluate);
            buf.append("\"");
            buf.append(" : ");
            buf.append(e.getMessage());
          }
          buf.append("\n");
        }
        if (buf.length() > 0) {
          debugProcess.printToConsole(buf.toString());
        }
      } finally {
        StringBuilderSpinAllocator.dispose(buf);
      }
    }
  }
Example #16
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);
                }
              });
    }
Example #17
0
  protected static boolean scheduleCommand(
      EvaluationContextImpl evaluationContext,
      @NotNull final XCompositeNode node,
      final SuspendContextCommandImpl command) {
    evaluationContext
        .getManagerThread()
        .schedule(
            new SuspendContextCommandImpl(command.getSuspendContext()) {
              @Override
              public void contextAction() throws Exception {
                command.contextAction();
              }

              @Override
              protected void commandCancelled() {
                node.setErrorMessage(DebuggerBundle.message("error.context.has.changed"));
              }
            });
    return true;
  }
  @Nullable
  private static List<Value> copyToBuffer(
      EvaluationContextImpl evaluationContext, ObjectReference bitmap, Dimension size)
      throws EvaluateException {
    DebugProcessImpl debugProcess = evaluationContext.getDebugProcess();
    VirtualMachineProxyImpl virtualMachineProxy = debugProcess.getVirtualMachineProxy();

    List<ReferenceType> classes = virtualMachineProxy.classesByName("byte[]");
    if (classes.size() != 1 || !(classes.get(0) instanceof ArrayType)) {
      return null;
    }
    ArrayType byteArrayType = (ArrayType) classes.get(0);

    classes = virtualMachineProxy.classesByName("java.nio.ByteBuffer");
    if (classes.size() != 1 || !(classes.get(0) instanceof ClassType)) {
      return null;
    }
    ClassType byteBufferType = (ClassType) classes.get(0);
    Method wrapMethod =
        DebuggerUtils.findMethod(byteBufferType, "wrap", "([B)Ljava/nio/ByteBuffer;");
    if (wrapMethod == null) {
      return null;
    }

    ArrayReference byteArray = byteArrayType.newInstance(size.width * size.height * 4);
    Value byteBufferRef =
        debugProcess.invokeMethod(
            evaluationContext, byteBufferType, wrapMethod, ImmutableList.of(byteArray));

    Method copyToBufferMethod =
        DebuggerUtils.findMethod(
            bitmap.referenceType(), "copyPixelsToBuffer", "(Ljava/nio/Buffer;)V");
    if (copyToBufferMethod == null) {
      return null;
    }

    debugProcess.invokeMethod(
        evaluationContext, bitmap, copyToBufferMethod, ImmutableList.of(byteBufferRef));
    return byteArray.getValues();
  }
  private static Value convertToPrimitive(
      EvaluationContextImpl context,
      ObjectReference value,
      final String conversionMethodName,
      String conversionMethodSignature)
      throws EvaluateException {
    final DebugProcessImpl process = context.getDebugProcess();
    final ClassType wrapperClass = (ClassType) value.referenceType();
    final List<Method> methods =
        wrapperClass.methodsByName(conversionMethodName, conversionMethodSignature);
    if (methods.size() == 0) {
      throw new EvaluateException(
          "Cannot convert to primitive value of type "
              + value.type()
              + ": Unable to find method "
              + conversionMethodName
              + conversionMethodSignature);
    }

    final Method method = methods.get(0);

    return process.invokeMethod(context, value, method, new ArrayList());
  }
Example #20
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;
    }
  }
  // copied from FrameVariablesTree
  private void buildVariables(
      DebuggerContextImpl debuggerContext,
      final EvaluationContextImpl evaluationContext,
      @NotNull DebugProcessImpl debugProcess,
      XValueChildrenList children,
      ObjectReference thisObjectReference,
      Location location)
      throws EvaluateException {
    final Set<String> visibleLocals = new HashSet<String>();
    if (NodeRendererSettings.getInstance().getClassRenderer().SHOW_VAL_FIELDS_AS_LOCAL_VARIABLES) {
      if (thisObjectReference != null
          && debugProcess.getVirtualMachineProxy().canGetSyntheticAttribute()) {
        final ReferenceType thisRefType = thisObjectReference.referenceType();
        if (thisRefType instanceof ClassType
            && location != null
            && thisRefType.equals(location.declaringType())
            && thisRefType.name().contains("$")) { // makes sense for nested classes only
          for (Field field : thisRefType.fields()) {
            if (DebuggerUtils.isSynthetic(field)
                && StringUtil.startsWith(
                    field.name(), FieldDescriptorImpl.OUTER_LOCAL_VAR_FIELD_PREFIX)) {
              final FieldDescriptorImpl fieldDescriptor =
                  myNodeManager.getFieldDescriptor(myDescriptor, thisObjectReference, field);
              children.add(JavaValue.create(fieldDescriptor, evaluationContext, myNodeManager));
              visibleLocals.add(fieldDescriptor.calcValueName());
            }
          }
        }
      }
    }

    boolean myAutoWatchMode = DebuggerSettings.getInstance().AUTO_VARIABLES_MODE;
    if (evaluationContext == null) {
      return;
    }
    final SourcePosition sourcePosition = debuggerContext.getSourcePosition();
    if (sourcePosition == null) {
      return;
    }

    try {
      if (!XDebuggerSettingsManager.getInstance().getDataViewSettings().isAutoExpressions()
          && !myAutoWatchMode) {
        // optimization
        superBuildVariables(evaluationContext, children);
      } else {
        final Map<String, LocalVariableProxyImpl> visibleVariables =
            getVisibleVariables(getStackFrameProxy());
        final Pair<Set<String>, Set<TextWithImports>> usedVars =
            ApplicationManager.getApplication()
                .runReadAction(
                    new Computable<Pair<Set<String>, Set<TextWithImports>>>() {
                      @Override
                      public Pair<Set<String>, Set<TextWithImports>> compute() {
                        return findReferencedVars(
                            ContainerUtil.union(visibleVariables.keySet(), visibleLocals),
                            sourcePosition);
                      }
                    });
        // add locals
        if (myAutoWatchMode) {
          for (String var : usedVars.first) {
            LocalVariableProxyImpl local = visibleVariables.get(var);
            if (local != null) {
              children.add(
                  JavaValue.create(
                      myNodeManager.getLocalVariableDescriptor(null, local),
                      evaluationContext,
                      myNodeManager));
            }
          }
        } else {
          superBuildVariables(evaluationContext, children);
        }
        final EvaluationContextImpl evalContextCopy =
            evaluationContext.createEvaluationContext(evaluationContext.getThisObject());
        evalContextCopy.setAutoLoadClasses(false);

        final Set<TextWithImports> extraVars =
            computeExtraVars(usedVars, sourcePosition, evaluationContext);

        // add extra vars
        addToChildrenFrom(extraVars, children, evaluationContext);

        // add expressions
        addToChildrenFrom(usedVars.second, children, evalContextCopy);
      }
    } catch (EvaluateException e) {
      if (e.getCause() instanceof AbsentInformationException) {
        children.add(
            new DummyMessageValueNode(
                MessageDescriptor.LOCAL_VARIABLES_INFO_UNAVAILABLE.getLabel(),
                XDebuggerUIConstants.INFORMATION_MESSAGE_ICON));
        // trying to collect values from variable slots
        try {
          for (Map.Entry<DecompiledLocalVariable, Value> entry :
              LocalVariablesUtil.fetchValues(getStackFrameProxy(), debugProcess).entrySet()) {
            children.add(
                JavaValue.create(
                    myNodeManager.getArgumentValueDescriptor(
                        null, entry.getKey(), entry.getValue()),
                    evaluationContext,
                    myNodeManager));
          }
        } catch (Exception ex) {
          LOG.info(ex);
        }
      } else {
        throw e;
      }
    }
  }
Example #22
0
 private DebuggerContextImpl getDebuggerContext() {
   return myEvaluationContext.getDebugProcess().getDebuggerContext();
 }
Example #23
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());
            }
          }
        });
  }
Example #24
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());
                      }
                    });
              }
            });
  }
 public Object evaluate(EvaluationContextImpl context) throws EvaluateException {
   return myCodeFragmentEvaluator.getValue(
       myLocalName, context.getDebugProcess().getVirtualMachineProxy());
 }