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 ExtensionGenerator implements ProtobufContainer { | 7 class ExtensionGenerator implements ProtobufContainer { |
8 final String fqname; | 8 final String fqname; |
9 final FieldDescriptorProto _descriptor; | 9 final FieldDescriptorProto _descriptor; |
10 final ProtobufContainer _parent; | 10 final ProtobufContainer _parent; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 builder = ',${SP}()${SP}=>${SP}new ${typeName}()'; | 62 builder = ',${SP}()${SP}=>${SP}new ${typeName}()'; |
63 } | 63 } |
64 } else { | 64 } else { |
65 if (_descriptor.label == FieldDescriptorProto_Label.LABEL_REPEATED) { | 65 if (_descriptor.label == FieldDescriptorProto_Label.LABEL_REPEATED) { |
66 initializer = ',${SP}()${SP}=>${SP}new PbList<${baseType}>()'; | 66 initializer = ',${SP}()${SP}=>${SP}new PbList<${baseType}>()'; |
67 } else if (field.hasInitialization) { | 67 } else if (field.hasInitialization) { |
68 initializer = ',${SP}${field.initialization}'; | 68 initializer = ',${SP}${field.initialization}'; |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 if (field.enum) { | 72 if (field.enm) { |
73 if (initializer.isEmpty) { | 73 if (initializer.isEmpty) { |
74 initializer = ',${SP}null'; | 74 initializer = ',${SP}null'; |
75 } | 75 } |
76 if (builder.isEmpty) { | 76 if (builder.isEmpty) { |
77 builder = ',${SP}null'; | 77 builder = ',${SP}null'; |
78 } | 78 } |
79 valueOf = ',${SP}(var v)${SP}=>${SP}${field.baseType}.valueOf(v)'; | 79 valueOf = ',${SP}(var v)${SP}=>${SP}${field.baseType}.valueOf(v)'; |
80 } | 80 } |
81 | 81 |
82 out.println('static final Extension $name${SP}=${SP}' | 82 out.println('static final Extension $name${SP}=${SP}' |
83 'new Extension(\'$extendee\',${SP}\'$name\',${SP}' | 83 'new Extension(\'$extendee\',${SP}\'$name\',${SP}' |
84 '${_descriptor.number},${SP}GeneratedMessage.$type' | 84 '${_descriptor.number},${SP}GeneratedMessage.$type' |
85 '${initializer}${builder}${valueOf}' | 85 '${initializer}${builder}${valueOf}' |
86 ');'); | 86 ');'); |
87 } | 87 } |
88 | 88 |
89 String get name => classname; | 89 String get name => classname; |
90 } | 90 } |
OLD | NEW |