Skip to content

Commit d46e208

Browse files
authored
Change all ocurrences of '$runtimeType#$hashCode' to use the idAndType method. (flutter#10871)
* Change all instances of '$runtimeType#$hashCode' to use the describeIdentity method. The describeIdentity method generates a shorter description with a consistent length consisting of the runtime type and the a 5 hex character long truncated version of the hash code.
1 parent 8b888e6 commit d46e208

28 files changed

+61
-52
lines changed

packages/flutter/lib/src/animation/animation.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ abstract class Animation<T> extends Listenable {
8181

8282
@override
8383
String toString() {
84-
return '$runtimeType#$hashCode(${toStringDetails()})';
84+
return '${describeIdentity(this)}(${toStringDetails()})';
8585
}
8686

8787
/// Provides a string describing the status of this object, but not including

packages/flutter/lib/src/foundation/change_notifier.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:meta/meta.dart';
77
import 'assertions.dart';
88
import 'basic_types.dart';
99
import 'observer_list.dart';
10+
import 'print.dart';
1011

1112
/// An object that maintains a list of listeners.
1213
abstract class Listenable {
@@ -185,5 +186,5 @@ class ValueNotifier<T> extends ChangeNotifier {
185186
}
186187

187188
@override
188-
String toString() => '$runtimeType#$hashCode($value)';
189+
String toString() => '${idAndType(this)}($value)';
189190
}

packages/flutter/lib/src/foundation/tree_diagnostics_mixin.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ import 'package:meta/meta.dart';
66

77
import 'print.dart';
88

9+
/// Returns a 5 character long hexadecimal hash code for [object].
10+
String shortHash(Object object) {
11+
return object.hashCode.toUnsigned(20).toRadixString(16).padLeft(5, '0');
12+
}
13+
14+
/// Returns a summary of [object]'s runtime type and hash code.
15+
String describeIdentity(Object object) =>
16+
'${object.runtimeType}#${shortHash(object)}';
17+
918
/// A mixin that helps dump string representations of trees.
1019
abstract class TreeDiagnosticsMixin {
1120
// This class is intended to be used as a mixin, and should not be
@@ -20,7 +29,7 @@ abstract class TreeDiagnosticsMixin {
2029
/// * [toStringShallow], for a detailed description of the object.
2130
/// * [toStringDeep], for a description of the subtree rooted at this object.
2231
@override
23-
String toString() => '$runtimeType#$hashCode';
32+
String toString() => describeIdentity(this);
2433

2534
/// Returns a one-line detailed description of the object.
2635
///

packages/flutter/lib/src/gestures/recognizer.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ abstract class GestureRecognizer extends GestureArenaMember {
8686
}
8787

8888
@override
89-
String toString() => '$runtimeType#$hashCode';
89+
String toString() => describeIdentity(this);
9090
}
9191

9292
/// Base class for gesture recognizers that can only recognize one
@@ -321,5 +321,5 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
321321
}
322322

323323
@override
324-
String toString() => '$runtimeType#$hashCode($state)';
324+
String toString() => '${describeIdentity(this)}($state)';
325325
}

packages/flutter/lib/src/material/app_bar.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
604604

605605
@override
606606
String toString() {
607-
return '$runtimeType#$hashCode(topPadding: ${topPadding.toStringAsFixed(1)}, bottomHeight: ${_bottomHeight.toStringAsFixed(1)}, ...)';
607+
return '${describeIdentity(this)}(topPadding: ${topPadding.toStringAsFixed(1)}, bottomHeight: ${_bottomHeight.toStringAsFixed(1)}, ...)';
608608
}
609609
}
610610

packages/flutter/lib/src/material/material.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,5 +425,5 @@ abstract class InkFeature {
425425
void paintFeature(Canvas canvas, Matrix4 transform);
426426

427427
@override
428-
String toString() => '$runtimeType#$hashCode';
428+
String toString() => describeIdentity(this);
429429
}

packages/flutter/lib/src/rendering/box.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ class BoxHitTestEntry extends HitTestEntry {
572572
final Offset localPosition;
573573

574574
@override
575-
String toString() => '${target.runtimeType}#${target.hashCode}@$localPosition';
575+
String toString() => '${describeIdentity(target)}@$localPosition';
576576
}
577577

578578
/// Parent data used by [RenderBox] and its subclasses.

packages/flutter/lib/src/rendering/object.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ abstract class _SemanticsFragment {
636636
Iterable<SemanticsNode> compile({ _SemanticsGeometry geometry, SemanticsNode currentSemantics, SemanticsNode parentSemantics });
637637

638638
@override
639-
String toString() => '$runtimeType#$hashCode';
639+
String toString() => describeIdentity(this);
640640
}
641641

642642
/// A SemanticsFragment that doesn't produce any [SemanticsNode]s when compiled.
@@ -2686,7 +2686,7 @@ abstract class RenderObject extends AbstractNode implements HitTestTarget {
26862686
/// Returns a human understandable name.
26872687
@override
26882688
String toString() {
2689-
String header = '$runtimeType#$hashCode';
2689+
String header = describeIdentity(this);
26902690
if (_relayoutBoundary != null && _relayoutBoundary != this) {
26912691
int count = 1;
26922692
RenderObject target = parent;

packages/flutter/lib/src/rendering/proxy_box.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2034,7 +2034,7 @@ abstract class CustomPainter extends Listenable {
20342034
bool hitTest(Offset position) => null;
20352035

20362036
@override
2037-
String toString() => '$runtimeType#$hashCode(${ _repaint?.toString() ?? "" })';
2037+
String toString() => '${describeIdentity(this)}(${ _repaint?.toString() ?? "" })';
20382038
}
20392039

20402040
/// Provides a canvas on which to draw during the paint phase.

packages/flutter/lib/src/rendering/semantics.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,5 +781,5 @@ class SemanticsOwner extends ChangeNotifier {
781781
}
782782

783783
@override
784-
String toString() => '$runtimeType#$hashCode';
784+
String toString() => describeIdentity(this);
785785
}

0 commit comments

Comments
 (0)