Search in sources :

Example 1 with BooleanValue

use of com.sun.jdi.BooleanValue in project che by eclipse.

the class Evaluator method operation.

public ExpressionValue operation(ExpressionValue leftExpression, ExpressionValue rightExpression, int op) {
    if (JavaParser.ASSIGN == op) {
        leftExpression.setValue(rightExpression.getValue());
        return leftExpression;
    }
    Value leftValue = leftExpression.getValue();
    Value rightValue = rightExpression.getValue();
    if (leftValue instanceof StringReference || rightValue instanceof StringReference) {
        if (JavaParser.PLUS == op) {
            return value(valueToString(leftValue) + valueToString(rightValue));
        }
    }
    if (leftValue instanceof ObjectReference || rightValue instanceof ObjectReference) {
        switch(op) {
            case JavaParser.EQUAL:
                return value(leftValue != null ? leftValue.equals(rightValue) : rightValue == null);
            case JavaParser.NOT_EQUAL:
                return value(!(leftValue != null ? leftValue.equals(rightValue) : rightValue == null));
            default:
                throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
        }
    }
    if (leftValue == null || rightValue == null) {
        // Neither one is object and operation is not assignation.
        throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
    }
    PrimitiveValue lp = (PrimitiveValue) leftValue;
    PrimitiveValue rp = (PrimitiveValue) rightValue;
    if (lp instanceof BooleanValue && rp instanceof BooleanValue) {
        switch(op) {
            case JavaParser.LOGICAL_AND:
                return value(lp.booleanValue() && rp.booleanValue());
            case JavaParser.LOGICAL_OR:
                return value(lp.booleanValue() || rp.booleanValue());
            case JavaParser.EQUAL:
                return value(lp.booleanValue() == rp.booleanValue());
            case JavaParser.NOT_EQUAL:
                return value(lp.booleanValue() != rp.booleanValue());
            case JavaParser.OR:
                return value(lp.booleanValue() | rp.booleanValue());
            case JavaParser.XOR:
                return value(lp.booleanValue() ^ rp.booleanValue());
            case JavaParser.AND:
                return value(lp.booleanValue() & rp.booleanValue());
            case JavaParser.OR_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.booleanValue() | rp.booleanValue()));
                return leftExpression;
            case JavaParser.XOR_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.booleanValue() ^ rp.booleanValue()));
                return leftExpression;
            case JavaParser.AND_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.booleanValue() & rp.booleanValue()));
                return leftExpression;
            default:
                throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
        }
    }
    switch(op) {
        case JavaParser.EQUAL:
            return value(lp.doubleValue() == rp.doubleValue());
        case JavaParser.NOT_EQUAL:
            return value(lp.doubleValue() != rp.doubleValue());
        case JavaParser.GREATER_THAN:
            return value(lp.doubleValue() > rp.doubleValue());
        case JavaParser.LESS_THAN:
            return value(lp.doubleValue() < rp.doubleValue());
        case JavaParser.GREATER_OR_EQUAL:
            return value(lp.doubleValue() >= rp.doubleValue());
        case JavaParser.LESS_OR_EQUAL:
            return value(lp.doubleValue() <= rp.doubleValue());
    }
    if (lp instanceof DoubleValue || rp instanceof DoubleValue) {
        switch(op) {
            case JavaParser.PLUS:
                return value(lp.doubleValue() + rp.doubleValue());
            case JavaParser.MINUS:
                return value(lp.doubleValue() - rp.doubleValue());
            case JavaParser.STAR:
                return value(lp.doubleValue() * rp.doubleValue());
            case JavaParser.DIV:
                return value(lp.doubleValue() / rp.doubleValue());
            case JavaParser.MOD:
                return value(lp.doubleValue() % rp.doubleValue());
            case JavaParser.PLUS_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.doubleValue() + rp.doubleValue()));
                return leftExpression;
            case JavaParser.MINUS_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.doubleValue() - rp.doubleValue()));
                return leftExpression;
            case JavaParser.STAR_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.doubleValue() * rp.doubleValue()));
                return leftExpression;
            case JavaParser.DIV_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.doubleValue() / rp.doubleValue()));
                return leftExpression;
            case JavaParser.MOD_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.doubleValue() % rp.doubleValue()));
                return leftExpression;
            default:
                throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
        }
    }
    if (lp instanceof FloatValue || rp instanceof FloatValue) {
        switch(op) {
            case JavaParser.PLUS:
                return value(lp.floatValue() + rp.floatValue());
            case JavaParser.MINUS:
                return value(lp.floatValue() - rp.floatValue());
            case JavaParser.STAR:
                return value(lp.floatValue() * rp.floatValue());
            case JavaParser.DIV:
                return value(lp.floatValue() / rp.floatValue());
            case JavaParser.MOD:
                return value(lp.floatValue() % rp.floatValue());
            case JavaParser.PLUS_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.floatValue() + rp.floatValue()));
                return leftExpression;
            case JavaParser.MINUS_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.floatValue() - rp.floatValue()));
                return leftExpression;
            case JavaParser.STAR_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.floatValue() * rp.longValue()));
                return leftExpression;
            case JavaParser.DIV_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.floatValue() / rp.floatValue()));
                return leftExpression;
            case JavaParser.MOD_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.floatValue() % rp.floatValue()));
                return leftExpression;
            default:
                throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
        }
    }
    if (lp instanceof LongValue || rp instanceof LongValue) {
        switch(op) {
            case JavaParser.PLUS:
                return value(lp.longValue() + rp.longValue());
            case JavaParser.MINUS:
                return value(lp.longValue() - rp.longValue());
            case JavaParser.STAR:
                return value(lp.longValue() * rp.longValue());
            case JavaParser.DIV:
                return value(lp.longValue() / rp.longValue());
            case JavaParser.MOD:
                return value(lp.longValue() % rp.longValue());
            case JavaParser.SHIFT_LEFT:
                return value(lp.longValue() << rp.longValue());
            case JavaParser.SHIFT_RIGHT:
                return value(lp.longValue() >> rp.longValue());
            case JavaParser.BIT_SHIFT_RIGHT:
                return value(lp.longValue() >>> rp.longValue());
            case JavaParser.OR:
                return value(lp.longValue() | rp.longValue());
            case JavaParser.XOR:
                return value(lp.longValue() ^ rp.longValue());
            case JavaParser.AND:
                return value(lp.longValue() & rp.longValue());
            case JavaParser.PLUS_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() + rp.longValue()));
                return leftExpression;
            case JavaParser.MINUS_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() - rp.longValue()));
                return leftExpression;
            case JavaParser.STAR_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() * rp.longValue()));
                return leftExpression;
            case JavaParser.DIV_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() / rp.longValue()));
                return leftExpression;
            case JavaParser.OR_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() | rp.longValue()));
                return leftExpression;
            case JavaParser.XOR_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() ^ rp.longValue()));
                return leftExpression;
            case JavaParser.AND_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() & rp.longValue()));
                return leftExpression;
            case JavaParser.SHIFT_LEFT_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() << rp.longValue()));
                return leftExpression;
            case JavaParser.SHIFT_RIGHT_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() >> rp.longValue()));
                return leftExpression;
            case JavaParser.BIT_SHIFT_RIGHT_ASSIGN:
                leftExpression.setValue(vm.mirrorOf(lp.longValue() >>> rp.longValue()));
                return leftExpression;
            default:
                throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
        }
    }
    switch(op) {
        case JavaParser.PLUS:
            return value(lp.intValue() + rp.intValue());
        case JavaParser.MINUS:
            return value(lp.intValue() - rp.intValue());
        case JavaParser.STAR:
            return value(lp.intValue() * rp.intValue());
        case JavaParser.DIV:
            return value(lp.intValue() / rp.intValue());
        case JavaParser.MOD:
            return value(lp.intValue() % rp.intValue());
        case JavaParser.SHIFT_LEFT:
            return value(lp.intValue() << rp.intValue());
        case JavaParser.SHIFT_RIGHT:
            return value(lp.intValue() >> rp.intValue());
        case JavaParser.BIT_SHIFT_RIGHT:
            return value(lp.intValue() >>> rp.intValue());
        case JavaParser.OR:
            return value(lp.intValue() | rp.intValue());
        case JavaParser.XOR:
            return value(lp.intValue() ^ rp.intValue());
        case JavaParser.AND:
            return value(lp.intValue() & rp.intValue());
        case JavaParser.PLUS_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() + rp.intValue()));
            return leftExpression;
        case JavaParser.MINUS_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() - rp.intValue()));
            return leftExpression;
        case JavaParser.STAR_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() * rp.intValue()));
            return leftExpression;
        case JavaParser.DIV_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() / rp.intValue()));
            return leftExpression;
        case JavaParser.OR_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() | rp.intValue()));
            return leftExpression;
        case JavaParser.XOR_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() ^ rp.intValue()));
            return leftExpression;
        case JavaParser.AND_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() & rp.intValue()));
            return leftExpression;
        case JavaParser.SHIFT_LEFT_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() << rp.intValue()));
            return leftExpression;
        case JavaParser.SHIFT_RIGHT_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() >> rp.intValue()));
            return leftExpression;
        case JavaParser.BIT_SHIFT_RIGHT_ASSIGN:
            leftExpression.setValue(vm.mirrorOf(lp.intValue() >>> rp.intValue()));
            return leftExpression;
        default:
            throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + leftValue + " and " + rightValue);
    }
}
Also used : ObjectReference(com.sun.jdi.ObjectReference) DoubleValue(com.sun.jdi.DoubleValue) BooleanValue(com.sun.jdi.BooleanValue) PrimitiveValue(com.sun.jdi.PrimitiveValue) IntegerValue(com.sun.jdi.IntegerValue) LongValue(com.sun.jdi.LongValue) DoubleValue(com.sun.jdi.DoubleValue) BooleanValue(com.sun.jdi.BooleanValue) FloatValue(com.sun.jdi.FloatValue) Value(com.sun.jdi.Value) LongValue(com.sun.jdi.LongValue) FloatValue(com.sun.jdi.FloatValue) StringReference(com.sun.jdi.StringReference) PrimitiveValue(com.sun.jdi.PrimitiveValue)

Example 2 with BooleanValue

use of com.sun.jdi.BooleanValue in project gravel by gravel-st.

the class VMTargetRemoteTest method testEvaluate.

@Test
public void testEvaluate() throws Throwable {
    ObjectReference promise = remote.evaluateForked("3+4");
    ThreadReference thread = ((ThreadReference) remote.invokeMethod(promise, "thread"));
    Value result1 = remote.invokeMethod(promise, "result");
    Value ex = remote.invokeMethod(promise, "throwable");
    printThreadState();
    VMTargetStarter.sleep(100);
    printThreadState();
    boolean isFinished = ((BooleanValue) remote.invokeMethod(promise, "isFinished")).booleanValue();
    assertTrue(isFinished);
    ObjectReference result = (ObjectReference) remote.invokeMethod(promise, "result");
    IntegerValue intValue = (IntegerValue) remote.invokeMethod(result, "intValue");
    assertEquals(7, intValue.intValue());
}
Also used : ObjectReference(com.sun.jdi.ObjectReference) BooleanValue(com.sun.jdi.BooleanValue) IntegerValue(com.sun.jdi.IntegerValue) IntegerValue(com.sun.jdi.IntegerValue) BooleanValue(com.sun.jdi.BooleanValue) Value(com.sun.jdi.Value) ThreadReference(com.sun.jdi.ThreadReference) Test(org.junit.Test)

Example 3 with BooleanValue

use of com.sun.jdi.BooleanValue in project che by eclipse.

the class Evaluator method unaryOperation.

public ExpressionValue unaryOperation(ExpressionValue expression, int op) {
    Value value = expression.getValue();
    if (!(value instanceof PrimitiveValue)) {
        throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + value);
    }
    if (value instanceof BooleanValue) {
        if (op == JavaParser.LOGICAL_NOT) {
            return value(!((BooleanValue) value).value());
        }
    }
    // TODO add support for other unary operations
    PrimitiveValue pv = (PrimitiveValue) value;
    if (pv instanceof DoubleValue) {
        switch(op) {
            case JavaParser.UNARY_PLUS:
                return value(pv.doubleValue());
            case JavaParser.UNARY_MINUS:
                return value(-pv.doubleValue());
            default:
                throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + value);
        }
    }
    if (pv instanceof FloatValue) {
        switch(op) {
            case JavaParser.UNARY_PLUS:
                return value(pv.floatValue());
            case JavaParser.UNARY_MINUS:
                return value(-pv.floatValue());
            default:
                throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + value);
        }
    }
    if (pv instanceof LongValue) {
        switch(op) {
            case JavaParser.NOT:
                return value(~pv.longValue());
            case JavaParser.UNARY_PLUS:
                return value(pv.longValue());
            case JavaParser.UNARY_MINUS:
                return value(-pv.longValue());
            default:
                throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + value);
        }
    }
    switch(op) {
        case JavaParser.NOT:
            return value(~pv.intValue());
        case JavaParser.UNARY_PLUS:
            return value(pv.intValue());
        case JavaParser.UNARY_MINUS:
            return value(-pv.intValue());
        default:
            throw new ExpressionException("Unsupported operation " + JavaParser.tokenNames[op] + " for " + value);
    }
}
Also used : DoubleValue(com.sun.jdi.DoubleValue) BooleanValue(com.sun.jdi.BooleanValue) PrimitiveValue(com.sun.jdi.PrimitiveValue) IntegerValue(com.sun.jdi.IntegerValue) LongValue(com.sun.jdi.LongValue) DoubleValue(com.sun.jdi.DoubleValue) BooleanValue(com.sun.jdi.BooleanValue) FloatValue(com.sun.jdi.FloatValue) Value(com.sun.jdi.Value) LongValue(com.sun.jdi.LongValue) FloatValue(com.sun.jdi.FloatValue) PrimitiveValue(com.sun.jdi.PrimitiveValue)

Example 4 with BooleanValue

use of com.sun.jdi.BooleanValue 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 5 with BooleanValue

use of com.sun.jdi.BooleanValue 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)

Aggregations

BooleanValue (com.sun.jdi.BooleanValue)6 Value (com.sun.jdi.Value)5 IntegerValue (com.sun.jdi.IntegerValue)3 ObjectReference (com.sun.jdi.ObjectReference)3 PrimitiveValue (com.sun.jdi.PrimitiveValue)3 DoubleValue (com.sun.jdi.DoubleValue)2 FloatValue (com.sun.jdi.FloatValue)2 LongValue (com.sun.jdi.LongValue)2 StringReference (com.sun.jdi.StringReference)2 ThreadReference (com.sun.jdi.ThreadReference)2 Test (org.junit.Test)2 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)1 EvaluationContext (com.intellij.debugger.engine.evaluation.EvaluationContext)1 VirtualMachineProxyImpl (com.intellij.debugger.jdi.VirtualMachineProxyImpl)1