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

Unified Diff: lib/options.dart

Issue 2043913005: Change how to set the Dart name of a field (Closed) Base URL: git@github.com:dart-lang/dart-protoc-plugin.git@master
Patch Set: better error checking, clean up pubspec 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/options.dart
diff --git a/lib/options.dart b/lib/options.dart
index 0679c025c4e3fe2759fb9a5046f1d014167e5ece..fcea3083a624567a221bac4568575a6e66c64c0f 100644
--- a/lib/options.dart
+++ b/lib/options.dart
@@ -46,11 +46,7 @@ bool genericOptionsParser(CodeGeneratorRequest request,
/// Options expected by the protoc code generation compiler.
class GenerationOptions {
- /// Maps a fully qualified field name, to the desired name we wish to
- /// generate. For example `MyMessage.has_field` to `HasFld`.
- final Map<String, String> fieldNameOverrides;
-
- GenerationOptions([this.fieldNameOverrides = const {}]);
+ GenerationOptions();
}
/// A parser for a name-value pair option. Options parsed in
@@ -70,47 +66,11 @@ abstract class SingleOptionParser {
GenerationOptions parseGenerationOptions(
CodeGeneratorRequest request, CodeGeneratorResponse response,
[Map<String, SingleOptionParser> parsers]) {
- var fieldNameOptionParser = new FieldNameOptionParser();
-
var newParsers = <String, SingleOptionParser>{};
if (parsers != null) newParsers.addAll(parsers);
- newParsers['field_name'] = fieldNameOptionParser;
if (genericOptionsParser(request, response, newParsers)) {
- return new GenerationOptions(fieldNameOptionParser.mappings);
+ return new GenerationOptions();
}
return null;
}
-
-/// A [SingleOptionParser] to parse the `field_name` option. This option
-/// overrides the default name given to some fields that would otherwise collide
-/// with existing field names in Dart core objects or in [GeneratedMessage].
-/// (see `README.md` for details).
-class FieldNameOptionParser implements SingleOptionParser {
- /// Maps a fully qualified field name, to the desired name we wish to
- /// generate. For example `MyMessage.has_field` to `HasFld`.
- final Map<String, String> mappings = {};
-
- void parse(String name, String value, onError(String message)) {
- if (value == null) {
- onError('Invalid field_name option, expected a non-emtpy value.');
- return;
- }
-
- List<String> fromTo = value.split('|');
- if (fromTo.length != 2) {
- onError('Invalid field_name option, expected a single "|" separator.');
- return;
- }
-
- var fromName = fromTo[0].trim();
- var toName = fromTo[1].trim();
- if (fromName.isEmpty || toName.isEmpty) {
- onError('Invalid field_name option, '
- '"from" and "to" names should not be empty.');
- return;
- }
-
- mappings['.$fromName'] = toName;
- }
-}

Powered by Google App Engine
This is Rietveld 408576698