| 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 }; | 194 }; |
| 195 | 195 |
| 196 /** | 196 /** |
| 197 * Class members for which the constructor argument should be optional, even | 197 * Class members for which the constructor argument should be optional, even |
| 198 * if the member is not an optional part of the protocol. For list types, | 198 * if the member is not an optional part of the protocol. For list types, |
| 199 * the constructor will default the member to the empty list. | 199 * the constructor will default the member to the empty list. |
| 200 */ | 200 */ |
| 201 static const Map<String, List<String>> _optionalConstructorArguments = const { | 201 static const Map<String, List<String>> _optionalConstructorArguments = const { |
| 202 'AnalysisErrorFixes': const ['fixes'], | 202 'AnalysisErrorFixes': const ['fixes'], |
| 203 'SourceChange': const ['edits', 'linkedEditGroups'], | 203 'SourceChange': const ['edits', 'linkedEditGroups'], |
| 204 'SourceFileEdit': const ['edits'], | 204 'SourceFileEdit': const ['time', 'edits'], |
| 205 'TypeHierarchyItem': const ['interfaces', 'mixins', 'subclasses'], | 205 'TypeHierarchyItem': const ['interfaces', 'mixins', 'subclasses'], |
| 206 }; | 206 }; |
| 207 | 207 |
| 208 /** | 208 /** |
| 209 * Visitor used to produce doc comments. | 209 * Visitor used to produce doc comments. |
| 210 */ | 210 */ |
| 211 final ToHtmlVisitor toHtmlVisitor; | 211 final ToHtmlVisitor toHtmlVisitor; |
| 212 | 212 |
| 213 /** | 213 /** |
| 214 * Types implied by the API. This includes types explicitly named in the | 214 * Types implied by the API. This includes types explicitly named in the |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 TypeDecl fieldType = field.type; | 616 TypeDecl fieldType = field.type; |
| 617 if (fieldType is TypeList) { | 617 if (fieldType is TypeList) { |
| 618 extraInitCode.add(() { | 618 extraInitCode.add(() { |
| 619 writeln('if (${field.name} == null) {'); | 619 writeln('if (${field.name} == null) {'); |
| 620 indent(() { | 620 indent(() { |
| 621 writeln('${field.name} = <${dartType(fieldType.itemType)}>[];'); | 621 writeln('${field.name} = <${dartType(fieldType.itemType)}>[];'); |
| 622 }); | 622 }); |
| 623 writeln('}'); | 623 writeln('}'); |
| 624 }); | 624 }); |
| 625 } | 625 } |
| 626 if (className == 'SourceFileEdit' && field.name == 'time') { |
| 627 extraInitCode.add(() { |
| 628 writeln('if (${field.name} == null) {'); |
| 629 indent(() { |
| 630 writeln('${field.name} = new DateTime.now().millisecondsSinceEpoch
;'); |
| 631 }); |
| 632 writeln('}'); |
| 633 }); |
| 634 } |
| 626 } else { | 635 } else { |
| 627 args.add(arg); | 636 args.add(arg); |
| 628 } | 637 } |
| 629 } | 638 } |
| 630 if (optionalArgs.isNotEmpty) { | 639 if (optionalArgs.isNotEmpty) { |
| 631 args.add('{${optionalArgs.join(', ')}}'); | 640 args.add('{${optionalArgs.join(', ')}}'); |
| 632 } | 641 } |
| 633 write('$className(${args.join(', ')})'); | 642 write('$className(${args.join(', ')})'); |
| 634 if (extraInitCode.isEmpty) { | 643 if (extraInitCode.isEmpty) { |
| 635 writeln(';'); | 644 writeln(';'); |
| (...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1301 CodegenProtocolVisitor visitor = new CodegenProtocolVisitor(readApi()); | 1310 CodegenProtocolVisitor visitor = new CodegenProtocolVisitor(readApi()); |
| 1302 return visitor.collectCode(visitor.visitApi); | 1311 return visitor.collectCode(visitor.visitApi); |
| 1303 }); | 1312 }); |
| 1304 | 1313 |
| 1305 /** | 1314 /** |
| 1306 * Translate spec_input.html into protocol_matchers.dart. | 1315 * Translate spec_input.html into protocol_matchers.dart. |
| 1307 */ | 1316 */ |
| 1308 main() { | 1317 main() { |
| 1309 target.generate(); | 1318 target.generate(); |
| 1310 } | 1319 } |
| OLD | NEW |