Example #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);
      }
    }
 @Override
 public void drop(final DnDEvent aEvent) {
   Object object = aEvent.getAttachedObject();
   if (object instanceof XValueNodeImpl[]) {
     final XValueNodeImpl[] nodes = (XValueNodeImpl[]) object;
     for (XValueNodeImpl node : nodes) {
       String expression = node.getValueContainer().getEvaluationExpression();
       if (expression != null) {
         addWatchExpression(expression, -1, false);
       }
     }
   } else if (object instanceof EventInfo) {
     String text = ((EventInfo) object).getTextForFlavor(DataFlavor.stringFlavor);
     if (text != null) {
       addWatchExpression(text, -1, false);
     }
   }
 }
  public static void editNew(@NotNull XValueNodeImpl parentNode) {
    ValueDescriptorImpl descriptor = ((JavaValue) parentNode.getValueContainer()).getDescriptor();
    EnumerationChildrenRenderer renderer = EnumerationChildrenRenderer.getCurrent(descriptor);
    XDebuggerTreeNode newNode = parentNode.addTemporaryEditorNode();
    DebuggerUIUtil.invokeLater(
        () ->
            new CustomFieldInplaceEditor(newNode, null, renderer) {
              @Override
              public void cancelEditing() {
                super.cancelEditing();
                parentNode.removeTemporaryEditorNode(newNode);
              }

              @Override
              protected List<Pair<String, TextWithImports>> getRendererChildren() {
                if (myRenderer != null) {
                  return myRenderer.getChildren();
                }
                String name = getTypeName(descriptor);
                EnumerationChildrenRenderer enumerationChildrenRenderer =
                    new EnumerationChildrenRenderer();
                enumerationChildrenRenderer.setAppendDefaultChildren(true);

                Renderer lastRenderer = descriptor.getLastRenderer();
                if (lastRenderer instanceof CompoundNodeRenderer
                    && !(((CompoundNodeRenderer) lastRenderer).getChildrenRenderer()
                        instanceof ExpressionChildrenRenderer)) {
                  ((CompoundNodeRenderer) lastRenderer)
                      .setChildrenRenderer(enumerationChildrenRenderer);
                } else {
                  NodeRenderer renderer =
                      NodeRendererSettings.getInstance()
                          .createCompoundTypeRenderer(
                              name, name, null, enumerationChildrenRenderer);
                  renderer.setEnabled(true);
                  NodeRendererSettings.getInstance().getCustomRenderers().addRenderer(renderer);
                  NodeRendererSettings.getInstance().fireRenderersChanged();
                }
                return enumerationChildrenRenderer.getChildren();
              }
            }.show());
  }
 @Nullable
 public static XValue getSelectedValue(@NotNull DataContext dataContext) {
   XValueNodeImpl node = getSelectedNode(dataContext);
   return node != null ? node.getValueContainer() : null;
 }