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

Side by Side Diff: lib/mixins_meta.dart

Issue 1196773004: changes for 0.3.9 (Closed) Base URL: https://github.com/dart-lang/dart-protobuf.git@master
Patch Set: add mixins_meta, move PbMapMixin to separate library Created 5 years, 6 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 | « CHANGELOG.md ('k') | lib/src/protobuf/coded_buffer_reader.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
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.
4
5 /// Provides metadata about mixins to dart-protoc-plugin.
6 /// (Experimental API; subject to change.)
7 library protobuf.mixins.meta;
8
9 /// Entry point called by dart-protoc-plugin.
10 PbMixin findMixin(String name) {
11 for (var m in _exportedMixins) {
12 if (m.name == name) {
13 return m;
14 }
15 }
16 return null; // not found
17 }
18
19 /// PbMixin contains the metadata needed by dart-protoc-plugin to apply a mixin.
20 ///
21 /// The mixin can be applied to a message using the options in dart_options.prot o.
Søren Gjesse 2015/06/23 06:49:56 Long line.
skybrian 2015/06/24 18:39:04 Done.
22 /// Only one mixin can be applied to each message, but that mixin can depend on
23 /// another mixin, recursively, similar to single inheritance.
24 class PbMixin {
25
26 /// The Dart symbol to be imported into the .pb.dart file.
Søren Gjesse 2015/06/23 06:49:56 Maybe be more explicit in this comment that this i
skybrian 2015/06/24 18:39:04 Done.
27 final String name;
28
29 /// The name of the file that the .pb.dart file should import the symbol from.
30 final String importFrom;
31
32 /// Another mixin to apply ahead of this one, or null for none.
33 final PbMixin parent;
34
35 /// Names that shouldn't be used by properties in the generated child class.
36 /// May be null if the mixin doesn't reserve any new names.
37 final List<String> reservedNames;
38
39 const PbMixin._raw(this.name,
40 {this.importFrom, this.parent, this.reservedNames});
41
42 /// Returns the mixin and its ancestors, in the order they should be applied.
43 Iterable<PbMixin> findMixinsToApply() {
44 var result = [this];
45 for (var p = parent; p != null; p = p.parent) {
46 result.add(p);
47 }
48 return result.reversed;
49 }
50
51 /// Returns all the reserved names, including from ancestor mixins.
52 Iterable<String> findReservedNames() {
53 var names = new Set<String>();
54 for (var m = this; m != null; m = m.parent) {
55 if (m.reservedNames != null) {
56 names.addAll(m.reservedNames);
57 }
58 }
59 return names;
60 }
61 }
62
63 /// The mixins that findMixin() can return.
64 const _exportedMixins = const [_pbMapMixin];
65
66 const _pbMapMixin = const PbMixin._raw("PbMapMixin",
67 importFrom: "package:protobuf/src/protobuf/mixins/map_mixin.dart",
68 parent: _mapMixin);
69
70 const _mapMixin = const PbMixin._raw("MapMixin",
Søren Gjesse 2015/06/23 06:49:56 This mixin is in this registry because it is requi
skybrian 2015/06/24 18:39:03 I'm relying on _exportedMixins to indicate whether
71 importFrom: "dart:collection",
72 reservedNames: const [
73 'addAll',
74 'containsKey',
75 'containsValue',
76 'forEach',
77 'putIfAbsent',
78 'remove',
79 'isEmpty',
80 'isNotEmpty',
81 'keys',
82 'length',
83 'values',
84 ]);
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | lib/src/protobuf/coded_buffer_reader.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698