Search in sources :

Example 16 with DebugProcessImpl

use of com.intellij.debugger.engine.DebugProcessImpl in project intellij-community by JetBrains.

the class ViewAsGroup method update.

public void update(final AnActionEvent event) {
    if (!DebuggerAction.isFirstStart(event)) {
        return;
    }
    myChildren = AnAction.EMPTY_ARRAY;
    final DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(event.getDataContext());
    final List<JavaValue> values = getSelectedValues(event);
    if (values.isEmpty()) {
        event.getPresentation().setEnabledAndVisible(false);
        return;
    }
    final DebugProcessImpl process = debuggerContext.getDebugProcess();
    if (process == null) {
        event.getPresentation().setEnabled(false);
        return;
    }
    process.getManagerThread().schedule(new DebuggerContextCommandImpl(debuggerContext) {

        public void threadAction() {
            myChildren = calcChildren(values);
            DebuggerAction.enableAction(event, myChildren.length > 0);
        }
    });
}
Also used : DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) JavaValue(com.intellij.debugger.engine.JavaValue) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl) DebuggerContextCommandImpl(com.intellij.debugger.engine.events.DebuggerContextCommandImpl)

Example 17 with DebugProcessImpl

use of com.intellij.debugger.engine.DebugProcessImpl in project intellij-community by JetBrains.

the class PopFrameAction method actionPerformed.

public void actionPerformed(@NotNull AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final JavaStackFrame stackFrame = getStackFrame(e);
    if (stackFrame == null || stackFrame.getStackFrameProxy().isBottom()) {
        return;
    }
    try {
        final DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(e.getDataContext());
        final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess();
        if (debugProcess == null) {
            return;
        }
        debugProcess.getSession().setSteppingThrough(stackFrame.getStackFrameProxy().threadProxy());
        if (evaluateFinallyBlocks(project, UIUtil.removeMnemonic(ActionsBundle.actionText(DebuggerActions.POP_FRAME)), stackFrame, new XDebuggerEvaluator.XEvaluationCallback() {

            @Override
            public void evaluated(@NotNull XValue result) {
                popFrame(debugProcess, debuggerContext, stackFrame);
            }

            @Override
            public void errorOccurred(@NotNull final String errorMessage) {
                ApplicationManager.getApplication().invokeLater(() -> Messages.showMessageDialog(project, DebuggerBundle.message("error.executing.finally", errorMessage), UIUtil.removeMnemonic(ActionsBundle.actionText(DebuggerActions.POP_FRAME)), Messages.getErrorIcon()));
            }
        }))
            return;
        popFrame(debugProcess, debuggerContext, stackFrame);
    } catch (NativeMethodException e2) {
        Messages.showMessageDialog(project, DebuggerBundle.message("error.native.method.exception"), UIUtil.removeMnemonic(ActionsBundle.actionText(DebuggerActions.POP_FRAME)), Messages.getErrorIcon());
    } catch (InvalidStackFrameException | VMDisconnectedException ignored) {
    }
}
Also used : NativeMethodException(com.sun.jdi.NativeMethodException) XDebuggerEvaluator(com.intellij.xdebugger.evaluation.XDebuggerEvaluator) InvalidStackFrameException(com.sun.jdi.InvalidStackFrameException) XValue(com.intellij.xdebugger.frame.XValue) VMDisconnectedException(com.sun.jdi.VMDisconnectedException) Project(com.intellij.openapi.project.Project) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) JavaStackFrame(com.intellij.debugger.engine.JavaStackFrame) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl)

Example 18 with DebugProcessImpl

use of com.intellij.debugger.engine.DebugProcessImpl 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 19 with DebugProcessImpl

use of com.intellij.debugger.engine.DebugProcessImpl in project intellij-community by JetBrains.

the class CreateRendererAction method actionPerformed.

public void actionPerformed(@NotNull final AnActionEvent event) {
    final DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(event.getDataContext());
    final List<JavaValue> values = ViewAsGroup.getSelectedValues(event);
    if (values.size() != 1) {
        return;
    }
    final JavaValue javaValue = values.get(0);
    final DebugProcessImpl process = debuggerContext.getDebugProcess();
    if (process == null) {
        return;
    }
    final Project project = event.getProject();
    process.getManagerThread().schedule(new DebuggerContextCommandImpl(debuggerContext) {

        public void threadAction() {
            Type type = javaValue.getDescriptor().getType();
            final String name = type != null ? type.name() : null;
            DebuggerUIUtil.invokeLater(() -> {
                final UserRenderersConfigurable ui = new UserRenderersConfigurable();
                ConfigurableBase<UserRenderersConfigurable, NodeRendererSettings> configurable = new ConfigurableBase<UserRenderersConfigurable, NodeRendererSettings>("reference.idesettings.debugger.typerenderers", DebuggerBundle.message("user.renderers.configurable.display.name"), "reference.idesettings.debugger.typerenderers") {

                    @NotNull
                    @Override
                    protected NodeRendererSettings getSettings() {
                        return NodeRendererSettings.getInstance();
                    }

                    @Override
                    protected UserRenderersConfigurable createUi() {
                        return ui;
                    }
                };
                SingleConfigurableEditor editor = new SingleConfigurableEditor(project, configurable);
                if (name != null) {
                    NodeRenderer renderer = NodeRendererSettings.getInstance().createCompoundTypeRenderer(name, name, null, null);
                    renderer.setEnabled(true);
                    ui.addRenderer(renderer);
                }
                editor.show();
            });
        }
    });
}
Also used : ConfigurableBase(com.intellij.openapi.options.ConfigurableBase) SingleConfigurableEditor(com.intellij.openapi.options.ex.SingleConfigurableEditor) JavaValue(com.intellij.debugger.engine.JavaValue) NotNull(org.jetbrains.annotations.NotNull) NodeRenderer(com.intellij.debugger.ui.tree.render.NodeRenderer) Project(com.intellij.openapi.project.Project) Type(com.sun.jdi.Type) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl) NodeRendererSettings(com.intellij.debugger.settings.NodeRendererSettings) UserRenderersConfigurable(com.intellij.debugger.settings.UserRenderersConfigurable) DebuggerContextCommandImpl(com.intellij.debugger.engine.events.DebuggerContextCommandImpl)

Example 20 with DebugProcessImpl

use of com.intellij.debugger.engine.DebugProcessImpl in project intellij-community by JetBrains.

the class AdjustArrayRangeAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(e.getDataContext());
    DebugProcessImpl debugProcess = debuggerContext.getDebugProcess();
    if (debugProcess == null) {
        return;
    }
    final Project project = debuggerContext.getProject();
    final XValueNodeImpl node = XDebuggerTreeActionBase.getSelectedNode(e.getDataContext());
    if (node == null) {
        return;
    }
    final XValue container = node.getValueContainer();
    if (!(container instanceof JavaValue)) {
        return;
    }
    final ValueDescriptorImpl descriptor = ((JavaValue) container).getDescriptor();
    ArrayRenderer renderer = getArrayRenderer(descriptor);
    if (renderer == null) {
        return;
    }
    //String title = createNodeTitle("", selectedNode);
    //String label = selectedNode.toString();
    //int index = label.indexOf('=');
    //if (index > 0) {
    //  title = title + " " + label.substring(index);
    //}
    String title = node.getName();
    final ArrayRenderer clonedRenderer = renderer.clone();
    clonedRenderer.setForced(true);
    if (ShowSettingsUtil.getInstance().editConfigurable(project, new NamedArrayConfigurable(title, clonedRenderer))) {
        debugProcess.getManagerThread().schedule(new SuspendContextCommandImpl(debuggerContext.getSuspendContext()) {

            @Override
            public void contextAction() throws Exception {
                final Renderer lastRenderer = descriptor.getLastRenderer();
                if (lastRenderer instanceof ArrayRenderer) {
                    ((JavaValue) container).setRenderer(clonedRenderer, node);
                } else if (lastRenderer instanceof CompoundNodeRenderer) {
                    final CompoundNodeRenderer compoundRenderer = (CompoundNodeRenderer) lastRenderer;
                    final ChildrenRenderer childrenRenderer = compoundRenderer.getChildrenRenderer();
                    if (childrenRenderer instanceof ExpressionChildrenRenderer) {
                        ExpressionChildrenRenderer.setPreferableChildrenRenderer(descriptor, clonedRenderer);
                        ((JavaValue) container).reBuild(node);
                    }
                }
            }
        });
    }
}
Also used : JavaValue(com.intellij.debugger.engine.JavaValue) SuspendContextCommandImpl(com.intellij.debugger.engine.events.SuspendContextCommandImpl) XValue(com.intellij.xdebugger.frame.XValue) Project(com.intellij.openapi.project.Project) ValueDescriptorImpl(com.intellij.debugger.ui.impl.watch.ValueDescriptorImpl) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) XValueNodeImpl(com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl)

Aggregations

DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)55 DebuggerContextImpl (com.intellij.debugger.impl.DebuggerContextImpl)20 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)15 Project (com.intellij.openapi.project.Project)15 Nullable (org.jetbrains.annotations.Nullable)11 DebuggerCommandImpl (com.intellij.debugger.engine.events.DebuggerCommandImpl)9 DebuggerTreeNodeImpl (com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl)9 DebuggerContextCommandImpl (com.intellij.debugger.engine.events.DebuggerContextCommandImpl)7 List (java.util.List)7 SourcePosition (com.intellij.debugger.SourcePosition)5 JavaValue (com.intellij.debugger.engine.JavaValue)5 StackFrameProxyImpl (com.intellij.debugger.jdi.StackFrameProxyImpl)5 ThreadReferenceProxyImpl (com.intellij.debugger.jdi.ThreadReferenceProxyImpl)5 VirtualMachineProxyImpl (com.intellij.debugger.jdi.VirtualMachineProxyImpl)5 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)4 NodeDescriptorImpl (com.intellij.debugger.ui.impl.watch.NodeDescriptorImpl)4 ThreadDescriptorImpl (com.intellij.debugger.ui.impl.watch.ThreadDescriptorImpl)4 XDebugSession (com.intellij.xdebugger.XDebugSession)4 ArrayList (java.util.ArrayList)4 NotNull (org.jetbrains.annotations.NotNull)4