Unverified Commit 277001d1 authored by Jacob Richman's avatar Jacob Richman Committed by GitHub

Inspector JSON protocol to support Flutter IntelliJ Plugin tree view. (#12932)

parent 792e7ce8
......@@ -743,6 +743,33 @@ abstract class DiagnosticsNode {
String get _separator => showSeparator ? ':' : '';
/// Serialize the node excluding its descendents to a JSON map.
///
/// Subclasses should override if they have additional properties that are
/// useful for the GUI tools that consume this JSON.
///
/// See also:
///
/// * [WidgetInspectorService], which forms the bridge between JSON returned
/// by this method and interactive tree views in the Flutter IntelliJ
/// plugin.
@mustCallSuper
Map<String, Object> toJsonMap() {
final Map<String, Object> data = <String, Object>{
'name': name,
'showSeparator': showSeparator,
'description': toDescription(),
'level': describeEnum(level),
'showName': showName,
'emptyBodyDescription': emptyBodyDescription,
'style': describeEnum(style),
'valueToString': value.toString(),
'type': runtimeType.toString(),
'hasChildren': getChildren().isNotEmpty,
};
return data;
}
/// Returns a string representation of this diagnostic that is compatible with
/// the style of the parent if the node is not the root.
///
......@@ -1054,6 +1081,13 @@ class StringProperty extends DiagnosticsProperty<String> {
/// Whether the value is enclosed in double quotes.
final bool quoted;
@override
Map<String, Object> toJsonMap() {
final Map<String, Object> json = super.toJsonMap();
json['quoted'] = quoted;
return json;
}
@override
String valueToString({ TextTreeConfiguration parentConfiguration }) {
String text = _description ?? value;
......@@ -1114,6 +1148,15 @@ abstract class _NumProperty<T extends num> extends DiagnosticsProperty<T> {
level: level,
);
@override
Map<String, Object> toJsonMap() {
final Map<String, Object> json = super.toJsonMap();
if (unit != null)
json['unit'] = unit;
json['numberToString'] = numberToString();
return json;
}
/// Optional unit the [value] is measured in.
///
......@@ -1326,6 +1369,17 @@ class FlagProperty extends DiagnosticsProperty<bool> {
level: level,
);
@override
Map<String, Object> toJsonMap() {
final Map<String, Object> json = super.toJsonMap();
if (ifTrue != null)
json['ifTrue'] = ifTrue;
if (ifFalse != null)
json['ifFalse'] = ifFalse;
return json;
}
/// Description to use if the property [value] is true.
///
/// If not specified and [value] equals true the property's priority [level]
......@@ -1443,6 +1497,15 @@ class IterableProperty<T> extends DiagnosticsProperty<Iterable<T>> {
return DiagnosticLevel.fine;
return super.level;
}
@override
Map<String, Object> toJsonMap() {
final Map<String, Object> json = super.toJsonMap();
if (value != null) {
json['values'] = value.map<String>((T value) => value.toString()).toList();
}
return json;
}
}
/// An property than displays enum values tersely.
......@@ -1581,6 +1644,14 @@ class ObjectFlagProperty<T> extends DiagnosticsProperty<T> {
return super.level;
}
@override
Map<String, Object> toJsonMap() {
final Map<String, Object> json = super.toJsonMap();
if (ifPresent != null)
json['ifPresent'] = ifPresent;
return json;
}
}
/// Signature for computing the value of a property.
......@@ -1683,6 +1754,28 @@ class DiagnosticsProperty<T> extends DiagnosticsNode {
final String _description;
@override
Map<String, Object> toJsonMap() {
final Map<String, Object> json = super.toJsonMap();
if (defaultValue != kNoDefaultValue)
json['defaultValue'] = defaultValue.toString();
if (ifEmpty != null)
json['ifEmpty'] = ifEmpty;
if (ifNull != null)
json['ifNull'] = ifNull;
if (tooltip != null)
json['tooltip'] = tooltip;
json['missingIfNull'] = missingIfNull;
if (exception != null)
json['exception'] = exception.toString();
json['propertyType'] = propertyType.toString();
json['valueToString'] = valueToString();
json['defaultLevel'] = describeEnum(_defaultLevel);
if (T is Diagnosticable)
json['isDiagnosticableValue'] = true;
return json;
}
/// Returns a string representation of the property value.
///
/// Subclasses should override this method instead of [toDescription] to
......
......@@ -3362,6 +3362,20 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
return chain.join(' \u2190 ');
}
/// Returns the parent chain from this element back to the root of the tree.
///
/// Useful for debug display of a tree of Elements with only nodes in the path
/// from the root to this Element expanded.
List<Element> debugGetDiagnosticChain() {
final List<Element> chain = <Element>[this];
Element node = _parent;
while (node != null) {
chain.add(node);
node = node._parent;
}
return chain;
}
/// A short, textual description of this element.
@override String toStringShort() {
return widget != null ? '${widget.toStringShort()}' : '[$runtimeType]';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment