SourceChange.fromJson constructor

SourceChange.fromJson(
  1. JsonDecoder jsonDecoder,
  2. String jsonPath,
  3. Object? json
)

Implementation

factory SourceChange.fromJson(
    JsonDecoder jsonDecoder, String jsonPath, Object? json) {
  json ??= {};
  if (json is Map) {
    String message;
    if (json.containsKey('message')) {
      message =
          jsonDecoder.decodeString('$jsonPath.message', json['message']);
    } else {
      throw jsonDecoder.mismatch(jsonPath, 'message');
    }
    List<SourceFileEdit> edits;
    if (json.containsKey('edits')) {
      edits = jsonDecoder.decodeList(
          '$jsonPath.edits',
          json['edits'],
          (String jsonPath, Object? json) =>
              SourceFileEdit.fromJson(jsonDecoder, jsonPath, json));
    } else {
      throw jsonDecoder.mismatch(jsonPath, 'edits');
    }
    List<LinkedEditGroup> linkedEditGroups;
    if (json.containsKey('linkedEditGroups')) {
      linkedEditGroups = jsonDecoder.decodeList(
          '$jsonPath.linkedEditGroups',
          json['linkedEditGroups'],
          (String jsonPath, Object? json) =>
              LinkedEditGroup.fromJson(jsonDecoder, jsonPath, json));
    } else {
      throw jsonDecoder.mismatch(jsonPath, 'linkedEditGroups');
    }
    Position? selection;
    if (json.containsKey('selection')) {
      selection = Position.fromJson(
          jsonDecoder, '$jsonPath.selection', json['selection']);
    }
    int? selectionLength;
    if (json.containsKey('selectionLength')) {
      selectionLength = jsonDecoder.decodeInt(
          '$jsonPath.selectionLength', json['selectionLength']);
    }
    String? id;
    if (json.containsKey('id')) {
      id = jsonDecoder.decodeString('$jsonPath.id', json['id']);
    }
    return SourceChange(message,
        edits: edits,
        linkedEditGroups: linkedEditGroups,
        selection: selection,
        selectionLength: selectionLength,
        id: id);
  } else {
    throw jsonDecoder.mismatch(jsonPath, 'SourceChange', json);
  }
}