Index: lib/mixins_meta.dart |
diff --git a/lib/mixins_meta.dart b/lib/mixins_meta.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6284c169a1bbd367683b913f9078a94e3f4be8ca |
--- /dev/null |
+++ b/lib/mixins_meta.dart |
@@ -0,0 +1,84 @@ |
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+/// Provides metadata about mixins to dart-protoc-plugin. |
+/// (Experimental API; subject to change.) |
+library protobuf.mixins.meta; |
+ |
+/// Entry point called by dart-protoc-plugin. |
+PbMixin findMixin(String name) { |
+ for (var m in _exportedMixins) { |
+ if (m.name == name) { |
+ return m; |
+ } |
+ } |
+ return null; // not found |
+} |
+ |
+/// PbMixin contains the metadata needed by dart-protoc-plugin to apply a mixin. |
+/// |
+/// The mixin can be applied to a message using the options in dart_options.proto. |
Søren Gjesse
2015/06/23 06:49:56
Long line.
skybrian
2015/06/24 18:39:04
Done.
|
+/// Only one mixin can be applied to each message, but that mixin can depend on |
+/// another mixin, recursively, similar to single inheritance. |
+class PbMixin { |
+ |
+ /// 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.
|
+ final String name; |
+ |
+ /// The name of the file that the .pb.dart file should import the symbol from. |
+ final String importFrom; |
+ |
+ /// Another mixin to apply ahead of this one, or null for none. |
+ final PbMixin parent; |
+ |
+ /// Names that shouldn't be used by properties in the generated child class. |
+ /// May be null if the mixin doesn't reserve any new names. |
+ final List<String> reservedNames; |
+ |
+ const PbMixin._raw(this.name, |
+ {this.importFrom, this.parent, this.reservedNames}); |
+ |
+ /// Returns the mixin and its ancestors, in the order they should be applied. |
+ Iterable<PbMixin> findMixinsToApply() { |
+ var result = [this]; |
+ for (var p = parent; p != null; p = p.parent) { |
+ result.add(p); |
+ } |
+ return result.reversed; |
+ } |
+ |
+ /// Returns all the reserved names, including from ancestor mixins. |
+ Iterable<String> findReservedNames() { |
+ var names = new Set<String>(); |
+ for (var m = this; m != null; m = m.parent) { |
+ if (m.reservedNames != null) { |
+ names.addAll(m.reservedNames); |
+ } |
+ } |
+ return names; |
+ } |
+} |
+ |
+/// The mixins that findMixin() can return. |
+const _exportedMixins = const [_pbMapMixin]; |
+ |
+const _pbMapMixin = const PbMixin._raw("PbMapMixin", |
+ importFrom: "package:protobuf/src/protobuf/mixins/map_mixin.dart", |
+ parent: _mapMixin); |
+ |
+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
|
+ importFrom: "dart:collection", |
+ reservedNames: const [ |
+ 'addAll', |
+ 'containsKey', |
+ 'containsValue', |
+ 'forEach', |
+ 'putIfAbsent', |
+ 'remove', |
+ 'isEmpty', |
+ 'isNotEmpty', |
+ 'keys', |
+ 'length', |
+ 'values', |
+]); |