Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(516)

Unified Diff: lib/file_generator.dart

Issue 2103743002: Rename mixin protos and add a check for undefined mixin name (Closed) Base URL: git@github.com:dart-lang/dart-protoc-plugin.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/file_generator.dart
diff --git a/lib/file_generator.dart b/lib/file_generator.dart
index a921786a1c9e398e3f76ef5850bbfafa0bca701c..8f8d2f2abda87f909b1b613544099ce89448cefe 100644
--- a/lib/file_generator.dart
+++ b/lib/file_generator.dart
@@ -18,15 +18,14 @@ class FileGenerator extends ProtobufContainer {
/// Does not check for existence of import files or classes.
static Map<String, PbMixin> _getDeclaredMixins(FileDescriptorProto desc) {
String mixinError(String error) =>
- 'Option "mixins" in file ${desc.name}: $error';
+ 'Option "mixins" in ${desc.name}: $error';
if (!desc.hasOptions() ||
- !desc.options.hasExtension(Dart_options.importedMixins)) {
+ !desc.options.hasExtension(Dart_options.imports)) {
return <String, PbMixin>{};
}
var dartMixins = <String, DartMixin>{};
- ImportedMixins importedMixins =
- desc.options.getExtension(Dart_options.importedMixins);
+ Imports importedMixins = desc.options.getExtension(Dart_options.imports);
frederikmutzel 2016/06/28 08:15:13 maybe rename the variable to imports as well?
skybrian 2016/06/28 08:40:34 Skipping for now.
for (DartMixin mixin in importedMixins.mixins) {
if (dartMixins.containsKey(mixin.name)) {
throw mixinError('Duplicate mixin name: "${mixin.name}"');
@@ -89,7 +88,7 @@ class FileGenerator extends ProtobufContainer {
return pbMixins;
}
- final FileDescriptorProto _fileDescriptor;
+ final FileDescriptorProto descriptor;
// The relative path used to import the .proto file, as a URI.
final Uri protoFileUri;
@@ -104,7 +103,7 @@ class FileGenerator extends ProtobufContainer {
bool _linked = false;
FileGenerator(FileDescriptorProto descriptor)
- : _fileDescriptor = descriptor,
+ : descriptor = descriptor,
protoFileUri = new Uri.file(descriptor.name) {
if (protoFileUri.isAbsolute) {
// protoc should never generate an import with an absolute path.
@@ -122,17 +121,17 @@ class FileGenerator extends ProtobufContainer {
}
// Load and register all enum and message types.
- for (EnumDescriptorProto enumType in _fileDescriptor.enumType) {
+ for (EnumDescriptorProto enumType in descriptor.enumType) {
enumGenerators.add(new EnumGenerator(enumType, this));
}
- for (DescriptorProto messageType in _fileDescriptor.messageType) {
+ for (DescriptorProto messageType in descriptor.messageType) {
messageGenerators.add(new MessageGenerator(
messageType, this, declaredMixins, defaultMixin));
}
- for (FieldDescriptorProto extension in _fileDescriptor.extension) {
+ for (FieldDescriptorProto extension in descriptor.extension) {
extensionGenerators.add(new ExtensionGenerator(extension, this));
}
- for (ServiceDescriptorProto service in _fileDescriptor.service) {
+ for (ServiceDescriptorProto service in descriptor.service) {
var serviceGen = new ServiceGenerator(service, this);
serviceGenerators.add(serviceGen);
clientApiGenerators.add(new ClientApiGenerator(serviceGen));
@@ -154,9 +153,9 @@ class FileGenerator extends ProtobufContainer {
_linked = true;
}
- String get package => _fileDescriptor.package;
+ String get package => descriptor.package;
String get classname => '';
- String get fqname => '.${_fileDescriptor.package}';
+ String get fqname => '.${descriptor.package}';
FileGenerator get fileGen => this;
// Extract the filename from a URI and remove the extension.
@@ -176,7 +175,7 @@ class FileGenerator extends ProtobufContainer {
if (!_linked) throw new StateError("not linked");
makeFile(String extension, String content) {
- Uri protoUrl = new Uri.file(_fileDescriptor.name);
+ Uri protoUrl = new Uri.file(descriptor.name);
Uri dartUrl = config.outputPathFor(protoUrl, extension);
return new CodeGeneratorResponse_File()
..name = dartUrl.path
@@ -235,7 +234,7 @@ class FileGenerator extends ProtobufContainer {
// We only add the dart:async import if there are services in the
// FileDescriptorProto.
- if (_fileDescriptor.service.isNotEmpty) {
+ if (descriptor.service.isNotEmpty) {
out.println("import 'dart:async';\n");
}
@@ -461,7 +460,7 @@ import 'package:protobuf/protobuf.dart';
///
/// (This should be unique to avoid warnings about duplicate Dart libraries.)
void _writeLibraryHeading(IndentingWriter out, [String extension]) {
- Uri filePath = new Uri.file(_fileDescriptor.name);
+ 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";
@@ -469,11 +468,11 @@ import 'package:protobuf/protobuf.dart';
var libraryName = _fileNameWithoutExtension(filePath).replaceAll('-', '_');
if (extension != null) libraryName += "_$extension";
- if (_fileDescriptor.package != '') {
+ 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 = _fileDescriptor.package + "_" + libraryName;
+ libraryName = descriptor.package + "_" + libraryName;
}
out.println('''
///
« no previous file with comments | « lib/code_generator.dart ('k') | lib/linker.dart » ('j') | lib/message_generator.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698