Sync changes from internal repo. (#107)
diff --git a/lib/file_generator.dart b/lib/file_generator.dart
index 4290cac..a4c4642 100644
--- a/lib/file_generator.dart
+++ b/lib/file_generator.dart
@@ -239,7 +239,7 @@
/// Writes the header and imports for the .pb.dart file.
void writeMainHeader(IndentingWriter out,
[OutputConfiguration config = const DefaultOutputConfiguration()]) {
- _writeLibraryHeading(out);
+ _writeHeading(out);
// We only add the dart:async import if there are generic client API
// generators for services in the FileDescriptorProto.
@@ -357,7 +357,7 @@
if (!_linked) throw new StateError("not linked");
var out = new IndentingWriter();
- _writeLibraryHeading(out, "pbenum");
+ _writeHeading(out);
if (enumCount > 0) {
// Make sure any other symbols in dart:core don't cause name conflicts
@@ -393,7 +393,7 @@
[OutputConfiguration config = const DefaultOutputConfiguration()]) {
if (!_linked) throw new StateError("not linked");
var out = new IndentingWriter();
- _writeLibraryHeading(out, "pbserver");
+ _writeHeading(out);
if (serviceGenerators.isNotEmpty) {
out.println('''
@@ -435,7 +435,7 @@
[OutputConfiguration config = const DefaultOutputConfiguration()]) {
if (!_linked) throw new StateError("not linked");
var out = new IndentingWriter();
- _writeLibraryHeading(out, "pbgrpc");
+ _writeHeading(out);
out.println('''
import 'dart:async';
@@ -469,7 +469,7 @@
[OutputConfiguration config = const DefaultOutputConfiguration()]) {
if (!_linked) throw new StateError("not linked");
var out = new IndentingWriter();
- _writeLibraryHeading(out, "pbjson");
+ _writeHeading(out);
// Import the .pbjson.dart files we depend on.
var imports = _findJsonProtosToImport();
@@ -508,30 +508,13 @@
return imports;
}
- /// Writes the library name at the top of the dart file.
- ///
- /// (This should be unique to avoid warnings about duplicate Dart libraries.)
- void _writeLibraryHeading(IndentingWriter out, [String extension]) {
- Uri filePath = new Uri.file(descriptor.name);
- if (filePath.isAbsolute) {
- // protoc should never generate a file descriptor with an absolute path.
- throw "FAILURE: File with an absolute path is not supported";
- }
-
- var libraryName = _fileNameWithoutExtension(filePath).replaceAll('-', '_');
- if (extension != null) libraryName += "_$extension";
- if (descriptor.package != '') {
- // Two .protos can be in the same proto package.
- // It isn't unique enough to use as a Dart library name.
- // But we can prepend it.
- libraryName = descriptor.package + "_" + libraryName;
- }
+ /// Writes the header at the top of the dart file.
+ void _writeHeading(IndentingWriter out) {
out.println('''
///
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
-library $libraryName;
''');
}
diff --git a/lib/src/dart_options.pb.dart b/lib/src/dart_options.pb.dart
index e730e4a..5d78a27 100644
--- a/lib/src/dart_options.pb.dart
+++ b/lib/src/dart_options.pb.dart
@@ -2,7 +2,6 @@
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
-library dart_options_dart_options;
// ignore: UNUSED_SHOWN_NAME
import 'dart:core' show int, bool, double, String, List, override;
diff --git a/lib/src/descriptor.pb.dart b/lib/src/descriptor.pb.dart
index 925a457..e34c94d 100644
--- a/lib/src/descriptor.pb.dart
+++ b/lib/src/descriptor.pb.dart
@@ -2,7 +2,6 @@
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
-library google.protobuf_descriptor;
// ignore: UNUSED_SHOWN_NAME
import 'dart:core' show int, bool, double, String, List, override;
diff --git a/lib/src/descriptor.pbenum.dart b/lib/src/descriptor.pbenum.dart
index 1408ca8..601fd97 100644
--- a/lib/src/descriptor.pbenum.dart
+++ b/lib/src/descriptor.pbenum.dart
@@ -2,7 +2,6 @@
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
-library google.protobuf_descriptor_pbenum;
// ignore_for_file: UNDEFINED_SHOWN_NAME,UNUSED_SHOWN_NAME
import 'dart:core' show int, dynamic, String, List, Map;
diff --git a/lib/src/plugin.pb.dart b/lib/src/plugin.pb.dart
index be55531..dd561ba 100644
--- a/lib/src/plugin.pb.dart
+++ b/lib/src/plugin.pb.dart
@@ -2,7 +2,6 @@
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
-library google.protobuf.compiler_plugin;
// ignore: UNUSED_SHOWN_NAME
import 'dart:core' show int, bool, double, String, List, override;
diff --git a/test/file_generator_test.dart b/test/file_generator_test.dart
index 4a8d3ed..8412a7f 100644
--- a/test/file_generator_test.dart
+++ b/test/file_generator_test.dart
@@ -77,7 +77,6 @@
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
-library test;
// ignore: UNUSED_SHOWN_NAME
import 'dart:core' show int, bool, double, String, List, override;
@@ -141,7 +140,6 @@
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
-library test_pbjson;
const PhoneNumber$json = const {
'1': 'PhoneNumber',
@@ -169,7 +167,6 @@
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
-library test;
// ignore: UNUSED_SHOWN_NAME
import 'dart:core' show int, bool, double, String, List, override;
@@ -183,7 +180,6 @@
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
-library test_pbenum;
// ignore_for_file: UNDEFINED_SHOWN_NAME,UNUSED_SHOWN_NAME
import 'dart:core' show int, dynamic, String, List, Map;
@@ -230,7 +226,6 @@
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
-library test_pbjson;
const PhoneType$json = const {
'1': 'PhoneType',
@@ -260,7 +255,6 @@
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
-library pb_library_test;
// ignore: UNUSED_SHOWN_NAME
import 'dart:core' show int, bool, double, String, List, override;
@@ -287,7 +281,6 @@
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
-library test;
// ignore: UNUSED_SHOWN_NAME
import 'dart:core' show int, bool, double, String, List, override;
@@ -324,7 +317,6 @@
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
-library test;
import 'dart:async';
// ignore: UNUSED_SHOWN_NAME
@@ -373,7 +365,6 @@
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
-library test_pbserver;
import 'dart:async';
@@ -440,7 +431,6 @@
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
-library test;
// ignore: UNUSED_SHOWN_NAME
import 'dart:core' show int, bool, double, String, List, override;
@@ -503,7 +493,6 @@
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
-library test_pbgrpc;
import 'dart:async';
@@ -662,7 +651,6 @@
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
-library test;
// ignore: UNUSED_SHOWN_NAME
import 'dart:core' show int, bool, double, String, List, override;
@@ -721,7 +709,6 @@
// Generated code. Do not modify.
///
// ignore_for_file: non_constant_identifier_names,library_prefixes
-library test_pbjson;
const M$json = const {
'1': 'M',