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

Side by Side Diff: lib/protobuf_field.dart

Issue 1829573002: Fix all strong mode warnings in protoc-plugin (Closed) Base URL: git@github.com:dart-lang/dart-protoc-plugin.git@master
Patch Set: regenerate pb.dart files Created 4 years, 8 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/options.dart ('k') | lib/src/descriptor.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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 /// Returns Dart code adding this field to a BuilderInfo object. 106 /// Returns Dart code adding this field to a BuilderInfo object.
107 /// The call will start with ".." and a method name. 107 /// The call will start with ".." and a method name.
108 /// [package] is the package where the code will be evaluated. 108 /// [package] is the package where the code will be evaluated.
109 String generateBuilderInfoCall(String package) { 109 String generateBuilderInfoCall(String package) {
110 String quotedName = "'$dartFieldName'"; 110 String quotedName = "'$dartFieldName'";
111 String type = baseType.getDartType(package); 111 String type = baseType.getDartType(package);
112 112
113 if (isRepeated) { 113 if (isRepeated) {
114 if (baseType.isMessage || baseType.isGroup) { 114 if (baseType.isMessage || baseType.isGroup) {
115 return '..pp($number, $quotedName, $typeConstant,' 115 return '..pp/*<$type>*/($number, $quotedName, $typeConstant,'
116 ' $type.$checkItem, $type.create)'; 116 ' $type.$checkItem, $type.create)';
117 } else if (baseType.isEnum) { 117 } else if (baseType.isEnum) {
118 return '..pp($number, $quotedName, $typeConstant,' 118 return '..pp/*<$type>*/($number, $quotedName, $typeConstant,'
119 ' $type.$checkItem, null, $type.valueOf)'; 119 ' $type.$checkItem, null, $type.valueOf)';
120 } else { 120 } else {
121 return '..p($number, $quotedName, $typeConstant)'; 121 return '..p/*<$type>*/($number, $quotedName, $typeConstant)';
122 } 122 }
123 } 123 }
124 124
125 String makeDefault = generateDefaultFunction(package); 125 String makeDefault = generateDefaultFunction(package);
126 if (baseType.isEnum) { 126 if (baseType.isEnum) {
127 String valueOf = '$type.valueOf'; 127 String valueOf = '$type.valueOf';
128 return '..e($number, $quotedName, $typeConstant, $makeDefault, $valueOf)'; 128 return '..e/*<$type>*/('
129 '$number, $quotedName, $typeConstant, $makeDefault, $valueOf)';
129 } 130 }
130 131
131 String prefix = '..a($number, $quotedName, $typeConstant'; 132 String prefix = '..a/*<$type>*/($number, $quotedName, $typeConstant';
132 if (makeDefault == null) return prefix + ')'; 133 if (makeDefault == null) return prefix + ')';
133 134
134 if (baseType.isMessage || baseType.isGroup) { 135 if (baseType.isMessage || baseType.isGroup) {
135 return prefix + ', $makeDefault, $type.create)'; 136 return prefix + ', $makeDefault, $type.create)';
136 } 137 }
137 138
138 return prefix + ', $makeDefault)'; 139 return prefix + ', $makeDefault)';
139 } 140 }
140 141
141 /// Returns a Dart expression that evaluates to this field's default value. 142 /// Returns a Dart expression that evaluates to this field's default value.
142 /// 143 ///
143 /// Returns "null" if unavailable, in which case FieldSet._getDefault() 144 /// Returns "null" if unavailable, in which case FieldSet._getDefault()
144 /// should be called instead. 145 /// should be called instead.
145 String getDefaultExpr() { 146 String getDefaultExpr() {
146 if (isRepeated) return "null"; 147 if (isRepeated) return "null";
147 switch (_field.type) { 148 switch (_field.type) {
148 case FieldDescriptorProto_Type.TYPE_BOOL: 149 case FieldDescriptorProto_Type.TYPE_BOOL:
149 return _getDefaultAsBoolExpr("false"); 150 return _getDefaultAsBoolExpr("false");
150 case FieldDescriptorProto_Type.TYPE_INT32: 151 case FieldDescriptorProto_Type.TYPE_INT32:
151 case FieldDescriptorProto_Type.TYPE_UINT32: 152 case FieldDescriptorProto_Type.TYPE_UINT32:
152 case FieldDescriptorProto_Type.TYPE_SINT32: 153 case FieldDescriptorProto_Type.TYPE_SINT32:
153 case FieldDescriptorProto_Type.TYPE_FIXED32: 154 case FieldDescriptorProto_Type.TYPE_FIXED32:
154 case FieldDescriptorProto_Type.TYPE_SFIXED32: 155 case FieldDescriptorProto_Type.TYPE_SFIXED32:
155 return _getDefaultAsInt32Expr("0"); 156 return _getDefaultAsInt32Expr("0");
156 case FieldDescriptorProto_Type.TYPE_STRING: 157 case FieldDescriptorProto_Type.TYPE_STRING:
157 return _getDefaultAsStringExpr("''"); 158 return _getDefaultAsStringExpr("''");
158 default: 159 default:
159 return "null"; 160 return "null";
160 } 161 }
161 } 162 }
162 163
163 /// Returns a function expression that returns the field's default value. 164 /// Returns a function expression that returns the field's default value.
164 /// 165 ///
165 /// [package] is the package where the expression will be evaluated. 166 /// [package] is the package where the expression will be evaluated.
166 /// Returns null if this field doesn't have an initializer. 167 /// Returns null if this field doesn't have an initializer.
167 String generateDefaultFunction(String package) { 168 String generateDefaultFunction(String package) {
168 if (isRepeated) { 169 if (isRepeated) {
169 return '() => new PbList()'; 170 return '() => new PbList()';
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 } 263 }
263 264
264 get _invalidDefaultValue => "dart-protoc-plugin:" 265 get _invalidDefaultValue => "dart-protoc-plugin:"
265 " invalid default value (${_field.defaultValue})" 266 " invalid default value (${_field.defaultValue})"
266 " found in field $fqname"; 267 " found in field $fqname";
267 268
268 _typeNotImplemented(String methodName) => "dart-protoc-plugin:" 269 _typeNotImplemented(String methodName) => "dart-protoc-plugin:"
269 " $methodName not implemented for type (${_field.type})" 270 " $methodName not implemented for type (${_field.type})"
270 " found in field $fqname"; 271 " found in field $fqname";
271 } 272 }
OLDNEW
« no previous file with comments | « lib/options.dart ('k') | lib/src/descriptor.pb.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698