Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: pkg/analysis_server/lib/src/protocol/protocol_internal.dart

Issue 1849973002: Fix the way generated code is made strong mode clean (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analysis_server.src.protocol.protocol_internal; 5 library analysis_server.src.protocol.protocol_internal;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:convert' hide JsonDecoder; 8 import 'dart:convert' hide JsonDecoder;
9 9
10 import 'package:analysis_server/plugin/protocol/protocol.dart'; 10 import 'package:analysis_server/plugin/protocol/protocol.dart';
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 return json; 296 return json;
297 } else if (json is String) { 297 } else if (json is String) {
298 return int.parse(json, onError: (String value) { 298 return int.parse(json, onError: (String value) {
299 throw mismatch(jsonPath, 'int', json); 299 throw mismatch(jsonPath, 'int', json);
300 }); 300 });
301 } 301 }
302 throw mismatch(jsonPath, 'int', json); 302 throw mismatch(jsonPath, 'int', json);
303 } 303 }
304 304
305 /** 305 /**
306 * Decode a JSON object that is expected to be a List. [decoder] is used to 306 * Decode a JSON object that is expected to be a List. The [decoder] is used
307 * decode the items in the list. 307 * to decode the items in the list.
308 *
309 * The type parameter [E] is the expected type of the elements in the list.
308 */ 310 */
309 List decodeList(String jsonPath, Object json, [JsonDecoderCallback decoder]) { 311 List/*<E>*/ decodeList/*<E>*/(String jsonPath, Object json,
312 [JsonDecoderCallback decoder]) {
310 if (json == null) { 313 if (json == null) {
311 return []; 314 return/*<E>*/ [];
312 } else if (json is List) { 315 } else if (json is List) {
313 List result = []; 316 List/*<E>*/ result = /*<E>*/ [];
314 for (int i = 0; i < json.length; i++) { 317 for (int i = 0; i < json.length; i++) {
315 result.add(decoder('$jsonPath[$i]', json[i])); 318 result.add(decoder('$jsonPath[$i]', json[i]) as Object/*=E*/);
Paul Berry 2016/03/31 19:44:02 Could we also get rid of this cast by parameterizi
Brian Wilkerson 2016/03/31 19:51:34 Yes. Done.
316 } 319 }
317 return result; 320 return result;
318 } else { 321 } else {
319 throw mismatch(jsonPath, 'List', json); 322 throw mismatch(jsonPath, 'List', json);
320 } 323 }
321 } 324 }
322 325
323 /** 326 /**
324 * Decode a JSON object that is expected to be a Map. [keyDecoder] is used 327 * Decode a JSON object that is expected to be a Map. [keyDecoder] is used
325 * to decode the keys, and [valueDecoder] is used to decode the values. 328 * to decode the keys, and [valueDecoder] is used to decode the values.
326 */ 329 */
327 Map decodeMap(String jsonPath, Object json, 330 Map/*<K, V>*/ decodeMap/*<K, V>*/(String jsonPath, Object json,
328 {JsonDecoderCallback keyDecoder, JsonDecoderCallback valueDecoder}) { 331 {JsonDecoderCallback keyDecoder, JsonDecoderCallback valueDecoder}) {
329 if (json == null) { 332 if (json == null) {
330 return {}; 333 return {};
331 } else if (json is Map) { 334 } else if (json is Map) {
332 Map result = {}; 335 Map/*<K, V>*/ result = /*<K, V>*/ {};
333 json.forEach((String key, value) { 336 json.forEach((String key, value) {
334 Object decodedKey; 337 Object/*=K*/ decodedKey;
335 if (keyDecoder != null) { 338 if (keyDecoder != null) {
336 decodedKey = keyDecoder('$jsonPath.key', key); 339 decodedKey = keyDecoder('$jsonPath.key', key) as Object/*=K*/;
Paul Berry 2016/03/31 19:44:02 Similar question here.
Brian Wilkerson 2016/03/31 19:51:34 Done.
337 } else { 340 } else {
338 decodedKey = key; 341 decodedKey = key as Object/*=K*/;
339 } 342 }
340 if (valueDecoder != null) { 343 if (valueDecoder != null) {
341 value = valueDecoder('$jsonPath[${JSON.encode(key)}]', value); 344 value = valueDecoder('$jsonPath[${JSON.encode(key)}]', value);
342 } 345 }
343 result[decodedKey] = value; 346 result[decodedKey] = value as Object/*=V*/;
344 }); 347 });
345 return result; 348 return result;
346 } else { 349 } else {
347 throw mismatch(jsonPath, 'Map', json); 350 throw mismatch(jsonPath, 'Map', json);
348 } 351 }
349 } 352 }
350 353
351 /** 354 /**
352 * Decode a JSON object that is expected to be a string. 355 * Decode a JSON object that is expected to be a string.
353 */ 356 */
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 buffer.write(' at '); 459 buffer.write(' at ');
457 buffer.write(jsonPath); 460 buffer.write(jsonPath);
458 return new Exception(buffer.toString()); 461 return new Exception(buffer.toString());
459 } 462 }
460 463
461 @override 464 @override
462 dynamic missingKey(String jsonPath, String key) { 465 dynamic missingKey(String jsonPath, String key) {
463 return new Exception('Missing key $key at $jsonPath'); 466 return new Exception('Missing key $key at $jsonPath');
464 } 467 }
465 } 468 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698