diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/ArrayObjectFormatter.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/ArrayObjectFormatter.java index a6dee13ef..994897bf6 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/ArrayObjectFormatter.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/ArrayObjectFormatter.java @@ -21,11 +21,30 @@ import com.sun.jdi.Type; import com.sun.jdi.Value; +/** + * Formatter for array objects in the Java Debug Interface (JDI). + * Extends the ObjectFormatter to provide string representations of array objects, + * incorporating the array length into the format. + */ public class ArrayObjectFormatter extends ObjectFormatter { + + /** + * Constructs an ArrayObjectFormatter with a specific type string function. + * + * @param typeStringFunction A function that generates a string representation based on the JDI type and options. + */ public ArrayObjectFormatter(BiFunction, String> typeStringFunction) { super(typeStringFunction); } + /** + * Generates a prefix for the array object string representation, + * including the array's type and length. + * + * @param value The object reference for the array. + * @param options Additional options to format the string. + * @return A string prefix for the array representation. + */ @Override protected String getPrefix(ObjectReference value, Map options) { String arrayTypeWithLength = String.format("[%s]", @@ -33,11 +52,25 @@ protected String getPrefix(ObjectReference value, Map options) { return super.getPrefix(value, options).replaceFirst("\\[]", arrayTypeWithLength); } + /** + * Determines if this formatter can handle the provided type, + * specifically checking for array types. + * + * @param type The JDI type of the object. + * @param options Additional options that might influence the formatting. + * @return True if the type is an array, false otherwise. + */ @Override public boolean acceptType(Type type, Map options) { return type != null && type.signature().charAt(0) == ARRAY; } + /** + * Calculates the length of the array. + * + * @param value The JDI value representing the array. + * @return The length of the array. + */ private static int arrayLength(Value value) { return ((ArrayReference) value).length(); } diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/BooleanFormatter.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/BooleanFormatter.java index ac13fb8d9..cdaddc0a1 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/BooleanFormatter.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/BooleanFormatter.java @@ -19,13 +19,33 @@ import com.sun.jdi.Value; import com.sun.jdi.VirtualMachine; +/** + * Formatter for boolean values in the Java Debug Interface (JDI). + * Implements the IValueFormatter interface to provide string representations + * and value conversions for boolean types. + */ public class BooleanFormatter implements IValueFormatter { + /** + * Converts a JDI value object into its string representation. + * + * @param value The value to be formatted to string. + * @param options Additional options affecting the format; unused in this formatter. + * @return A string representation of the boolean value, or "null" if the value is null. + */ @Override public String toString(Object value, Map options) { return value == null ? NullObjectFormatter.NULL_STRING : value.toString(); } + /** + * Determines if this formatter is applicable for the given type, + * specifically checking for boolean types. + * + * @param type The JDI type of the object. + * @param options Additional options that might influence the formatting; unused in this formatter. + * @return True if the type is a boolean, false otherwise. + */ @Override public boolean acceptType(Type type, Map options) { if (type == null) { @@ -35,6 +55,14 @@ public boolean acceptType(Type type, Map options) { return signature0 == BOOLEAN; } + /** + * Converts a string representation of a boolean into a JDI Value object. + * + * @param value The string value to convert. + * @param type The expected JDI type; used to fetch the VirtualMachine reference. + * @param options Additional conversion options; unused in this formatter. + * @return A JDI Value representing the boolean state indicated by the input string. + */ @Override public Value valueOf(String value, Type type, Map options) { VirtualMachine vm = type.virtualMachine(); diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/CharacterFormatter.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/CharacterFormatter.java index a8639ec41..e91a3c6c7 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/CharacterFormatter.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/CharacterFormatter.java @@ -19,13 +19,33 @@ import com.sun.jdi.Value; import com.sun.jdi.VirtualMachine; +/** + * Formatter for character values in the Java Debug Interface (JDI). + * Implements the IValueFormatter interface to provide string representations + * and value conversions for char types. + */ public class CharacterFormatter implements IValueFormatter { + /** + * Converts a JDI value object into its string representation. + * + * @param value The character value to be formatted to string. + * @param options Additional options affecting the format; unused in this formatter. + * @return A string representation of the character value, or "null" if the value is null. + */ @Override public String toString(Object value, Map options) { return value == null ? NullObjectFormatter.NULL_STRING : value.toString(); } + /** + * Determines if this formatter is applicable for the given type, + * specifically checking for char types. + * + * @param type The JDI type of the object. + * @param options Additional options that might influence the formatting; unused in this formatter. + * @return True if the type is a char, false otherwise. + */ @Override public boolean acceptType(Type type, Map options) { if (type == null) { @@ -35,17 +55,27 @@ public boolean acceptType(Type type, Map options) { return signature0 == CHAR; } + /** + * Converts a string representation of a character into a JDI Value object. + * + * @param value The string value to convert, expected to be a single character or a character within single quotes. + * @param type The expected JDI type; used to fetch the VirtualMachine reference. + * @param options Additional conversion options; unused in this formatter. + * @return A JDI Value representing the character indicated by the input string. Handles both single characters and characters encapsulated in single quotes. + */ @Override public Value valueOf(String value, Type type, Map options) { VirtualMachine vm = type.virtualMachine(); if (value == null) { return null; } + // Supports parsing character values encapsulated in single quotes, e.g., 'a'. if (value.length() == 3 && value.startsWith("'") && value.endsWith("'")) { return type.virtualMachine().mirrorOf(value.charAt(1)); } + // Default case for single characters not encapsulated in quotes. return vm.mirrorOf(value.charAt(0)); } } diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/ClassObjectFormatter.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/ClassObjectFormatter.java index 80491486f..5a4710113 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/ClassObjectFormatter.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/ClassObjectFormatter.java @@ -21,11 +21,29 @@ import com.sun.jdi.ObjectReference; import com.sun.jdi.Type; +/** + * Formatter for Java ClassObjectReferences in the Java Debug Interface (JDI). + * Extends the ObjectFormatter to provide customized string representations of Class objects, + * incorporating additional class type information. + */ public class ClassObjectFormatter extends ObjectFormatter { + + /** + * Constructs a ClassObjectFormatter with a specific function to generate string representations based on the JDI type. + * + * @param typeStringFunction A function that generates a string representation based on the JDI type and formatting options. + */ public ClassObjectFormatter(BiFunction, String> typeStringFunction) { super(typeStringFunction); } + /** + * Generates a string prefix for ClassObjectReference instances, enhancing the default object prefix with class type information. + * + * @param value The object reference, expected to be a ClassObjectReference. + * @param options Additional formatting options that may influence the output. + * @return A string prefix that includes both the default object prefix and the class's type information. + */ @Override protected String getPrefix(ObjectReference value, Map options) { Type classType = ((ClassObjectReference) value).reflectedType(); @@ -33,6 +51,13 @@ protected String getPrefix(ObjectReference value, Map options) { typeToStringFunction.apply(classType, options)); } + /** + * Determines if this formatter can handle the provided type, specifically targeting ClassObject and its signature. + * + * @param type The JDI type of the object. + * @param options Additional options that might influence the decision; unused in this formatter. + * @return True if the type is a ClassObject or matches the Class signature, false otherwise. + */ @Override public boolean acceptType(Type type, Map options) { return super.acceptType(type, options) && (type.signature().charAt(0) == CLASS_OBJECT diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/ITypeFormatter.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/ITypeFormatter.java index b8a556da7..39dfa8a28 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/ITypeFormatter.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/ITypeFormatter.java @@ -11,5 +11,12 @@ package com.microsoft.java.debug.core.adapter.formatter; +/** + * Represents a formatter dedicated to handling specific types within the Java Debug Interface (JDI). + * This interface extends the {@link IFormatter}, inheriting its methods for converting objects to string representations + * and determining applicability based on type. Implementers of this interface should provide type-specific + * formatting logic to accurately represent objects during debugging. + */ public interface ITypeFormatter extends IFormatter { + // Inherits all methods from IFormatter without adding new ones. } diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/NullObjectFormatter.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/NullObjectFormatter.java index d84360ae2..c9f0cea83 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/NullObjectFormatter.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/NullObjectFormatter.java @@ -16,19 +16,49 @@ import com.sun.jdi.Type; import com.sun.jdi.Value; +/** + * A formatter dedicated to handling null values in the Java Debug Interface (JDI). + * Implements the {@link IValueFormatter} interface, providing a uniform representation + * for null objects during debugging sessions. + */ public class NullObjectFormatter implements IValueFormatter { public static final String NULL_STRING = "null"; + /** + * Provides a string representation for null values. + * + * @param value The value to be formatted, expected to be null in this context. + * @param options Additional options affecting the format; unused in this formatter. + * @return A constant string "null" to represent null values. + */ @Override public String toString(Object value, Map options) { return NULL_STRING; } + /** + * Determines if this formatter is applicable for the given type, + * specifically targeting null types. + * + * @param type The JDI type of the object, expected to be null. + * @param options Additional options that might influence the decision; unused in this formatter. + * @return True if the type is null, indicating this formatter should be used. + */ @Override public boolean acceptType(Type type, Map options) { return type == null; } + /** + * Converts a string representation of null into a JDI Value object, which is also null. + * Throws {@link UnsupportedOperationException} if a non-null value is attempted to be set. + * + * @param value The string value to convert, expected to match "null". + * @param type The expected JDI type; unused in this formatter as the output is always null. + * @param options Additional conversion options; unused in this formatter. + * @return null, as the only supported conversion is from the string "null" to a null {@link Value}. + * @throws UnsupportedOperationException if set value is attempted with a non-null value. + */ @Override public Value valueOf(String value, Type type, Map options) { if (value == null || NULL_STRING.equals(value)) { diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/NumericFormatEnum.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/NumericFormatEnum.java index c9766d635..8c8df3261 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/NumericFormatEnum.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/NumericFormatEnum.java @@ -11,8 +11,27 @@ package com.microsoft.java.debug.core.adapter.formatter; +/** + * Defines the numeric formats that can be used for displaying numbers during debugging. + * This enumeration is utilized by formatters to convert numeric values into their + * string representations in various numeric bases. + */ public enum NumericFormatEnum { + /** + * Represents hexadecimal format. + * Numbers displayed in this format are prefixed with '0x' to indicate hexadecimal. + */ HEX, + + /** + * Represents octal format. + * Numbers displayed in this format are prefixed with '0' to indicate octal. + */ OCT, + + /** + * Represents decimal format. + * This is the standard numeric format, displaying numbers in base 10 with no prefix. + */ DEC } diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/NumericFormatter.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/NumericFormatter.java index b26667b93..715cd551b 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/NumericFormatter.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/NumericFormatter.java @@ -25,6 +25,11 @@ import com.sun.jdi.Value; import com.sun.jdi.VirtualMachine; +/** + * Implements a formatter for numeric values, providing string representations + * in various formats (decimal, hexadecimal, octal) and precision levels. + * This class supports long, int, short, byte, float, and double types from the JDI. + */ public class NumericFormatter implements IValueFormatter { public static final String NUMERIC_FORMAT_OPTION = "numeric_format"; public static final String NUMERIC_PRECISION_OPTION = "numeric_precision"; @@ -61,6 +66,16 @@ public String toString(Object obj, Map options) { throw new UnsupportedOperationException(String.format("%s is not a numeric type.", value.type().name())); } + /** + * Converts a string representation of a number into a JDI Value based on the type's signature. + * Supports conversion for numeric types including long, int, short, byte, float, and double. + * + * @param value The string value to be converted. + * @param type The JDI type for the conversion. + * @param options Unused in this formatter. + * @return A JDI Value representing the numeric value. + * @throws UnsupportedOperationException if the type is not numeric. + */ @Override public Value valueOf(String value, Type type, Map options) { VirtualMachine vm = type.virtualMachine(); @@ -112,6 +127,11 @@ public boolean acceptType(Type type, Map options) { || signature0 == DOUBLE; } + /** + * Provides the default formatting options for numeric values. + * + * @return A map containing default options for numeric format and precision. + */ @Override public Map getDefaultOptions() { Map options = new HashMap<>(); @@ -120,34 +140,78 @@ public Map getDefaultOptions() { return options; } + /** + * Formats a numeric value according to the specified numeric format in the options. + * + * @param value The numeric value to format. + * @param options A map containing the formatting options, which may specify the numeric format. + * @return A formatted string representation of the numeric value. + */ static String formatNumber(long value, Map options) { NumericFormatEnum formatEnum = getNumericFormatOption(options); return String.format(enumFormatMap.get(formatEnum), value); } + /** + * Parses a numeric string to its long value representation. + * + * @param number The string representation of the number. + * @return The long value of the parsed number. + */ private static long parseNumber(String number) { return Long.decode(number); } + /** + * Parses a numeric string to its double value representation. + * + * @param number The string representation of the number. + * @return The double value of the parsed number. + */ private static double parseFloatDouble(String number) { return Double.parseDouble(number); } + /** + * Formats a floating-point number according to the specified precision in the options. + * + * @param value The floating-point value to format. + * @param options A map containing the formatting options, which may specify the numeric precision. + * @return A formatted string representation of the floating-point value. + */ private static String formatFloatDouble(double value, Map options) { int precision = getFractionPrecision(options); return String.format(precision > 0 ? String.format("%%.%df", precision) : "%f", value); } + /** + * Retrieves the numeric format option from the provided options map. + * + * @param options A map containing the formatting options. + * @return The specified NumericFormatEnum, or the default format if not specified. + */ private static NumericFormatEnum getNumericFormatOption(Map options) { return options.containsKey(NUMERIC_FORMAT_OPTION) ? (NumericFormatEnum) options.get(NUMERIC_FORMAT_OPTION) : DEFAULT_NUMERIC_FORMAT; } + /** + * Checks if the given type signature corresponds to a floating-point number. + * + * @param signature0 The first character of the type signature. + * @return True if the type is a floating-point number, false otherwise. + */ private static boolean hasFraction(char signature0) { return signature0 == FLOAT || signature0 == DOUBLE; } + /** + * Retrieves the numeric precision option from the provided options map. + * + * @param options A map containing the formatting options. + * @return The specified numeric precision, or the default precision if not specified. + */ private static int getFractionPrecision(Map options) { return options.containsKey(NUMERIC_PRECISION_OPTION) ? (int) options.get(NUMERIC_PRECISION_OPTION) : DEFAULT_NUMERIC_PRECISION; diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/ObjectFormatter.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/ObjectFormatter.java index 25a44d27c..d950e0ec5 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/ObjectFormatter.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/ObjectFormatter.java @@ -11,13 +11,7 @@ package com.microsoft.java.debug.core.adapter.formatter; -import static com.microsoft.java.debug.core.adapter.formatter.TypeIdentifiers.ARRAY; -import static com.microsoft.java.debug.core.adapter.formatter.TypeIdentifiers.CLASS_LOADER; -import static com.microsoft.java.debug.core.adapter.formatter.TypeIdentifiers.CLASS_OBJECT; -import static com.microsoft.java.debug.core.adapter.formatter.TypeIdentifiers.OBJECT; -import static com.microsoft.java.debug.core.adapter.formatter.TypeIdentifiers.STRING; -import static com.microsoft.java.debug.core.adapter.formatter.TypeIdentifiers.THREAD; -import static com.microsoft.java.debug.core.adapter.formatter.TypeIdentifiers.THREAD_GROUP; +import static com.microsoft.java.debug.core.adapter.formatter.TypeIdentifiers.*; import java.util.Map; import java.util.function.BiFunction; @@ -26,23 +20,47 @@ import com.sun.jdi.Type; import com.sun.jdi.Value; +/** + * Provides a generic formatter for objects within the Java Debug Interface (JDI), + * capable of handling a broad range of object types including basic objects, arrays, + * strings, threads, thread groups, class loaders, and class objects. + */ public class ObjectFormatter implements IValueFormatter { /** - * The format type function for this object. + * A function that defines how types are converted to their string representations. */ protected final BiFunction, String> typeToStringFunction; + /** + * Constructs an ObjectFormatter with a custom type-to-string function. + * + * @param typeToStringFunction A function that generates string representations based on the JDI type and formatting options. + */ public ObjectFormatter(BiFunction, String> typeToStringFunction) { this.typeToStringFunction = typeToStringFunction; } + /** + * Formats an object reference to its string representation, including a type prefix and a unique identifier postfix. + * + * @param obj The object to format. + * @param options Additional formatting options. + * @return The formatted string representation of the object. + */ @Override public String toString(Object obj, Map options) { return String.format("%s@%s", getPrefix((ObjectReference) obj, options), getIdPostfix((ObjectReference) obj, options)); } + /** + * Determines if this formatter is applicable for the provided JDI type. + * + * @param type The type of the object to check. + * @param options Additional options that might influence formatting (unused here). + * @return True if the formatter supports the given type; false otherwise. + */ @Override public boolean acceptType(Type type, Map options) { if (type == null) { @@ -51,10 +69,17 @@ public boolean acceptType(Type type, Map options) { char tag = type.signature().charAt(0); return (tag == OBJECT) || (tag == ARRAY) || (tag == STRING) || (tag == THREAD) || (tag == THREAD_GROUP) - || (tag == CLASS_LOADER) - || (tag == CLASS_OBJECT); + || (tag == CLASS_LOADER) || (tag == CLASS_OBJECT); } + /** + * Unsupported operation for setting the value of an object from its string representation. + * + * @param value The string representation of the value to set. + * @param type The JDI type of the object. + * @param options Formatting options (unused). + * @return Currently, always throws UnsupportedOperationException. + */ @Override public Value valueOf(String value, Type type, Map options) { if (value == null || NullObjectFormatter.NULL_STRING.equals(value)) { @@ -64,15 +89,23 @@ public Value valueOf(String value, Type type, Map options) { } /** - * The type with additional prefix before id=${id} of this object.(eg: class, array length) - * @param value The object value. - * @param options additional information about expected format - * @return the type name with additional text + * Generates a type-specific prefix for the object's string representation. + * + * @param value The object whose type prefix is to be generated. + * @param options Additional formatting options. + * @return A string representing the type-specific prefix. */ protected String getPrefix(ObjectReference value, Map options) { return typeToStringFunction.apply(value.type(), options); } + /** + * Generates a unique identifier postfix for the object's string representation. + * + * @param obj The object whose unique ID postfix is to be generated. + * @param options Additional formatting options. + * @return A string representing the object's unique identifier. + */ protected static String getIdPostfix(ObjectReference obj, Map options) { return NumericFormatter.formatNumber(obj.uniqueID(), options); } diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/SimpleTypeFormatter.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/SimpleTypeFormatter.java index 207366981..dd455372a 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/SimpleTypeFormatter.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/SimpleTypeFormatter.java @@ -16,18 +16,22 @@ import com.sun.jdi.Type; +/** + * Implements a type formatter to provide string representations of JDI types, + * with the option to use fully qualified class names or simple names. + * It facilitates readability and customization in how types are presented during debugging. + */ public class SimpleTypeFormatter implements ITypeFormatter { public static final String QUALIFIED_CLASS_NAME_OPTION = "qualified_class_name"; private static final boolean DEFAULT_QUALIFIED_CLASS_NAME_OPTION = false; /** - * Format a JDI type, using the SimpleTypeFormatter.QUALIFIED_FORMAT_OPTION to control whether or not - * to use the fully qualified name. Set QUALIFIED_FORMAT_OPTION to true(java.lang.Boolean) to enable - * fully qualified name, the default option for QUALIFIED_FORMAT_OPTION is false. + * Formats the given JDI type into a string representation. + * The format can be controlled via options to either show the fully qualified class name or just the simple name. * - * @param type the Jdi type - * @param options the format options - * @return the type name + * @param type The JDI type to be formatted. + * @param options Formatting options that dictate whether to use the fully qualified name. + * @return The formatted string representation of the type. */ @Override public String toString(Object type, Map options) { @@ -39,11 +43,23 @@ public String toString(Object type, Map options) { return showQualifiedClassName(options) ? typeName : trimTypeName(typeName); } + /** + * Always accepts the provided type since it is capable of formatting any type. + * + * @param type The JDI type. + * @param options Not used in this method. + * @return Always true, indicating that any type is supported. + */ @Override public boolean acceptType(Type type, Map options) { return true; } + /** + * Provides the default formatting options for this formatter. + * + * @return A map containing the default options, specifying the use of simple names by default. + */ @Override public Map getDefaultOptions() { Map options = new HashMap<>(); @@ -52,9 +68,11 @@ public Map getDefaultOptions() { } /** - * An utility method for convert fully qualified class name to the simplified class name. - * @param type the fully qualified class name - * @return the simplified class name + * Trims a fully qualified class name to its simple name. + * If the class name contains a dot, it returns the substring after the last dot. + * + * @param type The fully qualified class name. + * @return The simple class name without package qualification. */ public static String trimTypeName(String type) { if (type.indexOf('.') >= 0) { @@ -63,6 +81,12 @@ public static String trimTypeName(String type) { return type; } + /** + * Determines whether to show fully qualified class names based on the provided options. + * + * @param options The formatting options map which may contain a value for {@link #QUALIFIED_CLASS_NAME_OPTION}. + * @return True if the options specify to show fully qualified names; otherwise, false. + */ private static boolean showQualifiedClassName(Map options) { return options.containsKey(QUALIFIED_CLASS_NAME_OPTION) ? (Boolean) options.get(QUALIFIED_CLASS_NAME_OPTION) : DEFAULT_QUALIFIED_CLASS_NAME_OPTION; diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/StringObjectFormatter.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/StringObjectFormatter.java index 299f7dd32..2a3ddb5c5 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/StringObjectFormatter.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/StringObjectFormatter.java @@ -23,6 +23,10 @@ import com.sun.jdi.Type; import com.sun.jdi.Value; +/** + * A formatter dedicated to string objects, providing enhanced string representations + * with support for maximum length constraints. + */ public class StringObjectFormatter extends ObjectFormatter implements IValueFormatter { public static final String MAX_STRING_LENGTH_OPTION = "max_string_length"; private static final int DEFAULT_MAX_STRING_LENGTH = 0; @@ -32,6 +36,11 @@ public StringObjectFormatter() { super(null); } + /** + * Provides the default options for string formatting, including a maximum string length. + * + * @return A map containing default options for string formatting. + */ @Override public Map getDefaultOptions() { Map options = new HashMap<>(); @@ -39,6 +48,13 @@ public Map getDefaultOptions() { return options; } + /** + * Formats a `StringReference` into a string representation, applying maximum length constraints if specified. + * + * @param value The string reference to format. + * @param options A map containing formatting options such as 'max_string_length'. + * @return A formatted string representation enclosed in quotes. + */ @Override public String toString(Object value, Map options) { int maxLength = getMaxStringLength(options); @@ -46,12 +62,27 @@ public String toString(Object value, Map options) { maxLength > 0 ? StringUtils.abbreviate(((StringReference) value).value(), maxLength) : ((StringReference) value).value()); } + /** + * Determines if this formatter can handle the provided type, specifically targeting string types. + * + * @param type The JDI type of the object. + * @param options Unused in this method. + * @return True if the type is a string, false otherwise. + */ @Override public boolean acceptType(Type type, Map options) { return type != null && (type.signature().charAt(0) == STRING || type.signature().equals(STRING_SIGNATURE)); } + /** + * Converts a string value back into a `StringReference`, considering any provided options. + * + * @param value The string value to convert. + * @param type The JDI type for the conversion, expected to be `StringType`. + * @param options Unused in this formatter. + * @return A `StringReference` representing the given string value. + */ @Override public Value valueOf(String value, Type type, Map options) { if (value == null || NullObjectFormatter.NULL_STRING.equals(value)) { @@ -65,6 +96,12 @@ public Value valueOf(String value, Type type, Map options) { return type.virtualMachine().mirrorOf(value); } + /** + * Retrieves the maximum string length from the provided options, applying a default if not specified. + * + * @param options Formatting options potentially containing a 'max_string_length' key. + * @return The maximum string length to apply, or a default value if unspecified. + */ private static int getMaxStringLength(Map options) { return options.containsKey(MAX_STRING_LENGTH_OPTION) ? (int) options.get(MAX_STRING_LENGTH_OPTION) : DEFAULT_MAX_STRING_LENGTH; diff --git a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/TypeIdentifiers.java b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/TypeIdentifiers.java index 611c9d2d3..fe54c94bb 100644 --- a/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/TypeIdentifiers.java +++ b/com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/formatter/TypeIdentifiers.java @@ -11,24 +11,31 @@ package com.microsoft.java.debug.core.adapter.formatter; +/** + * Defines constants for JDI type signatures. These identifiers are used to + * recognize specific types during the debugging process, enabling tailored + * formatting and processing for various data types. + */ public final class TypeIdentifiers { - public static final char ARRAY = '['; - public static final char BYTE = 'B'; - public static final char CHAR = 'C'; - public static final char OBJECT = 'L'; - public static final char FLOAT = 'F'; - public static final char DOUBLE = 'D'; - public static final char INT = 'I'; - public static final char LONG = 'J'; - public static final char SHORT = 'S'; - public static final char BOOLEAN = 'Z'; - public static final char STRING = 's'; - public static final char THREAD = 't'; + public static final char ARRAY = '['; // Identifies an array type. + public static final char BYTE = 'B'; // Identifies a byte type. + public static final char CHAR = 'C'; // Identifies a char type. + public static final char OBJECT = 'L'; // Identifies an object type. + public static final char FLOAT = 'F'; // Identifies a float type. + public static final char DOUBLE = 'D'; // Identifies a double type. + public static final char INT = 'I'; // Identifies an int type. + public static final char LONG = 'J'; // Identifies a long type. + public static final char SHORT = 'S'; // Identifies a short type. + public static final char BOOLEAN = 'Z'; // Identifies a boolean type. + public static final char STRING = 's'; // Identifies for string types. + public static final char THREAD = 't'; // Identifies for thread types. - public static final char THREAD_GROUP = 'g'; - public static final char CLASS_LOADER = 'l'; - public static final char CLASS_OBJECT = 'c'; + // Specific Java types + public static final char THREAD_GROUP = 'g'; // A custom identifier for ThreadGroup types. + public static final char CLASS_LOADER = 'l'; // A custom identifier for ClassLoader types. + public static final char CLASS_OBJECT = 'c'; // A custom identifier for Class types. - public static final String STRING_SIGNATURE = "Ljava/lang/String;"; - public static final String CLASS_SIGNATURE = "Ljava/lang/Class;"; + // Full signatures for certain types + public static final String STRING_SIGNATURE = "Ljava/lang/String;"; // The full signature for the String class. + public static final String CLASS_SIGNATURE = "Ljava/lang/Class;"; // The full signature for the Class class. }