generateMainFile method
IndentingWriter
generateMainFile([
- OutputConfiguration config = const DefaultOutputConfiguration()
Returns the contents of the .pb.dart file for this .proto file.
Implementation
IndentingWriter generateMainFile(
[OutputConfiguration config = const DefaultOutputConfiguration()]) {
if (!_linked) throw StateError('not linked');
final out = makeWriter();
writeMainHeader(out, config);
// Generate code.
for (final m in messageGenerators) {
m.generate(out);
}
// Generate code for extensions defined at top-level using a class
// name derived from the file name.
if (extensionGenerators.isNotEmpty) {
// TODO(antonm): do not generate a class.
final className = extensionClassName(descriptor, usedTopLevelNames);
out.addBlock('class $className {', '}\n', () {
for (final x in extensionGenerators) {
x.generate(out);
}
out.println(
'static void registerAllExtensions($protobufImportPrefix.ExtensionRegistry '
'registry) {');
for (final x in extensionGenerators) {
out.println(' registry.add(${x.name});');
}
out.println('}');
});
}
for (final c in clientApiGenerators) {
c.generate(out);
}
return out;
}