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

Side by Side Diff: pkg/analysis_server/tool/spec/codegen_dart_protocol.dart

Issue 483613006: Allow null as a synonym for {} when decoding JSON objects. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « pkg/analysis_server/test/domain_analysis_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 codegen.protocol; 5 library codegen.protocol;
6 6
7 import 'dart:convert'; 7 import 'dart:convert';
8 8
9 import 'api.dart'; 9 import 'api.dart';
10 import 'codegen_tools.dart'; 10 import 'codegen_tools.dart';
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 * Emit the method for decoding an object from JSON. 531 * Emit the method for decoding an object from JSON.
532 */ 532 */
533 void emitObjectFromJsonConstructor(String className, TypeObject 533 void emitObjectFromJsonConstructor(String className, TypeObject
534 type, ImpliedType impliedType) { 534 type, ImpliedType impliedType) {
535 String humanReadableNameString = literalString(impliedType.humanReadableName 535 String humanReadableNameString = literalString(impliedType.humanReadableName
536 ); 536 );
537 writeln( 537 writeln(
538 'factory $className.fromJson(JsonDecoder jsonDecoder, String jsonPath, O bject json) {' 538 'factory $className.fromJson(JsonDecoder jsonDecoder, String jsonPath, O bject json) {'
539 ); 539 );
540 indent(() { 540 indent(() {
541 writeln('if (json == null) {');
542 indent(() {
543 writeln('json = {};');
544 });
545 writeln('}');
541 writeln('if (json is Map) {'); 546 writeln('if (json is Map) {');
542 indent(() { 547 indent(() {
543 List<String> args = <String>[]; 548 List<String> args = <String>[];
544 List<String> optionalArgs = <String>[]; 549 List<String> optionalArgs = <String>[];
545 for (TypeObjectField field in type.fields) { 550 for (TypeObjectField field in type.fields) {
546 String fieldNameString = literalString(field.name); 551 String fieldNameString = literalString(field.name);
547 String fieldAccessor = 'json[$fieldNameString]'; 552 String fieldAccessor = 'json[$fieldNameString]';
548 String jsonPath = 'jsonPath + ${literalString('.${field.name}')}'; 553 String jsonPath = 'jsonPath + ${literalString('.${field.name}')}';
549 if (field.value != null) { 554 if (field.value != null) {
550 String valueString = literalString(field.value); 555 String valueString = literalString(field.value);
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 CodegenProtocolVisitor visitor = new CodegenProtocolVisitor(readApi()); 828 CodegenProtocolVisitor visitor = new CodegenProtocolVisitor(readApi());
824 return visitor.collectCode(visitor.visitApi); 829 return visitor.collectCode(visitor.visitApi);
825 }); 830 });
826 831
827 /** 832 /**
828 * Translate spec_input.html into protocol_matchers.dart. 833 * Translate spec_input.html into protocol_matchers.dart.
829 */ 834 */
830 main() { 835 main() {
831 target.generate(); 836 target.generate();
832 } 837 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/domain_analysis_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698