Search in sources :

Example 1 with DebuggerTree

use of com.intellij.debugger.ui.impl.watch.DebuggerTree 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 2 with DebuggerTree

use of com.intellij.debugger.ui.impl.watch.DebuggerTree in project intellij-community by JetBrains.

the class ToggleFieldBreakpointAction method getPlace.

@Nullable
public static SourcePosition getPlace(AnActionEvent event) {
    final DataContext dataContext = event.getDataContext();
    final Project project = event.getData(CommonDataKeys.PROJECT);
    if (project == null) {
        return null;
    }
    if (ActionPlaces.PROJECT_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.STRUCTURE_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.FAVORITES_VIEW_POPUP.equals(event.getPlace())) {
        final PsiElement psiElement = event.getData(CommonDataKeys.PSI_ELEMENT);
        if (psiElement instanceof PsiField) {
            return SourcePosition.createFromElement(psiElement);
        }
        return null;
    }
    final DebuggerTreeNodeImpl selectedNode = DebuggerAction.getSelectedNode(dataContext);
    if (selectedNode != null && selectedNode.getDescriptor() instanceof FieldDescriptorImpl) {
        final DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(dataContext);
        final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess();
        if (debugProcess != null) {
            // if there is an active debug session
            final Ref<SourcePosition> positionRef = new Ref<>(null);
            debugProcess.getManagerThread().invokeAndWait(new DebuggerContextCommandImpl(debuggerContext) {

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

                @Override
                public void threadAction() {
                    ApplicationManager.getApplication().runReadAction(() -> positionRef.set(SourcePositionProvider.getSourcePosition(selectedNode.getDescriptor(), project, debuggerContext)));
                }
            });
            final SourcePosition sourcePosition = positionRef.get();
            if (sourcePosition != null) {
                return sourcePosition;
            }
        }
    }
    if (DebuggerAction.isContextView(event)) {
        DebuggerTree tree = DebuggerTree.DATA_KEY.getData(dataContext);
        if (tree != null && tree.getSelectionPath() != null) {
            DebuggerTreeNodeImpl node = ((DebuggerTreeNodeImpl) tree.getSelectionPath().getLastPathComponent());
            if (node != null && node.getDescriptor() instanceof FieldDescriptorImpl) {
                Field field = ((FieldDescriptorImpl) node.getDescriptor()).getField();
                DebuggerSession session = tree.getDebuggerContext().getDebuggerSession();
                PsiClass psiClass = DebuggerUtils.findClass(field.declaringType().name(), project, (session != null) ? session.getSearchScope() : GlobalSearchScope.allScope(project));
                if (psiClass != null) {
                    psiClass = (PsiClass) psiClass.getNavigationElement();
                    final PsiField psiField = psiClass.findFieldByName(field.name(), true);
                    if (psiField != null) {
                        return SourcePosition.createFromElement(psiField);
                    }
                }
            }
        }
        return null;
    }
    Editor editor = event.getData(CommonDataKeys.EDITOR);
    if (editor == null) {
        editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
    }
    if (editor != null) {
        final Document document = editor.getDocument();
        PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
        if (file != null) {
            final VirtualFile virtualFile = file.getVirtualFile();
            FileType fileType = virtualFile != null ? virtualFile.getFileType() : null;
            if (StdFileTypes.JAVA == fileType || StdFileTypes.CLASS == fileType) {
                final PsiField field = FieldBreakpoint.findField(project, document, editor.getCaretModel().getOffset());
                if (field != null) {
                    return SourcePosition.createFromElement(field);
                }
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DebuggerTreeNodeImpl(com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl) Document(com.intellij.openapi.editor.Document) DebuggerTree(com.intellij.debugger.ui.impl.watch.DebuggerTree) FieldDescriptorImpl(com.intellij.debugger.ui.impl.watch.FieldDescriptorImpl) Project(com.intellij.openapi.project.Project) Field(com.sun.jdi.Field) Ref(com.intellij.openapi.util.Ref) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) FileType(com.intellij.openapi.fileTypes.FileType) SourcePosition(com.intellij.debugger.SourcePosition) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl) Editor(com.intellij.openapi.editor.Editor) DebuggerContextCommandImpl(com.intellij.debugger.engine.events.DebuggerContextCommandImpl) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with DebuggerTree

use of com.intellij.debugger.ui.impl.watch.DebuggerTree in project intellij-community by JetBrains.

the class DebuggerAction method getSelectedNodes.

@Nullable
public static DebuggerTreeNodeImpl[] getSelectedNodes(DataContext dataContext) {
    DebuggerTree tree = getTree(dataContext);
    if (tree == null)
        return null;
    TreePath[] paths = tree.getSelectionPaths();
    if (paths == null || paths.length == 0) {
        return EMPTY_TREE_NODE_ARRAY;
    }
    List<DebuggerTreeNodeImpl> nodes = new ArrayList<>(paths.length);
    for (TreePath path : paths) {
        Object component = path.getLastPathComponent();
        if (component instanceof DebuggerTreeNodeImpl) {
            nodes.add((DebuggerTreeNodeImpl) component);
        }
    }
    return nodes.toArray(new DebuggerTreeNodeImpl[nodes.size()]);
}
Also used : DebuggerTreeNodeImpl(com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl) TreePath(javax.swing.tree.TreePath) ArrayList(java.util.ArrayList) XDebuggerTree(com.intellij.xdebugger.impl.ui.tree.XDebuggerTree) DebuggerTree(com.intellij.debugger.ui.impl.watch.DebuggerTree) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with DebuggerTree

use of com.intellij.debugger.ui.impl.watch.DebuggerTree in project intellij-community by JetBrains.

the class DebuggerAction method getSelectedNode.

@Nullable
public static DebuggerTreeNodeImpl getSelectedNode(DataContext dataContext) {
    DebuggerTree tree = getTree(dataContext);
    if (tree == null)
        return null;
    if (tree.getSelectionCount() != 1) {
        return null;
    }
    TreePath path = tree.getSelectionPath();
    if (path == null) {
        return null;
    }
    Object component = path.getLastPathComponent();
    if (!(component instanceof DebuggerTreeNodeImpl)) {
        return null;
    }
    return (DebuggerTreeNodeImpl) component;
}
Also used : DebuggerTreeNodeImpl(com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl) TreePath(javax.swing.tree.TreePath) XDebuggerTree(com.intellij.xdebugger.impl.ui.tree.XDebuggerTree) DebuggerTree(com.intellij.debugger.ui.impl.watch.DebuggerTree) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with DebuggerTree

use of com.intellij.debugger.ui.impl.watch.DebuggerTree in project intellij-community by JetBrains.

the class DebuggerTreePanel method dispose.

@Override
public void dispose() {
    Disposer.dispose(myRebuildAlarm);
    try {
        super.dispose();
    } finally {
        final DebuggerTree tree = myTree;
        if (tree != null) {
            Disposer.dispose(tree);
        }
        // prevent mem leak from inside Swing
        myTree = null;
    }
}
Also used : DebuggerTree(com.intellij.debugger.ui.impl.watch.DebuggerTree)

Aggregations

DebuggerTree (com.intellij.debugger.ui.impl.watch.DebuggerTree)5 DebuggerTreeNodeImpl (com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl)4 Nullable (org.jetbrains.annotations.Nullable)3 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)2 DebuggerContextCommandImpl (com.intellij.debugger.engine.events.DebuggerContextCommandImpl)2 DebuggerContextImpl (com.intellij.debugger.impl.DebuggerContextImpl)2 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)2 Ref (com.intellij.openapi.util.Ref)2 XDebuggerTree (com.intellij.xdebugger.impl.ui.tree.XDebuggerTree)2 TreePath (javax.swing.tree.TreePath)2 SourcePosition (com.intellij.debugger.SourcePosition)1 TreeBuilder (com.intellij.debugger.ui.impl.tree.TreeBuilder)1 FieldDescriptorImpl (com.intellij.debugger.ui.impl.watch.FieldDescriptorImpl)1 NodeDescriptorImpl (com.intellij.debugger.ui.impl.watch.NodeDescriptorImpl)1 ValueDescriptorImpl (com.intellij.debugger.ui.impl.watch.ValueDescriptorImpl)1 ValueDescriptor (com.intellij.debugger.ui.tree.ValueDescriptor)1 Document (com.intellij.openapi.editor.Document)1 Editor (com.intellij.openapi.editor.Editor)1 FileType (com.intellij.openapi.fileTypes.FileType)1 Project (com.intellij.openapi.project.Project)1