Skip to content

Commit 415f2ba

Browse files
committed
ClassObjectFormatter
1 parent 2ad2638 commit 415f2ba

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,43 @@
2121
import com.sun.jdi.ObjectReference;
2222
import com.sun.jdi.Type;
2323

24+
/**
25+
* Formatter for Java ClassObjectReferences in the Java Debug Interface (JDI).
26+
* Extends the ObjectFormatter to provide customized string representations of Class objects,
27+
* incorporating additional class type information.
28+
*/
2429
public class ClassObjectFormatter extends ObjectFormatter {
30+
31+
/**
32+
* Constructs a ClassObjectFormatter with a specific function to generate string representations based on the JDI type.
33+
*
34+
* @param typeStringFunction A function that generates a string representation based on the JDI type and formatting options.
35+
*/
2536
public ClassObjectFormatter(BiFunction<Type, Map<String, Object>, String> typeStringFunction) {
2637
super(typeStringFunction);
2738
}
2839

40+
/**
41+
* Generates a string prefix for ClassObjectReference instances, enhancing the default object prefix with class type information.
42+
*
43+
* @param value The object reference, expected to be a ClassObjectReference.
44+
* @param options Additional formatting options that may influence the output.
45+
* @return A string prefix that includes both the default object prefix and the class's type information.
46+
*/
2947
@Override
3048
protected String getPrefix(ObjectReference value, Map<String, Object> options) {
3149
Type classType = ((ClassObjectReference) value).reflectedType();
3250
return String.format("%s (%s)", super.getPrefix(value, options),
3351
typeToStringFunction.apply(classType, options));
3452
}
3553

54+
/**
55+
* Determines if this formatter can handle the provided type, specifically targeting ClassObject and its signature.
56+
*
57+
* @param type The JDI type of the object.
58+
* @param options Additional options that might influence the decision; unused in this formatter.
59+
* @return True if the type is a ClassObject or matches the Class signature, false otherwise.
60+
*/
3661
@Override
3762
public boolean acceptType(Type type, Map<String, Object> options) {
3863
return super.acceptType(type, options) && (type.signature().charAt(0) == CLASS_OBJECT

0 commit comments

Comments
 (0)