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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | reflectable/lib/src/encoding_constants.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: reflectable/lib/reflectable.dart
diff --git a/reflectable/lib/reflectable.dart b/reflectable/lib/reflectable.dart
index 5b8281293a5b07f386590ce1709bdea29817a48a..22bafaf207d4569c730f2119ad74431f02289ac3 100644
--- a/reflectable/lib/reflectable.dart
+++ b/reflectable/lib/reflectable.dart
@@ -90,7 +90,7 @@ abstract class ReflectableInterface {
/// which means that the behavior of the instance can be expressed by
/// generating code in the class. Generalizations of this setup may
/// be supported in the future if compelling use cases come up.
-class Reflectable extends implementation.ReflectableImpl
+abstract class Reflectable extends implementation.ReflectableImpl
implements ReflectableInterface {
// Intended to near-uniquely identify this class in target programs.
static const thisClassName = reflectable_class_constants.name;
@@ -108,6 +108,19 @@ class Reflectable extends implementation.ReflectableImpl
const Reflectable.fromList(List<ReflectCapability> capabilities)
: super.fromList(capabilities);
+
+
+ /// Returns the canonicalized instance of the given reflector [type].
+ ///
+ /// If [type] is not a subclass of [Reflectable], or if it is such a class
+ /// but no entities are covered (that is, it is unused, so we don't have
+ /// any reflection data for it) then [null] is returned.
+ static Reflectable getInstance(Type type) {
+ for (Reflectable reflector in implementation.reflectors) {
+ if (reflector.runtimeType == type) return reflector;
+ }
+ return null;
+ }
}
/// Returns true if the transformed version is running, false otherwise.
« 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