|
17 | 17 | import java.util.concurrent.CompletableFuture; |
18 | 18 | import java.util.concurrent.CompletionException; |
19 | 19 | import java.util.concurrent.ExecutionException; |
| 20 | +import java.util.logging.Level; |
| 21 | +import java.util.logging.Logger; |
20 | 22 |
|
21 | 23 | import org.apache.commons.lang3.StringUtils; |
22 | 24 |
|
| 25 | +import com.microsoft.java.debug.core.Configuration; |
23 | 26 | import com.microsoft.java.debug.core.DebugException; |
24 | 27 | import com.microsoft.java.debug.core.DebugSettings; |
25 | 28 | import com.microsoft.java.debug.core.adapter.AdapterUtils; |
|
28 | 31 | import com.microsoft.java.debug.core.adapter.IDebugRequestHandler; |
29 | 32 | import com.microsoft.java.debug.core.adapter.IEvaluationProvider; |
30 | 33 | import com.microsoft.java.debug.core.adapter.variables.IVariableFormatter; |
| 34 | +import com.microsoft.java.debug.core.adapter.variables.JavaLogicalStructureManager; |
31 | 35 | import com.microsoft.java.debug.core.adapter.variables.StackFrameReference; |
32 | 36 | import com.microsoft.java.debug.core.adapter.variables.VariableProxy; |
33 | 37 | import com.microsoft.java.debug.core.adapter.variables.VariableUtils; |
|
37 | 41 | import com.microsoft.java.debug.core.protocol.Requests.EvaluateArguments; |
38 | 42 | import com.microsoft.java.debug.core.protocol.Responses; |
39 | 43 | import com.sun.jdi.ArrayReference; |
| 44 | +import com.sun.jdi.ClassNotLoadedException; |
| 45 | +import com.sun.jdi.IncompatibleThreadStateException; |
| 46 | +import com.sun.jdi.IntegerValue; |
| 47 | +import com.sun.jdi.InvalidTypeException; |
| 48 | +import com.sun.jdi.InvocationException; |
40 | 49 | import com.sun.jdi.ObjectReference; |
41 | 50 | import com.sun.jdi.Value; |
42 | 51 | import com.sun.jdi.VoidValue; |
43 | 52 |
|
44 | 53 | public class EvaluateRequestHandler implements IDebugRequestHandler { |
| 54 | + protected static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME); |
| 55 | + |
45 | 56 | @Override |
46 | 57 | public List<Command> getTargetCommands() { |
47 | 58 | return Arrays.asList(Command.EVALUATE); |
@@ -80,12 +91,31 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments, |
80 | 91 | long threadId = stackFrameReference.getThread().uniqueID(); |
81 | 92 | if (value instanceof ObjectReference) { |
82 | 93 | VariableProxy varProxy = new VariableProxy(stackFrameReference.getThread(), "eval", value); |
83 | | - int referenceId = VariableUtils.hasChildren(value, showStaticVariables) |
84 | | - ? context.getRecyclableIdPool().addObject(threadId, varProxy) : 0; |
85 | | - int indexedVariableId = value instanceof ArrayReference ? ((ArrayReference) value).length() : 0; |
| 94 | + int indexedVariables = -1; |
| 95 | + if (value instanceof ArrayReference) { |
| 96 | + indexedVariables = ((ArrayReference) value).length(); |
| 97 | + } else if (value instanceof ObjectReference && DebugSettings.getCurrent().showLogicalStructure |
| 98 | + && engine != null |
| 99 | + && JavaLogicalStructureManager.isIndexedVariable((ObjectReference) value)) { |
| 100 | + try { |
| 101 | + Value sizeValue = JavaLogicalStructureManager.getLogicalSize((ObjectReference) value, stackFrameReference.getThread(), engine); |
| 102 | + if (sizeValue != null && sizeValue instanceof IntegerValue) { |
| 103 | + indexedVariables = ((IntegerValue) sizeValue).value(); |
| 104 | + } |
| 105 | + } catch (InvalidTypeException | ClassNotLoadedException | IncompatibleThreadStateException |
| 106 | + | InvocationException | InterruptedException | ExecutionException | UnsupportedOperationException e) { |
| 107 | + logger.log(Level.INFO, |
| 108 | + String.format("Failed to get the logical size for the type %s.", value.type().name()), e); |
| 109 | + } |
| 110 | + } |
| 111 | + int referenceId = 0; |
| 112 | + if (indexedVariables > 0 || (indexedVariables < 0 && VariableUtils.hasChildren(value, showStaticVariables))) { |
| 113 | + referenceId = context.getRecyclableIdPool().addObject(threadId, varProxy); |
| 114 | + } |
| 115 | + |
86 | 116 | response.body = new Responses.EvaluateResponseBody(variableFormatter.valueToString(value, options), |
87 | 117 | referenceId, variableFormatter.typeToString(value == null ? null : value.type(), options), |
88 | | - indexedVariableId); |
| 118 | + Math.max(indexedVariables, 0)); |
89 | 119 | return response; |
90 | 120 | } |
91 | 121 | // for primitive value |
|
0 commit comments