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

Side by Side Diff: lib/src/protobuf/field_info.dart

Issue 814213003: Allow constants as field initial values as well as creation thunks (Closed) Base URL: https://github.com/dart-lang/dart-protobuf@master
Patch Set: Created 6 years 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/src/protobuf/extension.dart ('k') | lib/src/protobuf/generated_message.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 protobuf; 5 part of protobuf;
6 6
7 /** 7 /**
8 * An object representing a protobuf message field. 8 * An object representing a protobuf message field.
9 */ 9 */
10 class FieldInfo { 10 class FieldInfo {
11 final String name; 11 final String name;
12 final int tagNumber; 12 final int tagNumber;
13 final int type; 13 final int type;
14 final MakeDefaultFunc makeDefault; 14 final MakeDefaultFunc makeDefault;
15 final CreateBuilderFunc subBuilder; 15 final CreateBuilderFunc subBuilder;
16 final ValueOfFunc valueOf; 16 final ValueOfFunc valueOf;
17 17
18 FieldInfo(this.name, this.tagNumber, int type, 18 FieldInfo(this.name, this.tagNumber, int type,
19 [MakeDefaultFunc makeDefault, 19 [dynamic defaultOrMaker,
20 this.subBuilder, 20 this.subBuilder,
21 this.valueOf]) 21 this.valueOf])
22 : this.type = type, 22 : this.type = type,
23 this.makeDefault = makeDefault == null ? 23 this.makeDefault = findMakeDefault(type, defaultOrMaker);
24 GeneratedMessage._defaultForType(type) : makeDefault; 24
25 static MakeDefaultFunc findMakeDefault(int type, dynamic defaultOrMaker) {
26 if (defaultOrMaker == null) return GeneratedMessage._defaultForType(type);
27 if (defaultOrMaker is MakeDefaultFunc) return defaultOrMaker;
28 return () => defaultOrMaker;
29 }
25 30
26 String toString() => name; 31 String toString() => name;
27 } 32 }
OLDNEW
« no previous file with comments | « lib/src/protobuf/extension.dart ('k') | lib/src/protobuf/generated_message.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698