@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));
  }
  @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));
                            }
                          });
                }
              }
            });
  }
  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));
  }
  @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;
  }
 @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);
      }
    }
  }
  @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());
  }
 private DebuggerContextImpl getDebuggerContext() {
   return myEvaluationContext.getDebugProcess().getDebuggerContext();
 }
 public Object evaluate(EvaluationContextImpl context) throws EvaluateException {
   return myCodeFragmentEvaluator.getValue(
       myLocalName, context.getDebugProcess().getVirtualMachineProxy());
 }