Search in sources :

Example 6 with DebuggerTreeNodeImpl

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

the class JumpToObjectAction method update.

@Override
public void update(final AnActionEvent e) {
    if (!isFirstStart(e)) {
        return;
    }
    final DebuggerContextImpl debuggerContext = getDebuggerContext(e.getDataContext());
    final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess();
    if (debugProcess == null) {
        e.getPresentation().setVisible(false);
        return;
    }
    DebuggerTreeNodeImpl selectedNode = getSelectedNode(e.getDataContext());
    if (selectedNode == null) {
        e.getPresentation().setVisible(false);
        return;
    }
    final NodeDescriptorImpl descriptor = selectedNode.getDescriptor();
    if (descriptor instanceof ValueDescriptor) {
        debugProcess.getManagerThread().schedule(new EnableCommand(debuggerContext, (ValueDescriptor) descriptor, debugProcess, e));
    } else {
        e.getPresentation().setVisible(false);
    }
}
Also used : DebuggerTreeNodeImpl(com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) ValueDescriptor(com.intellij.debugger.ui.tree.ValueDescriptor) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl) NodeDescriptorImpl(com.intellij.debugger.ui.impl.watch.NodeDescriptorImpl)

Example 7 with DebuggerTreeNodeImpl

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

the class ToggleFieldBreakpointAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    if (project == null) {
        return;
    }
    final SourcePosition place = getPlace(e);
    if (place != null) {
        Document document = PsiDocumentManager.getInstance(project).getDocument(place.getFile());
        if (document != null) {
            DebuggerManagerEx debuggerManager = DebuggerManagerEx.getInstanceEx(project);
            BreakpointManager manager = debuggerManager.getBreakpointManager();
            final int offset = place.getOffset();
            final Breakpoint breakpoint = offset >= 0 ? manager.findBreakpoint(document, offset, FieldBreakpoint.CATEGORY) : null;
            if (breakpoint == null) {
                FieldBreakpoint fieldBreakpoint = manager.addFieldBreakpoint(document, offset);
                if (fieldBreakpoint != null) {
                    if (DebuggerAction.isContextView(e)) {
                        final DebuggerTreeNodeImpl selectedNode = DebuggerAction.getSelectedNode(e.getDataContext());
                        if (selectedNode != null && selectedNode.getDescriptor() instanceof FieldDescriptorImpl) {
                            ObjectReference object = ((FieldDescriptorImpl) selectedNode.getDescriptor()).getObject();
                            if (object != null) {
                                long id = object.uniqueID();
                                InstanceFilter[] instanceFilters = new InstanceFilter[] { InstanceFilter.create(Long.toString(id)) };
                                fieldBreakpoint.setInstanceFilters(instanceFilters);
                                fieldBreakpoint.setInstanceFiltersEnabled(true);
                            }
                        }
                    }
                    final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
                    if (editor != null) {
                        manager.editBreakpoint(fieldBreakpoint, editor);
                    }
                }
            } else {
                manager.removeBreakpoint(breakpoint);
            }
        }
    }
}
Also used : FieldBreakpoint(com.intellij.debugger.ui.breakpoints.FieldBreakpoint) Breakpoint(com.intellij.debugger.ui.breakpoints.Breakpoint) InstanceFilter(com.intellij.debugger.InstanceFilter) DebuggerManagerEx(com.intellij.debugger.DebuggerManagerEx) DebuggerTreeNodeImpl(com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl) FieldBreakpoint(com.intellij.debugger.ui.breakpoints.FieldBreakpoint) Document(com.intellij.openapi.editor.Document) BreakpointManager(com.intellij.debugger.ui.breakpoints.BreakpointManager) FieldBreakpoint(com.intellij.debugger.ui.breakpoints.FieldBreakpoint) Breakpoint(com.intellij.debugger.ui.breakpoints.Breakpoint) FieldDescriptorImpl(com.intellij.debugger.ui.impl.watch.FieldDescriptorImpl) Project(com.intellij.openapi.project.Project) ObjectReference(com.sun.jdi.ObjectReference) SourcePosition(com.intellij.debugger.SourcePosition) Editor(com.intellij.openapi.editor.Editor)

Example 8 with DebuggerTreeNodeImpl

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

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

use of com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl 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)

Aggregations

DebuggerTreeNodeImpl (com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl)26 DebuggerContextImpl (com.intellij.debugger.impl.DebuggerContextImpl)11 NodeDescriptorImpl (com.intellij.debugger.ui.impl.watch.NodeDescriptorImpl)10 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)9 ThreadDescriptorImpl (com.intellij.debugger.ui.impl.watch.ThreadDescriptorImpl)7 ValueDescriptor (com.intellij.debugger.ui.tree.ValueDescriptor)6 Nullable (org.jetbrains.annotations.Nullable)6 DebuggerContextCommandImpl (com.intellij.debugger.engine.events.DebuggerContextCommandImpl)5 Project (com.intellij.openapi.project.Project)5 SourcePosition (com.intellij.debugger.SourcePosition)4 DebuggerTree (com.intellij.debugger.ui.impl.watch.DebuggerTree)4 DebuggerCommandImpl (com.intellij.debugger.engine.events.DebuggerCommandImpl)3 ThreadReferenceProxyImpl (com.intellij.debugger.jdi.ThreadReferenceProxyImpl)3 Presentation (com.intellij.openapi.actionSystem.Presentation)3 SuspendContextImpl (com.intellij.debugger.engine.SuspendContextImpl)2 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)2 FieldDescriptorImpl (com.intellij.debugger.ui.impl.watch.FieldDescriptorImpl)2 ValueDescriptorImpl (com.intellij.debugger.ui.impl.watch.ValueDescriptorImpl)2 NodeDescriptor (com.intellij.debugger.ui.tree.NodeDescriptor)2 Document (com.intellij.openapi.editor.Document)2