Beispiel #1
0
  @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);
  }
Beispiel #2
0
  @Override
  public PsiElement getChildValueExpression(DebuggerTreeNode node, DebuggerContext context)
      throws EvaluateException {
    FieldDescriptor fieldDescriptor = (FieldDescriptor) node.getDescriptor();

    PsiElementFactory elementFactory =
        JavaPsiFacade.getInstance(node.getProject()).getElementFactory();
    try {
      return elementFactory.createExpressionFromText(
          "this." + fieldDescriptor.getField().name(),
          DebuggerUtils.findClass(
              fieldDescriptor.getObject().referenceType().name(),
              context.getProject(),
              context.getDebugProcess().getSearchScope()));
    } catch (IncorrectOperationException e) {
      throw new EvaluateException(
          DebuggerBundle.message("error.invalid.field.name", fieldDescriptor.getField().name()),
          null);
    }
  }