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