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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « CHANGELOG.md ('k') | lib/src/protobuf/coded_buffer_reader.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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',
+]);
« 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