Search in sources :

Example 26 with EvaluateException

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

the class NodeDescriptorFactoryImpl method createDescriptorTree.

private static DescriptorTree createDescriptorTree(final StackFrameProxy frameProxy, final DescriptorTree fromTree) {
    int frameCount = -1;
    int frameIndex = -1;
    if (frameProxy != null) {
        try {
            final ThreadReferenceProxy threadReferenceProxy = frameProxy.threadProxy();
            frameCount = threadReferenceProxy.frameCount();
            frameIndex = frameProxy.getFrameIndex();
        } catch (EvaluateException e) {
        // ignored
        }
    }
    final boolean isInitial = !fromTree.frameIdEquals(frameCount, frameIndex);
    DescriptorTree descriptorTree = new DescriptorTree(isInitial);
    descriptorTree.setFrameId(frameCount, frameIndex);
    return descriptorTree;
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) ThreadReferenceProxy(com.intellij.debugger.engine.jdi.ThreadReferenceProxy)

Example 27 with EvaluateException

use of com.intellij.debugger.engine.evaluation.EvaluateException 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 28 with EvaluateException

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

the class ArrayElementDescriptorImpl method getModifier.

@Override
public XValueModifier getModifier(JavaValue value) {
    return new JavaValueModifier(value) {

        @Override
        protected void setValueImpl(@NotNull String expression, @NotNull XModificationCallback callback) {
            final ArrayElementDescriptorImpl elementDescriptor = ArrayElementDescriptorImpl.this;
            final ArrayReference array = elementDescriptor.getArray();
            if (array != null) {
                if (VirtualMachineProxyImpl.isCollected(array)) {
                    // will only be the case if debugger does not use ObjectReference.disableCollection() because of Patches.IBM_JDK_DISABLE_COLLECTION_BUG
                    Messages.showWarningDialog(getProject(), DebuggerBundle.message("evaluation.error.array.collected") + "\n" + DebuggerBundle.message("warning.recalculate"), DebuggerBundle.message("title.set.value"));
                    //node.getParent().calcValue();
                    return;
                }
                final ArrayType arrType = (ArrayType) array.referenceType();
                final DebuggerContextImpl debuggerContext = DebuggerManagerEx.getInstanceEx(getProject()).getContext();
                set(expression, callback, debuggerContext, new SetValueRunnable() {

                    public void setValue(EvaluationContextImpl evaluationContext, Value newValue) throws ClassNotLoadedException, InvalidTypeException, EvaluateException {
                        array.setValue(elementDescriptor.getIndex(), preprocessValue(evaluationContext, newValue, arrType.componentType()));
                        update(debuggerContext);
                    }

                    public ReferenceType loadClass(EvaluationContextImpl evaluationContext, String className) throws InvocationException, ClassNotLoadedException, IncompatibleThreadStateException, InvalidTypeException, EvaluateException {
                        return evaluationContext.getDebugProcess().loadClass(evaluationContext, className, arrType.classLoader());
                    }
                });
            }
        }
    };
}
Also used : NotNull(org.jetbrains.annotations.NotNull) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) JavaValueModifier(com.intellij.debugger.engine.JavaValueModifier) EvaluationContextImpl(com.intellij.debugger.engine.evaluation.EvaluationContextImpl) JavaValue(com.intellij.debugger.engine.JavaValue) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl)

Example 29 with EvaluateException

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

the class DebuggerTreeNodeExpression method createEvaluationText.

public static TextWithImports createEvaluationText(final DebuggerTreeNodeImpl node, final DebuggerContextImpl context) throws EvaluateException {
    final EvaluateException[] ex = new EvaluateException[] { null };
    final TextWithImports textWithImports = PsiDocumentManager.getInstance(context.getProject()).commitAndRunReadAction((Computable<TextWithImports>) () -> {
        try {
            final PsiExpression expressionText = getEvaluationExpression(node, context);
            if (expressionText != null) {
                return new TextWithImportsImpl(expressionText);
            }
        } catch (EvaluateException e) {
            ex[0] = e;
        }
        return null;
    });
    if (ex[0] != null) {
        throw ex[0];
    }
    return textWithImports;
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) TextWithImports(com.intellij.debugger.engine.evaluation.TextWithImports) TextWithImportsImpl(com.intellij.debugger.engine.evaluation.TextWithImportsImpl)

Example 30 with EvaluateException

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

the class ExpressionChildrenRenderer method buildChildren.

public void buildChildren(final Value value, final ChildrenBuilder builder, final EvaluationContext evaluationContext) {
    final NodeManager nodeManager = builder.getNodeManager();
    try {
        final ValueDescriptor parentDescriptor = builder.getParentDescriptor();
        final Value childrenValue = evaluateChildren(evaluationContext.createEvaluationContext(value), parentDescriptor);
        NodeRenderer renderer = getChildrenRenderer(childrenValue, parentDescriptor);
        renderer.buildChildren(childrenValue, builder, evaluationContext);
    } catch (final EvaluateException e) {
        List<DebuggerTreeNode> errorChildren = new ArrayList<>();
        errorChildren.add(nodeManager.createMessageNode(DebuggerBundle.message("error.unable.to.evaluate.expression") + " " + e.getMessage()));
        builder.setChildren(errorChildren);
    }
}
Also used : NodeManager(com.intellij.debugger.ui.tree.NodeManager) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) ValueDescriptor(com.intellij.debugger.ui.tree.ValueDescriptor) BooleanValue(com.sun.jdi.BooleanValue) Value(com.sun.jdi.Value) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)62 StackFrameProxyImpl (com.intellij.debugger.jdi.StackFrameProxyImpl)13 NotNull (org.jetbrains.annotations.NotNull)12 Nullable (org.jetbrains.annotations.Nullable)12 EvaluationContextImpl (com.intellij.debugger.engine.evaluation.EvaluationContextImpl)11 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)10 DebuggerContextImpl (com.intellij.debugger.impl.DebuggerContextImpl)10 SourcePosition (com.intellij.debugger.SourcePosition)8 JavaValue (com.intellij.debugger.engine.JavaValue)8 JavaValueModifier (com.intellij.debugger.engine.JavaValueModifier)6 Value (com.sun.jdi.Value)6 Project (com.intellij.openapi.project.Project)5 IncorrectOperationException (com.intellij.util.IncorrectOperationException)5 Method (com.sun.jdi.Method)5 ObjectReference (com.sun.jdi.ObjectReference)5 TextWithImports (com.intellij.debugger.engine.evaluation.TextWithImports)4 ExpressionEvaluator (com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator)4 SuspendContextCommandImpl (com.intellij.debugger.engine.events.SuspendContextCommandImpl)4 SuspendContextImpl (com.intellij.debugger.engine.SuspendContextImpl)3 DebuggerContextCommandImpl (com.intellij.debugger.engine.events.DebuggerContextCommandImpl)3