diff --git a/packages/flutter/lib/src/cupertino/icon_theme_data.dart b/packages/flutter/lib/src/cupertino/icon_theme_data.dart index 2769fbd4f0..41de478b1e 100644 --- a/packages/flutter/lib/src/cupertino/icon_theme_data.dart +++ b/packages/flutter/lib/src/cupertino/icon_theme_data.dart @@ -8,7 +8,7 @@ import 'colors.dart'; /// An [IconThemeData] subclass that automatically resolves its [color] when retrieved /// using [IconTheme.of]. -class CupertinoIconThemeData extends IconThemeData with DiagnosticableMixin { +class CupertinoIconThemeData extends IconThemeData with DiagnosticableMixin implements Diagnosticable { /// Creates a [CupertinoIconThemeData]. /// /// The opacity applies to both explicit and default icon colors. The value diff --git a/packages/flutter/lib/src/foundation/assertions.dart b/packages/flutter/lib/src/foundation/assertions.dart index 9154267469..7381a7b150 100644 --- a/packages/flutter/lib/src/foundation/assertions.dart +++ b/packages/flutter/lib/src/foundation/assertions.dart @@ -351,7 +351,7 @@ class FlutterErrorDetails extends Diagnosticable { return longMessage; } - Diagnosticable _exceptionToDiagnosticable() { + DiagnosticableMixin _exceptionToDiagnosticable() { if (exception is FlutterError) { return exception as FlutterError; } @@ -374,7 +374,7 @@ class FlutterErrorDetails extends Diagnosticable { if (kReleaseMode) { return DiagnosticsNode.message(formatException()); } - final Diagnosticable diagnosticable = _exceptionToDiagnosticable(); + final DiagnosticableMixin diagnosticable = _exceptionToDiagnosticable(); DiagnosticsNode summary; if (diagnosticable != null) { final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); @@ -388,7 +388,7 @@ class FlutterErrorDetails extends Diagnosticable { void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); final DiagnosticsNode verb = ErrorDescription('thrown${ context != null ? ErrorDescription(" $context") : ""}'); - final Diagnosticable diagnosticable = _exceptionToDiagnosticable(); + final DiagnosticableMixin diagnosticable = _exceptionToDiagnosticable(); if (exception is NullThrownError) { properties.add(ErrorDescription('The null value was $verb.')); } else if (exception is num) { diff --git a/packages/flutter/lib/src/foundation/diagnostics.dart b/packages/flutter/lib/src/foundation/diagnostics.dart index 118e1d071f..04c2f3f9e8 100644 --- a/packages/flutter/lib/src/foundation/diagnostics.dart +++ b/packages/flutter/lib/src/foundation/diagnostics.dart @@ -2640,7 +2640,7 @@ class DiagnosticsProperty extends DiagnosticsNode { Map toJsonMap(DiagnosticsSerializationDelegate delegate) { final T v = value; List> properties; - if (delegate.expandPropertyValues && delegate.includeProperties && v is Diagnosticable && getProperties().isEmpty) { + if (delegate.expandPropertyValues && delegate.includeProperties && v is DiagnosticableMixin && getProperties().isEmpty) { // Exclude children for expanded nodes to avoid cycles. delegate = delegate.copyWith(subtreeDepth: 0, includeProperties: false); properties = DiagnosticsNode.toJsonList( @@ -2666,7 +2666,7 @@ class DiagnosticsProperty extends DiagnosticsNode { json['exception'] = exception.toString(); json['propertyType'] = propertyType.toString(); json['defaultLevel'] = describeEnum(_defaultLevel); - if (value is Diagnosticable || value is DiagnosticsNode) + if (value is DiagnosticableMixin || value is DiagnosticsNode) json['isDiagnosticableValue'] = true; if (v is num) // Workaround for https://github.com/flutter/flutter/issues/39937#issuecomment-529558033. @@ -2846,7 +2846,7 @@ class DiagnosticsProperty extends DiagnosticsNode { if (object is DiagnosticsNode) { return object.getProperties(); } - if (object is Diagnosticable) { + if (object is DiagnosticableMixin) { return object.toDiagnosticsNode(style: style).getProperties(); } } @@ -2860,7 +2860,7 @@ class DiagnosticsProperty extends DiagnosticsNode { if (object is DiagnosticsNode) { return object.getChildren(); } - if (object is Diagnosticable) { + if (object is DiagnosticableMixin) { return object.toDiagnosticsNode(style: style).getChildren(); } } @@ -2870,8 +2870,8 @@ class DiagnosticsProperty extends DiagnosticsNode { /// [DiagnosticsNode] that lazily calls the associated [Diagnosticable] [value] /// to implement [getChildren] and [getProperties]. -class DiagnosticableNode extends DiagnosticsNode { - /// Create a diagnostics describing a [Diagnosticable] value. +class DiagnosticableNode extends DiagnosticsNode { + /// Create a diagnostics describing a [DiagnosticableMixin] value. /// /// The [value] argument must not be null. DiagnosticableNode({ @@ -2991,7 +2991,7 @@ String describeEnum(Object enumEntry) { } /// Builder to accumulate properties and configuration used to assemble a -/// [DiagnosticsNode] from a [Diagnosticable] object. +/// [DiagnosticsNode] from a [DiagnosticableMixin] object. class DiagnosticPropertiesBuilder { /// Creates a [DiagnosticPropertiesBuilder] with [properties] initialize to /// an empty array. @@ -3053,10 +3053,8 @@ abstract class Diagnosticable with DiagnosticableMixin { const Diagnosticable(); } -/// A mixin class that provides the implementation for [Diagnosticable]. -/// -/// This mixin can be used to add diagnostics to a class which already has an -/// base class. +/// A mixin class for providing string and [DiagnosticsNode] debug +/// representations describing the properties of an object. /// /// The string debug representation is generated from the intermediate /// [DiagnosticsNode] representation. The [DiagnosticsNode] representation is @@ -3108,9 +3106,9 @@ mixin DiagnosticableMixin { /// relationship between the parent and the node. For example, pass /// [DiagnosticsTreeStyle.offstage] to indicate that a node is offstage. DiagnosticsNode toDiagnosticsNode({ String name, DiagnosticsTreeStyle style }) { - return DiagnosticableNode( + return DiagnosticableNode( name: name, - value: this as Diagnosticable, + value: this, style: style, ); } @@ -3338,8 +3336,8 @@ mixin DiagnosticableMixin { /// See also: /// /// * [DiagnosticableTreeMixin], a mixin that implements this class. -/// * [Diagnosticable], which should be used instead of this class to provide -/// diagnostics for objects without children. +/// * [DiagnosticableMixin], which should be used instead of this class to +/// provide diagnostics for objects without children. abstract class DiagnosticableTree extends Diagnosticable { /// Abstract const constructor. This constructor enables subclasses to provide /// const constructors so that they can be used in const expressions. @@ -3643,7 +3641,7 @@ abstract class DiagnosticsSerializationDelegate { /// will be included. bool get includeProperties; - /// Whether properties that have a [Diagnosticable] as value should be + /// Whether properties that have a [DiagnosticableMixin] as value should be /// expanded. bool get expandPropertyValues; diff --git a/packages/flutter/lib/src/scheduler/ticker.dart b/packages/flutter/lib/src/scheduler/ticker.dart index 7da128a986..96041984ce 100644 --- a/packages/flutter/lib/src/scheduler/ticker.dart +++ b/packages/flutter/lib/src/scheduler/ticker.dart @@ -38,7 +38,7 @@ abstract class TickerProvider { Ticker createTicker(TickerCallback onTick); } -// TODO(jacobr): make Ticker Diagnosticable to simplify reporting errors +// TODO(jacobr): make Ticker use DiagnosticableMixin to simplify reporting errors // related to a ticker. /// Calls its callback once per animation frame. /// diff --git a/packages/flutter/lib/src/widgets/shortcuts.dart b/packages/flutter/lib/src/widgets/shortcuts.dart index 44caef6279..d7e10760ff 100644 --- a/packages/flutter/lib/src/widgets/shortcuts.dart +++ b/packages/flutter/lib/src/widgets/shortcuts.dart @@ -110,7 +110,7 @@ class KeySet { /// This is a thin wrapper around a [Set], but changes the equality comparison /// from an identity comparison to a contents comparison so that non-identical /// sets with the same keys in them will compare as equal. -class LogicalKeySet extends KeySet with DiagnosticableMixin { +class LogicalKeySet extends KeySet with DiagnosticableMixin implements Diagnosticable { /// A constructor for making a [LogicalKeySet] of up to four keys. /// /// If you need a set of more than four keys, use [LogicalKeySet.fromSet]. @@ -201,7 +201,7 @@ class ShortcutMapProperty extends DiagnosticsProperty /// /// A [ShortcutManager] is obtained by calling [Shortcuts.of] on the context of /// the widget that you want to find a manager for. -class ShortcutManager extends ChangeNotifier with DiagnosticableMixin { +class ShortcutManager extends ChangeNotifier with DiagnosticableMixin implements Diagnosticable { /// Constructs a [ShortcutManager]. /// /// The [shortcuts] argument must not be null. diff --git a/packages/flutter/lib/src/widgets/widget_inspector.dart b/packages/flutter/lib/src/widgets/widget_inspector.dart index 4d021afd80..fcd5940fbd 100644 --- a/packages/flutter/lib/src/widgets/widget_inspector.dart +++ b/packages/flutter/lib/src/widgets/widget_inspector.dart @@ -635,7 +635,7 @@ class _DiagnosticsPathNode { } List<_DiagnosticsPathNode> _followDiagnosticableChain( - List chain, { + List chain, { String name, DiagnosticsTreeStyle style, }) { @@ -644,7 +644,7 @@ List<_DiagnosticsPathNode> _followDiagnosticableChain( return path; DiagnosticsNode diagnostic = chain.first.toDiagnosticsNode(name: name, style: style); for (int i = 1; i < chain.length; i += 1) { - final Diagnosticable target = chain[i]; + final DiagnosticableMixin target = chain[i]; bool foundMatch = false; final List children = diagnostic.getChildren(); for (int j = 0; j < children.length; j += 1) { @@ -1550,7 +1550,7 @@ mixin WidgetInspectorService { return true; } final Object value = node.value; - if (value is! Diagnosticable) { + if (value is! DiagnosticableMixin) { return true; } if (value is! Element || !isWidgetCreationTracked()) { diff --git a/packages/flutter/test/foundation/diagnostics_test.dart b/packages/flutter/test/foundation/diagnostics_test.dart index 403c7418f5..ca5ad5da1c 100644 --- a/packages/flutter/test/foundation/diagnostics_test.dart +++ b/packages/flutter/test/foundation/diagnostics_test.dart @@ -180,7 +180,7 @@ void validatePropertyJsonSerializationHelper(final Map json, Dia } expect(json['propertyType'], equals(property.propertyType.toString())); expect(json.containsKey('defaultLevel'), isTrue); - if (property.value is Diagnosticable) { + if (property.value is DiagnosticableMixin) { expect(json['isDiagnosticableValue'], isTrue); } else { expect(json.containsKey('isDiagnosticableValue'), isFalse); diff --git a/packages/flutter/test/widgets/shortcuts_test.dart b/packages/flutter/test/widgets/shortcuts_test.dart index 5f628eaa8d..c974cf0151 100644 --- a/packages/flutter/test/widgets/shortcuts_test.dart +++ b/packages/flutter/test/widgets/shortcuts_test.dart @@ -322,5 +322,29 @@ void main() { expect(description.length, equals(1)); expect(description[0], equals('shortcuts: ')); }); + test('Shortcuts diagnostics work when manager specified.', () { + final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); + + Shortcuts( + manager: ShortcutManager(), + shortcuts: { + LogicalKeySet( + LogicalKeyboardKey.keyA, + LogicalKeyboardKey.keyB, + ): const Intent(ActivateAction.key) + }, + ).debugFillProperties(builder); + + final List description = builder.properties + .where((DiagnosticsNode node) { + return !node.isFiltered(DiagnosticLevel.info); + }) + .map((DiagnosticsNode node) => node.toString()) + .toList(); + + expect(description.length, equals(2)); + expect(description[0], equalsIgnoringHashCodes('manager: ShortcutManager#00000(shortcuts: {})')); + expect(description[1], equalsIgnoringHashCodes('shortcuts: {{Key A + Key B}: Intent#00000(key: [])}')); + }); }); }