Unverified Commit f002839d authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Better print-out of semantics tree (#15302)

parent 2890e18b
...@@ -883,6 +883,8 @@ abstract class DiagnosticsNode { ...@@ -883,6 +883,8 @@ abstract class DiagnosticsNode {
builder.write( builder.write(
config.isNameOnOwnLine || description.contains('\n') ? '\n' : ' '); config.isNameOnOwnLine || description.contains('\n') ? '\n' : ' ');
if (description.contains('\n') && style == DiagnosticsTreeStyle.singleLine)
builder.prefixOtherLines += ' ';
} }
builder.prefixOtherLines += children.isEmpty ? builder.prefixOtherLines += children.isEmpty ?
config.propertyPrefixNoChildren : config.propertyPrefixIfChildren; config.propertyPrefixNoChildren : config.propertyPrefixIfChildren;
......
...@@ -255,7 +255,7 @@ class MatrixUtils { ...@@ -255,7 +255,7 @@ class MatrixUtils {
List<String> debugDescribeTransform(Matrix4 transform) { List<String> debugDescribeTransform(Matrix4 transform) {
if (transform == null) if (transform == null)
return const <String>['null']; return const <String>['null'];
final List<String> matrix = transform.toString().split('\n').map((String s) => ' $s').toList(); final List<String> matrix = transform.toString().split('\n').toList();
matrix.removeLast(); matrix.removeLast();
return matrix; return matrix;
} }
......
...@@ -1378,15 +1378,8 @@ class SemanticsNode extends AbstractNode with DiagnosticableTreeMixin { ...@@ -1378,15 +1378,8 @@ class SemanticsNode extends AbstractNode with DiagnosticableTreeMixin {
} }
final List<String> actions = _actions.keys.map((SemanticsAction action) => describeEnum(action)).toList()..sort(); final List<String> actions = _actions.keys.map((SemanticsAction action) => describeEnum(action)).toList()..sort();
properties.add(new IterableProperty<String>('actions', actions, ifEmpty: null)); properties.add(new IterableProperty<String>('actions', actions, ifEmpty: null));
if (_hasFlag(SemanticsFlag.hasEnabledState)) final List<String> flags = SemanticsFlag.values.values.where((SemanticsFlag flag) => _hasFlag(flag)).map((SemanticsFlag flag) => flag.toString().substring('SemanticsFlag.'.length)).toList();
properties.add(new FlagProperty('isEnabled', value: _hasFlag(SemanticsFlag.isEnabled), ifFalse: 'disabled')); properties.add(new IterableProperty<String>('flags', flags, ifEmpty: null));
if (_hasFlag(SemanticsFlag.hasCheckedState))
properties.add(new FlagProperty('isChecked', value: _hasFlag(SemanticsFlag.isChecked), ifTrue: 'checked', ifFalse: 'unchecked'));
properties.add(new FlagProperty('isInMutuallyExcusiveGroup', value: _hasFlag(SemanticsFlag.isInMutuallyExclusiveGroup), ifTrue: 'mutually-exclusive'));
properties.add(new FlagProperty('isSelected', value: _hasFlag(SemanticsFlag.isSelected), ifTrue: 'selected'));
properties.add(new FlagProperty('isFocused', value: _hasFlag(SemanticsFlag.isFocused), ifTrue: 'focused'));
properties.add(new FlagProperty('isButton', value: _hasFlag(SemanticsFlag.isButton), ifTrue: 'button'));
properties.add(new FlagProperty('isTextField', value: _hasFlag(SemanticsFlag.isTextField), ifTrue: 'textField'));
properties.add(new FlagProperty('isInvisible', value: isInvisible, ifTrue: 'invisible')); properties.add(new FlagProperty('isInvisible', value: isInvisible, ifTrue: 'invisible'));
properties.add(new StringProperty('label', _label, defaultValue: '')); properties.add(new StringProperty('label', _label, defaultValue: ''));
properties.add(new StringProperty('value', _value, defaultValue: '')); properties.add(new StringProperty('value', _value, defaultValue: ''));
...@@ -1422,7 +1415,7 @@ class SemanticsNode extends AbstractNode with DiagnosticableTreeMixin { ...@@ -1422,7 +1415,7 @@ class SemanticsNode extends AbstractNode with DiagnosticableTreeMixin {
@override @override
DiagnosticsNode toDiagnosticsNode({ DiagnosticsNode toDiagnosticsNode({
String name, String name,
DiagnosticsTreeStyle style: DiagnosticsTreeStyle.dense, DiagnosticsTreeStyle style: DiagnosticsTreeStyle.sparse,
DebugSemanticsDumpOrder childOrder: DebugSemanticsDumpOrder.geometricOrder, DebugSemanticsDumpOrder childOrder: DebugSemanticsDumpOrder.geometricOrder,
}) { }) {
return new _SemanticsDiagnosticableNode( return new _SemanticsDiagnosticableNode(
......
...@@ -15,10 +15,10 @@ void main() { ...@@ -15,10 +15,10 @@ void main() {
final Matrix4 identity = new Matrix4.identity(); final Matrix4 identity = new Matrix4.identity();
final List<String> description = debugDescribeTransform(identity); final List<String> description = debugDescribeTransform(identity);
expect(description, equals(<String>[ expect(description, equals(<String>[
' [0] 1.0,0.0,0.0,0.0', '[0] 1.0,0.0,0.0,0.0',
' [1] 0.0,1.0,0.0,0.0', '[1] 0.0,1.0,0.0,0.0',
' [2] 0.0,0.0,1.0,0.0', '[2] 0.0,0.0,1.0,0.0',
' [3] 0.0,0.0,0.0,1.0', '[3] 0.0,0.0,0.0,1.0',
])); ]));
}); });
......
...@@ -126,9 +126,20 @@ void main() { ...@@ -126,9 +126,20 @@ void main() {
expect( expect(
root.toStringDeep(childOrder: DebugSemanticsDumpOrder.geometricOrder), root.toStringDeep(childOrder: DebugSemanticsDumpOrder.geometricOrder),
'SemanticsNode#3(STALE, owner: null, Rect.fromLTRB(0.0, 0.0, 10.0, 5.0))\n' 'SemanticsNode#3\n'
'├SemanticsNode#1(STALE, owner: null, Rect.fromLTRB(0.0, 0.0, 5.0, 5.0))\n' ' │ STALE\n'
'└SemanticsNode#2(STALE, owner: null, Rect.fromLTRB(5.0, 0.0, 10.0, 5.0))\n', ' │ owner: null\n'
' │ Rect.fromLTRB(0.0, 0.0, 10.0, 5.0)\n'
' │\n'
' ├─SemanticsNode#1\n'
' │ STALE\n'
' │ owner: null\n'
' │ Rect.fromLTRB(0.0, 0.0, 5.0, 5.0)\n'
' │\n'
' └─SemanticsNode#2\n'
' STALE\n'
' owner: null\n'
' Rect.fromLTRB(5.0, 0.0, 10.0, 5.0)\n'
); );
}); });
...@@ -287,16 +298,38 @@ void main() { ...@@ -287,16 +298,38 @@ void main() {
); );
expect( expect(
root.toStringDeep(childOrder: DebugSemanticsDumpOrder.geometricOrder), root.toStringDeep(childOrder: DebugSemanticsDumpOrder.geometricOrder),
'SemanticsNode#3(STALE, owner: null, Rect.fromLTRB(0.0, 0.0, 20.0, 5.0))\n' 'SemanticsNode#3\n'
'├SemanticsNode#2(STALE, owner: null, Rect.fromLTRB(10.0, 0.0, 15.0, 5.0))\n' ' │ STALE\n'
'└SemanticsNode#1(STALE, owner: null, Rect.fromLTRB(15.0, 0.0, 20.0, 5.0))\n', ' │ owner: null\n'
' │ Rect.fromLTRB(0.0, 0.0, 20.0, 5.0)\n'
' │\n'
' ├─SemanticsNode#2\n'
' │ STALE\n'
' │ owner: null\n'
' │ Rect.fromLTRB(10.0, 0.0, 15.0, 5.0)\n'
' │\n'
' └─SemanticsNode#1\n'
' STALE\n'
' owner: null\n'
' Rect.fromLTRB(15.0, 0.0, 20.0, 5.0)\n'
); );
expect( expect(
root.toStringDeep(childOrder: DebugSemanticsDumpOrder.inverseHitTest), root.toStringDeep(childOrder: DebugSemanticsDumpOrder.inverseHitTest),
'SemanticsNode#3(STALE, owner: null, Rect.fromLTRB(0.0, 0.0, 20.0, 5.0))\n' 'SemanticsNode#3\n'
'├SemanticsNode#1(STALE, owner: null, Rect.fromLTRB(15.0, 0.0, 20.0, 5.0))\n' ' │ STALE\n'
'└SemanticsNode#2(STALE, owner: null, Rect.fromLTRB(10.0, 0.0, 15.0, 5.0))\n', ' │ owner: null\n'
' │ Rect.fromLTRB(0.0, 0.0, 20.0, 5.0)\n'
' │\n'
' ├─SemanticsNode#1\n'
' │ STALE\n'
' │ owner: null\n'
' │ Rect.fromLTRB(15.0, 0.0, 20.0, 5.0)\n'
' │\n'
' └─SemanticsNode#2\n'
' STALE\n'
' owner: null\n'
' Rect.fromLTRB(10.0, 0.0, 15.0, 5.0)\n'
); );
final SemanticsNode child3 = new SemanticsNode() final SemanticsNode child3 = new SemanticsNode()
...@@ -320,22 +353,68 @@ void main() { ...@@ -320,22 +353,68 @@ void main() {
expect( expect(
rootComplex.toStringDeep(childOrder: DebugSemanticsDumpOrder.geometricOrder), rootComplex.toStringDeep(childOrder: DebugSemanticsDumpOrder.geometricOrder),
'SemanticsNode#7(STALE, owner: null, Rect.fromLTRB(0.0, 0.0, 25.0, 5.0))\n' 'SemanticsNode#7\n'
'├SemanticsNode#4(STALE, owner: null, Rect.fromLTRB(0.0, 0.0, 10.0, 5.0))\n' ' │ STALE\n'
'│├SemanticsNode#6(STALE, owner: null, Rect.fromLTRB(0.0, 0.0, 5.0, 5.0))\n' ' │ owner: null\n'
'│└SemanticsNode#5(STALE, owner: null, Rect.fromLTRB(5.0, 0.0, 10.0, 5.0))\n' ' │ Rect.fromLTRB(0.0, 0.0, 25.0, 5.0)\n'
'├SemanticsNode#2(STALE, owner: null, Rect.fromLTRB(10.0, 0.0, 15.0, 5.0))\n' ' │\n'
'└SemanticsNode#1(STALE, owner: null, Rect.fromLTRB(15.0, 0.0, 20.0, 5.0))\n', ' ├─SemanticsNode#4\n'
' │ │ STALE\n'
' │ │ owner: null\n'
' │ │ Rect.fromLTRB(0.0, 0.0, 10.0, 5.0)\n'
' │ │\n'
' │ ├─SemanticsNode#6\n'
' │ │ STALE\n'
' │ │ owner: null\n'
' │ │ Rect.fromLTRB(0.0, 0.0, 5.0, 5.0)\n'
' │ │\n'
' │ └─SemanticsNode#5\n'
' │ STALE\n'
' │ owner: null\n'
' │ Rect.fromLTRB(5.0, 0.0, 10.0, 5.0)\n'
' │\n'
' ├─SemanticsNode#2\n'
' │ STALE\n'
' │ owner: null\n'
' │ Rect.fromLTRB(10.0, 0.0, 15.0, 5.0)\n'
' │\n'
' └─SemanticsNode#1\n'
' STALE\n'
' owner: null\n'
' Rect.fromLTRB(15.0, 0.0, 20.0, 5.0)\n'
); );
expect( expect(
rootComplex.toStringDeep(childOrder: DebugSemanticsDumpOrder.inverseHitTest), rootComplex.toStringDeep(childOrder: DebugSemanticsDumpOrder.inverseHitTest),
'SemanticsNode#7(STALE, owner: null, Rect.fromLTRB(0.0, 0.0, 25.0, 5.0))\n' 'SemanticsNode#7\n'
'├SemanticsNode#1(STALE, owner: null, Rect.fromLTRB(15.0, 0.0, 20.0, 5.0))\n' ' │ STALE\n'
'├SemanticsNode#2(STALE, owner: null, Rect.fromLTRB(10.0, 0.0, 15.0, 5.0))\n' ' │ owner: null\n'
'└SemanticsNode#4(STALE, owner: null, Rect.fromLTRB(0.0, 0.0, 10.0, 5.0))\n' ' │ Rect.fromLTRB(0.0, 0.0, 25.0, 5.0)\n'
' ├SemanticsNode#5(STALE, owner: null, Rect.fromLTRB(5.0, 0.0, 10.0, 5.0))\n' ' │\n'
' └SemanticsNode#6(STALE, owner: null, Rect.fromLTRB(0.0, 0.0, 5.0, 5.0))\n', ' ├─SemanticsNode#1\n'
' │ STALE\n'
' │ owner: null\n'
' │ Rect.fromLTRB(15.0, 0.0, 20.0, 5.0)\n'
' │\n'
' ├─SemanticsNode#2\n'
' │ STALE\n'
' │ owner: null\n'
' │ Rect.fromLTRB(10.0, 0.0, 15.0, 5.0)\n'
' │\n'
' └─SemanticsNode#4\n'
' │ STALE\n'
' │ owner: null\n'
' │ Rect.fromLTRB(0.0, 0.0, 10.0, 5.0)\n'
' │\n'
' ├─SemanticsNode#5\n'
' │ STALE\n'
' │ owner: null\n'
' │ Rect.fromLTRB(5.0, 0.0, 10.0, 5.0)\n'
' │\n'
' └─SemanticsNode#6\n'
' STALE\n'
' owner: null\n'
' Rect.fromLTRB(0.0, 0.0, 5.0, 5.0)\n'
); );
}); });
...@@ -343,12 +422,33 @@ void main() { ...@@ -343,12 +422,33 @@ void main() {
final SemanticsNode minimalProperties = new SemanticsNode(); final SemanticsNode minimalProperties = new SemanticsNode();
expect( expect(
minimalProperties.toStringDeep(), minimalProperties.toStringDeep(),
'SemanticsNode#1(Rect.fromLTRB(0.0, 0.0, 0.0, 0.0), invisible)\n', 'SemanticsNode#1\n'
' Rect.fromLTRB(0.0, 0.0, 0.0, 0.0)\n'
' invisible\n'
); );
expect( expect(
minimalProperties.toStringDeep(minLevel: DiagnosticLevel.hidden), minimalProperties.toStringDeep(minLevel: DiagnosticLevel.hidden),
'SemanticsNode#1(owner: null, isMergedIntoParent: false, mergeAllDescendantsIntoThisNode: false, Rect.fromLTRB(0.0, 0.0, 0.0, 0.0), actions: [], isInMutuallyExcusiveGroup: false, isSelected: false, isFocused: false, isButton: false, isTextField: false, invisible, label: "", value: "", increasedValue: "", decreasedValue: "", hint: "", textDirection: null, nextNodeId: null, previousNodeId: null, sortOrder: null, scrollExtentMin: null, scrollPosition: null, scrollExtentMax: null)\n' 'SemanticsNode#1\n'
' owner: null\n'
' isMergedIntoParent: false\n'
' mergeAllDescendantsIntoThisNode: false\n'
' Rect.fromLTRB(0.0, 0.0, 0.0, 0.0)\n'
' actions: []\n'
' flags: []\n'
' invisible\n'
' label: ""\n'
' value: ""\n'
' increasedValue: ""\n'
' decreasedValue: ""\n'
' hint: ""\n'
' textDirection: null\n'
' nextNodeId: null\n'
' previousNodeId: null\n'
' sortOrder: null\n'
' scrollExtentMin: null\n'
' scrollPosition: null\n'
' scrollExtentMax: null\n'
); );
final SemanticsConfiguration config = new SemanticsConfiguration() final SemanticsConfiguration config = new SemanticsConfiguration()
...@@ -369,7 +469,19 @@ void main() { ...@@ -369,7 +469,19 @@ void main() {
..updateWith(config: config, childrenInInversePaintOrder: null); ..updateWith(config: config, childrenInInversePaintOrder: null);
expect( expect(
allProperties.toStringDeep(), allProperties.toStringDeep(),
equalsIgnoringHashCodes('SemanticsNode#2(STALE, owner: null, merge boundary ⛔️, Rect.fromLTRB(60.0, 20.0, 80.0, 50.0), actions: [longPress, scrollUp, showOnScreen], unchecked, selected, button, label: "Use all the properties", textDirection: rtl, sortOrder: SemanticsSortOrder#8e690(keys: [OrdinalSortKey#ca2b8(order: 1.0)]))\n'), equalsIgnoringHashCodes(
'SemanticsNode#2\n'
' STALE\n'
' owner: null\n'
' merge boundary ⛔️\n'
' Rect.fromLTRB(60.0, 20.0, 80.0, 50.0)\n'
' actions: longPress, scrollUp, showOnScreen\n'
' flags: hasCheckedState, isSelected, isButton\n'
' label: "Use all the properties"\n'
' textDirection: rtl\n'
' sortOrder: SemanticsSortOrder#b555b(keys:\n'
' [OrdinalSortKey#19df5(order: 1.0)])\n'
),
); );
expect( expect(
allProperties.getSemanticsData().toString(), allProperties.getSemanticsData().toString(),
...@@ -381,7 +493,10 @@ void main() { ...@@ -381,7 +493,10 @@ void main() {
..transform = new Matrix4.diagonal3(new Vector3(10.0, 10.0, 1.0)); ..transform = new Matrix4.diagonal3(new Vector3(10.0, 10.0, 1.0));
expect( expect(
scaled.toStringDeep(), scaled.toStringDeep(),
'SemanticsNode#3(STALE, owner: null, Rect.fromLTRB(50.0, 10.0, 70.0, 40.0) scaled by 10.0x)\n', 'SemanticsNode#3\n'
' STALE\n'
' owner: null\n'
' Rect.fromLTRB(50.0, 10.0, 70.0, 40.0) scaled by 10.0x\n',
); );
expect( expect(
scaled.getSemanticsData().toString(), scaled.getSemanticsData().toString(),
......
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