use of com.sun.jdi.Value in project intellij-community by JetBrains.
the class UnaryExpressionEvaluator method evaluate.
public Object evaluate(EvaluationContextImpl context) throws EvaluateException {
Value operand = (Value) myOperandEvaluator.evaluate(context);
VirtualMachineProxyImpl vm = context.getDebugProcess().getVirtualMachineProxy();
if (myOperationType == JavaTokenType.PLUS) {
if (DebuggerUtils.isNumeric(operand)) {
return operand;
}
throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.numeric.expected"));
} else if (myOperationType == JavaTokenType.MINUS) {
if (DebuggerUtils.isInteger(operand)) {
long v = ((PrimitiveValue) operand).longValue();
return DebuggerUtilsEx.createValue(vm, myExpectedType, -v);
}
if (DebuggerUtils.isNumeric(operand)) {
double v = ((PrimitiveValue) operand).doubleValue();
return DebuggerUtilsEx.createValue(vm, myExpectedType, -v);
}
throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.numeric.expected"));
} else if (myOperationType == JavaTokenType.TILDE) {
if (DebuggerUtils.isInteger(operand)) {
long v = ((PrimitiveValue) operand).longValue();
return DebuggerUtilsEx.createValue(vm, myExpectedType, ~v);
}
throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.integer.expected"));
} else if (myOperationType == JavaTokenType.EXCL) {
if (operand instanceof BooleanValue) {
boolean v = ((BooleanValue) operand).booleanValue();
return DebuggerUtilsEx.createValue(vm, myExpectedType, !v);
}
throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.boolean.expected"));
}
throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.operation.not.supported", myOperationText));
}
use of com.sun.jdi.Value 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);
}
}
use of com.sun.jdi.Value in project intellij-community by JetBrains.
the class ExpressionChildrenRenderer method getChildValueExpression.
public PsiExpression getChildValueExpression(DebuggerTreeNode node, DebuggerContext context) throws EvaluateException {
Value expressionValue = node.getParent().getDescriptor().getUserData(EXPRESSION_VALUE);
if (expressionValue == null) {
throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("error.unable.to.evaluate.expression"));
}
NodeRenderer childrenRenderer = getChildrenRenderer(expressionValue, (ValueDescriptor) node.getParent().getDescriptor());
PsiExpression childrenPsiExpression = myChildrenExpression.getPsiExpression(node.getProject());
if (childrenPsiExpression == null) {
return null;
}
return DebuggerTreeNodeExpression.substituteThis(childrenRenderer.getChildValueExpression(node, context), (PsiExpression) childrenPsiExpression.copy(), expressionValue);
}
use of com.sun.jdi.Value in project intellij-community by JetBrains.
the class ExpressionChildrenRenderer method isExpandable.
public boolean isExpandable(Value value, final EvaluationContext context, NodeDescriptor parentDescriptor) {
final EvaluationContext evaluationContext = context.createEvaluationContext(value);
if (!StringUtil.isEmpty(myChildrenExpandable.getReferenceExpression().getText())) {
try {
Value expanded = myChildrenExpandable.getEvaluator(evaluationContext.getProject()).evaluate(evaluationContext);
if (expanded instanceof BooleanValue) {
return ((BooleanValue) expanded).booleanValue();
}
} catch (EvaluateException e) {
// ignored
}
}
try {
Value children = evaluateChildren(evaluationContext, parentDescriptor);
ChildrenRenderer defaultChildrenRenderer = DebugProcessImpl.getDefaultRenderer(value.type());
return defaultChildrenRenderer.isExpandable(children, evaluationContext, parentDescriptor);
} catch (EvaluateException e) {
return true;
}
}
use of com.sun.jdi.Value 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;
}
Aggregations