|
21 | 21 | import com.sun.jdi.ObjectReference; |
22 | 22 | import com.sun.jdi.Type; |
23 | 23 |
|
| 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 | + */ |
24 | 29 | 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 | + */ |
25 | 36 | public ClassObjectFormatter(BiFunction<Type, Map<String, Object>, String> typeStringFunction) { |
26 | 37 | super(typeStringFunction); |
27 | 38 | } |
28 | 39 |
|
| 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 | + */ |
29 | 47 | @Override |
30 | 48 | protected String getPrefix(ObjectReference value, Map<String, Object> options) { |
31 | 49 | Type classType = ((ClassObjectReference) value).reflectedType(); |
32 | 50 | return String.format("%s (%s)", super.getPrefix(value, options), |
33 | 51 | typeToStringFunction.apply(classType, options)); |
34 | 52 | } |
35 | 53 |
|
| 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 | + */ |
36 | 61 | @Override |
37 | 62 | public boolean acceptType(Type type, Map<String, Object> options) { |
38 | 63 | return super.acceptType(type, options) && (type.signature().charAt(0) == CLASS_OBJECT |
|
0 commit comments