Exemplo n.º 1
0
  protected boolean shouldDisplay(
      EvaluationContext context, @NotNull ObjectReference objInstance, @NotNull Field field) {
    final boolean isSynthetic = DebuggerUtils.isSynthetic(field);
    if (!SHOW_SYNTHETICS && isSynthetic) {
      return false;
    }
    if (SHOW_VAL_FIELDS_AS_LOCAL_VARIABLES && isSynthetic) {
      try {
        final StackFrameProxy frameProxy = context.getFrameProxy();
        if (frameProxy != null) {
          final Location location = frameProxy.location();
          if (location != null
              && objInstance.equals(context.getThisObject())
              && Comparing.equal(objInstance.referenceType(), location.declaringType())
              && StringUtil.startsWith(
                  field.name(), FieldDescriptorImpl.OUTER_LOCAL_VAR_FIELD_PREFIX)) {
            return false;
          }
        }
      } catch (EvaluateException ignored) {
      }
    }
    if (!SHOW_STATIC && field.isStatic()) {
      return false;
    }

    if (!SHOW_STATIC_FINAL && field.isStatic() && field.isFinal()) {
      return false;
    }

    return true;
  }
Exemplo n.º 2
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");
   }
 }
Exemplo n.º 3
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);
  }
Exemplo n.º 4
0
 @Nullable
 public static String getEnumConstantName(@NotNull ObjectReference objRef, ClassType classType) {
   do {
     if (!classType.isPrepared()) {
       return null;
     }
     classType = classType.superclass();
     if (classType == null) {
       return null;
     }
   } while (!(CommonClassNames.JAVA_LANG_ENUM.equals(classType.name())));
   //noinspection HardCodedStringLiteral
   final Field field = classType.fieldByName("name");
   if (field == null) {
     return null;
   }
   final Value value = objRef.getValue(field);
   if (!(value instanceof StringReference)) {
     return null;
   }
   return ((StringReference) value).value();
 }