Skip to content

Commit f29fa8a

Browse files
committed
add binary format for variables;
1 parent 93963b9 commit f29fa8a

3 files changed

Lines changed: 199 additions & 182 deletions

File tree

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/NumericFormatEnum.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
package com.microsoft.java.debug.core.adapter.formatter;
1313

1414
public enum NumericFormatEnum {
15+
BIN,
1516
HEX,
1617
OCT,
1718
DEC

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/NumericFormatter.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,15 @@ public class NumericFormatter implements IValueFormatter {
3030
public static final String NUMERIC_PRECISION_OPTION = "numeric_precision";
3131
private static final NumericFormatEnum DEFAULT_NUMERIC_FORMAT = NumericFormatEnum.DEC;
3232
private static final int DEFAULT_NUMERIC_PRECISION = 0;
33-
private static final Map<NumericFormatEnum, String> enumFormatMap = new HashMap<>();
3433

35-
static {
36-
enumFormatMap.put(NumericFormatEnum.DEC, "%d");
37-
enumFormatMap.put(NumericFormatEnum.HEX, "%#x");
38-
enumFormatMap.put(NumericFormatEnum.OCT, "%#o");
39-
}
34+
private static final String HEX_PREFIX = "0x";
35+
private static final String OCT_PREFIX = "0";
36+
private static final String BIN_PREFIX = "0b";
4037

4138
/**
4239
* Get the string representations for an object.
4340
*
44-
* @param obj the value object
41+
* @param obj the value object
4542
* @param options extra information for printing
4643
* @return the string representations.
4744
*/
@@ -91,7 +88,6 @@ public Value valueOf(String value, Type type, Map<String, Object> options) {
9188
throw new UnsupportedOperationException(String.format("%s is not a numeric type.", type.name()));
9289
}
9390

94-
9591
/**
9692
* The conditional function for this formatter.
9793
*
@@ -122,11 +118,21 @@ public Map<String, Object> getDefaultOptions() {
122118

123119
static String formatNumber(long value, Map<String, Object> options) {
124120
NumericFormatEnum formatEnum = getNumericFormatOption(options);
125-
return String.format(enumFormatMap.get(formatEnum), value);
121+
switch (formatEnum) {
122+
case HEX:
123+
return HEX_PREFIX + Long.toHexString(value);
124+
case OCT:
125+
return OCT_PREFIX + Long.toOctalString(value);
126+
case BIN:
127+
return BIN_PREFIX + Long.toBinaryString(value);
128+
default:
129+
return Long.toString(value);
130+
}
126131
}
127132

128133
private static long parseNumber(String number) {
129-
return Long.decode(number);
134+
return number.startsWith(BIN_PREFIX)
135+
? Long.parseLong(number.substring(2), 2) : Long.decode(number);
130136
}
131137

132138
private static double parseFloatDouble(String number) {

0 commit comments

Comments
 (0)