Reflectable class abstract
Reflectable is used as metadata, marking classes for reflection.
If a class has an instance of a subclass of this class in its
metadata
1 then it will be included in the root set of classes
with support for reflection based on this package. Other classes
outside the root set may also be included, e.g., if it is specified
that all subtypes of a given class in the root set are included.
For classes and instances not included, all reflective operations
will throw an exception. For included classes and instances,
invocations of the operations in mirrors.dart are supported if
the ReflectCapability values given as constructor arguments
include the capability to run those operations; the operations
will throw an exception if the relevant capability is not included.
Terminology: We use the term reflector class to denote a
direct subclass of Reflectable with a zero-argument const
constructor that is used as metadata on a class in the target
program in one of the two supported manners: as a const
constructor expression (@MyReflectable()
), or as an identifier
(@myReflectable
) which is a top-level const
whose value is
an instance of the given reflector class
(const myReflectable = const MyReflectable();
). We use the
term reflector-annotated class to denote a class whose
metadata includes an instance of a reflector class.
Note that the role played by this class includes much of the role played by a MirrorSystem with dart:mirrors.
Footnotes:
- Currently, the only setup which is supported is when
the metadata object is an instance of a direct subclass of the
class Reflectable, say
MyReflectable
, and that subclass defines aconst
constructor taking zero arguments. This ensures that every subclass of Reflectable used as metadata is a singleton class, 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.
- Implemented types
Constructors
- Reflectable([ReflectCapability? cap0, ReflectCapability? cap1, ReflectCapability? cap2, ReflectCapability? cap3, ReflectCapability? cap4, ReflectCapability? cap5, ReflectCapability? cap6, ReflectCapability? cap7, ReflectCapability? cap8, ReflectCapability? cap9])
-
Const constructor, to enable usage as metadata, allowing for varargs
style invocation with up to ten arguments.
const
-
Reflectable.fromList(List<
ReflectCapability> capabilities) -
const
Properties
-
annotatedClasses
→ Iterable<
ClassMirror> -
Returns an Iterable of all the classes that can be reflected over in
this Reflectable.
no setterinherited
-
capabilities
→ List<
ReflectCapability> -
Specifies limits on the support for reflective operations on instances
of classes having an instance of this ReflectableBase as metadata.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
-
libraries
→ Map<
Uri, LibraryMirror> -
Returns a map of all libraries in the current isolate.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
canReflect(
Object reflectee) → bool -
Returns true if this reflector has capabilities for the given instance.
inherited
-
canReflectType(
Type type) → bool -
Returns true if this reflector has capabilities for the given Type.
inherited
-
findLibrary(
String libraryName) → LibraryMirror -
Returns a mirror of the given library
library
.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
reflect(
Object reflectee) → InstanceMirror -
Returns a mirror of the given object
reflectee
.inherited -
reflectType(
Type type) → TypeMirror -
Returns a mirror of the given type
type
.inherited -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
getInstance(
Type type) → Reflectable? -
Returns the canonicalized instance of the given reflector
type
.
Constants
- thisClassId → const String
- thisClassName → const String