Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
import com.sun.jdi.StringReference;
import com.sun.jdi.Type;
import com.sun.jdi.Value;
import com.sun.jdi.PrimitiveType;
import com.sun.jdi.ClassNotLoadedException;

public class VariablesRequestHandler implements IDebugRequestHandler {
protected static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
Expand All @@ -82,7 +84,7 @@ public class VariablesRequestHandler implements IDebugRequestHandler {
* single-threaded JDWP request processing strategy,
* a single JDWP latency is about 10ms.
*/
static final long USABLE_JDWP_LATENCY = 10/**ms*/;
static final long USABLE_JDWP_LATENCY = 10/*ms*/;

@Override
public List<Command> getTargetCommands() {
Expand Down Expand Up @@ -370,10 +372,12 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
referenceId = context.getRecyclableIdPool().addObject(containerNode.getThreadId(), varProxy);
}

String[] rawAttributes = extractAttributes(javaVariable);

Types.Variable typedVariables = new Types.Variable(name, valueString, typeString, referenceId, evaluateName);
typedVariables.indexedVariables = Math.max(indexedVariables, 0);
if (varProxy != null && varProxy.isLazyVariable()) {
typedVariables.presentationHint = new VariablePresentationHint(true);
if ((varProxy != null && varProxy.isLazyVariable()) || (rawAttributes.length > 0)) {
typedVariables.presentationHint = new VariablePresentationHint(varProxy != null && varProxy.isLazyVariable(), rawAttributes);
}

if (detailsValue != null) {
Expand All @@ -391,6 +395,36 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
return CompletableFuture.completedFuture(response);
}

private String[] extractAttributes(Variable variable) {
final List<String> attributes = new ArrayList<>();
if (variable.field != null) {
if (variable.field.isStatic()) {
attributes.add("static");
}
if (variable.field.isFinal()) {
// static final Primitive or StringRef fields are compile-time constants in Java
boolean isPrimitive;
try {
isPrimitive = variable.field.type() instanceof PrimitiveType;
} catch (ClassNotLoadedException e) { /* type() not yet loaded indicates some ReferenceType */
isPrimitive = false;
}
boolean canBeTrueConstant = (isPrimitive || variable.field instanceof StringReference);
if (variable.field.isStatic() && canBeTrueConstant) {
attributes.add("constant");
}
attributes.add("readOnly");
}
}
// local 'final' variables get inlined by the compiler and do not appear

if (variable.value instanceof StringReference) {
attributes.add("rawString");
}

return attributes.toArray(new String[0]);
}

private boolean supportsLogicStructureView(IDebugAdapterContext context) {
return (!useAsyncJDWP(context) || context.getJDWPLatency() <= USABLE_JDWP_LATENCY)
&& DebugSettings.getCurrent().showLogicalStructure;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,13 @@ public static class StackFrame {
/**
* Constructs a StackFrame with the given information.
*
* @param id
* the stack frame id
* @param name
* the stack frame name
* @param src
* source info of the stack frame
* @param ln
* line number of the stack frame
* @param col
* column number of the stack frame
* @param presentationHint
* An optional hint for how to present this frame in the UI.
* Values: 'normal', 'label', 'subtle'
* @param id the stack frame id
* @param name the stack frame name
* @param src source info of the stack frame
* @param ln line number of the stack frame
* @param col column number of the stack frame
* @param presentationHint An optional hint for how to present this frame in the UI.
* Values: 'normal', 'label', 'subtle'
*/
public StackFrame(int id, String name, Source src, int ln, int col, String presentationHint) {
this.id = id;
Expand Down Expand Up @@ -408,9 +402,11 @@ public static class ExceptionDetails {

public static class VariablePresentationHint {
public boolean lazy;
public String[] attributes;

public VariablePresentationHint(boolean lazy) {
public VariablePresentationHint(boolean lazy, String[] attributes) {
this.lazy = lazy;
this.attributes = attributes;
}
}

Expand Down