コード例 #1
0
    @Override
    public void renderValue(@NotNull XValueTextRenderer renderer, @Nullable XValueNodeImpl node) {
      boolean compact = node != null;
      if (myError != null) {
        if (myValue.endsWith(myError)) {
          renderer.renderValue(myValue.substring(0, myValue.length() - myError.length()));
        }
        renderer.renderError(myError);
      } else {
        if (compact && node.getValueContainer() instanceof JavaValue) {
          final JavaValue container = (JavaValue) node.getValueContainer();

          if (container.getDescriptor().isArray()) {
            final ArrayReference value = (ArrayReference) container.getDescriptor().getValue();
            final ArrayType type = (ArrayType) container.getDescriptor().getType();
            if (type != null) {
              final String typeName = type.componentTypeName();
              if (TypeConversionUtil.isPrimitive(typeName)
                  || CommonClassNames.JAVA_LANG_STRING.equals(typeName)) {
                int size = value.length();
                int max =
                    Math.min(size, CommonClassNames.JAVA_LANG_STRING.equals(typeName) ? 5 : 10);
                // TODO [eu]: this is a quick fix for IDEA-136606, need to move this away from
                // EDT!!!
                final List<Value> values = value.getValues(0, max);
                int i = 0;
                final List<String> vals = new ArrayList<String>(max);
                while (i < values.size()) {
                  vals.add(StringUtil.first(values.get(i).toString(), 15, true));
                  i++;
                }
                String more = "";
                if (vals.size() < size) {
                  more = ", + " + (size - vals.size()) + " more";
                }

                renderer.renderValue("{" + StringUtil.join(vals, ", ") + more + "}");
                return;
              }
            }
          }
        }

        String value = myValue;
        if (myValueDescriptor.isString()) {
          renderer.renderStringValue(myValue, "\"\\", XValueNode.MAX_VALUE_LENGTH);
          return;
        } else if (myValueDescriptor.getLastRenderer() instanceof ToStringRenderer
            || myValueDescriptor.getLastRenderer() instanceof ToStringBasedRenderer) {
          value = StringUtil.wrapWithDoubleQuote(truncateToMaxLength(myValue));
        } else if (myValueDescriptor.getLastRenderer() instanceof CompoundReferenceRenderer) {
          value = truncateToMaxLength(myValue);
        }
        renderer.renderValue(value);
      }
    }
コード例 #2
0
  @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();
  }
コード例 #3
0
 private static ArrayReference createURLArray(EvaluationContext context)
     throws EvaluateException, InvocationException, InvalidTypeException, ClassNotLoadedException,
         IncompatibleThreadStateException {
   DebugProcess process = context.getDebugProcess();
   ArrayType arrayType =
       (ArrayType) process.findClass(context, "java.net.URL[]", context.getClassLoader());
   ArrayReference arrayRef = arrayType.newInstance(1);
   keep(arrayRef, context);
   ClassType classType =
       (ClassType) process.findClass(context, "java.net.URL", context.getClassLoader());
   VirtualMachineProxyImpl proxy = (VirtualMachineProxyImpl) process.getVirtualMachineProxy();
   StringReference url = proxy.mirrorOf("file:a");
   keep(url, context);
   ObjectReference reference =
       process.newInstance(
           context,
           classType,
           classType.concreteMethodByName("<init>", "(Ljava/lang/String;)V"),
           Collections.singletonList(url));
   keep(reference, context);
   arrayRef.setValues(Collections.singletonList(reference));
   return arrayRef;
 }