Search in sources :

Example 16 with Value

use of com.sun.jdi.Value in project intellij-community by JetBrains.

the class UnaryExpressionEvaluator method evaluate.

public Object evaluate(EvaluationContextImpl context) throws EvaluateException {
    Value operand = (Value) myOperandEvaluator.evaluate(context);
    VirtualMachineProxyImpl vm = context.getDebugProcess().getVirtualMachineProxy();
    if (myOperationType == JavaTokenType.PLUS) {
        if (DebuggerUtils.isNumeric(operand)) {
            return operand;
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.numeric.expected"));
    } else if (myOperationType == JavaTokenType.MINUS) {
        if (DebuggerUtils.isInteger(operand)) {
            long v = ((PrimitiveValue) operand).longValue();
            return DebuggerUtilsEx.createValue(vm, myExpectedType, -v);
        }
        if (DebuggerUtils.isNumeric(operand)) {
            double v = ((PrimitiveValue) operand).doubleValue();
            return DebuggerUtilsEx.createValue(vm, myExpectedType, -v);
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.numeric.expected"));
    } else if (myOperationType == JavaTokenType.TILDE) {
        if (DebuggerUtils.isInteger(operand)) {
            long v = ((PrimitiveValue) operand).longValue();
            return DebuggerUtilsEx.createValue(vm, myExpectedType, ~v);
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.integer.expected"));
    } else if (myOperationType == JavaTokenType.EXCL) {
        if (operand instanceof BooleanValue) {
            boolean v = ((BooleanValue) operand).booleanValue();
            return DebuggerUtilsEx.createValue(vm, myExpectedType, !v);
        }
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.boolean.expected"));
    }
    throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.operation.not.supported", myOperationText));
}
Also used : VirtualMachineProxyImpl(com.intellij.debugger.jdi.VirtualMachineProxyImpl) BooleanValue(com.sun.jdi.BooleanValue) PrimitiveValue(com.sun.jdi.PrimitiveValue) BooleanValue(com.sun.jdi.BooleanValue) Value(com.sun.jdi.Value) PrimitiveValue(com.sun.jdi.PrimitiveValue)

Example 17 with Value

use of com.sun.jdi.Value in project intellij-community by JetBrains.

the class ValueHint method evaluateAndShowHint.

@Override
protected void evaluateAndShowHint() {
    final DebuggerContextImpl debuggerContext = DebuggerManagerEx.getInstanceEx(getProject()).getContext();
    final DebuggerSession debuggerSession = debuggerContext.getDebuggerSession();
    if (debuggerSession == null || !debuggerSession.isPaused())
        return;
    try {
        final ExpressionEvaluator evaluator = getExpressionEvaluator(debuggerContext);
        if (evaluator == null)
            return;
        debuggerContext.getDebugProcess().getManagerThread().schedule(new DebuggerContextCommandImpl(debuggerContext) {

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

            @Override
            public void threadAction() {
                try {
                    final EvaluationContextImpl evaluationContext = debuggerContext.createEvaluationContext();
                    final String expressionText = ApplicationManager.getApplication().runReadAction(new Computable<String>() {

                        @Override
                        public String compute() {
                            return myCurrentExpression.getText();
                        }
                    });
                    final TextWithImports text = new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, expressionText);
                    final Value value = myValueToShow != null ? myValueToShow : evaluator.evaluate(evaluationContext);
                    final WatchItemDescriptor descriptor = new WatchItemDescriptor(getProject(), text, value);
                    if (!isActiveTooltipApplicable(value) || getType() == ValueHintType.MOUSE_OVER_HINT) {
                        if (getType() == ValueHintType.MOUSE_OVER_HINT) {
                            // force using default renderer for mouse over hint in order to not to call accidentally methods while rendering
                            // otherwise, if the hint is invoked explicitly, show it with the right "auto" renderer
                            descriptor.setRenderer(DebugProcessImpl.getDefaultRenderer(value));
                        }
                        descriptor.updateRepresentation(evaluationContext, new DescriptorLabelListener() {

                            @Override
                            public void labelChanged() {
                                if (getCurrentRange() != null) {
                                    if (getType() != ValueHintType.MOUSE_OVER_HINT || descriptor.isValueValid()) {
                                        final SimpleColoredText simpleColoredText = DebuggerTreeRenderer.getDescriptorText(debuggerContext, descriptor, true);
                                        if (isActiveTooltipApplicable(value)) {
                                            simpleColoredText.append(" (" + DebuggerBundle.message("active.tooltip.suggestion") + ")", SimpleTextAttributes.GRAYED_ATTRIBUTES);
                                        }
                                        showHint(simpleColoredText, descriptor);
                                    }
                                }
                            }
                        });
                    } else {
                        createAndShowTree(expressionText, descriptor);
                    }
                } catch (EvaluateException e) {
                    LOG.debug(e);
                }
            }
        });
    } catch (EvaluateException e) {
        LOG.debug(e);
    }
}
Also used : SimpleColoredText(com.intellij.ui.SimpleColoredText) DescriptorLabelListener(com.intellij.debugger.ui.tree.render.DescriptorLabelListener) ExpressionEvaluator(com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator) WatchItemDescriptor(com.intellij.debugger.ui.impl.watch.WatchItemDescriptor) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) PrimitiveValue(com.sun.jdi.PrimitiveValue) Value(com.sun.jdi.Value) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl) DebuggerContextCommandImpl(com.intellij.debugger.engine.events.DebuggerContextCommandImpl)

Example 18 with Value

use of com.sun.jdi.Value in project intellij-community by JetBrains.

the class ExpressionChildrenRenderer method getChildValueExpression.

public PsiExpression getChildValueExpression(DebuggerTreeNode node, DebuggerContext context) throws EvaluateException {
    Value expressionValue = node.getParent().getDescriptor().getUserData(EXPRESSION_VALUE);
    if (expressionValue == null) {
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("error.unable.to.evaluate.expression"));
    }
    NodeRenderer childrenRenderer = getChildrenRenderer(expressionValue, (ValueDescriptor) node.getParent().getDescriptor());
    PsiExpression childrenPsiExpression = myChildrenExpression.getPsiExpression(node.getProject());
    if (childrenPsiExpression == null) {
        return null;
    }
    return DebuggerTreeNodeExpression.substituteThis(childrenRenderer.getChildValueExpression(node, context), (PsiExpression) childrenPsiExpression.copy(), expressionValue);
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) BooleanValue(com.sun.jdi.BooleanValue) Value(com.sun.jdi.Value)

Example 19 with Value

use of com.sun.jdi.Value in project intellij-community by JetBrains.

the class ExpressionChildrenRenderer method isExpandable.

public boolean isExpandable(Value value, final EvaluationContext context, NodeDescriptor parentDescriptor) {
    final EvaluationContext evaluationContext = context.createEvaluationContext(value);
    if (!StringUtil.isEmpty(myChildrenExpandable.getReferenceExpression().getText())) {
        try {
            Value expanded = myChildrenExpandable.getEvaluator(evaluationContext.getProject()).evaluate(evaluationContext);
            if (expanded instanceof BooleanValue) {
                return ((BooleanValue) expanded).booleanValue();
            }
        } catch (EvaluateException e) {
        // ignored
        }
    }
    try {
        Value children = evaluateChildren(evaluationContext, parentDescriptor);
        ChildrenRenderer defaultChildrenRenderer = DebugProcessImpl.getDefaultRenderer(value.type());
        return defaultChildrenRenderer.isExpandable(children, evaluationContext, parentDescriptor);
    } catch (EvaluateException e) {
        return true;
    }
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) BooleanValue(com.sun.jdi.BooleanValue) BooleanValue(com.sun.jdi.BooleanValue) Value(com.sun.jdi.Value) EvaluationContext(com.intellij.debugger.engine.evaluation.EvaluationContext)

Example 20 with Value

use of com.sun.jdi.Value in project intellij-community by JetBrains.

the class ExpressionChildrenRenderer method evaluateChildren.

private Value evaluateChildren(EvaluationContext context, NodeDescriptor descriptor) throws EvaluateException {
    final ExpressionEvaluator evaluator = myChildrenExpression.getEvaluator(context.getProject());
    Value value = evaluator.evaluate(context);
    DebuggerUtilsEx.keep(value, context);
    descriptor.putUserData(EXPRESSION_VALUE, value);
    return value;
}
Also used : BooleanValue(com.sun.jdi.BooleanValue) Value(com.sun.jdi.Value) ExpressionEvaluator(com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator)

Aggregations

Value (com.sun.jdi.Value)23 BooleanValue (com.sun.jdi.BooleanValue)9 PrimitiveValue (com.sun.jdi.PrimitiveValue)7 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)6 ObjectReference (com.sun.jdi.ObjectReference)5 ExpressionEvaluator (com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator)4 IntegerValue (com.sun.jdi.IntegerValue)4 ValueDescriptor (com.intellij.debugger.ui.tree.ValueDescriptor)3 DoubleValue (com.sun.jdi.DoubleValue)3 FloatValue (com.sun.jdi.FloatValue)3 LongValue (com.sun.jdi.LongValue)3 SourcePosition (com.intellij.debugger.SourcePosition)2 EvaluationContext (com.intellij.debugger.engine.evaluation.EvaluationContext)2 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)2 NodeDescriptor (com.intellij.debugger.ui.tree.NodeDescriptor)2 Project (com.intellij.openapi.project.Project)2 AbstractValueHint (com.intellij.xdebugger.impl.evaluate.quick.common.AbstractValueHint)2 AbsentInformationException (com.sun.jdi.AbsentInformationException)2 Method (com.sun.jdi.Method)2 StackFrame (com.sun.jdi.StackFrame)2