Search in sources :

Example 11 with EvaluateException

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

the class BoxingEvaluator method convertToWrapper.

private static Value convertToWrapper(EvaluationContextImpl context, PrimitiveValue value, String wrapperTypeName) throws EvaluateException {
    final DebugProcessImpl process = context.getDebugProcess();
    final ClassType wrapperClass = (ClassType) process.findClass(context, wrapperTypeName, null);
    final String methodSignature = "(" + JVMNameUtil.getPrimitiveSignature(value.type().name()) + ")L" + wrapperTypeName.replace('.', '/') + ";";
    Method method = wrapperClass.concreteMethodByName("valueOf", methodSignature);
    if (method == null) {
        // older JDK version
        method = wrapperClass.concreteMethodByName(JVMNameUtil.CONSTRUCTOR_NAME, methodSignature);
    }
    if (method == null) {
        throw new EvaluateException("Cannot construct wrapper object for value of type " + value.type() + ": Unable to find either valueOf() or constructor method");
    }
    return process.invokeMethod(context, wrapperClass, method, Collections.singletonList(value));
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl)

Example 12 with EvaluateException

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

the class BoxingEvaluator method evaluate.

public Object evaluate(EvaluationContextImpl context) throws EvaluateException {
    final Object result = myOperand.evaluate(context);
    if (result == null || result instanceof ObjectReference) {
        return result;
    }
    if (result instanceof PrimitiveValue) {
        PrimitiveValue primitiveValue = (PrimitiveValue) result;
        PsiPrimitiveType primitiveType = PsiJavaParserFacadeImpl.getPrimitiveType(primitiveValue.type().name());
        if (primitiveType != null) {
            return convertToWrapper(context, primitiveValue, primitiveType.getBoxedTypeName());
        }
    }
    throw new EvaluateException("Cannot perform boxing conversion for a value of type " + ((Value) result).type().name());
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) PsiPrimitiveType(com.intellij.psi.PsiPrimitiveType)

Example 13 with EvaluateException

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

the class StackFrameProxyImpl method getStackFrame.

/**
   * Use with caution. Better access stackframe data through the Proxy's methods
   */
@Override
public StackFrame getStackFrame() throws EvaluateException {
    DebuggerManagerThreadImpl.assertIsManagerThread();
    checkValid();
    if (myStackFrame == null) {
        try {
            final ThreadReference threadRef = myThreadProxy.getThreadReference();
            myStackFrame = threadRef.frame(getFrameIndex());
        } catch (IndexOutOfBoundsException e) {
            throw new EvaluateException(e.getMessage(), e);
        } catch (ObjectCollectedException ignored) {
            throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.thread.collected"));
        } catch (IncompatibleThreadStateException e) {
            throw EvaluateExceptionUtil.createEvaluateException(e);
        }
    }
    return myStackFrame;
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException)

Example 14 with EvaluateException

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

the class NewClassInstanceEvaluator method evaluate.

public Object evaluate(EvaluationContextImpl context) throws EvaluateException {
    DebugProcessImpl debugProcess = context.getDebugProcess();
    Object obj = myClassTypeEvaluator.evaluate(context);
    if (!(obj instanceof ClassType)) {
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.cannot.evaluate.class.type"));
    }
    ClassType classType = (ClassType) obj;
    // find constructor
    Method method = DebuggerUtils.findMethod(classType, JVMNameUtil.CONSTRUCTOR_NAME, myConstructorSignature.getName(debugProcess));
    if (method == null) {
        throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.cannot.resolve.constructor", myConstructorSignature.getDisplayName(debugProcess)));
    }
    // evaluate arguments
    List<Value> arguments;
    if (!ArrayUtil.isEmpty(myParamsEvaluators)) {
        arguments = new ArrayList<>(myParamsEvaluators.length);
        for (Evaluator evaluator : myParamsEvaluators) {
            Object res = evaluator.evaluate(context);
            if (!(res instanceof Value) && res != null) {
                LOG.error("Unable to call newInstance, evaluator " + evaluator + " result is not Value, but " + res);
            }
            //noinspection ConstantConditions
            arguments.add((Value) res);
        }
    } else {
        arguments = Collections.emptyList();
    }
    ObjectReference objRef;
    try {
        objRef = debugProcess.newInstance(context, classType, method, arguments);
    } catch (EvaluateException e) {
        throw EvaluateExceptionUtil.createEvaluateException(e);
    }
    return objRef;
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl)

Example 15 with EvaluateException

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

the class UnBoxingEvaluator method convertToPrimitive.

private static Value convertToPrimitive(EvaluationContextImpl context, ObjectReference value, final String conversionMethodName, String conversionMethodSignature) throws EvaluateException {
    final DebugProcessImpl process = context.getDebugProcess();
    final ClassType wrapperClass = (ClassType) value.referenceType();
    Method method = wrapperClass.concreteMethodByName(conversionMethodName, conversionMethodSignature);
    if (method == null) {
        throw new EvaluateException("Cannot convert to primitive value of type " + value.type() + ": Unable to find method " + conversionMethodName + conversionMethodSignature);
    }
    return process.invokeMethod(context, value, method, Collections.emptyList());
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) Method(com.sun.jdi.Method) ClassType(com.sun.jdi.ClassType)

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