EditFormatResult.fromJson constructor

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

Implementation

factory EditFormatResult.fromJson(
    JsonDecoder jsonDecoder, String jsonPath, Object? json) {
  json ??= {};
  if (json is Map) {
    List<SourceEdit> edits;
    if (json.containsKey('edits')) {
      edits = jsonDecoder.decodeList(
          '$jsonPath.edits',
          json['edits'],
          (String jsonPath, Object? json) =>
              SourceEdit.fromJson(jsonDecoder, jsonPath, json));
    } else {
      throw jsonDecoder.mismatch(jsonPath, 'edits');
    }
    int selectionOffset;
    if (json.containsKey('selectionOffset')) {
      selectionOffset = jsonDecoder.decodeInt(
          '$jsonPath.selectionOffset', json['selectionOffset']);
    } else {
      throw jsonDecoder.mismatch(jsonPath, 'selectionOffset');
    }
    int selectionLength;
    if (json.containsKey('selectionLength')) {
      selectionLength = jsonDecoder.decodeInt(
          '$jsonPath.selectionLength', json['selectionLength']);
    } else {
      throw jsonDecoder.mismatch(jsonPath, 'selectionLength');
    }
    return EditFormatResult(edits, selectionOffset, selectionLength);
  } else {
    throw jsonDecoder.mismatch(jsonPath, 'edit.format result', json);
  }
}