Search in sources :

Example 1 with SuspendContextCommandImpl

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

the class JavaValue method computePresentation.

@Override
public void computePresentation(@NotNull final XValueNode node, @NotNull XValuePlace place) {
    final SuspendContextImpl suspendContext = myEvaluationContext.getSuspendContext();
    myEvaluationContext.getManagerThread().schedule(new SuspendContextCommandImpl(suspendContext) {

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

        @Override
        protected void commandCancelled() {
            node.setPresentation(null, new XErrorValuePresentation(DebuggerBundle.message("error.context.has.changed")), false);
        }

        @Override
        public void contextAction() throws Exception {
            if (node.isObsolete()) {
                return;
            }
            if (!myContextSet) {
                myValueDescriptor.setContext(myEvaluationContext);
            }
            myValueDescriptor.updateRepresentation(myEvaluationContext, new DescriptorLabelListener() {

                @Override
                public void labelChanged() {
                    Icon nodeIcon = DebuggerTreeRenderer.getValueIcon(myValueDescriptor);
                    final String value = getValueString();
                    @SuppressWarnings("ThrowableResultOfMethodCallIgnored") EvaluateException exception = myValueDescriptor.getEvaluateException();
                    XValuePresentation presentation = new JavaValuePresentation(value, myValueDescriptor.getIdLabel(), exception != null ? exception.getMessage() : null, myValueDescriptor);
                    if (myValueDescriptor.getLastRenderer() instanceof FullValueEvaluatorProvider) {
                        XFullValueEvaluator evaluator = ((FullValueEvaluatorProvider) myValueDescriptor.getLastRenderer()).getFullValueEvaluator(myEvaluationContext, myValueDescriptor);
                        if (evaluator != null) {
                            node.setFullValueEvaluator(evaluator);
                        }
                    } else if (value.length() > XValueNode.MAX_VALUE_LENGTH) {
                        node.setFullValueEvaluator(new JavaFullValueEvaluator(myEvaluationContext) {

                            @Override
                            public void evaluate(@NotNull final XFullValueEvaluationCallback callback) {
                                final ValueDescriptorImpl fullValueDescriptor = myValueDescriptor.getFullValueDescriptor();
                                fullValueDescriptor.updateRepresentation(myEvaluationContext, new DescriptorLabelListener() {

                                    @Override
                                    public void labelChanged() {
                                        callback.evaluated(fullValueDescriptor.getValueText());
                                    }
                                });
                            }
                        });
                    }
                    node.setPresentation(nodeIcon, presentation, myValueDescriptor.isExpandable());
                }
            });
        }
    });
}
Also used : XValuePresentation(com.intellij.xdebugger.frame.presentation.XValuePresentation) SuspendContextCommandImpl(com.intellij.debugger.engine.events.SuspendContextCommandImpl) NotNull(org.jetbrains.annotations.NotNull) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) XErrorValuePresentation(com.intellij.xdebugger.frame.presentation.XErrorValuePresentation)

Example 2 with SuspendContextCommandImpl

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

the class JavaValue method computeChildren.

@Override
public void computeChildren(@NotNull final XCompositeNode node) {
    scheduleCommand(myEvaluationContext, node, new SuspendContextCommandImpl(myEvaluationContext.getSuspendContext()) {

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

        @Override
        public void contextAction() throws Exception {
            final XValueChildrenList children = new XValueChildrenList();
            final NodeRenderer renderer = myValueDescriptor.getRenderer(myEvaluationContext.getDebugProcess());
            final Ref<Integer> remainingNum = new Ref<>(0);
            renderer.buildChildren(myValueDescriptor.getValue(), new ChildrenBuilder() {

                @Override
                public NodeDescriptorFactory getDescriptorManager() {
                    return myNodeManager;
                }

                @Override
                public NodeManager getNodeManager() {
                    return myNodeManager;
                }

                @Override
                public ValueDescriptor getParentDescriptor() {
                    return myValueDescriptor;
                }

                @Override
                public void setRemaining(int remaining) {
                    remainingNum.set(remaining);
                }

                @Override
                public void initChildrenArrayRenderer(ArrayRenderer renderer) {
                    renderer.START_INDEX = myCurrentChildrenStart;
                    renderer.END_INDEX = myCurrentChildrenStart + XCompositeNode.MAX_CHILDREN_TO_SHOW - 1;
                    myCurrentChildrenStart += XCompositeNode.MAX_CHILDREN_TO_SHOW;
                }

                @Override
                public void setChildren(List<DebuggerTreeNode> nodes) {
                    for (DebuggerTreeNode node : nodes) {
                        final NodeDescriptor descriptor = node.getDescriptor();
                        if (descriptor instanceof ValueDescriptorImpl) {
                            // Value is calculated already in NodeManagerImpl
                            children.add(create(JavaValue.this, (ValueDescriptorImpl) descriptor, myEvaluationContext, myNodeManager, false));
                        } else if (descriptor instanceof MessageDescriptor) {
                            children.add(new JavaStackFrame.DummyMessageValueNode(descriptor.getLabel(), null));
                        }
                    }
                }
            }, myEvaluationContext);
            node.addChildren(children, true);
            if (remainingNum.get() > 0) {
                node.tooManyChildren(remainingNum.get());
            }
        }
    });
}
Also used : SuspendContextCommandImpl(com.intellij.debugger.engine.events.SuspendContextCommandImpl) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) Ref(com.intellij.openapi.util.Ref) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with SuspendContextCommandImpl

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

the class JavaValue method calculateEvaluationExpression.

@NotNull
@Override
public Promise<XExpression> calculateEvaluationExpression() {
    if (evaluationExpression != null) {
        return Promise.resolve(evaluationExpression);
    } else {
        final AsyncPromise<XExpression> res = new AsyncPromise<>();
        myEvaluationContext.getManagerThread().schedule(new SuspendContextCommandImpl(myEvaluationContext.getSuspendContext()) {

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

            @Override
            public void contextAction() throws Exception {
                evaluationExpression = ApplicationManager.getApplication().runReadAction(new Computable<XExpression>() {

                    @Override
                    public XExpression compute() {
                        try {
                            PsiElement psiExpression = getDescriptor().getTreeEvaluation(JavaValue.this, getDebuggerContext());
                            if (psiExpression != null) {
                                XExpression res = TextWithImportsImpl.toXExpression(new TextWithImportsImpl(psiExpression));
                                // add runtime imports if any
                                Set<String> imports = psiExpression.getUserData(DebuggerTreeNodeExpression.ADDITIONAL_IMPORTS_KEY);
                                if (imports != null && res != null) {
                                    if (res.getCustomInfo() != null) {
                                        imports.add(res.getCustomInfo());
                                    }
                                    res = new XExpressionImpl(res.getExpression(), res.getLanguage(), StringUtil.join(imports, ","), res.getMode());
                                }
                                return res;
                            }
                        } catch (EvaluateException e) {
                            LOG.info(e);
                        }
                        return null;
                    }
                });
                res.setResult(evaluationExpression);
            }
        });
        return res;
    }
}
Also used : Set(java.util.Set) XExpressionImpl(com.intellij.xdebugger.impl.breakpoints.XExpressionImpl) SuspendContextCommandImpl(com.intellij.debugger.engine.events.SuspendContextCommandImpl) AsyncPromise(org.jetbrains.concurrency.AsyncPromise) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) XExpression(com.intellij.xdebugger.XExpression) TextWithImportsImpl(com.intellij.debugger.engine.evaluation.TextWithImportsImpl) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with SuspendContextCommandImpl

use of com.intellij.debugger.engine.events.SuspendContextCommandImpl 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)

Example 5 with SuspendContextCommandImpl

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

the class DescriptorTestCase method resume.

@Override
protected void resume(final SuspendContextImpl suspendContext) {
    final DebugProcessImpl localProcess = suspendContext.getDebugProcess();
    invokeRatherLater(new SuspendContextCommandImpl(suspendContext) {

        @Override
        public void contextAction() throws Exception {
            flushDescriptors();
            localProcess.getManagerThread().schedule(localProcess.createResumeCommand(suspendContext, Priority.LOW));
        }
    });
}
Also used : DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) SuspendContextCommandImpl(com.intellij.debugger.engine.events.SuspendContextCommandImpl) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException)

Aggregations

SuspendContextCommandImpl (com.intellij.debugger.engine.events.SuspendContextCommandImpl)14 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)9 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)3 NotNull (org.jetbrains.annotations.NotNull)3 EvaluationContextImpl (com.intellij.debugger.engine.evaluation.EvaluationContextImpl)2 DebuggerCommandImpl (com.intellij.debugger.engine.events.DebuggerCommandImpl)2 ExecutionException (com.intellij.execution.ExecutionException)2 Project (com.intellij.openapi.project.Project)2 PsiElement (com.intellij.psi.PsiElement)2 CompoundRuntimeException (com.intellij.util.lang.CompoundRuntimeException)2 VMDisconnectedException (com.sun.jdi.VMDisconnectedException)2 EvaluatingComputable (com.intellij.debugger.EvaluatingComputable)1 NoDataException (com.intellij.debugger.NoDataException)1 SourcePosition (com.intellij.debugger.SourcePosition)1 JavaValue (com.intellij.debugger.engine.JavaValue)1 SuspendContextImpl (com.intellij.debugger.engine.SuspendContextImpl)1 TextWithImportsImpl (com.intellij.debugger.engine.evaluation.TextWithImportsImpl)1 DebuggerContextCommandImpl (com.intellij.debugger.engine.events.DebuggerContextCommandImpl)1 SuspendContextCommand (com.intellij.debugger.engine.managerThread.SuspendContextCommand)1 LocatableEventRequestor (com.intellij.debugger.engine.requests.LocatableEventRequestor)1