static String getValue (Value v) { if (v == null) { return "null"; } if (v instanceof VoidValue) { return "void"; } if (v instanceof CharValue) { return "\'" + v.toString () + "\'"; } if (v instanceof PrimitiveValue) { return v.toString (); } try { if (v instanceof StringReference) { String str = ShortenedStrings.getStringWithLengthControl((StringReference) v); return "\"" + str + "\""; } if (v instanceof ClassObjectReference) { return "class " + ReferenceTypeWrapper.name(ClassObjectReferenceWrapper.reflectedType((ClassObjectReference) v)); } if (v instanceof ArrayReference) { return "#" + ObjectReferenceWrapper.uniqueID((ArrayReference) v) + "(length=" + ArrayReferenceWrapper.length((ArrayReference) v) + ")"; } return "#" + ObjectReferenceWrapper.uniqueID((ObjectReference) v); } catch (InternalExceptionWrapper iex) { return ""; } catch (ObjectCollectedExceptionWrapper oex) { return ""; } catch (VMDisconnectedExceptionWrapper dex) { return ""; } }
public static F3Value wrap(F3VirtualMachine f3vm, Value value) { if (value == null) { return null; } if (value instanceof PrimitiveValue) { if (value instanceof BooleanValue) { return f3vm.booleanValue((BooleanValue)value); } else if (value instanceof CharValue) { return f3vm.charValue((CharValue)value); } else if (value instanceof ByteValue) { return f3vm.byteValue((ByteValue)value); } else if (value instanceof ShortValue) { return f3vm.shortValue((ShortValue)value); } else if (value instanceof IntegerValue) { return f3vm.integerValue((IntegerValue)value); } else if (value instanceof LongValue) { return f3vm.longValue((LongValue)value); } else if (value instanceof FloatValue) { return f3vm.floatValue((FloatValue)value); } else if (value instanceof DoubleValue) { return f3vm.doubleValue((DoubleValue)value); } else { throw new IllegalArgumentException("illegal primitive value : " + value); } } else if (value instanceof VoidValue) { return f3vm.voidValue(); } else if (value instanceof ObjectReference) { return wrap(f3vm, (ObjectReference)value); } else { throw new IllegalArgumentException("illegal value: " + value); } }
public boolean equals(Object obj) { return (obj != null) && (obj instanceof VoidValue) && super.equals(obj); }
public VoidValue mirrorOfVoid() { if (voidVal == null) { voidVal = new VoidValueImpl(this); } return voidVal; }
@Override public CompletableFuture<Response> handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { EvaluateArguments evalArguments = (EvaluateArguments) arguments; final boolean showStaticVariables = DebugSettings.getCurrent().showStaticVariables; Map<String, Object> options = context.getVariableFormatter().getDefaultOptions(); VariableUtils.applyFormatterOptions(options, evalArguments.format != null && evalArguments.format.hex); String expression = evalArguments.expression; if (StringUtils.isBlank(expression)) { return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.EVALUATE_FAILURE, "Failed to evaluate. Reason: Empty expression cannot be evaluated."); } StackFrameReference stackFrameReference = (StackFrameReference) context.getRecyclableIdPool().getObjectById(evalArguments.frameId); if (stackFrameReference == null) { // stackFrameReference is null means the stackframe is continued by user manually, return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.EVALUATE_FAILURE, "Failed to evaluate. Reason: Cannot evaluate because the thread is resumed."); } return CompletableFuture.supplyAsync(() -> { try { IEvaluationProvider engine = context.getProvider(IEvaluationProvider.class); Value value = engine.evaluate(expression, stackFrameReference.getThread(), stackFrameReference.getDepth()).get(); IVariableFormatter variableFormatter = context.getVariableFormatter(); if (value instanceof VoidValue) { response.body = new Responses.EvaluateResponseBody(value.toString(), 0, "<void>", 0); return response; } long threadId = stackFrameReference.getThread().uniqueID(); if (value instanceof ObjectReference) { VariableProxy varProxy = new VariableProxy(stackFrameReference.getThread(), "eval", value); int referenceId = VariableUtils.hasChildren(value, showStaticVariables) ? context.getRecyclableIdPool().addObject(threadId, varProxy) : 0; int indexedVariableId = value instanceof ArrayReference ? ((ArrayReference) value).length() : 0; response.body = new Responses.EvaluateResponseBody(variableFormatter.valueToString(value, options), referenceId, variableFormatter.typeToString(value == null ? null : value.type(), options), indexedVariableId); return response; } // for primitive value response.body = new Responses.EvaluateResponseBody(variableFormatter.valueToString(value, options), 0, variableFormatter.typeToString(value == null ? null : value.type(), options), 0); return response; } catch (InterruptedException | ExecutionException e) { Throwable cause = e; if (e instanceof ExecutionException && e.getCause() != null) { cause = e.getCause(); } // TODO: distinguish user error of wrong expression(eg: compilation error) logger.log(Level.WARNING, String.format("Cannot evalution expression because of %s.", cause.toString()), cause); throw new CompletionException(cause); } }); }
public VoidValue mirrorOfVoid() { return voidValue(); }
public F3VoidValue(F3VirtualMachine f3vm, VoidValue underlying) { super(f3vm, underlying); }
@Override protected VoidValue underlying() { return (VoidValue) super.underlying(); }
@Test public void testMirrorOfVoidValue() { VoidValue vv = getVM().mirrorOfVoid(); Assert.assertNotNull(vv); }
private void runAction(final EvaluationContextImpl context, LocatableEvent event) { final DebugProcessImpl debugProcess = context.getDebugProcess(); if (LOG_ENABLED || LOG_EXPRESSION_ENABLED) { final StringBuilder buf = StringBuilderSpinAllocator.alloc(); try { if (LOG_ENABLED) { buf.append(getEventMessage(event)); buf.append("\n"); } final TextWithImports expressionToEvaluate = getLogMessage(); if (LOG_EXPRESSION_ENABLED && expressionToEvaluate != null && !"".equals(expressionToEvaluate.getText())) { if(!debugProcess.isAttached()) { return; } try { ExpressionEvaluator evaluator = DebuggerInvocationUtil.commitAndRunReadAction(getProject(), new EvaluatingComputable<ExpressionEvaluator>() { @Override public ExpressionEvaluator compute() throws EvaluateException { return EvaluatorBuilderImpl.build(expressionToEvaluate, ContextUtil.getContextElement(context), ContextUtil.getSourcePosition(context)); } }); final Value eval = evaluator.evaluate(context); final String result = eval instanceof VoidValue ? "void" : DebuggerUtils.getValueAsString(context, eval); buf.append(result); } catch (EvaluateException e) { buf.append(DebuggerBundle.message("error.unable.to.evaluate.expression")); buf.append(" \""); buf.append(expressionToEvaluate); buf.append("\""); buf.append(" : "); buf.append(e.getMessage()); } buf.append("\n"); } if (buf.length() > 0) { debugProcess.printToConsole(buf.toString()); } } finally { StringBuilderSpinAllocator.dispose(buf); } } if (REMOVE_AFTER_HIT) { handleTemporaryBreakpointHit(debugProcess); } }