SourceChange.fromJson constructor

SourceChange.fromJson(
  1. JsonDecoder jsonDecoder,
  2. String jsonPath,
  3. Object? json, {
  4. ClientUriConverter? clientUriConverter,
})

Implementation

factory SourceChange.fromJson(
  JsonDecoder jsonDecoder,
  String jsonPath,
  Object? json, {
  ClientUriConverter? clientUriConverter,
}) {
  json ??= {};
  if (json is! Map) {
    throw jsonDecoder.mismatch(jsonPath, "'SourceChange'", json);
  }
  String message;
  if (json case {'message': var encodedMessage}) {
    message = jsonDecoder.decodeString('$jsonPath.message', encodedMessage);
  } else {
    throw jsonDecoder.mismatch(jsonPath, "'message'", json);
  }
  List<SourceFileEdit> edits;
  if (json case {'edits': var encodedEdits}) {
    edits = jsonDecoder.decodeList(
      '$jsonPath.edits',
      encodedEdits,
      (String jsonPath, Object? json) => SourceFileEdit.fromJson(
        jsonDecoder,
        jsonPath,
        json,
        clientUriConverter: clientUriConverter,
      ),
    );
  } else {
    throw jsonDecoder.mismatch(jsonPath, "'edits'", json);
  }
  List<LinkedEditGroup> linkedEditGroups;
  if (json case {'linkedEditGroups': var encodedLinkedEditGroups}) {
    linkedEditGroups = jsonDecoder.decodeList(
      '$jsonPath.linkedEditGroups',
      encodedLinkedEditGroups,
      (String jsonPath, Object? json) => LinkedEditGroup.fromJson(
        jsonDecoder,
        jsonPath,
        json,
        clientUriConverter: clientUriConverter,
      ),
    );
  } else {
    throw jsonDecoder.mismatch(jsonPath, "'linkedEditGroups'", json);
  }
  Position? selection;
  if (json case {'selection': var encodedSelection}) {
    selection = Position.fromJson(
      jsonDecoder,
      '$jsonPath.selection',
      encodedSelection,
      clientUriConverter: clientUriConverter,
    );
  }
  int? selectionLength;
  if (json case {'selectionLength': var encodedSelectionLength}) {
    selectionLength = jsonDecoder.decodeInt(
      '$jsonPath.selectionLength',
      encodedSelectionLength,
    );
  }
  String? id;
  if (json case {'id': var encodedId}) {
    id = jsonDecoder.decodeString('$jsonPath.id', encodedId);
  }
  return SourceChange(
    message,
    edits: edits,
    linkedEditGroups: linkedEditGroups,
    selection: selection,
    selectionLength: selectionLength,
    id: id,
  );
}