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 buildChildren( final Value value, final ChildrenBuilder builder, final EvaluationContext evaluationContext) { DebuggerManagerThreadImpl.assertIsManagerThread(); final ValueDescriptorImpl parentDescriptor = (ValueDescriptorImpl) builder.getParentDescriptor(); final NodeManager nodeManager = builder.getNodeManager(); final NodeDescriptorFactory nodeDescriptorFactory = builder.getDescriptorManager(); List<DebuggerTreeNode> children = new ArrayList<>(); if (value instanceof ObjectReference) { final ObjectReference objRef = (ObjectReference) value; final ReferenceType refType = objRef.referenceType(); // default ObjectReference processing List<Field> fields = refType.allFields(); if (!fields.isEmpty()) { Set<String> names = new HashSet<>(); for (Field field : fields) { if (shouldDisplay(evaluationContext, objRef, field)) { FieldDescriptor fieldDescriptor = createFieldDescriptor( parentDescriptor, nodeDescriptorFactory, objRef, field, evaluationContext); String name = fieldDescriptor.getName(); if (names.contains(name)) { fieldDescriptor.putUserData(FieldDescriptor.SHOW_DECLARING_TYPE, Boolean.TRUE); } else { names.add(name); } children.add(nodeManager.createNode(fieldDescriptor, evaluationContext)); } } if (children.isEmpty()) { children.add( nodeManager.createMessageNode( DebuggerBundle.message("message.node.class.no.fields.to.display"))); } else if (XDebuggerSettingsManager.getInstance().getDataViewSettings().isSortValues()) { children.sort(NodeManagerImpl.getNodeComparator()); } } else { children.add( nodeManager.createMessageNode(MessageDescriptor.CLASS_HAS_NO_FIELDS.getLabel())); } } builder.setChildren(children); }