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

Side by Side Diff: reflectable/lib/reflectable.dart

Issue 1391543003: Creates `reflectors`, as a meta-meta feature that enables dynamic selection of a "mirror system". (Closed) Base URL: https://github.com/dart-lang/reflectable.git@master
Patch Set: Review response. Created 5 years, 2 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 | « no previous file | reflectable/lib/src/encoding_constants.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) 2015, the Dart Team. All rights reserved. Use of this 1 // Copyright (c) 2015, the Dart Team. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in 2 // source code is governed by a BSD-style license that can be found in
3 // the LICENSE file. 3 // the LICENSE file.
4 4
5 // This is the main library in package reflectable. 5 // This is the main library in package reflectable.
6 6
7 // TODO(eernst) doc: Write "library dartdoc" for this library. 7 // TODO(eernst) doc: Write "library dartdoc" for this library.
8 8
9 library reflectable.reflectable; 9 library reflectable.reflectable;
10 10
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 /// ----- 83 /// -----
84 /// **Footnotes:** 84 /// **Footnotes:**
85 /// 1. Currently, the only setup which is supported is when 85 /// 1. Currently, the only setup which is supported is when
86 /// the metadata object is an instance of a direct subclass of the 86 /// the metadata object is an instance of a direct subclass of the
87 /// class [Reflectable], say `MyReflectable`, and that subclass defines 87 /// class [Reflectable], say `MyReflectable`, and that subclass defines
88 /// a `const` constructor taking zero arguments. This ensures that 88 /// a `const` constructor taking zero arguments. This ensures that
89 /// every subclass of Reflectable used as metadata is a singleton class, 89 /// every subclass of Reflectable used as metadata is a singleton class,
90 /// which means that the behavior of the instance can be expressed by 90 /// which means that the behavior of the instance can be expressed by
91 /// generating code in the class. Generalizations of this setup may 91 /// generating code in the class. Generalizations of this setup may
92 /// be supported in the future if compelling use cases come up. 92 /// be supported in the future if compelling use cases come up.
93 class Reflectable extends implementation.ReflectableImpl 93 abstract class Reflectable extends implementation.ReflectableImpl
94 implements ReflectableInterface { 94 implements ReflectableInterface {
95 // Intended to near-uniquely identify this class in target programs. 95 // Intended to near-uniquely identify this class in target programs.
96 static const thisClassName = reflectable_class_constants.name; 96 static const thisClassName = reflectable_class_constants.name;
97 static const thisClassId = reflectable_class_constants.id; 97 static const thisClassId = reflectable_class_constants.id;
98 98
99 /// Const constructor, to enable usage as metadata, allowing for varargs 99 /// Const constructor, to enable usage as metadata, allowing for varargs
100 /// style invocation with up to ten arguments. 100 /// style invocation with up to ten arguments.
101 const Reflectable([ReflectCapability cap0 = null, 101 const Reflectable([ReflectCapability cap0 = null,
102 ReflectCapability cap1 = null, ReflectCapability cap2 = null, 102 ReflectCapability cap1 = null, ReflectCapability cap2 = null,
103 ReflectCapability cap3 = null, ReflectCapability cap4 = null, 103 ReflectCapability cap3 = null, ReflectCapability cap4 = null,
104 ReflectCapability cap5 = null, ReflectCapability cap6 = null, 104 ReflectCapability cap5 = null, ReflectCapability cap6 = null,
105 ReflectCapability cap7 = null, ReflectCapability cap8 = null, 105 ReflectCapability cap7 = null, ReflectCapability cap8 = null,
106 ReflectCapability cap9 = null]) 106 ReflectCapability cap9 = null])
107 : super(cap0, cap1, cap2, cap3, cap4, cap5, cap6, cap7, cap8, cap9); 107 : super(cap0, cap1, cap2, cap3, cap4, cap5, cap6, cap7, cap8, cap9);
108 108
109 const Reflectable.fromList(List<ReflectCapability> capabilities) 109 const Reflectable.fromList(List<ReflectCapability> capabilities)
110 : super.fromList(capabilities); 110 : super.fromList(capabilities);
111
112
113 /// Returns the canonicalized instance of the given reflector [type].
114 ///
115 /// If [type] is not a subclass of [Reflectable], or if it is such a class
116 /// but no entities are covered (that is, it is unused, so we don't have
117 /// any reflection data for it) then [null] is returned.
118 static Reflectable getInstance(Type type) {
119 for (Reflectable reflector in implementation.reflectors) {
120 if (reflector.runtimeType == type) return reflector;
121 }
122 return null;
123 }
111 } 124 }
112 125
113 /// Returns true if the transformed version is running, false otherwise. 126 /// Returns true if the transformed version is running, false otherwise.
114 bool get isTransformed => implementation.isTransformed; 127 bool get isTransformed => implementation.isTransformed;
OLDNEW
« no previous file with comments | « no previous file | reflectable/lib/src/encoding_constants.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698