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

Side by Side Diff: lib/protobuf_field.dart

Issue 2086253002: Allow application of external mixins to generated dart protos. (Closed) Base URL: https://github.com/dart-lang/dart-protoc-plugin.git@master
Patch Set: Add dart options for override annotations. These make it possible to annotate generated getters, se… Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « lib/message_generator.dart ('k') | lib/src/dart_options.pb.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of protoc; 5 part of protoc;
6 6
7 class ProtobufField { 7 class ProtobufField {
8 static final RegExp HEX_LITERAL_REGEX = 8 static final RegExp HEX_LITERAL_REGEX =
9 new RegExp(r'^0x[0-9a-f]+$', multiLine: false, caseSensitive: false); 9 new RegExp(r'^0x[0-9a-f]+$', multiLine: false, caseSensitive: false);
10 static final RegExp INTEGER_LITERAL_REGEX = new RegExp(r'^[+-]?[0-9]+$'); 10 static final RegExp INTEGER_LITERAL_REGEX = new RegExp(r'^[+-]?[0-9]+$');
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 bool get isRequired => 48 bool get isRequired =>
49 descriptor.label == FieldDescriptorProto_Label.LABEL_REQUIRED; 49 descriptor.label == FieldDescriptorProto_Label.LABEL_REQUIRED;
50 50
51 bool get isRepeated => 51 bool get isRepeated =>
52 descriptor.label == FieldDescriptorProto_Label.LABEL_REPEATED; 52 descriptor.label == FieldDescriptorProto_Label.LABEL_REPEATED;
53 53
54 /// True if the field is to be encoded with [packed=true] encoding. 54 /// True if the field is to be encoded with [packed=true] encoding.
55 bool get isPacked => 55 bool get isPacked =>
56 isRepeated && descriptor.options != null && descriptor.options.packed; 56 isRepeated && descriptor.options != null && descriptor.options.packed;
57 57
58 /// Whether the field has the `overrideGetter` annotation set to true.
59 bool get overridesGetter => _hasBooleanOption(Dart_options.overrideGetter);
60
61 /// Whether the field has the `overrideSetter` annotation set to true.
62 bool get overridesSetter => _hasBooleanOption(Dart_options.overrideSetter);
63
64 /// Whether the field has the `overrideHasMethod` annotation set to true.
65 bool get overridesHasMethod =>
66 _hasBooleanOption(Dart_options.overrideHasMethod);
67
68 /// Whether the field has the `overrideClearMethod` annotation set to true.
69 bool get overridesClearMethod =>
70 _hasBooleanOption(Dart_options.overrideClearMethod);
71
58 /// True if this field uses the Int64 from the fixnum package. 72 /// True if this field uses the Int64 from the fixnum package.
59 bool get needsFixnumImport => baseType.unprefixed == "Int64"; 73 bool get needsFixnumImport => baseType.unprefixed == "Int64";
60 74
61 /// Returns the expression to use for the Dart type. 75 /// Returns the expression to use for the Dart type.
62 /// 76 ///
63 /// This will be a List for repeated types. 77 /// This will be a List for repeated types.
64 /// [package] is the package where we are generating code. 78 /// [package] is the package where we are generating code.
65 String getDartType(String package) { 79 String getDartType(String package) {
66 if (isRepeated) return baseType.getRepeatedDartType(package); 80 if (isRepeated) return baseType.getRepeatedDartType(package);
67 return baseType.getDartType(package); 81 return baseType.getDartType(package);
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 return '\'$value\''; 250 return '\'$value\'';
237 } 251 }
238 252
239 String _getDefaultAsInt32Expr(String noDefault) { 253 String _getDefaultAsInt32Expr(String noDefault) {
240 if (descriptor.hasDefaultValue() && '0' != descriptor.defaultValue) { 254 if (descriptor.hasDefaultValue() && '0' != descriptor.defaultValue) {
241 return '${descriptor.defaultValue}'; 255 return '${descriptor.defaultValue}';
242 } 256 }
243 return noDefault; 257 return noDefault;
244 } 258 }
245 259
260 bool _hasBooleanOption(Extension extension) =>
261 descriptor?.options?.getExtension(extension) ?? false;
262
246 get _invalidDefaultValue => "dart-protoc-plugin:" 263 get _invalidDefaultValue => "dart-protoc-plugin:"
247 " invalid default value (${descriptor.defaultValue})" 264 " invalid default value (${descriptor.defaultValue})"
248 " found in field $fqname"; 265 " found in field $fqname";
249 266
250 _typeNotImplemented(String methodName) => "dart-protoc-plugin:" 267 _typeNotImplemented(String methodName) => "dart-protoc-plugin:"
251 " $methodName not implemented for type (${descriptor.type})" 268 " $methodName not implemented for type (${descriptor.type})"
252 " found in field $fqname"; 269 " found in field $fqname";
253 } 270 }
OLDNEW
« no previous file with comments | « lib/message_generator.dart ('k') | lib/src/dart_options.pb.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698