Search in sources :

Example 6 with Value

use of com.sun.jdi.Value in project intellij-community by JetBrains.

the class ValueHint method getSelectedExpression.

private static Trinity<PsiElement, TextRange, Value> getSelectedExpression(final Project project, final Editor editor, final Point point, final ValueHintType type) {
    final Ref<PsiElement> selectedExpression = Ref.create(null);
    final Ref<TextRange> currentRange = Ref.create(null);
    final Ref<Value> preCalculatedValue = Ref.create(null);
    PsiDocumentManager.getInstance(project).commitAndRunReadAction(() -> {
        // Point -> offset
        final int offset = calculateOffset(editor, point);
        PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
        if (psiFile == null || !psiFile.isValid()) {
            return;
        }
        int selectionStart = editor.getSelectionModel().getSelectionStart();
        int selectionEnd = editor.getSelectionModel().getSelectionEnd();
        if ((type == ValueHintType.MOUSE_CLICK_HINT || type == ValueHintType.MOUSE_ALT_OVER_HINT) && (selectionStart <= offset && offset <= selectionEnd)) {
            PsiElement ctx = (selectionStart > 0) ? psiFile.findElementAt(selectionStart - 1) : psiFile.findElementAt(selectionStart);
            try {
                String text = editor.getSelectionModel().getSelectedText();
                if (text != null && ctx != null) {
                    final JVMElementFactory factory = JVMElementFactories.getFactory(ctx.getLanguage(), project);
                    if (factory == null) {
                        return;
                    }
                    selectedExpression.set(factory.createExpressionFromText(text, ctx));
                    currentRange.set(new TextRange(editor.getSelectionModel().getSelectionStart(), editor.getSelectionModel().getSelectionEnd()));
                }
            } catch (IncorrectOperationException ignored) {
            }
        }
        if (currentRange.get() == null) {
            PsiElement elementAtCursor = psiFile.findElementAt(offset);
            if (elementAtCursor == null) {
                return;
            }
            Pair<PsiElement, TextRange> pair = findExpression(elementAtCursor, type == ValueHintType.MOUSE_CLICK_HINT || type == ValueHintType.MOUSE_ALT_OVER_HINT);
            if (pair == null) {
                if (type == ValueHintType.MOUSE_OVER_HINT) {
                    final DebuggerSession debuggerSession = DebuggerManagerEx.getInstanceEx(project).getContext().getDebuggerSession();
                    if (debuggerSession != null && debuggerSession.isPaused()) {
                        final Pair<Method, Value> lastExecuted = debuggerSession.getProcess().getLastExecutedMethod();
                        if (lastExecuted != null) {
                            final Method method = lastExecuted.getFirst();
                            if (method != null) {
                                final Pair<PsiElement, TextRange> expressionPair = findExpression(elementAtCursor, true);
                                if (expressionPair != null && expressionPair.getFirst() instanceof PsiMethodCallExpression) {
                                    final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression) expressionPair.getFirst();
                                    final PsiMethod psiMethod = methodCallExpression.resolveMethod();
                                    if (psiMethod != null) {
                                        final JVMName jvmSignature = JVMNameUtil.getJVMSignature(psiMethod);
                                        try {
                                            if (method.name().equals(psiMethod.getName()) && method.signature().equals(jvmSignature.getName(debuggerSession.getProcess()))) {
                                                pair = expressionPair;
                                                preCalculatedValue.set(lastExecuted.getSecond());
                                            }
                                        } catch (EvaluateException ignored) {
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (pair == null) {
                return;
            }
            selectedExpression.set(pair.getFirst());
            currentRange.set(pair.getSecond());
        }
    });
    return Trinity.create(selectedExpression.get(), currentRange.get(), preCalculatedValue.get());
}
Also used : JVMName(com.intellij.debugger.engine.JVMName) Method(com.sun.jdi.Method) AbstractValueHint(com.intellij.xdebugger.impl.evaluate.quick.common.AbstractValueHint) DebuggerSession(com.intellij.debugger.impl.DebuggerSession) PrimitiveValue(com.sun.jdi.PrimitiveValue) Value(com.sun.jdi.Value) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Example 7 with Value

use of com.sun.jdi.Value in project intellij-community by JetBrains.

the class LambdaAsyncMethodFilter method onReached.

@Override
public int onReached(SuspendContextImpl context, RequestHint hint) {
    try {
        StackFrameProxyImpl proxy = context.getFrameProxy();
        if (proxy != null) {
            Value lambdaReference = ContainerUtil.getOrElse(proxy.getArgumentValues(), myParamNo, null);
            if (lambdaReference instanceof ObjectReference) {
                final SourcePosition pos = myMethodFilter.getBreakpointPosition();
                if (pos != null) {
                    Project project = context.getDebugProcess().getProject();
                    long lambdaId = ((ObjectReference) lambdaReference).uniqueID();
                    StepIntoBreakpoint breakpoint = new LambdaInstanceBreakpoint(project, lambdaId, pos, myMethodFilter);
                    ClassInstanceMethodFilter.setUpStepIntoBreakpoint(context, breakpoint, hint);
                    return RequestHint.RESUME;
                }
            }
        }
    } catch (EvaluateException ignore) {
    }
    return RequestHint.STOP;
}
Also used : StackFrameProxyImpl(com.intellij.debugger.jdi.StackFrameProxyImpl) Project(com.intellij.openapi.project.Project) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) ObjectReference(com.sun.jdi.ObjectReference) SourcePosition(com.intellij.debugger.SourcePosition) Value(com.sun.jdi.Value) StepIntoBreakpoint(com.intellij.debugger.ui.breakpoints.StepIntoBreakpoint)

Example 8 with Value

use of com.sun.jdi.Value in project intellij-community by JetBrains.

the class ExpressionChildrenRenderer method buildChildren.

public void buildChildren(final Value value, final ChildrenBuilder builder, final EvaluationContext evaluationContext) {
    final NodeManager nodeManager = builder.getNodeManager();
    try {
        final ValueDescriptor parentDescriptor = builder.getParentDescriptor();
        final Value childrenValue = evaluateChildren(evaluationContext.createEvaluationContext(value), parentDescriptor);
        NodeRenderer renderer = getChildrenRenderer(childrenValue, parentDescriptor);
        renderer.buildChildren(childrenValue, builder, evaluationContext);
    } catch (final EvaluateException e) {
        List<DebuggerTreeNode> errorChildren = new ArrayList<>();
        errorChildren.add(nodeManager.createMessageNode(DebuggerBundle.message("error.unable.to.evaluate.expression") + " " + e.getMessage()));
        builder.setChildren(errorChildren);
    }
}
Also used : NodeManager(com.intellij.debugger.ui.tree.NodeManager) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) ValueDescriptor(com.intellij.debugger.ui.tree.ValueDescriptor) BooleanValue(com.sun.jdi.BooleanValue) Value(com.sun.jdi.Value) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with Value

use of com.sun.jdi.Value in project intellij-community by JetBrains.

the class ToStringRenderer method calcLabel.

@Override
public String calcLabel(final ValueDescriptor valueDescriptor, EvaluationContext evaluationContext, final DescriptorLabelListener labelListener) throws EvaluateException {
    final Value value = valueDescriptor.getValue();
    BatchEvaluator.getBatchEvaluator(evaluationContext.getDebugProcess()).invoke(new ToStringCommand(evaluationContext, value) {

        @Override
        public void evaluationResult(String message) {
            valueDescriptor.setValueLabel(StringUtil.notNullize(message));
            labelListener.labelChanged();
        }

        @Override
        public void evaluationError(String message) {
            final String msg = value != null ? message + " " + DebuggerBundle.message("evaluation.error.cannot.evaluate.tostring", value.type().name()) : message;
            valueDescriptor.setValueLabelFailed(new EvaluateException(msg, null));
            labelListener.labelChanged();
        }
    });
    return XDebuggerUIConstants.COLLECTING_DATA_MESSAGE;
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) Value(com.sun.jdi.Value)

Example 10 with Value

use of com.sun.jdi.Value in project intellij-community by JetBrains.

the class DescriptorTestCase method expandAll.

protected void expandAll(final Tree tree, final Runnable runnable, final Set<Value> alreadyExpanded, final NodeFilter filter, final SuspendContextImpl context) {
    invokeRatherLater(context, () -> {
        boolean anyCollapsed = false;
        for (int i = 0; i < tree.getRowCount(); i++) {
            final TreeNode treeNode = (TreeNode) tree.getPathForRow(i).getLastPathComponent();
            if (tree.isCollapsed(i) && !treeNode.isLeaf()) {
                NodeDescriptor nodeDescriptor = null;
                if (treeNode instanceof DebuggerTreeNodeImpl) {
                    nodeDescriptor = ((DebuggerTreeNodeImpl) treeNode).getDescriptor();
                }
                boolean shouldExpand = filter == null || filter.shouldExpand(treeNode);
                if (shouldExpand) {
                    // additional checks to prevent infinite expand
                    if (nodeDescriptor instanceof ValueDescriptor) {
                        final Value value = ((ValueDescriptor) nodeDescriptor).getValue();
                        shouldExpand = !alreadyExpanded.contains(value);
                        if (shouldExpand) {
                            alreadyExpanded.add(value);
                        }
                    }
                }
                if (shouldExpand) {
                    anyCollapsed = true;
                    tree.expandRow(i);
                }
            }
        }
        if (anyCollapsed) {
            expandAll(tree, runnable, alreadyExpanded, filter, context);
        } else {
            runnable.run();
        }
    });
}
Also used : DebuggerTreeNodeImpl(com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl) TreeNode(javax.swing.tree.TreeNode) ValueDescriptor(com.intellij.debugger.ui.tree.ValueDescriptor) NodeDescriptor(com.intellij.debugger.ui.tree.NodeDescriptor) Value(com.sun.jdi.Value)

Aggregations

Value (com.sun.jdi.Value)23 BooleanValue (com.sun.jdi.BooleanValue)9 PrimitiveValue (com.sun.jdi.PrimitiveValue)7 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)6 ObjectReference (com.sun.jdi.ObjectReference)5 ExpressionEvaluator (com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator)4 IntegerValue (com.sun.jdi.IntegerValue)4 ValueDescriptor (com.intellij.debugger.ui.tree.ValueDescriptor)3 DoubleValue (com.sun.jdi.DoubleValue)3 FloatValue (com.sun.jdi.FloatValue)3 LongValue (com.sun.jdi.LongValue)3 SourcePosition (com.intellij.debugger.SourcePosition)2 EvaluationContext (com.intellij.debugger.engine.evaluation.EvaluationContext)2 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)2 NodeDescriptor (com.intellij.debugger.ui.tree.NodeDescriptor)2 Project (com.intellij.openapi.project.Project)2 AbstractValueHint (com.intellij.xdebugger.impl.evaluate.quick.common.AbstractValueHint)2 AbsentInformationException (com.sun.jdi.AbsentInformationException)2 Method (com.sun.jdi.Method)2 StackFrame (com.sun.jdi.StackFrame)2