generateEnumFile method

IndentingWriter generateEnumFile([
  1. OutputConfiguration config = const DefaultOutputConfiguration()
])

Returns the contents of the .pbenum.dart file for this .proto file.

Implementation

IndentingWriter generateEnumFile(
    [OutputConfiguration config = const DefaultOutputConfiguration()]) {
  if (!_linked) throw StateError('not linked');

  final out = makeWriter();
  _writeHeading(out);

  final importWriter = ImportWriter();

  if (enumCount > 0) {
    // Make sure any other symbols in dart:core don't cause name conflicts
    // with enums that have the same name.
    importWriter.addImport(_coreImportUrl, prefix: coreImportPrefix);
    importWriter.addImport(_protobufImportUrl, prefix: protobufImportPrefix);
  }

  for (final publicDependency in descriptor.publicDependency) {
    _addExport(importWriter, config,
        Uri.file(descriptor.dependency[publicDependency]), '.pbenum.dart');
  }

  if (importWriter.hasImports) {
    out.println(importWriter.emit());
  }

  for (final e in enumGenerators) {
    e.generate(out);
  }

  for (final m in messageGenerators) {
    m.generateEnums(out);
  }

  return out;
}