OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of protoc; | 5 part of protoc; |
6 | 6 |
7 abstract class ProtobufContainer { | 7 abstract class ProtobufContainer { |
8 String get package; | 8 String get package; |
9 String get classname; | 9 String get classname; |
10 String get fqname; | 10 String get fqname; |
11 String get packageImportPrefix => package.replaceAll('.', r'$'); | 11 String get packageImportPrefix => package.replaceAll('.', r'$'); |
12 } | 12 } |
13 | 13 |
14 class CodeGenerator extends ProtobufContainer { | 14 class CodeGenerator extends ProtobufContainer { |
15 final Stream<List<int>> _streamIn; | 15 final Stream<List<int>> _streamIn; |
16 final IOSink _streamOut; | 16 final IOSink _streamOut; |
17 final IOSink _streamErr; | 17 final IOSink _streamErr; |
18 | 18 |
19 CodeGenerator(this._streamIn, this._streamOut, this._streamErr); | 19 CodeGenerator(this._streamIn, this._streamOut, this._streamErr); |
20 | 20 |
21 /// Runs the code generator. The optional [optionParsers] can be used to | 21 /// Runs the code generator. The optional [optionParsers] can be used to |
22 /// change how command line options are parsed (see [parseGenerationOptions] | 22 /// change how command line options are parsed (see [parseGenerationOptions] |
23 /// for details), and [outputConfiguration] can be used to override where | 23 /// for details), and [outputConfiguration] can be used to override where |
24 /// generated files are created and how imports between generated files are | 24 /// generated files are created and how imports between generated files are |
25 /// constructed (see [OutputConfiguration] for details). | 25 /// constructed (see [OutputConfiguration] for details). |
26 void generate({ | 26 void generate({ |
27 Map<String, SingleOptionParser> optionParsers, | 27 Map<String, SingleOptionParser> optionParsers, |
28 OutputConfiguration outputConfiguration}) { | 28 OutputConfiguration outputConfiguration}) { |
29 | |
30 var extensions = new ExtensionRegistry(); | |
31 Dart_options.registerAllExtensions(extensions); | |
32 | |
29 _streamIn | 33 _streamIn |
30 .fold(new BytesBuilder(), (builder, data) => builder..add(data)) | 34 .fold(new BytesBuilder(), (builder, data) => builder..add(data)) |
31 .then((builder) => builder.takeBytes()) | 35 .then((builder) => builder.takeBytes()) |
32 .then((List<int> bytes) { | 36 .then((List<int> bytes) { |
33 var request = new CodeGeneratorRequest.fromBuffer(bytes); | 37 var request = new CodeGeneratorRequest.fromBuffer(bytes, extensions) ; |
Søren Gjesse
2015/06/22 18:29:38
Long line.
skybrian
2015/06/23 02:21:25
Done.
| |
34 var response = new CodeGeneratorResponse(); | 38 var response = new CodeGeneratorResponse(); |
35 | 39 |
36 // Parse the options in the request. Return the errors is any. | 40 // Parse the options in the request. Return the errors is any. |
37 var options = parseGenerationOptions( | 41 var options = parseGenerationOptions( |
38 request, response, optionParsers); | 42 request, response, optionParsers); |
39 if (options == null) { | 43 if (options == null) { |
40 _streamOut.add(response.writeToBuffer()); | 44 _streamOut.add(response.writeToBuffer()); |
41 return; | 45 return; |
42 } | 46 } |
43 | 47 |
(...skipping 10 matching lines...) Expand all Loading... | |
54 response.file.addAll( | 58 response.file.addAll( |
55 generators.map((filegen) => filegen.generateResponse())); | 59 generators.map((filegen) => filegen.generateResponse())); |
56 _streamOut.add(response.writeToBuffer()); | 60 _streamOut.add(response.writeToBuffer()); |
57 }); | 61 }); |
58 } | 62 } |
59 | 63 |
60 String get package => ''; | 64 String get package => ''; |
61 String get classname => null; | 65 String get classname => null; |
62 String get fqname => ''; | 66 String get fqname => ''; |
63 } | 67 } |
OLD | NEW |