public CompletableFuture handle()

in com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/InlineValuesRequestHandler.java [72:160]


    public CompletableFuture<Response> handle(Command command, Arguments arguments, Response response,
            IDebugAdapterContext context) {
        InlineValuesArguments inlineValuesArgs = (InlineValuesArguments) arguments;
        int variableCount = inlineValuesArgs == null || inlineValuesArgs.variables == null ? 0 : inlineValuesArgs.variables.length;
        InlineVariable[] inlineVariables = inlineValuesArgs.variables;
        StackFrameReference stackFrameReference = (StackFrameReference) context.getRecyclableIdPool().getObjectById(inlineValuesArgs.frameId);
        if (stackFrameReference == null) {
            logger.log(Level.SEVERE, String.format("InlineValues failed: invalid stackframe id %d.", inlineValuesArgs.frameId));
            response.body = new Responses.InlineValuesResponse(null);
            return CompletableFuture.completedFuture(response);
        }

        IStackFrameManager stackFrameManager = context.getStackFrameManager();
        StackFrame frame = stackFrameManager.getStackFrame(stackFrameReference);
        if (frame == null) {
            logger.log(Level.SEVERE, String.format("InlineValues failed: stale stackframe id %d.", inlineValuesArgs.frameId));
            response.body = new Responses.InlineValuesResponse(null);
            return CompletableFuture.completedFuture(response);
        }

        Variable[] values = new Variable[variableCount];
        try {
            if (isLambdaFrame(frame)) {
                // Lambda expression stores the captured variables from 'outer' scope in a synthetic stackframe below the lambda frame.
                StackFrame syntheticLambdaFrame = stackFrameReference.getThread().frame(stackFrameReference.getDepth() + 1);
                resolveValuesFromThisVariable(syntheticLambdaFrame.thisObject(), inlineVariables, values, true);
            }

            resolveValuesFromThisVariable(frame.thisObject(), inlineVariables, values, false);
        } catch (Exception ex) {
            // do nothig
        }

        Types.Variable[] result = new Types.Variable[variableCount];
        IVariableFormatter variableFormatter = context.getVariableFormatter();
        Map<String, Object> formatterOptions = variableFormatter.getDefaultOptions();
        Map<InlineVariable, Types.Variable> calculatedValues = new HashMap<>();
        IEvaluationProvider evaluationEngine = context.getProvider(IEvaluationProvider.class);
        for (int i = 0; i < variableCount; i++) {
            if (values[i] == null) {
                continue;
            }

            if (calculatedValues.containsKey(inlineVariables[i])) {
                result[i] = calculatedValues.get(inlineVariables[i]);
                continue;
            }

            Value value = values[i].value;
            String name = values[i].name;
            int indexedVariables = -1;
            Value sizeValue = null;
            if (value instanceof ArrayReference) {
                indexedVariables = ((ArrayReference) value).length();
            } else if (value instanceof ObjectReference && DebugSettings.getCurrent().showLogicalStructure && evaluationEngine != null) {
                try {
                    JavaLogicalStructure structure = JavaLogicalStructureManager.getLogicalStructure((ObjectReference) value);
                    if (structure != null && structure.getSizeExpression() != null) {
                        sizeValue = structure.getSize((ObjectReference) value, frame.thread(), evaluationEngine);
                        if (sizeValue != null && sizeValue instanceof IntegerValue) {
                            indexedVariables = ((IntegerValue) sizeValue).value();
                        }
                    }
                } catch (CancellationException | IllegalArgumentException | InterruptedException | ExecutionException | UnsupportedOperationException e) {
                    logger.log(Level.INFO,
                            String.format("Failed to get the logical size for the type %s.", value.type().name()), e);
                }
            }

            Types.Variable formattedVariable = new Types.Variable(name, variableFormatter.valueToString(value, formatterOptions));
            formattedVariable.indexedVariables = Math.max(indexedVariables, 0);
            String detailsValue = null;
            if (sizeValue != null) {
                detailsValue = "size=" + variableFormatter.valueToString(sizeValue, formatterOptions);
            } else if (DebugSettings.getCurrent().showToString) {
                detailsValue = VariableDetailUtils.formatDetailsValue(value, frame.thread(), variableFormatter, formatterOptions, evaluationEngine);
            }

            if (detailsValue != null) {
                formattedVariable.value = formattedVariable.value + " " + detailsValue;
            }

            result[i] = formattedVariable;
            calculatedValues.put(inlineVariables[i], formattedVariable);
        }

        response.body = new Responses.InlineValuesResponse(result);
        return CompletableFuture.completedFuture(response);
    }