| 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 'package:html/dom.dart' as dom; | 9 import 'package:html/dom.dart' as dom; |
| 10 | 10 |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 writeln('} catch(_) {'); | 342 writeln('} catch(_) {'); |
| 343 indent(() { | 343 indent(() { |
| 344 writeln('// Fall through'); | 344 writeln('// Fall through'); |
| 345 }); | 345 }); |
| 346 writeln('}'); | 346 writeln('}'); |
| 347 }); | 347 }); |
| 348 writeln('}'); | 348 writeln('}'); |
| 349 String humanReadableNameString = | 349 String humanReadableNameString = |
| 350 literalString(impliedType.humanReadableName); | 350 literalString(impliedType.humanReadableName); |
| 351 writeln( | 351 writeln( |
| 352 'throw jsonDecoder.mismatch(jsonPath, $humanReadableNameString);'); | 352 'throw jsonDecoder.mismatch(jsonPath, $humanReadableNameString, json);
'); |
| 353 }); | 353 }); |
| 354 writeln('}'); | 354 writeln('}'); |
| 355 } | 355 } |
| 356 | 356 |
| 357 /** | 357 /** |
| 358 * Emit the class to encapsulate an object type. | 358 * Emit the class to encapsulate an object type. |
| 359 */ | 359 */ |
| 360 void emitObjectClass( | 360 void emitObjectClass( |
| 361 String className, TypeObject type, ImpliedType impliedType) { | 361 String className, TypeObject type, ImpliedType impliedType) { |
| 362 docComment(toHtmlVisitor.collectHtml(() { | 362 docComment(toHtmlVisitor.collectHtml(() { |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 List<String> optionalArgs = <String>[]; | 583 List<String> optionalArgs = <String>[]; |
| 584 for (TypeObjectField field in type.fields) { | 584 for (TypeObjectField field in type.fields) { |
| 585 String fieldNameString = literalString(field.name); | 585 String fieldNameString = literalString(field.name); |
| 586 String fieldAccessor = 'json[$fieldNameString]'; | 586 String fieldAccessor = 'json[$fieldNameString]'; |
| 587 String jsonPath = 'jsonPath + ${literalString('.${field.name}')}'; | 587 String jsonPath = 'jsonPath + ${literalString('.${field.name}')}'; |
| 588 if (field.value != null) { | 588 if (field.value != null) { |
| 589 String valueString = literalString(field.value); | 589 String valueString = literalString(field.value); |
| 590 writeln('if ($fieldAccessor != $valueString) {'); | 590 writeln('if ($fieldAccessor != $valueString) {'); |
| 591 indent(() { | 591 indent(() { |
| 592 writeln( | 592 writeln( |
| 593 'throw jsonDecoder.mismatch(jsonPath, "equal " + $valueString)
;'); | 593 'throw jsonDecoder.mismatch(jsonPath, "equal " + $valueString,
json);'); |
| 594 }); | 594 }); |
| 595 writeln('}'); | 595 writeln('}'); |
| 596 continue; | 596 continue; |
| 597 } | 597 } |
| 598 if (isOptionalConstructorArg(className, field)) { | 598 if (isOptionalConstructorArg(className, field)) { |
| 599 optionalArgs.add('${field.name}: ${field.name}'); | 599 optionalArgs.add('${field.name}: ${field.name}'); |
| 600 } else { | 600 } else { |
| 601 args.add(field.name); | 601 args.add(field.name); |
| 602 } | 602 } |
| 603 TypeDecl fieldType = field.type; | 603 TypeDecl fieldType = field.type; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 620 } else { | 620 } else { |
| 621 writeln(); | 621 writeln(); |
| 622 } | 622 } |
| 623 } | 623 } |
| 624 args.addAll(optionalArgs); | 624 args.addAll(optionalArgs); |
| 625 writeln('return new $className(${args.join(', ')});'); | 625 writeln('return new $className(${args.join(', ')});'); |
| 626 }); | 626 }); |
| 627 writeln('} else {'); | 627 writeln('} else {'); |
| 628 indent(() { | 628 indent(() { |
| 629 writeln( | 629 writeln( |
| 630 'throw jsonDecoder.mismatch(jsonPath, $humanReadableNameString);'); | 630 'throw jsonDecoder.mismatch(jsonPath, $humanReadableNameString, json
);'); |
| 631 }); | 631 }); |
| 632 writeln('}'); | 632 writeln('}'); |
| 633 }); | 633 }); |
| 634 writeln('}'); | 634 writeln('}'); |
| 635 } | 635 } |
| 636 | 636 |
| 637 /** | 637 /** |
| 638 * Emit the hashCode getter for an object class. | 638 * Emit the hashCode getter for an object class. |
| 639 */ | 639 */ |
| 640 void emitObjectHashCode(TypeObject type, String className) { | 640 void emitObjectHashCode(TypeObject type, String className) { |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 | 1223 |
| 1224 @override | 1224 @override |
| 1225 String get asClosure => '($type value) => ${callback('value')}'; | 1225 String get asClosure => '($type value) => ${callback('value')}'; |
| 1226 | 1226 |
| 1227 @override | 1227 @override |
| 1228 bool get isIdentity => false; | 1228 bool get isIdentity => false; |
| 1229 | 1229 |
| 1230 @override | 1230 @override |
| 1231 String asSnippet(String value) => callback(value); | 1231 String asSnippet(String value) => callback(value); |
| 1232 } | 1232 } |
| OLD | NEW |