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