Search in sources :

Example 6 with ExpressionEvaluator

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

the class CompilingEvaluator method evaluate.

@Override
public Value evaluate(final EvaluationContext evaluationContext) throws EvaluateException {
    DebugProcess process = evaluationContext.getDebugProcess();
    EvaluationContextImpl autoLoadContext = ((EvaluationContextImpl) evaluationContext).createEvaluationContext(evaluationContext.getThisObject());
    autoLoadContext.setAutoLoadClasses(true);
    ClassLoaderReference classLoader = ClassLoadingUtils.getClassLoader(autoLoadContext, process);
    autoLoadContext.setClassLoader(classLoader);
    String version = ((VirtualMachineProxyImpl) process.getVirtualMachineProxy()).version();
    Collection<ClassObject> classes = compile(JdkVersionUtil.getVersion(version));
    defineClasses(classes, autoLoadContext, process, classLoader);
    try {
        // invoke base evaluator on call code
        SourcePosition position = ContextUtil.getSourcePosition(evaluationContext);
        ExpressionEvaluator evaluator = DebuggerInvocationUtil.commitAndRunReadAction(myProject, new EvaluatingComputable<ExpressionEvaluator>() {

            @Override
            public ExpressionEvaluator compute() throws EvaluateException {
                TextWithImports callCode = getCallCode();
                PsiElement copyContext = myData.getAnchor();
                CodeFragmentFactory factory = DebuggerUtilsEx.findAppropriateCodeFragmentFactory(callCode, copyContext);
                return factory.getEvaluatorBuilder().build(factory.createCodeFragment(callCode, copyContext, myProject), position);
            }
        });
        return evaluator.evaluate(autoLoadContext);
    } catch (Exception e) {
        throw new EvaluateException("Error during generated code invocation " + e, e);
    }
}
Also used : VirtualMachineProxyImpl(com.intellij.debugger.jdi.VirtualMachineProxyImpl) ClassObject(com.intellij.openapi.compiler.ClassObject) ClassLoaderReference(com.sun.jdi.ClassLoaderReference) ExpressionEvaluator(com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator) DebugProcess(com.intellij.debugger.engine.DebugProcess) SourcePosition(com.intellij.debugger.SourcePosition) PsiElement(com.intellij.psi.PsiElement)

Example 7 with ExpressionEvaluator

use of com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator 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)

Example 8 with ExpressionEvaluator

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

the class LabelRenderer method calcLabel.

public String calcLabel(ValueDescriptor descriptor, EvaluationContext evaluationContext, DescriptorLabelListener labelListener) throws EvaluateException {
    final Value value = descriptor.getValue();
    String result;
    final DebugProcess debugProcess = evaluationContext.getDebugProcess();
    if (value != null) {
        try {
            final ExpressionEvaluator evaluator = myLabelExpression.getEvaluator(debugProcess.getProject());
            if (!debugProcess.isAttached()) {
                throw EvaluateExceptionUtil.PROCESS_EXITED;
            }
            EvaluationContext thisEvaluationContext = evaluationContext.createEvaluationContext(value);
            Value labelValue = evaluator.evaluate(thisEvaluationContext);
            result = DebuggerUtils.getValueAsString(thisEvaluationContext, labelValue);
        } catch (final EvaluateException ex) {
            throw new EvaluateException(DebuggerBundle.message("error.unable.to.evaluate.expression") + " " + ex.getMessage(), ex);
        }
    } else {
        //noinspection HardCodedStringLiteral
        result = "null";
    }
    return result;
}
Also used : DebugProcess(com.intellij.debugger.engine.DebugProcess) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) Value(com.sun.jdi.Value) EvaluationContext(com.intellij.debugger.engine.evaluation.EvaluationContext) ExpressionEvaluator(com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator)

Example 9 with ExpressionEvaluator

use of com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator 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)

Aggregations

ExpressionEvaluator (com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator)9 SourcePosition (com.intellij.debugger.SourcePosition)4 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)4 Value (com.sun.jdi.Value)4 DebuggerContextImpl (com.intellij.debugger.impl.DebuggerContextImpl)3 StackFrameProxyImpl (com.intellij.debugger.jdi.StackFrameProxyImpl)3 PsiElement (com.intellij.psi.PsiElement)3 Nullable (org.jetbrains.annotations.Nullable)3 DebugProcess (com.intellij.debugger.engine.DebugProcess)2 DebuggerContextCommandImpl (com.intellij.debugger.engine.events.DebuggerContextCommandImpl)2 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)2 DebuggerUtilsEx (com.intellij.debugger.impl.DebuggerUtilsEx)2 Project (com.intellij.openapi.project.Project)2 com.intellij.psi (com.intellij.psi)2 ThreeState (com.intellij.util.ThreeState)2 NotNull (org.jetbrains.annotations.NotNull)2 DebuggerBundle (com.intellij.debugger.DebuggerBundle)1 DebuggerContext (com.intellij.debugger.DebuggerContext)1 DebuggerManagerEx (com.intellij.debugger.DebuggerManagerEx)1 ContextUtil (com.intellij.debugger.engine.ContextUtil)1