Exemple #1
0
 protected static String calcLabel(ValueDescriptor descriptor) {
   final ValueDescriptorImpl valueDescriptor = (ValueDescriptorImpl) descriptor;
   final Value value = valueDescriptor.getValue();
   if (value instanceof ObjectReference) {
     if (value instanceof StringReference) {
       return ((StringReference) value).value();
     } else if (value instanceof ClassObjectReference) {
       ReferenceType type = ((ClassObjectReference) value).reflectedType();
       return (type != null) ? type.name() : "{...}";
     } else {
       final ObjectReference objRef = (ObjectReference) value;
       final Type type = objRef.type();
       if (type instanceof ClassType && ((ClassType) type).isEnum()) {
         final String name = getEnumConstantName(objRef, (ClassType) type);
         if (name != null) {
           return name;
         } else {
           return type.name();
         }
       } else {
         return "";
       }
     }
   } else if (value == null) {
     //noinspection HardCodedStringLiteral
     return "null";
   } else {
     return DebuggerBundle.message("label.undefined");
   }
 }
    @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);
      }
    }
 @NotNull
 @Override
 public String getSeparator() {
   String fullName = myValueDescriptor.calcValueName();
   String name = myValueDescriptor.getName();
   if (!StringUtil.isEmpty(fullName) && !name.equals(fullName) && fullName.startsWith(name)) {
     return fullName.substring(name.length()) + " " + DEFAULT_SEPARATOR;
   }
   return DEFAULT_SEPARATOR;
 }
 @NotNull
 @Override
 public String getSeparator() {
   boolean emptyAfterSeparator =
       !myValueDescriptor.isShowIdLabel() && StringUtil.isEmpty(myValue);
   String declaredType = myValueDescriptor.getDeclaredTypeLabel();
   if (!StringUtil.isEmpty(declaredType)) {
     return emptyAfterSeparator ? declaredType : declaredType + " " + DEFAULT_SEPARATOR;
   }
   return emptyAfterSeparator ? "" : DEFAULT_SEPARATOR;
 }
 protected JavaValue(
     JavaValue parent,
     @NotNull ValueDescriptorImpl valueDescriptor,
     @NotNull EvaluationContextImpl evaluationContext,
     NodeManagerImpl nodeManager,
     boolean contextSet) {
   super(valueDescriptor.calcValueName());
   myParent = parent;
   myValueDescriptor = valueDescriptor;
   myEvaluationContext = evaluationContext;
   myNodeManager = nodeManager;
   myContextSet = contextSet;
 }
 public void setRenderer(NodeRenderer nodeRenderer, final XValueNodeImpl node) {
   DebuggerManagerThreadImpl.assertIsManagerThread();
   myValueDescriptor.setRenderer(nodeRenderer);
   myCurrentChildrenStart = 0;
   node.getTree()
       .getLaterInvocator()
       .offer(
           new Runnable() {
             @Override
             public void run() {
               node.clearChildren();
               computePresentation(node, XValuePlace.TREE);
             }
           });
 }
 public void setRenderer(NodeRenderer nodeRenderer, final XValueNodeImpl node) {
   DebuggerManagerThreadImpl.assertIsManagerThread();
   myValueDescriptor.setRenderer(nodeRenderer);
   reBuild(node);
 }
 @Override
 public String getValueText() {
   return myValueDescriptor.getValueText();
 }
 @Nullable
 @Override
 public XValueModifier getModifier() {
   return myValueDescriptor.canSetValue() ? new JavaValueModifier(this) : null;
 }
 public Project getProject() {
   return myValueDescriptor.getProject();
 }
 @NotNull
 String getValueString() {
   return myValueDescriptor.getValueText();
 }
 @Override
 public boolean isModified() {
   return myValueDescriptor.isDirty();
 }
 @Nullable
 private static String getTypeName(ValueDescriptorImpl descriptor) {
   Type type = descriptor.getType();
   return type != null ? type.name() : null;
 }