diagnostics_tree.dart 2.54 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'enum_util.dart';
import 'find.dart';
import 'message.dart';

/// [DiagnosticsNode] tree types that can be requested by [GetDiagnosticsTree].
enum DiagnosticsType {
  /// The [DiagnosticsNode] tree formed by [RenderObject]s.
  renderObject,

  /// The [DiagnosticsNode] tree formed by [Widget]s.
  widget,
}

EnumIndex<DiagnosticsType> _diagnosticsTypeIndex = EnumIndex<DiagnosticsType>(DiagnosticsType.values);

20
/// A Flutter Driver command to retrieve the JSON-serialized [DiagnosticsNode]
21 22 23 24 25 26
/// tree of the object identified by [finder].
///
/// The [DiagnosticsType] of the [DiagnosticsNode] tree returned is specified by
/// [diagnosticsType].
class GetDiagnosticsTree extends CommandWithTarget {
  /// Creates a [GetDiagnosticsTree] Flutter Driver command.
27
  GetDiagnosticsTree(super.finder, this.diagnosticsType, {
28 29
    this.subtreeDepth = 0,
    this.includeProperties = true,
30
    super.timeout,
31
  });
32 33

  /// Deserializes this command from the value generated by [serialize].
34
  GetDiagnosticsTree.deserialize(super.json, super.finderFactory)
35
      : subtreeDepth = int.parse(json['subtreeDepth']!),
36
        includeProperties = json['includeProperties'] == 'true',
37
        diagnosticsType = _diagnosticsTypeIndex.lookupBySimpleName(json['diagnosticsType']!),
38
        super.deserialize();
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

  /// How many levels of children to include in the JSON result.
  ///
  /// Defaults to zero, which will only return the [DiagnosticsNode] information
  /// of the object identified by [finder].
  final int subtreeDepth;

  /// Whether the properties of a [DiagnosticsNode] should be included.
  final bool includeProperties;

  /// The type of [DiagnosticsNode] tree that is requested.
  final DiagnosticsType diagnosticsType;

  @override
  Map<String, String> serialize() => super.serialize()..addAll(<String, String>{
    'subtreeDepth': subtreeDepth.toString(),
    'includeProperties': includeProperties.toString(),
    'diagnosticsType': _diagnosticsTypeIndex.toSimpleName(diagnosticsType),
  });

  @override
  String get kind => 'get_diagnostics_tree';
}

/// The result of a [GetDiagnosticsTree] command.
class DiagnosticsTreeResult extends Result {
  /// Creates a [DiagnosticsTreeResult].
  const DiagnosticsTreeResult(this.json);

68
  /// The JSON encoded [DiagnosticsNode] tree requested by the
69
  /// [GetDiagnosticsTree] command.
70
  final Map<String, dynamic> json;
71 72 73 74

  @override
  Map<String, dynamic> toJson() => json;
}