Search in sources :

Example 1 with ValueMarkup

use of com.intellij.xdebugger.impl.ui.tree.ValueMarkup in project intellij-community by JetBrains.

the class JavaMarkObjectActionHandler method suggestMarkup.

private static Map<ObjectReference, ValueMarkup> suggestMarkup(ObjectReference objRef) {
    final Map<ObjectReference, ValueMarkup> result = new HashMap<>();
    for (ObjectReference ref : getReferringObjects(objRef)) {
        if (!(ref instanceof ClassObjectReference)) {
            // consider references from statisc fields only
            continue;
        }
        final ReferenceType refType = ((ClassObjectReference) ref).reflectedType();
        if (!refType.isAbstract()) {
            continue;
        }
        for (Field field : refType.visibleFields()) {
            if (!(field.isStatic() && field.isFinal())) {
                continue;
            }
            if (DebuggerUtils.isPrimitiveType(field.typeName())) {
                continue;
            }
            final Value fieldValue = refType.getValue(field);
            if (!(fieldValue instanceof ObjectReference)) {
                continue;
            }
            final ValueMarkup markup = result.get((ObjectReference) fieldValue);
            final String fieldName = field.name();
            final Color autoMarkupColor = getAutoMarkupColor();
            if (markup == null) {
                result.put((ObjectReference) fieldValue, new ValueMarkup(fieldName, autoMarkupColor, createMarkupTooltipText(null, refType, fieldName)));
            } else {
                final String currentText = markup.getText();
                if (!currentText.contains(fieldName)) {
                    final String currentTooltip = markup.getToolTipText();
                    final String tooltip = createMarkupTooltipText(currentTooltip, refType, fieldName);
                    result.put((ObjectReference) fieldValue, new ValueMarkup(currentText + ", " + fieldName, autoMarkupColor, tooltip));
                }
            }
        }
    }
    return result;
}
Also used : HashMap(com.intellij.util.containers.HashMap) ValueMarkup(com.intellij.xdebugger.impl.ui.tree.ValueMarkup)

Example 2 with ValueMarkup

use of com.intellij.xdebugger.impl.ui.tree.ValueMarkup in project intellij-community by JetBrains.

the class JavaMarkObjectActionHandler method perform.

@Override
public void perform(@NotNull Project project, AnActionEvent event) {
    final DebuggerTreeNodeImpl node = DebuggerAction.getSelectedNode(event.getDataContext());
    if (node == null) {
        return;
    }
    final NodeDescriptorImpl descriptor = node.getDescriptor();
    if (!(descriptor instanceof ValueDescriptorImpl)) {
        return;
    }
    final DebuggerTree tree = node.getTree();
    tree.saveState(node);
    final Component parent = event.getData(CONTEXT_COMPONENT);
    final ValueDescriptorImpl valueDescriptor = ((ValueDescriptorImpl) descriptor);
    final DebuggerContextImpl debuggerContext = tree.getDebuggerContext();
    final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess();
    final ValueMarkup markup = valueDescriptor.getMarkup(debugProcess);
    debugProcess.getManagerThread().invoke(new DebuggerContextCommandImpl(debuggerContext) {

        public Priority getPriority() {
            return Priority.HIGH;
        }

        public void threadAction() {
            boolean sessionRefreshNeeded = true;
            try {
                if (markup != null) {
                    valueDescriptor.setMarkup(debugProcess, null);
                } else {
                    final String defaultText = valueDescriptor.getName();
                    final Ref<Pair<ValueMarkup, Boolean>> result = new Ref<>(null);
                    try {
                        final boolean suggestAdditionalMarkup = canSuggestAdditionalMarkup(debugProcess, valueDescriptor.getValue());
                        SwingUtilities.invokeAndWait(() -> {
                            ObjectMarkupPropertiesDialog dialog = new ObjectMarkupPropertiesDialog(parent, defaultText, suggestAdditionalMarkup);
                            if (dialog.showAndGet()) {
                                result.set(Pair.create(dialog.getConfiguredMarkup(), dialog.isMarkAdditionalFields()));
                            }
                        });
                    } catch (InterruptedException ignored) {
                    } catch (InvocationTargetException e) {
                        LOG.error(e);
                    }
                    final Pair<ValueMarkup, Boolean> pair = result.get();
                    if (pair != null) {
                        valueDescriptor.setMarkup(debugProcess, pair.first);
                        if (pair.second) {
                            final Value value = valueDescriptor.getValue();
                            final Map<ObjectReference, ValueMarkup> additionalMarkup = suggestMarkup((ObjectReference) value);
                            if (!additionalMarkup.isEmpty()) {
                                final Map<ObjectReference, ValueMarkup> map = NodeDescriptorImpl.getMarkupMap(debugProcess);
                                if (map != null) {
                                    for (Map.Entry<ObjectReference, ValueMarkup> entry : additionalMarkup.entrySet()) {
                                        final ObjectReference key = entry.getKey();
                                        if (!map.containsKey(key)) {
                                            map.put(key, entry.getValue());
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        sessionRefreshNeeded = false;
                    }
                }
            } finally {
                final boolean _sessionRefreshNeeded = sessionRefreshNeeded;
                SwingUtilities.invokeLater(new Runnable() {

                    public void run() {
                        tree.restoreState(node);
                        final TreeBuilder model = tree.getMutableModel();
                        refreshLabelsRecursively(model.getRoot(), model, valueDescriptor.getValue());
                        if (_sessionRefreshNeeded) {
                            final DebuggerSession session = debuggerContext.getDebuggerSession();
                            if (session != null) {
                                session.refresh(true);
                            }
                        }
                    }

                    private void refreshLabelsRecursively(Object node, TreeBuilder model, Value value) {
                        if (node instanceof DebuggerTreeNodeImpl) {
                            final DebuggerTreeNodeImpl _node = (DebuggerTreeNodeImpl) node;
                            final NodeDescriptorImpl descriptor = _node.getDescriptor();
                            if (descriptor instanceof ValueDescriptor && Comparing.equal(value, ((ValueDescriptor) descriptor).getValue())) {
                                _node.labelChanged();
                            }
                        }
                        final int childCount = model.getChildCount(node);
                        for (int idx = 0; idx < childCount; idx++) {
                            refreshLabelsRecursively(model.getChild(node, idx), model, value);
                        }
                    }
                });
            }
        }
    });
}
Also used : DebuggerTreeNodeImpl(com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl) ValueDescriptor(com.intellij.debugger.ui.tree.ValueDescriptor) ValueDescriptorImpl(com.intellij.debugger.ui.impl.watch.ValueDescriptorImpl) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) NodeDescriptorImpl(com.intellij.debugger.ui.impl.watch.NodeDescriptorImpl) Pair(com.intellij.openapi.util.Pair) DebuggerTree(com.intellij.debugger.ui.impl.watch.DebuggerTree) ValueMarkup(com.intellij.xdebugger.impl.ui.tree.ValueMarkup) InvocationTargetException(java.lang.reflect.InvocationTargetException) TreeBuilder(com.intellij.debugger.ui.impl.tree.TreeBuilder) Ref(com.intellij.openapi.util.Ref) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl) HashMap(com.intellij.util.containers.HashMap) Map(java.util.Map) DebuggerContextCommandImpl(com.intellij.debugger.engine.events.DebuggerContextCommandImpl)

Example 3 with ValueMarkup

use of com.intellij.xdebugger.impl.ui.tree.ValueMarkup in project intellij-community by JetBrains.

the class DebuggerTreeNodeImpl method updateCaches.

private void updateCaches() {
    final NodeDescriptorImpl descriptor = getDescriptor();
    myIcon = DebuggerTreeRenderer.getDescriptorIcon(descriptor);
    final DebuggerContextImpl context = getTree().getDebuggerContext();
    myText = DebuggerTreeRenderer.getDescriptorText(context, descriptor, DebuggerUIUtil.getColorScheme(myTree), false);
    if (descriptor instanceof ValueDescriptor) {
        final ValueMarkup markup = ((ValueDescriptor) descriptor).getMarkup(context.getDebugProcess());
        myMarkupTooltipText = markup != null ? markup.getToolTipText() : null;
    } else {
        myMarkupTooltipText = null;
    }
}
Also used : ValueDescriptor(com.intellij.debugger.ui.tree.ValueDescriptor) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl) ValueMarkup(com.intellij.xdebugger.impl.ui.tree.ValueMarkup)

Example 4 with ValueMarkup

use of com.intellij.xdebugger.impl.ui.tree.ValueMarkup in project intellij-community by JetBrains.

the class DebuggerTreeRenderer method getDescriptorText.

private static SimpleColoredText getDescriptorText(DebuggerContextImpl debuggerContext, NodeDescriptorImpl descriptor, EditorColorsScheme colorScheme, boolean multiline, boolean appendValue) {
    SimpleColoredText descriptorText = new SimpleColoredText();
    String text;
    String nodeName;
    if (descriptor == null) {
        text = "";
        nodeName = null;
    } else {
        text = descriptor.getLabel();
        nodeName = descriptor.getName();
    }
    if (text.equals(XDebuggerUIConstants.COLLECTING_DATA_MESSAGE)) {
        descriptorText.append(XDebuggerUIConstants.COLLECTING_DATA_MESSAGE, XDebuggerUIConstants.COLLECTING_DATA_HIGHLIGHT_ATTRIBUTES);
        return descriptorText;
    }
    if (descriptor instanceof ValueDescriptor) {
        final ValueMarkup markup = ((ValueDescriptor) descriptor).getMarkup(debuggerContext.getDebugProcess());
        if (markup != null) {
            descriptorText.append("[" + markup.getText() + "] ", new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD, markup.getColor()));
        }
    }
    String[] strings = breakString(text, nodeName);
    if (strings[0] != null) {
        if (descriptor instanceof MessageDescriptor && ((MessageDescriptor) descriptor).getKind() == MessageDescriptor.SPECIAL) {
            descriptorText.append(strings[0], SPECIAL_NODE_ATTRIBUTES);
        } else {
            descriptorText.append(strings[0], DEFAULT_ATTRIBUTES);
        }
    }
    if (strings[1] != null) {
        descriptorText.append(strings[1], XDebuggerUIConstants.VALUE_NAME_ATTRIBUTES);
    }
    if (strings[2] != null) {
        if (descriptor instanceof ValueDescriptorImpl) {
            if (multiline && strings[2].indexOf('\n') >= 0) {
                strings = breakString(strings[2], "=");
                if (strings[2] != null) {
                    strings[2] = strings[0] + strings[1] + "\n" + strings[2];
                }
            }
            ValueDescriptorImpl valueDescriptor = (ValueDescriptorImpl) descriptor;
            String valueLabel = valueDescriptor.getValueLabel();
            strings = breakString(strings[2], valueLabel);
            if (strings[0] != null) {
                descriptorText.append(strings[0], DEFAULT_ATTRIBUTES);
            }
            if (appendValue && strings[1] != null) {
                if (valueLabel != null && StringUtil.startsWithChar(valueLabel, '{') && valueLabel.indexOf('}') > 0 && !StringUtil.endsWithChar(valueLabel, '}')) {
                    int idx = valueLabel.indexOf('}');
                    String objectId = valueLabel.substring(0, idx + 1);
                    valueLabel = valueLabel.substring(idx + 1);
                    descriptorText.append(objectId, OBJECT_ID_HIGHLIGHT_ATTRIBUTES);
                }
                valueLabel = DebuggerUtilsEx.truncateString(valueLabel);
                final SimpleTextAttributes valueLabelAttribs;
                if (valueDescriptor.isDirty()) {
                    valueLabelAttribs = XDebuggerUIConstants.CHANGED_VALUE_ATTRIBUTES;
                } else {
                    TextAttributes attributes = null;
                    if (valueDescriptor.isNull()) {
                        attributes = colorScheme.getAttributes(JavaHighlightingColors.KEYWORD);
                    } else if (valueDescriptor.isString()) {
                        attributes = colorScheme.getAttributes(JavaHighlightingColors.STRING);
                    }
                    valueLabelAttribs = attributes != null ? SimpleTextAttributes.fromTextAttributes(attributes) : DEFAULT_ATTRIBUTES;
                }
                final EvaluateException exception = descriptor.getEvaluateException();
                if (exception != null) {
                    final String errorMessage = exception.getMessage();
                    if (valueLabel.endsWith(errorMessage)) {
                        appendValueTextWithEscapesRendering(descriptorText, valueLabel.substring(0, valueLabel.length() - errorMessage.length()), valueLabelAttribs, colorScheme);
                        descriptorText.append(errorMessage, XDebuggerUIConstants.EXCEPTION_ATTRIBUTES);
                    } else {
                        appendValueTextWithEscapesRendering(descriptorText, valueLabel, valueLabelAttribs, colorScheme);
                        descriptorText.append(errorMessage, XDebuggerUIConstants.EXCEPTION_ATTRIBUTES);
                    }
                } else {
                    if (valueLabel.equals(XDebuggerUIConstants.COLLECTING_DATA_MESSAGE)) {
                        descriptorText.append(XDebuggerUIConstants.COLLECTING_DATA_MESSAGE, XDebuggerUIConstants.COLLECTING_DATA_HIGHLIGHT_ATTRIBUTES);
                    } else {
                        appendValueTextWithEscapesRendering(descriptorText, valueLabel, valueLabelAttribs, colorScheme);
                    }
                }
            }
        } else {
            descriptorText.append(strings[2], DEFAULT_ATTRIBUTES);
        }
    }
    return descriptorText;
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) ValueDescriptor(com.intellij.debugger.ui.tree.ValueDescriptor) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) ValueMarkup(com.intellij.xdebugger.impl.ui.tree.ValueMarkup)

Example 5 with ValueMarkup

use of com.intellij.xdebugger.impl.ui.tree.ValueMarkup in project intellij-community by JetBrains.

the class XMarkObjectActionHandler method perform.

@Override
public void perform(@NotNull Project project, AnActionEvent event) {
    XDebugSession session = XDebuggerManager.getInstance(project).getCurrentSession();
    if (session == null)
        return;
    XValueMarkers<?, ?> markers = ((XDebugSessionImpl) session).getValueMarkers();
    XValueNodeImpl node = XDebuggerTreeActionBase.getSelectedNode(event.getDataContext());
    if (markers == null || node == null)
        return;
    XValue value = node.getValueContainer();
    boolean detachedView = DebuggerUIUtil.isInDetachedTree(event);
    XDebuggerTreeState treeState = XDebuggerTreeState.saveState(node.getTree());
    ValueMarkup existing = markers.getMarkup(value);
    if (existing != null) {
        markers.unmarkValue(value);
    } else {
        ValueMarkerPresentationDialog dialog = new ValueMarkerPresentationDialog(event.getData(CONTEXT_COMPONENT), node.getName());
        dialog.show();
        ValueMarkup markup = dialog.getConfiguredMarkup();
        if (dialog.isOK() && markup != null) {
            markers.markValue(value, markup);
        }
    }
    if (detachedView) {
        node.getTree().rebuildAndRestore(treeState);
    }
    session.rebuildViews();
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) XDebuggerTreeState(com.intellij.xdebugger.impl.ui.tree.XDebuggerTreeState) ValueMarkerPresentationDialog(com.intellij.xdebugger.impl.ui.tree.ValueMarkerPresentationDialog) XValueNodeImpl(com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl) XValue(com.intellij.xdebugger.frame.XValue) ValueMarkup(com.intellij.xdebugger.impl.ui.tree.ValueMarkup) XDebugSessionImpl(com.intellij.xdebugger.impl.XDebugSessionImpl)

Aggregations

ValueMarkup (com.intellij.xdebugger.impl.ui.tree.ValueMarkup)9 ValueDescriptor (com.intellij.debugger.ui.tree.ValueDescriptor)3 Map (java.util.Map)3 DebuggerContextImpl (com.intellij.debugger.impl.DebuggerContextImpl)2 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)2 HashMap (com.intellij.util.containers.HashMap)2 XDebugSession (com.intellij.xdebugger.XDebugSession)2 XDebugSessionImpl (com.intellij.xdebugger.impl.XDebugSessionImpl)2 HashMap (java.util.HashMap)2 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)1 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)1 DebuggerContextCommandImpl (com.intellij.debugger.engine.events.DebuggerContextCommandImpl)1 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)1 TreeBuilder (com.intellij.debugger.ui.impl.tree.TreeBuilder)1 DebuggerTree (com.intellij.debugger.ui.impl.watch.DebuggerTree)1 DebuggerTreeNodeImpl (com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl)1 NodeDescriptorImpl (com.intellij.debugger.ui.impl.watch.NodeDescriptorImpl)1 ValueDescriptorImpl (com.intellij.debugger.ui.impl.watch.ValueDescriptorImpl)1 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)1 Pair (com.intellij.openapi.util.Pair)1