Search in sources :

Example 46 with EvaluateException

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

the class NodeManagerImpl method getContextKeyForFrame.

@Nullable
public static String getContextKeyForFrame(final StackFrameProxyImpl frame) {
    if (frame == null) {
        return null;
    }
    try {
        final Location location = frame.location();
        final Method method = DebuggerUtilsEx.getMethod(location);
        if (method == null) {
            return null;
        }
        final ReferenceType referenceType = location.declaringType();
        final StringBuilder builder = StringBuilderSpinAllocator.alloc();
        try {
            return builder.append(referenceType.signature()).append("#").append(method.name()).append(method.signature()).toString();
        } finally {
            StringBuilderSpinAllocator.dispose(builder);
        }
    } catch (EvaluateException ignored) {
    } catch (InternalException ie) {
        if (ie.errorCode() != 23) {
            // INVALID_METHODID
            throw ie;
        }
    }
    return null;
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) Method(com.sun.jdi.Method) ReferenceType(com.sun.jdi.ReferenceType) Location(com.sun.jdi.Location) InternalException(com.sun.jdi.InternalException) Nullable(org.jetbrains.annotations.Nullable)

Example 47 with EvaluateException

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

the class ValueDescriptorImpl method calcRepresentation.

@Override
protected String calcRepresentation(EvaluationContextImpl context, DescriptorLabelListener labelListener) {
    DebuggerManagerThreadImpl.assertIsManagerThread();
    final NodeRenderer renderer = getRenderer(context.getDebugProcess());
    final EvaluateException valueException = myValueException;
    myIsExpandable = (valueException == null || valueException.getExceptionFromTargetVM() != null) && renderer.isExpandable(getValue(), context, this);
    try {
        setValueIcon(renderer.calcValueIcon(this, context, labelListener));
    } catch (EvaluateException e) {
        LOG.info(e);
        setValueIcon(null);
    }
    String label;
    if (valueException == null) {
        try {
            label = renderer.calcLabel(this, context, labelListener);
        } catch (EvaluateException e) {
            label = setValueLabelFailed(e);
        }
    } else {
        label = setValueLabelFailed(valueException);
    }
    setValueLabel(label);
    // we have overridden getLabel
    return "";
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException)

Example 48 with EvaluateException

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

the class DebuggerTreeNodeExpression method substituteThis.

@Nullable
public static PsiExpression substituteThis(@Nullable PsiElement expressionWithThis, PsiExpression howToEvaluateThis, Value howToEvaluateThisValue) throws EvaluateException {
    if (expressionWithThis == null)
        return null;
    PsiExpression result = (PsiExpression) expressionWithThis.copy();
    PsiClass thisClass = PsiTreeUtil.getContextOfType(result, PsiClass.class, true);
    boolean castNeeded = true;
    if (thisClass != null) {
        PsiType type = howToEvaluateThis.getType();
        if (type != null) {
            if (type instanceof PsiClassType) {
                PsiClass psiClass = ((PsiClassType) type).resolve();
                if (psiClass != null && (psiClass == thisClass || psiClass.isInheritor(thisClass, true))) {
                    castNeeded = false;
                }
            } else if (type instanceof PsiArrayType) {
                LanguageLevel languageLevel = PsiUtil.getLanguageLevel(expressionWithThis);
                if (thisClass == JavaPsiFacade.getInstance(expressionWithThis.getProject()).getElementFactory().getArrayClass(languageLevel)) {
                    castNeeded = false;
                }
            }
        }
    }
    if (castNeeded) {
        howToEvaluateThis = castToRuntimeType(howToEvaluateThis, howToEvaluateThisValue);
    }
    ChangeContextUtil.encodeContextInfo(result, false);
    PsiExpression psiExpression;
    try {
        psiExpression = (PsiExpression) ChangeContextUtil.decodeContextInfo(result, thisClass, howToEvaluateThis);
    } catch (IncorrectOperationException e) {
        throw new EvaluateException(DebuggerBundle.message("evaluation.error.invalid.this.expression", result.getText(), howToEvaluateThis.getText()), null);
    }
    try {
        PsiExpression res = JavaPsiFacade.getInstance(howToEvaluateThis.getProject()).getElementFactory().createExpressionFromText(psiExpression.getText(), howToEvaluateThis.getContext());
        res.putUserData(ADDITIONAL_IMPORTS_KEY, howToEvaluateThis.getUserData(ADDITIONAL_IMPORTS_KEY));
        return res;
    } catch (IncorrectOperationException e) {
        throw new EvaluateException(e.getMessage(), e);
    }
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) LanguageLevel(com.intellij.pom.java.LanguageLevel) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Nullable(org.jetbrains.annotations.Nullable)

Example 49 with EvaluateException

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

the class LocalVariableDescriptorImpl method getModifier.

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

        @Override
        protected void setValueImpl(@NotNull String expression, @NotNull XModificationCallback callback) {
            final LocalVariableProxyImpl local = LocalVariableDescriptorImpl.this.getLocalVariable();
            if (local != null) {
                final DebuggerContextImpl debuggerContext = DebuggerManagerEx.getInstanceEx(getProject()).getContext();
                set(expression, callback, debuggerContext, new SetValueRunnable() {

                    public void setValue(EvaluationContextImpl evaluationContext, Value newValue) throws ClassNotLoadedException, InvalidTypeException, EvaluateException {
                        debuggerContext.getFrameProxy().setValue(local, preprocessValue(evaluationContext, newValue, local.getType()));
                        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 : LocalVariableProxyImpl(com.intellij.debugger.jdi.LocalVariableProxyImpl) 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 50 with EvaluateException

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

the class ColorObjectRenderer method calcValueIcon.

public Icon calcValueIcon(ValueDescriptor descriptor, EvaluationContext evaluationContext, DescriptorLabelListener listener) throws EvaluateException {
    final Value value = descriptor.getValue();
    if (value instanceof ObjectReference) {
        try {
            final ObjectReference objRef = (ObjectReference) value;
            final ReferenceType refType = objRef.referenceType();
            final Field valueField = refType.fieldByName("value");
            if (valueField != null) {
                final Value rgbValue = objRef.getValue(valueField);
                if (rgbValue instanceof IntegerValue) {
                    @SuppressWarnings("UseJBColor") final Color color = new Color(((IntegerValue) rgbValue).value(), true);
                    return JBUI.scale(new ColorIcon(16, 12, color, true));
                }
            }
        } catch (Exception e) {
            throw new EvaluateException(e.getMessage(), e);
        }
    }
    return null;
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) ColorIcon(com.intellij.util.ui.ColorIcon) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException)

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