Commit 5bce52d6 authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

try use_string_buffers lint (#10034)

parent 18eac03d
...@@ -136,7 +136,7 @@ linter: ...@@ -136,7 +136,7 @@ linter:
- unnecessary_this - unnecessary_this
# - use_rethrow_when_possible # not yet tested # - use_rethrow_when_possible # not yet tested
# - use_setters_to_change_properties # not yet tested # - use_setters_to_change_properties # not yet tested
# - use_string_buffers # not yet tested # - use_string_buffers # https://github.com/dart-lang/linter/pull/664
# - use_to_and_as_if_applicable # not yet tested # - use_to_and_as_if_applicable # not yet tested
# === pub rules === # === pub rules ===
......
...@@ -134,7 +134,7 @@ linter: ...@@ -134,7 +134,7 @@ linter:
- unnecessary_this - unnecessary_this
# - use_rethrow_when_possible # not yet tested # - use_rethrow_when_possible # not yet tested
# - use_setters_to_change_properties # not yet tested # - use_setters_to_change_properties # not yet tested
# - use_string_buffers # not yet tested # - use_string_buffers # https://github.com/dart-lang/linter/pull/664
# - use_to_and_as_if_applicable # not yet tested # - use_to_and_as_if_applicable # not yet tested
# === pub rules === # === pub rules ===
......
...@@ -349,19 +349,21 @@ class ContainerLayer extends Layer { ...@@ -349,19 +349,21 @@ class ContainerLayer extends Layer {
String debugDescribeChildren(String prefix) { String debugDescribeChildren(String prefix) {
if (firstChild == null) if (firstChild == null)
return ''; return '';
String result = '$prefix \u2502\n'; final StringBuffer result = new StringBuffer()
..write(prefix)
..write(' \u2502\n');
Layer child = firstChild; Layer child = firstChild;
int count = 1; int count = 1;
while (child != lastChild) { while (child != lastChild) {
result += '${child.toStringDeep("$prefix \u251C\u2500child $count: ", "$prefix \u2502")}'; result.write(child.toStringDeep("$prefix \u251C\u2500child $count: ", "$prefix \u2502"));
count += 1; count += 1;
child = child.nextSibling; child = child.nextSibling;
} }
if (child != null) { if (child != null) {
assert(child == lastChild); assert(child == lastChild);
result += '${child.toStringDeep("$prefix \u2514\u2500child $count: ", "$prefix ")}'; result.write(child.toStringDeep("$prefix \u2514\u2500child $count: ", "$prefix "));
} }
return result; return result.toString();
} }
} }
......
...@@ -3059,20 +3059,22 @@ abstract class ContainerRenderObjectMixin<ChildType extends RenderObject, Parent ...@@ -3059,20 +3059,22 @@ abstract class ContainerRenderObjectMixin<ChildType extends RenderObject, Parent
@override @override
String debugDescribeChildren(String prefix) { String debugDescribeChildren(String prefix) {
if (firstChild != null) { if (firstChild != null) {
String result = '$prefix \u2502\n'; final StringBuffer result = new StringBuffer()
..write(prefix)
..write(' \u2502\n');
ChildType child = firstChild; ChildType child = firstChild;
int count = 1; int count = 1;
while (child != lastChild) { while (child != lastChild) {
result += '${child.toStringDeep("$prefix \u251C\u2500child $count: ", "$prefix \u2502")}'; result.write(child.toStringDeep("$prefix \u251C\u2500child $count: ", "$prefix \u2502"));
count += 1; count += 1;
final ParentDataType childParentData = child.parentData; final ParentDataType childParentData = child.parentData;
child = childParentData.nextSibling; child = childParentData.nextSibling;
} }
if (child != null) { if (child != null) {
assert(child == lastChild); assert(child == lastChild);
result += '${child.toStringDeep("$prefix \u2514\u2500child $count: ", "$prefix ")}'; result.write(child.toStringDeep("$prefix \u2514\u2500child $count: ", "$prefix "));
} }
return result; return result.toString();
} }
return ''; return '';
} }
......
...@@ -590,15 +590,18 @@ class SemanticsNode extends AbstractNode { ...@@ -590,15 +590,18 @@ class SemanticsNode extends AbstractNode {
/// Returns a string representation of this node and its descendants. /// Returns a string representation of this node and its descendants.
String toStringDeep([String prefixLineOne = '', String prefixOtherLines = '']) { String toStringDeep([String prefixLineOne = '', String prefixOtherLines = '']) {
String result = '$prefixLineOne$this\n'; final StringBuffer result = new StringBuffer()
..write(prefixLineOne)
..write(this)
..write('\n');
if (_children != null && _children.isNotEmpty) { if (_children != null && _children.isNotEmpty) {
for (int index = 0; index < _children.length - 1; index += 1) { for (int index = 0; index < _children.length - 1; index += 1) {
final SemanticsNode child = _children[index]; final SemanticsNode child = _children[index];
result += '${child.toStringDeep("$prefixOtherLines \u251C", "$prefixOtherLines \u2502")}'; result.write(child.toStringDeep("$prefixOtherLines \u251C", "$prefixOtherLines \u2502"));
} }
result += '${_children.last.toStringDeep("$prefixOtherLines \u2514", "$prefixOtherLines ")}'; result.write(_children.last.toStringDeep("$prefixOtherLines \u2514", "$prefixOtherLines "));
} }
return result; return result.toString();
} }
} }
......
...@@ -476,16 +476,18 @@ abstract class RenderViewportBase<ParentDataClass extends ContainerParentDataMix ...@@ -476,16 +476,18 @@ abstract class RenderViewportBase<ParentDataClass extends ContainerParentDataMix
if (firstChild == null) if (firstChild == null)
return '$prefix\n'; return '$prefix\n';
int count = indexOfFirstChild; int count = indexOfFirstChild;
String result = '$prefix \u2502\n'; final StringBuffer result = new StringBuffer()
..write(prefix)
..write(' \u2502\n');
RenderSliver child = firstChild; RenderSliver child = firstChild;
while (child != lastChild) { while (child != lastChild) {
result += '${child.toStringDeep("$prefix \u251C\u2500${labelForChild(count)}: ", "$prefix \u2502")}'; result.write(child.toStringDeep("$prefix \u251C\u2500${labelForChild(count)}: ", "$prefix \u2502"));
count += 1; count += 1;
child = childAfter(child); child = childAfter(child);
} }
assert(child == lastChild); assert(child == lastChild);
result += '${child.toStringDeep("$prefix \u2514\u2500${labelForChild(count)}: ", "$prefix ")}'; result.write(child.toStringDeep("$prefix \u2514\u2500${labelForChild(count)}: ", "$prefix "));
return result; return result.toString();
} }
// API TO BE IMPLEMENTED BY SUBCLASSES // API TO BE IMPLEMENTED BY SUBCLASSES
......
...@@ -2936,16 +2936,19 @@ abstract class Element implements BuildContext { ...@@ -2936,16 +2936,19 @@ abstract class Element implements BuildContext {
/// A detailed, textual description of this element, includings its children. /// A detailed, textual description of this element, includings its children.
String toStringDeep([String prefixLineOne = '', String prefixOtherLines = '']) { String toStringDeep([String prefixLineOne = '', String prefixOtherLines = '']) {
String result = '$prefixLineOne$this\n'; final StringBuffer result = new StringBuffer()
..write(prefixLineOne)
..write(this)
..write('\n');
final List<Element> children = <Element>[]; final List<Element> children = <Element>[];
visitChildren(children.add); visitChildren(children.add);
if (children.isNotEmpty) { if (children.isNotEmpty) {
final Element last = children.removeLast(); final Element last = children.removeLast();
for (Element child in children) for (Element child in children)
result += '${child.toStringDeep("$prefixOtherLines\u251C", "$prefixOtherLines\u2502")}'; result.write(child.toStringDeep("$prefixOtherLines\u251C", "$prefixOtherLines\u2502"));
result += '${last.toStringDeep("$prefixOtherLines\u2514", "$prefixOtherLines ")}'; result.write(last.toStringDeep("$prefixOtherLines\u2514", "$prefixOtherLines "));
} }
return result; return result.toString();
} }
/// Returns true if the element has been marked as needing rebuilding. /// Returns true if the element has been marked as needing rebuilding.
......
...@@ -560,26 +560,31 @@ class _RenderTheatre extends RenderBox ...@@ -560,26 +560,31 @@ class _RenderTheatre extends RenderBox
@override @override
String debugDescribeChildren(String prefix) { String debugDescribeChildren(String prefix) {
String result = ''; final StringBuffer result = new StringBuffer();
if (child != null) if (child != null)
result += '$prefix \u2502\n${child.toStringDeep('$prefix \u251C\u2500onstage: ', '$prefix \u254E')}'; result
..write(prefix)
..write(' \u2502\n')
..write(child.toStringDeep('$prefix \u251C\u2500onstage: ', '$prefix \u254E'));
if (firstChild != null) { if (firstChild != null) {
RenderBox child = firstChild; RenderBox child = firstChild;
int count = 1; int count = 1;
while (child != lastChild) { while (child != lastChild) {
result += '${child.toStringDeep("$prefix \u254E\u254Coffstage $count: ", "$prefix \u254E")}'; result.write(child.toStringDeep("$prefix \u254E\u254Coffstage $count: ", "$prefix \u254E"));
count += 1; count += 1;
final StackParentData childParentData = child.parentData; final StackParentData childParentData = child.parentData;
child = childParentData.nextSibling; child = childParentData.nextSibling;
} }
if (child != null) { if (child != null) {
assert(child == lastChild); assert(child == lastChild);
result += '${child.toStringDeep("$prefix \u2514\u254Coffstage $count: ", "$prefix ")}'; result.write(child.toStringDeep("$prefix \u2514\u254Coffstage $count: ", "$prefix "));
} }
} else { } else {
result += '$prefix \u2514\u254Cno offstage children'; result
..write(prefix)
..write(' \u2514\u254Cno offstage children');
} }
return result; return result.toString();
} }
@override @override
......
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