Search in sources :

Example 21 with EvaluateException

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

the class ClassObjectRenderer method getFullValueEvaluator.

@Nullable
@Override
public XFullValueEvaluator getFullValueEvaluator(final EvaluationContextImpl evaluationContext, final ValueDescriptorImpl valueDescriptor) {
    return new JavaValue.JavaFullValueEvaluator(DebuggerBundle.message("message.node.navigate"), evaluationContext) {

        @Override
        public void evaluate(@NotNull XFullValueEvaluationCallback callback) {
            Value value = valueDescriptor.getValue();
            ClassType type = ((ClassType) value.type());
            Method nameMethod = type.concreteMethodByName("getName", "()Ljava/lang/String;");
            if (nameMethod != null) {
                try {
                    final DebugProcessImpl process = evaluationContext.getDebugProcess();
                    Value res = process.invokeMethod(evaluationContext, (ObjectReference) value, nameMethod, Collections.emptyList());
                    if (res instanceof StringReference) {
                        callback.evaluated("");
                        final String line = ((StringReference) res).value();
                        ApplicationManager.getApplication().runReadAction(() -> {
                            final PsiClass psiClass = DebuggerUtils.findClass(line, valueDescriptor.getProject(), process.getSearchScope());
                            if (psiClass != null) {
                                DebuggerUIUtil.invokeLater(() -> psiClass.navigate(true));
                            }
                        });
                    }
                } catch (EvaluateException e) {
                    LOG.info("Exception while getting type name", e);
                }
            }
        }

        @Override
        public boolean isShowValuePopup() {
            return false;
        }
    };
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) JavaValue(com.intellij.debugger.engine.JavaValue) PsiClass(com.intellij.psi.PsiClass) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable)

Example 22 with EvaluateException

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

the class EvaluationDescriptor method calcValue.

public final Value calcValue(EvaluationContextImpl evaluationContext) throws EvaluateException {
    try {
        PsiDocumentManager.getInstance(myProject).commitAndRunReadAction(() -> {
        });
        EvaluationContextImpl thisEvaluationContext = getEvaluationContext(evaluationContext);
        SourcePosition position = ContextUtil.getSourcePosition(evaluationContext);
        PsiElement psiContext = ContextUtil.getContextElement(evaluationContext, position);
        ExpressionEvaluator evaluator = ReadAction.compute(() -> {
            PsiCodeFragment code = getEvaluationCode(thisEvaluationContext);
            try {
                return DebuggerUtilsEx.findAppropriateCodeFragmentFactory(getEvaluationText(), psiContext).getEvaluatorBuilder().build(code, position);
            } catch (UnsupportedExpressionException ex) {
                ExpressionEvaluator eval = CompilingEvaluatorImpl.create(myProject, code.getContext(), element -> code);
                if (eval != null) {
                    return eval;
                }
                throw ex;
            }
        });
        if (!thisEvaluationContext.getDebugProcess().isAttached()) {
            throw EvaluateExceptionUtil.PROCESS_EXITED;
        }
        StackFrameProxyImpl frameProxy = thisEvaluationContext.getFrameProxy();
        if (frameProxy == null) {
            throw EvaluateExceptionUtil.NULL_STACK_FRAME;
        }
        Value value = evaluator.evaluate(thisEvaluationContext);
        DebuggerUtilsEx.keep(value, thisEvaluationContext);
        myModifier = evaluator.getModifier();
        setLvalue(myModifier != null);
        return value;
    } catch (final EvaluateException ex) {
        throw new EvaluateException(ex.getLocalizedMessage(), ex);
    } catch (ObjectCollectedException ex) {
        throw EvaluateExceptionUtil.OBJECT_WAS_COLLECTED;
    }
}
Also used : StackFrameContext(com.intellij.debugger.engine.StackFrameContext) Modifier(com.intellij.debugger.engine.evaluation.expression.Modifier) DebuggerContextImpl(com.intellij.debugger.impl.DebuggerContextImpl) ContextUtil(com.intellij.debugger.engine.ContextUtil) DebuggerUtilsEx(com.intellij.debugger.impl.DebuggerUtilsEx) EvaluationContextImpl(com.intellij.debugger.engine.evaluation.EvaluationContextImpl) ReadAction(com.intellij.openapi.application.ReadAction) ExpressionEvaluator(com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator) XValueModifier(com.intellij.xdebugger.frame.XValueModifier) TextWithImports(com.intellij.debugger.engine.evaluation.TextWithImports) Project(com.intellij.openapi.project.Project) DebuggerBundle(com.intellij.debugger.DebuggerBundle) StackFrameProxyImpl(com.intellij.debugger.jdi.StackFrameProxyImpl) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) UnsupportedExpressionException(com.intellij.debugger.engine.evaluation.expression.UnsupportedExpressionException) JavaValueModifier(com.intellij.debugger.engine.JavaValueModifier) EvaluateExceptionUtil(com.intellij.debugger.engine.evaluation.EvaluateExceptionUtil) JavaValue(com.intellij.debugger.engine.JavaValue) Nullable(org.jetbrains.annotations.Nullable) DebuggerContext(com.intellij.debugger.DebuggerContext) DebuggerManagerEx(com.intellij.debugger.DebuggerManagerEx) com.sun.jdi(com.sun.jdi) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) SourcePosition(com.intellij.debugger.SourcePosition) StackFrameProxyImpl(com.intellij.debugger.jdi.StackFrameProxyImpl) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) EvaluationContextImpl(com.intellij.debugger.engine.evaluation.EvaluationContextImpl) SourcePosition(com.intellij.debugger.SourcePosition) JavaValue(com.intellij.debugger.engine.JavaValue) UnsupportedExpressionException(com.intellij.debugger.engine.evaluation.expression.UnsupportedExpressionException) ExpressionEvaluator(com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator)

Example 23 with EvaluateException

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

the class EvaluationDescriptor method getModifier.

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

        @Override
        protected void setValueImpl(@NotNull String expression, @NotNull XModificationCallback callback) {
            final EvaluationDescriptor evaluationDescriptor = EvaluationDescriptor.this;
            if (evaluationDescriptor.canSetValue()) {
                final DebuggerContextImpl debuggerContext = DebuggerManagerEx.getInstanceEx(getProject()).getContext();
                set(expression, callback, debuggerContext, new SetValueRunnable() {

                    public void setValue(EvaluationContextImpl evaluationContext, Value newValue) throws ClassNotLoadedException, InvalidTypeException, EvaluateException {
                        final Modifier modifier = evaluationDescriptor.getModifier();
                        modifier.setValue(preprocessValue(evaluationContext, newValue, modifier.getExpectedType()));
                        update(debuggerContext);
                    }

                    public ReferenceType loadClass(EvaluationContextImpl evaluationContext, String className) throws InvocationException, ClassNotLoadedException, IncompatibleThreadStateException, InvalidTypeException, EvaluateException {
                        return evaluationContext.getDebugProcess().loadClass(evaluationContext, className, evaluationContext.getClassLoader());
                    }
                });
            }
        }
    };
}
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) Modifier(com.intellij.debugger.engine.evaluation.expression.Modifier) XValueModifier(com.intellij.xdebugger.frame.XValueModifier) JavaValueModifier(com.intellij.debugger.engine.JavaValueModifier)

Example 24 with EvaluateException

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

the class FieldDescriptorImpl method getModifier.

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

        @Override
        protected void setValueImpl(@NotNull String expression, @NotNull XModificationCallback callback) {
            final DebuggerContextImpl debuggerContext = DebuggerManagerEx.getInstanceEx(getProject()).getContext();
            FieldDescriptorImpl fieldDescriptor = FieldDescriptorImpl.this;
            final Field field = fieldDescriptor.getField();
            if (!field.isStatic()) {
                final ObjectReference object = fieldDescriptor.getObject();
                if (object != null) {
                    set(expression, callback, debuggerContext, new SetValueRunnable() {

                        public void setValue(EvaluationContextImpl evaluationContext, Value newValue) throws ClassNotLoadedException, InvalidTypeException, EvaluateException {
                            object.setValue(field, preprocessValue(evaluationContext, newValue, field.type()));
                            update(debuggerContext);
                        }

                        public ReferenceType loadClass(EvaluationContextImpl evaluationContext, String className) throws InvocationException, ClassNotLoadedException, IncompatibleThreadStateException, InvalidTypeException, EvaluateException {
                            return evaluationContext.getDebugProcess().loadClass(evaluationContext, className, field.declaringType().classLoader());
                        }
                    });
                }
            } else {
                // field is static
                ReferenceType refType = field.declaringType();
                if (refType instanceof ClassType) {
                    final ClassType classType = (ClassType) refType;
                    set(expression, callback, debuggerContext, new SetValueRunnable() {

                        public void setValue(EvaluationContextImpl evaluationContext, Value newValue) throws ClassNotLoadedException, InvalidTypeException, EvaluateException {
                            classType.setValue(field, preprocessValue(evaluationContext, newValue, field.type()));
                            update(debuggerContext);
                        }

                        public ReferenceType loadClass(EvaluationContextImpl evaluationContext, String className) throws InvocationException, ClassNotLoadedException, IncompatibleThreadStateException, InvalidTypeException, EvaluateException {
                            return evaluationContext.getDebugProcess().loadClass(evaluationContext, className, field.declaringType().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 25 with EvaluateException

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

the class FieldDescriptorImpl method getDescriptorEvaluation.

@Override
public PsiExpression getDescriptorEvaluation(DebuggerContext context) throws EvaluateException {
    PsiElementFactory elementFactory = JavaPsiFacade.getInstance(myProject).getElementFactory();
    String fieldName;
    if (isStatic()) {
        String typeName = myField.declaringType().name().replace('$', '.');
        typeName = DebuggerTreeNodeExpression.normalize(typeName, PositionUtil.getContextElement(context), myProject);
        fieldName = typeName + "." + getName();
    } else {
        //noinspection HardCodedStringLiteral
        fieldName = isOuterLocalVariableValue() ? StringUtil.trimStart(getName(), OUTER_LOCAL_VAR_FIELD_PREFIX) : "this." + getName();
    }
    try {
        return elementFactory.createExpressionFromText(fieldName, null);
    } catch (IncorrectOperationException e) {
        throw new EvaluateException(DebuggerBundle.message("error.invalid.field.name", getName()), e);
    }
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) PsiElementFactory(com.intellij.psi.PsiElementFactory) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

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