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

Unified Diff: lib/file_generator.dart

Issue 93743006: Use package names as import prefixes when generating code (Closed) Base URL: https://github.com/dart-lang/dart-protoc-plugin.git@master
Patch Set: Addressed review commetns Created 6 years, 12 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
« no previous file with comments | « lib/extension_generator.dart ('k') | lib/message_generator.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/file_generator.dart
diff --git a/lib/file_generator.dart b/lib/file_generator.dart
index 7cd92cddf0d69c71c2b0c917540c012a918e91f6..cb908add7900f7463b5eaf7a619f42e0e05fde0a 100644
--- a/lib/file_generator.dart
+++ b/lib/file_generator.dart
@@ -28,6 +28,7 @@ class FileGenerator implements ProtobufContainer {
}
}
+ String get package => _fileDescriptor.package;
String get classname => '';
String get fqname => '.${_fileDescriptor.package}';
@@ -128,7 +129,14 @@ class FileGenerator implements ProtobufContainer {
}
// Create a relative path from the current file to the import.
Uri relativeProtoPath = _relative(importPath, filePath);
- out.println("import '${_generatedFilePath(relativeProtoPath)}';");
+ // Find the file generator for this import as it contains the
+ // package name.
+ FileGenerator fileGenerator = _context.lookupFile(import);
+ out.print("import '${_generatedFilePath(relativeProtoPath)}'");
+ if (package != fileGenerator.package) {
+ out.print(' as ${fileGenerator.package}');
+ }
+ out.println(';');
}
out.println('');
@@ -169,12 +177,19 @@ class GenerationContext {
final GenerationOptions options;
final Map<String, ProtobufContainer> _registry =
<String, ProtobufContainer>{};
+ final Map<String, FileGenerator> _files =
+ <String, FileGenerator>{};
GenerationContext(this.options);
void register(ProtobufContainer container) {
_registry[container.fqname] = container;
+ if (container is FileGenerator) {
+ _files[container._fileDescriptor.name] = container;
+ }
}
ProtobufContainer operator [](String fqname) => _registry[fqname];
+
+ FileGenerator lookupFile(String name) => _files[name];
}
« no previous file with comments | « lib/extension_generator.dart ('k') | lib/message_generator.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698