Unverified Commit 5b12b746 authored by Polina Cherkasova's avatar Polina Cherkasova Committed by GitHub

Cleanup: stop accepting DiagnosticsNode as input from DevTools. (#129302)

parent 590ef2d4
...@@ -1722,8 +1722,8 @@ mixin WidgetInspectorService { ...@@ -1722,8 +1722,8 @@ mixin WidgetInspectorService {
return _safeJsonEncode(_getProperties(diagnosticsNodeId, groupName)); return _safeJsonEncode(_getProperties(diagnosticsNodeId, groupName));
} }
List<Object> _getProperties(String? diagnosticsOrDiagnosticableId, String groupName) { List<Object> _getProperties(String? diagnosticableId, String groupName) {
final DiagnosticsNode? node = _idToDiagnosticsNode(diagnosticsOrDiagnosticableId); final DiagnosticsNode? node = _idToDiagnosticsNode(diagnosticableId);
if (node == null) { if (node == null) {
return const <Object>[]; return const <Object>[];
} }
...@@ -1760,28 +1760,22 @@ mixin WidgetInspectorService { ...@@ -1760,28 +1760,22 @@ mixin WidgetInspectorService {
return _safeJsonEncode(_getChildrenSummaryTree(diagnosticsNodeId, groupName)); return _safeJsonEncode(_getChildrenSummaryTree(diagnosticsNodeId, groupName));
} }
DiagnosticsNode? _idToDiagnosticsNode(String? diagnosticsOrDiagnosticableId) { DiagnosticsNode? _idToDiagnosticsNode(String? diagnosticableId) {
// TODO(polina-c): start always assuming Diagnosticable, when DevTools stops sending DiagnosticsNode to final Object? object = toObject(diagnosticableId);
// APIs that invoke this method.
// https://github.com/flutter/devtools/issues/3951
final Object? object = toObject(diagnosticsOrDiagnosticableId);
return objectToDiagnosticsNode(object); return objectToDiagnosticsNode(object);
} }
/// If posiible, returns [DiagnosticsNode] for the object. /// If possible, returns [DiagnosticsNode] for the object.
@visibleForTesting @visibleForTesting
static DiagnosticsNode? objectToDiagnosticsNode(Object? object) { static DiagnosticsNode? objectToDiagnosticsNode(Object? object) {
if (object is DiagnosticsNode) {
return object;
}
if (object is Diagnosticable) { if (object is Diagnosticable) {
return object.toDiagnosticsNode(); return object.toDiagnosticsNode();
} }
return null; return null;
} }
List<Object> _getChildrenSummaryTree(String? diagnosticsOrDiagnosticableId, String groupName) { List<Object> _getChildrenSummaryTree(String? diagnosticableId, String groupName) {
final DiagnosticsNode? node = _idToDiagnosticsNode(diagnosticsOrDiagnosticableId); final DiagnosticsNode? node = _idToDiagnosticsNode(diagnosticableId);
if (node == null) { if (node == null) {
return <Object>[]; return <Object>[];
} }
...@@ -1791,17 +1785,17 @@ mixin WidgetInspectorService { ...@@ -1791,17 +1785,17 @@ mixin WidgetInspectorService {
} }
/// Returns a JSON representation of the children of the [DiagnosticsNode] /// Returns a JSON representation of the children of the [DiagnosticsNode]
/// object that [diagnosticsOrDiagnosticableId] references providing information needed /// object that [diagnosticableId] references providing information needed
/// for the details subtree view. /// for the details subtree view.
/// ///
/// The details subtree shows properties inline and includes all children /// The details subtree shows properties inline and includes all children
/// rather than a filtered set of important children. /// rather than a filtered set of important children.
String getChildrenDetailsSubtree(String diagnosticsOrDiagnosticableId, String groupName) { String getChildrenDetailsSubtree(String diagnosticableId, String groupName) {
return _safeJsonEncode(_getChildrenDetailsSubtree(diagnosticsOrDiagnosticableId, groupName)); return _safeJsonEncode(_getChildrenDetailsSubtree(diagnosticableId, groupName));
} }
List<Object> _getChildrenDetailsSubtree(String? diagnosticsOrDiagnosticableId, String groupName) { List<Object> _getChildrenDetailsSubtree(String? diagnosticableId, String groupName) {
final DiagnosticsNode? node = _idToDiagnosticsNode(diagnosticsOrDiagnosticableId); final DiagnosticsNode? node = _idToDiagnosticsNode(diagnosticableId);
// With this value of minDepth we only expand one extra level of important nodes. // With this value of minDepth we only expand one extra level of important nodes.
final InspectorSerializationDelegate delegate = InspectorSerializationDelegate(groupName: groupName, includeProperties: true, service: this); final InspectorSerializationDelegate delegate = InspectorSerializationDelegate(groupName: groupName, includeProperties: true, service: this);
return _nodesToJson(node == null ? const <DiagnosticsNode>[] : _getChildrenFiltered(node, delegate), delegate, parent: node); return _nodesToJson(node == null ? const <DiagnosticsNode>[] : _getChildrenFiltered(node, delegate), delegate, parent: node);
...@@ -1913,19 +1907,19 @@ mixin WidgetInspectorService { ...@@ -1913,19 +1907,19 @@ mixin WidgetInspectorService {
/// * [getChildrenDetailsSubtree], a method to get children of a node /// * [getChildrenDetailsSubtree], a method to get children of a node
/// in the details subtree. /// in the details subtree.
String getDetailsSubtree( String getDetailsSubtree(
String diagnosticsOrDiagnosticableId, String diagnosticableId,
String groupName, { String groupName, {
int subtreeDepth = 2, int subtreeDepth = 2,
}) { }) {
return _safeJsonEncode(_getDetailsSubtree(diagnosticsOrDiagnosticableId, groupName, subtreeDepth)); return _safeJsonEncode(_getDetailsSubtree(diagnosticableId, groupName, subtreeDepth));
} }
Map<String, Object?>? _getDetailsSubtree( Map<String, Object?>? _getDetailsSubtree(
String? diagnosticsOrDiagnosticableId, String? diagnosticableId,
String? groupName, String? groupName,
int subtreeDepth, int subtreeDepth,
) { ) {
final DiagnosticsNode? root = _idToDiagnosticsNode(diagnosticsOrDiagnosticableId); final DiagnosticsNode? root = _idToDiagnosticsNode(diagnosticableId);
if (root == null) { if (root == null) {
return null; return null;
} }
...@@ -1941,15 +1935,12 @@ mixin WidgetInspectorService { ...@@ -1941,15 +1935,12 @@ mixin WidgetInspectorService {
} }
/// Returns a [DiagnosticsNode] representing the currently selected [Element]. /// Returns a [DiagnosticsNode] representing the currently selected [Element].
///
/// If the currently selected [Element] is identical to the [Element]
/// referenced by `previousSelectionId` then the previous [DiagnosticsNode] is
/// reused.
// TODO(polina-c): delete [previousSelectionId] when it is not used in DevTools
// https://github.com/flutter/devtools/issues/3951
@protected @protected
String getSelectedWidget(String? previousSelectionId, String groupName) { String getSelectedWidget(String? previousSelectionId, String groupName) {
return _safeJsonEncode(_getSelectedWidget(previousSelectionId, groupName)); if (previousSelectionId != null) {
debugPrint('previousSelectionId is deprecated in API');
}
return _safeJsonEncode(_getSelectedWidget(null, groupName));
} }
/// Captures an image of the current state of an [object] that is a /// Captures an image of the current state of an [object] that is a
...@@ -2025,11 +2016,11 @@ mixin WidgetInspectorService { ...@@ -2025,11 +2016,11 @@ mixin WidgetInspectorService {
Future<Map<String, Object?>> _getLayoutExplorerNode( Future<Map<String, Object?>> _getLayoutExplorerNode(
Map<String, String> parameters, Map<String, String> parameters,
) { ) {
final String? diagnosticsOrDiagnosticableId = parameters['id']; final String? diagnosticableId = parameters['id'];
final int subtreeDepth = int.parse(parameters['subtreeDepth']!); final int subtreeDepth = int.parse(parameters['subtreeDepth']!);
final String? groupName = parameters['groupName']; final String? groupName = parameters['groupName'];
Map<String, dynamic>? result = <String, dynamic>{}; Map<String, dynamic>? result = <String, dynamic>{};
final DiagnosticsNode? root = _idToDiagnosticsNode(diagnosticsOrDiagnosticableId); final DiagnosticsNode? root = _idToDiagnosticsNode(diagnosticableId);
if (root == null) { if (root == null) {
return Future<Map<String, dynamic>>.value(<String, dynamic>{ return Future<Map<String, dynamic>>.value(<String, dynamic>{
'result': result, 'result': result,
...@@ -2233,14 +2224,11 @@ mixin WidgetInspectorService { ...@@ -2233,14 +2224,11 @@ mixin WidgetInspectorService {
/// if the selected [Element] should be shown in the summary tree otherwise /// if the selected [Element] should be shown in the summary tree otherwise
/// returns the first ancestor of the selected [Element] shown in the summary /// returns the first ancestor of the selected [Element] shown in the summary
/// tree. /// tree.
/// String getSelectedSummaryWidget(String? previousSelectionId, String groupName) {
/// If the currently selected [Element] is identical to the [Element] if (previousSelectionId != null) {
/// referenced by `previousSelectionId` then the previous [DiagnosticsNode] is debugPrint('previousSelectionId is deprecated in API');
/// reused. }
// TODO(polina-c): delete paramater [previousSelectionId] when it is not used in DevTools return _safeJsonEncode(_getSelectedSummaryWidget(null, groupName));
// https://github.com/flutter/devtools/issues/3951
String getSelectedSummaryWidget(String previousSelectionId, String groupName) {
return _safeJsonEncode(_getSelectedSummaryWidget(previousSelectionId, groupName));
} }
_Location? _getSelectedSummaryWidgetLocation(String? previousSelectionId) { _Location? _getSelectedSummaryWidgetLocation(String? previousSelectionId) {
...@@ -3609,7 +3597,6 @@ class InspectorSerializationDelegate implements DiagnosticsSerializationDelegate ...@@ -3609,7 +3597,6 @@ class InspectorSerializationDelegate implements DiagnosticsSerializationDelegate
final Map<String, Object?> result = <String, Object?>{}; final Map<String, Object?> result = <String, Object?>{};
final Object? value = node.value; final Object? value = node.value;
if (_interactive) { if (_interactive) {
result['objectId'] = service.toId(node, groupName!);
result['valueId'] = service.toId(value, groupName!); result['valueId'] = service.toId(value, groupName!);
} }
if (summaryTree) { if (summaryTree) {
......
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