OLD | NEW |
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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 initialization = '()${SP}=>${SP}<int>[$byteList]'; | 260 initialization = '()${SP}=>${SP}<int>[$byteList]'; |
261 } | 261 } |
262 } | 262 } |
263 break; | 263 break; |
264 case FieldDescriptorProto_Type.TYPE_GROUP: | 264 case FieldDescriptorProto_Type.TYPE_GROUP: |
265 ProtobufContainer groupType = context[field.typeName]; | 265 ProtobufContainer groupType = context[field.typeName]; |
266 if (groupType != null) { | 266 if (groupType != null) { |
267 typePackage = groupType.package; | 267 typePackage = groupType.package; |
268 baseType = groupType.classname; | 268 baseType = groupType.classname; |
269 typeString = write(groupType.classname); | 269 typeString = write(groupType.classname); |
270 prefixedBaseType = groupType.package + '.' + baseType; | 270 prefixedBaseType = groupType.packageImportPrefix + '.' + baseType; |
271 prefixedTypeString = write(prefixedBaseType); | 271 prefixedTypeString = write(prefixedBaseType); |
272 codedStreamType = 'Group'; | 272 codedStreamType = 'Group'; |
273 } else { | 273 } else { |
274 throw 'FAILURE: Unknown group type reference ${field.typeName}'; | 274 throw 'FAILURE: Unknown group type reference ${field.typeName}'; |
275 } | 275 } |
276 initialization = '()${SP}=>${SP}new ${baseType}()'; | 276 initialization = '()${SP}=>${SP}new ${baseType}()'; |
277 prefixedInitialization = '()${SP}=>${SP}new ${prefixedBaseType}()'; | 277 prefixedInitialization = '()${SP}=>${SP}new ${prefixedBaseType}()'; |
278 break; | 278 break; |
279 case FieldDescriptorProto_Type.TYPE_MESSAGE: | 279 case FieldDescriptorProto_Type.TYPE_MESSAGE: |
280 ProtobufContainer messageType = context[field.typeName]; | 280 ProtobufContainer messageType = context[field.typeName]; |
281 if (messageType != null) { | 281 if (messageType != null) { |
282 typePackage = messageType.package; | 282 typePackage = messageType.package; |
283 baseType = messageType.classname; | 283 baseType = messageType.classname; |
284 typeString = write(baseType); | 284 typeString = write(baseType); |
285 prefixedBaseType = messageType.package + '.' + baseType; | 285 prefixedBaseType = messageType.packageImportPrefix + '.' + baseType; |
286 prefixedTypeString = write(prefixedBaseType); | 286 prefixedTypeString = write(prefixedBaseType); |
287 codedStreamType = 'Message'; | 287 codedStreamType = 'Message'; |
288 } else { | 288 } else { |
289 throw 'FAILURE: Unknown message type reference ${field.typeName}'; | 289 throw 'FAILURE: Unknown message type reference ${field.typeName}'; |
290 } | 290 } |
291 initialization = '()${SP}=>${SP}new ${baseType}()'; | 291 initialization = '()${SP}=>${SP}new ${baseType}()'; |
292 prefixedInitialization = '()${SP}=>${SP}new ${prefixedBaseType}()'; | 292 prefixedInitialization = '()${SP}=>${SP}new ${prefixedBaseType}()'; |
293 break; | 293 break; |
294 case FieldDescriptorProto_Type.TYPE_ENUM: | 294 case FieldDescriptorProto_Type.TYPE_ENUM: |
295 EnumGenerator enumType = context[field.typeName]; | 295 EnumGenerator enumType = context[field.typeName]; |
296 if (enumType != null) { | 296 if (enumType != null) { |
297 typePackage = enumType.package; | 297 typePackage = enumType.package; |
298 baseType = enumType.classname; | 298 baseType = enumType.classname; |
299 typeString = write(enumType.classname); | 299 typeString = write(enumType.classname); |
300 codedStreamType = 'Enum'; | 300 codedStreamType = 'Enum'; |
301 prefixedBaseType = enumType.package + '.' + baseType; | 301 prefixedBaseType = enumType.packageImportPrefix + '.' + baseType; |
302 prefixedTypeString = write(prefixedBaseType); | 302 prefixedTypeString = write(prefixedBaseType); |
303 packable = true; | 303 packable = true; |
304 if (!repeats) { | 304 if (!repeats) { |
305 if (field.hasDefaultValue() && !field.defaultValue.isEmpty) { | 305 if (field.hasDefaultValue() && !field.defaultValue.isEmpty) { |
306 initialization = | 306 initialization = |
307 '()${SP}=>${SP}${baseType}.${field.defaultValue}'; | 307 '()${SP}=>${SP}${baseType}.${field.defaultValue}'; |
308 prefixedInitialization = | 308 prefixedInitialization = |
309 '()${SP}=>${SP}${prefixedBaseType}.${field.defaultValue}'; | 309 '()${SP}=>${SP}${prefixedBaseType}.${field.defaultValue}'; |
310 } else if (!enumType._canonicalValues.isEmpty) { | 310 } else if (!enumType._canonicalValues.isEmpty) { |
311 initialization = | 311 initialization = |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 return 2; // Length-delimited | 385 return 2; // Length-delimited |
386 case FieldDescriptorProto_Type.TYPE_GROUP: | 386 case FieldDescriptorProto_Type.TYPE_GROUP: |
387 return 3; // Start group | 387 return 3; // Start group |
388 case FieldDescriptorProto_Type.TYPE_FLOAT: | 388 case FieldDescriptorProto_Type.TYPE_FLOAT: |
389 case FieldDescriptorProto_Type.TYPE_FIXED32: | 389 case FieldDescriptorProto_Type.TYPE_FIXED32: |
390 case FieldDescriptorProto_Type.TYPE_SFIXED32: | 390 case FieldDescriptorProto_Type.TYPE_SFIXED32: |
391 return 5; // 32-bit | 391 return 5; // 32-bit |
392 } | 392 } |
393 } | 393 } |
394 } | 394 } |
OLD | NEW |