| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 } |
| OLD | NEW |