dart.mirrors


Functions
currentMirrorSystem(): MirrorSystem
mirrorSystemOf(SendPort port): Future<MirrorSystem>
reflect(Object reflectee): InstanceMirror
reflectClass(Type key): ClassMirror
Classes
ClassMirror
ClosureMirror
Comment
DeclarationMirror
FunctionTypeMirror
InstanceMirror
IsolateMirror
LibraryMirror
MethodMirror
Mirror
MirrorException
MirrorSystem
MirroredCompilationError
MirroredError
MirroredUncaughtExceptionError
MirrorsUsed
ObjectMirror
ParameterMirror
SourceLocation
TypeMirror
TypeVariableMirror
TypedefMirror
VariableMirror

Basic reflection in Dart, with support for introspection and dynamic evaluation.

Introspection is that subset of reflection by which a running program can examine its own structure. For example, a function that prints out the names of all the members of an arbitrary object.

Dynamic evaluation refers the ability to evaluate code that has not been literally specified at compile time, such as calling a method whose name is provided as an argument (because it is looked up in a database, or provided interactively by the user).

How to interpret this library's documentation

As a rule, the names of Dart declarations are represented using instances of class Symbol. Whenever the doc speaks of an object s of class Symbol denoting a name, it means the string that was used to construct s.

The documentation frequently abuses notation with Dart pseudo-code such as o.x(a), where o and a are defined to be objects; what is actually meant in these cases is o'.x(a') where o' and a' are Dart variables bound to o and a respectively. Furthermore, o' and a' are assumed to be fresh variables (meaning that they are distinct from any other variables in the program).

Sometimes the documentation refers to serializable objects. An object is serializable across isolates if and only if it is an instance of num, bool, String, a list of objects that are serializable across isolates, or a map with keys and values that are all serializable across isolates.

Functions

static MirrorSystem currentMirrorSystem()

Returns a MirrorSystem for the current isolate.

static Future<MirrorSystem> mirrorSystemOf(SendPort port)

Creates a MirrorSystem for the isolate which is listening on the SendPort.

static InstanceMirror reflect(Object reflectee)

Returns an InstanceMirror reflecting reflectee. If reflectee is function or an instance of a class that has a call method, the returned instance mirror will be a ClosureMirror.

Note that since one cannot obtain an object from another isolate, this function can only be used to obtain mirrors on objects of the current isolate.

static ClassMirror reflectClass(Type key)

Let C be the original class declaration of the class represented by key. This function returns a ClassMirror reflecting C.

If key is not an instance of Type then this function throws an ArgumentError. If key is the Type dynamic, throws an ArgumentError because dynamic is not a class.

Note that since one cannot obtain a Type object from another isolate, this function can only be used to obtain class mirrors on classes of the current isolate.


Abstract class ClassMirror implements TypeMirror, ObjectMirror

Fields
constructors: Map
getters: Map
hasReflectedType: bool
isOriginalDeclaration: bool
members: Map
methods: Map
originalDeclaration: ClassMirror
reflectedType: Type
setters: Map
superclass: ClassMirror
superinterfaces: List
typeArguments: List
typeVariables: List
variables: Map
Getters and Setters
constructors: Map<Symbol, MethodMirror>
getters: Map<Symbol, MethodMirror>
hasReflectedType: bool
isOriginalDeclaration: bool
members: Map<Symbol, Mirror>
methods: Map<Symbol, MethodMirror>
originalDeclaration: ClassMirror
reflectedType: Type
setters: Map<Symbol, MethodMirror>
superclass: ClassMirror
superinterfaces: List<ClassMirror>
typeArguments: List<TypeMirror>
typeVariables: List<TypeVariableMirror>
variables: Map<Symbol, VariableMirror>
Constructors
ClassMirror()
Methods
==(dynamic other): bool
newInstance(Symbol constructorName, List<dynamic> positionalArguments, Map<Symbol, dynamic> namedArguments): InstanceMirror
newInstanceAsync(Symbol constructorName, List<dynamic> positionalArguments, Map<Symbol, dynamic> namedArguments): Future<InstanceMirror>

A ClassMirror reflects a Dart language class.

Fields

final Map constructors
final Map getters
final bool hasReflectedType
final bool isOriginalDeclaration
final Map members
final Map methods
final ClassMirror originalDeclaration
final Type reflectedType
final Map setters
final ClassMirror superclass
final List superinterfaces
final List typeArguments
final List typeVariables
final Map variables

Getters and Setters

Map<Symbol, MethodMirror> get constructors

An immutable map from names to mirrors for all constructor declarations for this type.

Map<Symbol, MethodMirror> get getters

An immutable map from names to mirrors for all getter declarations for this type.

bool get hasReflectedType

Returns true if this mirror reflects a non-generic class or an instantiated generic class in the current isolate. Otherwise, returns false.

bool get isOriginalDeclaration

Is this the original declaration of this type?

For most classes, they are their own original declaration. For generic classes, however, there is a distinction between the original class declaration, which has unbound type variables, and the instantiations of generic classes, which have bound type variables.

Map<Symbol, Mirror> get members

An immutable map from from names to mirrors for all members of this type.

The members of a type are its methods, fields, getters, and setters. Note that constructors and type variables are not considered to be members of a type.

This does not include inherited members.

Map<Symbol, MethodMirror> get methods

An immutable map from names to mirrors for all method, declarations for this type. This does not include getters and setters.

ClassMirror get originalDeclaration

A mirror on the original declaration of this type.

For most classes, they are their own original declaration. For generic classes, however, there is a distinction between the original class declaration, which has unbound type variables, and the instantiations of generic classes, which have bound type variables.

Type get reflectedType

If hasReflectedType returns true, returns the corresponding Type. Otherwise, an UnsupportedError is thrown.

Map<Symbol, MethodMirror> get setters

An immutable map from names to mirrors for all setter declarations for this type.

ClassMirror get superclass

A mirror on the superclass on the reflectee.

If this type is Object or a typedef, the superClass will be null.

List<ClassMirror> get superinterfaces

A list of mirrors on the superinterfaces of the reflectee.

List<TypeMirror> get typeArguments

An immutable list with mirrors for all type arguments for this type.

If the the reflectee is an invocation of a generic class, the type arguments are the bindings of its type parameters. If the reflectee is the original declaration of a generic, it has no type arguments and this method returns an empty list. If the reflectee is a not generic, then it has no type arguments and this method returns an empty list.

This list preserves the order of declaration of the type variables.

List<TypeVariableMirror> get typeVariables

An immutable list with mirrors for all type variables for this type.

If this type is a generic declaration or an invocation of a generic declaration, the returned list contains mirrors on the type variables. Otherwise, the returned list is empty.

This list preserves the order of declaration of the type variables.

Map<Symbol, VariableMirror> get variables

An immutable map from names to mirrors for all variable declarations for this type.

Constructors

ClassMirror()

Methods

bool ==(dynamic other)

Returns true if this mirror is equal to other. Otherwise returns false.

The equality holds if and only if (1) other is a mirror of the same kind and (2) This mirror and other reflect the same class.

Note that if the reflected class is an invocation of a generic class,(2) implies that the reflected class and other have equal type arguments.

InstanceMirror newInstance(Symbol constructorName, List<dynamic> positionalArguments, Map<Symbol, dynamic> namedArguments)

Invokes the named constructor and returns a mirror on the result.

Let c be the class reflected by this mirror let a1, ..., an be the elements of positionalArguments let k1, ..., km be the identifiers denoted by the elements of namedArguments.keys and let v1, ..., vm be the elements of namedArguments.values. If constructorName was created from the empty string Then this method will execute the instance creation expression new c(a1, ..., an, k1: v1, ..., km: vm) in a scope that has access to the private members of c. Otherwise, let f be the simple name of the constructor denoted by constructorName Then this method will execute the instance creation expression new c.f(a1, ..., an, k1: v1, ..., km: vm) in a scope that has access to the private members of c. In either case: If the expression evaluates to a result r, this method returns the result of calling reflect(r). If evaluating the expression causes a compilation error this method throws a MirroredCompilationError. If evaluating the expression throws an exception e (that it does not catch) this method throws e.

Future<InstanceMirror> newInstanceAsync(Symbol constructorName, List<dynamic> positionalArguments, Map<Symbol, dynamic> namedArguments)

Invokes the named function and returns a mirror on the result. The arguments must be instances of InstanceMirror, or of a type that is serializable across isolates (currently num, String, or bool).

Let c be the class reflected by this mirror, let a1, ..., an be the elements of positionalArguments let k1, ..., km be the identifiers denoted by the elements of namedArguments.keys and let v1, ..., vm be the elements of namedArguments.values. For each ai, if ai is an instance of InstanceMirror, let pi be the object reflected by ai; otherwise let pi = ai, i in 1 ...n. Likewise, for each vj, if vj is an instance of InstanceMirror, let qj be the object reflected by vj; otherwise let qj = vj, j in 1 ...m. If any of the pi, qj is not an instance of InstanceMirror and is not serializable across isolates, an exception is thrown. If constructorName was created from the empty string Then this method will execute the instance creation expression new c(a1, ..., an, k1: v1, ..., km: vm) in a scope that has access to the private members of c. Otherwise, let f be the simple name of the constructor denoted by constructorName Then this method will execute the instance creation expression new c.f(a1, ..., an, k1: v1, ..., km: vm) in a scope that has access to the private members of c. In either case: The method returns a future k. If the invocation returns a result r, k will be completed with the result of calling reflect(r). If the invocation throws an exception e (that it does not catch) then k is completed with a MirrorError wrapping e.


Abstract class ClosureMirror implements InstanceMirror

Fields
function: MethodMirror
Getters and Setters
function: MethodMirror
Constructors
ClosureMirror()
Methods
apply(List<dynamic> positionalArguments, Map<Symbol, dynamic> namedArguments): InstanceMirror
applyAsync(List<dynamic> positionalArguments, Map<Symbol, dynamic> namedArguments): Future<InstanceMirror>
findInContext(Symbol name): Future<InstanceMirror>

A ClosureMirror reflects a closure.

A ClosureMirror provides access to its captured variables and provides the ability to execute its reflectee.

Fields

final MethodMirror function

Getters and Setters

MethodMirror get function

A mirror on the function associated with this closure.

Constructors

ClosureMirror()

Methods

InstanceMirror apply(List<dynamic> positionalArguments, Map<Symbol, dynamic> namedArguments)

Executes the closure and returns a mirror on the result. Let f be the closure reflected by this mirror, let a1, ..., an be the elements of positionalArguments let k1, ..., km be the identifiers denoted by the elements of namedArguments.keys and let v1, ..., vm be the elements of namedArguments.values. Then this method will perform the method invocation f(a1, ..., an, k1: v1, ..., km: vm) If the invocation returns a result r, this method returns the result of calling reflect(r). If the invocation causes a compilation error this method throws a MirrorError. If the invocation throws an exception e (that it does not catch) this method throws e.

Future<InstanceMirror> applyAsync(List<dynamic> positionalArguments, Map<Symbol, dynamic> namedArguments)

Executes the closure and returns a mirror on the result.

Let f be the closure reflected by this mirror, let a1, ..., an be the elements of positionalArguments let k1, ..., km be the identifiers denoted by the elements of namedArguments.keys and let v1, ..., vm be the elements of namedArguments.values. For each ai, if ai is an instance of InstanceMirror, let pi be the object reflected by ai; otherwise let pi = ai, i in 1 ...n. Likewise, for each vj, if vj is an instance of InstanceMirror, let qj be the object reflected by vj; otherwise let qj = vj, j in 1 ...m. If any of the pi, qj is not an instance of InstanceMirror and is not serializable across isolates, an exception is thrown. Then this method will perform the function invocation f(p1, ..., pn, k1: q1, ..., km: qm) The method returns a future k. If the invocation returns a result r, k will be completed with the result of calling reflect(r). If the invocation throws an exception e (that it does not catch) then k is completed with a MirrorError wrapping e.

The arguments must be instances of InstanceMirror, or of a type that is serializable across isolates (currently num, String, or bool).

Future<InstanceMirror> findInContext(Symbol name)

Looks up the value of a name in the scope of the closure. The result is a mirror on that value.

Let s be the contents of the string used to construct the symbol name.

If the expression s occurs within the source code of the reflectee, and that any such occurrence refers to a declaration outside the reflectee, then let v be the result of evaluating the expression s at such an occurrence. If s = this, and the reflectee was defined within the instance scope of an object o, then let v be o.

The returned value is the result of invoking the method reflect on v.


Class Comment

Fields
isDocComment: bool
text: String
trimmedText: String
Constructors
Comment(String text, String trimmedText, bool isDocComment)

Class used for encoding comments as metadata annotations.

Fields

final bool isDocComment

Is true if this comment is a documentation comment.

That is, that the comment is either enclosed in / ... */ or starts with /// .

final String text

The comment text as written in the source text.

final String trimmedText

The comment text without the start, end, and padding text.

For example, if text is / Comment text. */ then the trimmedText is Comment text. .

Constructors

Comment(String text, String trimmedText, bool isDocComment)

Abstract class DeclarationMirror implements Mirror

Fields
isPrivate: bool
isTopLevel: bool
location: SourceLocation
metadata: List
owner: DeclarationMirror
qualifiedName: Symbol
simpleName: Symbol
Getters and Setters
isPrivate: bool
isTopLevel: bool
location: SourceLocation
metadata: List<InstanceMirror>
owner: DeclarationMirror
qualifiedName: Symbol
simpleName: Symbol
Constructors
DeclarationMirror()

A DeclarationMirror reflects some entity declared in a Dart program.

Fields

final bool isPrivate
final bool isTopLevel
final SourceLocation location
final List metadata
final DeclarationMirror owner
final Symbol qualifiedName
final Symbol simpleName

Getters and Setters

bool get isPrivate

Returns true if this declaration is considered private according to the Dart language specification. Always returns false if this declaration is a library. Otherwise return false.

bool get isTopLevel

Is this declaration top-level?

This is defined to be equivalent to: mirror.owner != null && mirror.owner is LibraryMirror

SourceLocation get location

The source location of this Dart language entity.

List<InstanceMirror> get metadata

A list of the metadata associated with this declaration.

Let D be the declaration this mirror reflects. If D is decorated with annotations A1, ..., An where n > 0, then for each annotation Ai associated with D, 1 <= i <= n, let ci be the constant object specified by Ai. Then this method returns a list whose members are instance mirrors on c1, ..., cn. If no annotations are associated with D, then an empty list is returned.

DeclarationMirror get owner

A mirror on the owner of this Dart language entity. This is the declaration immediately surrounding the reflectee.

For a library, the owner is null. For a class declaration, typedef or top level function or variable, the owner is the enclosing library. For a mixin application S with M, the owner is the owner of M. For class Null, the owner is the dart:core library. For a constructor, the owner is the immediately enclosing class. For a method, instance variable or a static variable, the owner is the immediately enclosing class, unless the class is a mixin application S with M, in which case the owner is M. Note that M may be an invocation of a generic. For a parameter, local variable or local function the owner is the immediately enclosing function.

Symbol get qualifiedName

The fully-qualified name for this Dart language entity.

This name is qualified by the name of the owner. For instance, the qualified name of a method 'method' in class 'Class' in library 'library' is 'library.Class.method'.

Returns a Symbol constructed from a string representing the fully qualified name of the reflectee. Let o be the owner of this mirror, let r be the reflectee of this mirror, let p be the fully qualified name of the reflectee of o, and let s be the simple name of r computed by simpleName. The fully qualified name of r is the concatenation of p, '.', and s.

Because an isolate can contain more than one library with the same name (at different URIs), a fully-qualified name does not uniquely identify any language entity.

Symbol get simpleName

The simple name for this Dart language entity.

The simple name is in most cases the the identifier name of the entity, such as 'method' for a method void method() {...} or 'mylibrary' for a library 'mylibrary'; declaration.

Constructors

DeclarationMirror()

Abstract class FunctionTypeMirror implements ClassMirror

Fields
callMethod: MethodMirror
parameters: List
returnType: TypeMirror
Getters and Setters
callMethod: MethodMirror
parameters: List<ParameterMirror>
returnType: TypeMirror
Constructors
FunctionTypeMirror()

A FunctionTypeMirror represents the type of a function in the Dart language.

Fields

final MethodMirror callMethod
final List parameters
final TypeMirror returnType

Getters and Setters

MethodMirror get callMethod

A mirror on the call method for the reflectee.

List<ParameterMirror> get parameters

Returns a list of the parameter types of the reflectee.

TypeMirror get returnType

Returns the return type of the reflectee.

Constructors

FunctionTypeMirror()

Abstract class InstanceMirror implements ObjectMirror

Fields
hasReflectee: bool
reflectee: dynamic
type: ClassMirror
Getters and Setters
hasReflectee: bool
reflectee: dynamic
type: ClassMirror
Constructors
InstanceMirror()
Methods
==(dynamic other): bool
delegate(Invocation invocation): dynamic

An InstanceMirror reflects an instance of a Dart language object.

Fields

final bool hasReflectee
final dynamic reflectee
final ClassMirror type

Getters and Setters

bool get hasReflectee

Does reflectee contain the instance reflected by this mirror? This will always be true in the local case (reflecting instances in the same isolate), but only true in the remote case if this mirror reflects a simple value.

A value is simple if one of the following holds: - the value is null - the value is of type num - the value is of type bool - the value is of type String

dynamic get reflectee

If the InstanceMirror reflects an instance it is meaningful to have a local reference to, we provide access to the actual instance here.

If you access reflectee when hasReflectee is false, an exception is thrown.

ClassMirror get type

A mirror on the type of the reflectee.

Returns a mirror on the actual class of the reflectee. The class of the reflectee may differ from the object returned by invoking runtimeType on the reflectee.

Constructors

InstanceMirror()

Methods

bool ==(dynamic other)

Returns true if this mirror is equal to other. The equality holds if and only if (1) other is a mirror of the same kind and (2) either (a) hasReflectee is true and so is identical(reflectee, other.reflectee) or (b) the remote objects reflected by this mirror and by other are identical.

dynamic delegate(Invocation invocation)

Perform invocation on reflectee. Equivalent to

this.invoke(invocation.memberName,

        invocation.positionalArguments,
        invocation.namedArguments);


Abstract class IsolateMirror implements Mirror

Fields
debugName: String
isCurrent: bool
rootLibrary: LibraryMirror
Getters and Setters
debugName: String
isCurrent: bool
rootLibrary: LibraryMirror
Constructors
IsolateMirror()
Methods
==(dynamic other): bool

An IsolateMirror reflects an isolate.

Fields

final String debugName
final bool isCurrent
final LibraryMirror rootLibrary

Getters and Setters

String get debugName

Returns a unique name used to refer to an isolate in debugging messages.

bool get isCurrent

Returns true if and only if this mirror reflects the currently running isolate. Otherwise returns false.

LibraryMirror get rootLibrary

Returns a LibraryMirror on the root library for this isolate.

Constructors

IsolateMirror()

Methods

bool ==(dynamic other)

Returns true if this mirror is equal to other. Otherwise returns false. The equality holds if and only if (1) other is a mirror of the same kind and (2) the isolate being reflected by this mirror is the same isolate being reflected by other.


Abstract class LibraryMirror implements DeclarationMirror, ObjectMirror

Fields
classes: Map
functions: Map
getters: Map
members: Map
setters: Map
uri: Uri
variables: Map
Getters and Setters
classes: Map<Symbol, ClassMirror>
functions: Map<Symbol, MethodMirror>
getters: Map<Symbol, MethodMirror>
members: Map<Symbol, Mirror>
setters: Map<Symbol, MethodMirror>
uri: Uri
variables: Map<Symbol, VariableMirror>
Constructors
LibraryMirror()
Methods
==(dynamic other): bool

A LibraryMirror reflects a Dart language library, providing access to the variables, functions, and classes of the library.

Fields

final Map classes
final Map functions
final Map getters
final Map members
final Map setters
final Uri uri
final Map variables

Getters and Setters

Map<Symbol, ClassMirror> get classes

An immutable map from names to mirrors for all class declarations in this library.

Map<Symbol, MethodMirror> get functions

An immutable map from names to mirrors for all function, getter, and setter declarations in this library.

Map<Symbol, MethodMirror> get getters

An immutable map from names to mirrors for all getter declarations in this library.

Map<Symbol, Mirror> get members

An immutable map from from names to mirrors for all members in this library.

The members of a library are its top-level classes, functions, variables, getters, and setters.

Map<Symbol, MethodMirror> get setters

An immutable map from names to mirrors for all setter declarations in this library.

Uri get uri

The absolute uri of the library.

Map<Symbol, VariableMirror> get variables

An immutable map from names to mirrors for all variable declarations in this library.

Constructors

LibraryMirror()

Methods

bool ==(dynamic other)

Returns true if this mirror is equal to other. Otherwise returns false.

The equality holds if and only if (1) other is a mirror of the same kind and (2) The library being reflected by this mirror and the library being reflected by other are the same library in the same isolate.


Abstract class MethodMirror implements DeclarationMirror

Fields
constructorName: Symbol
isAbstract: bool
isConstConstructor: bool
isConstructor: bool
isFactoryConstructor: bool
isGenerativeConstructor: bool
isGetter: bool
isOperator: bool
isRedirectingConstructor: bool
isRegularMethod: bool
isSetter: bool
isStatic: bool
parameters: List
returnType: TypeMirror
source: String
Getters and Setters
constructorName: Symbol
isAbstract: bool
isConstConstructor: bool
isConstructor: bool
isFactoryConstructor: bool
isGenerativeConstructor: bool
isGetter: bool
isOperator: bool
isRedirectingConstructor: bool
isRegularMethod: bool
isSetter: bool
isStatic: bool
parameters: List<ParameterMirror>
returnType: TypeMirror
source: String
Constructors
MethodMirror()
Methods
==(dynamic other): bool

A MethodMirror reflects a Dart language function, method, constructor, getter, or setter.

Fields

final Symbol constructorName
final bool isAbstract
final bool isConstConstructor
final bool isConstructor
final bool isFactoryConstructor
final bool isGenerativeConstructor
final bool isGetter
final bool isOperator
final bool isRedirectingConstructor
final bool isRegularMethod
final bool isSetter
final bool isStatic
final List parameters
final TypeMirror returnType
final String source

Getters and Setters

Symbol get constructorName

The constructor name for named constructors and factory methods.

For unnamed constructors, this is the empty string. For non-constructors, this is the empty string.

For example, 'bar' is the constructor name for constructor Foo.bar of type Foo.

bool get isAbstract

Is the reflectee abstract?

bool get isConstConstructor

Is the reflectee a const constructor?

bool get isConstructor

Is the reflectee a constructor?

bool get isFactoryConstructor

Is the reflectee a factory constructor?

bool get isGenerativeConstructor

Is the reflectee a generative constructor?

bool get isGetter

Is the reflectee a getter?

bool get isOperator

Is the reflectee an operator?

bool get isRedirectingConstructor

Is the reflectee a redirecting constructor?

bool get isRegularMethod

Is the reflectee a regular function or method?

A function or method is regular if it is not a getter, setter, or constructor. Note that operators, by this definition, are regular methods.

bool get isSetter

Is the reflectee a setter?

bool get isStatic

Is the reflectee static?

For the purposes of the mirrors library, a top-level function is considered static.

List<ParameterMirror> get parameters

A list of mirrors on the parameters for the reflectee.

TypeMirror get returnType

A mirror on the return type for the reflectee.

String get source

The source code for the reflectee, if available. Otherwise null.

Constructors

MethodMirror()

Methods

bool ==(dynamic other)

Returns true if this mirror is equal to other.

The equality holds if and only if (1) other is a mirror of the same kind and (2) simpleName == other.simpleName and owner == other.owner.


Abstract class Mirror

Fields
mirrors: MirrorSystem
Getters and Setters
mirrors: MirrorSystem
Constructors
Mirror()

A Mirror reflects some Dart language entity.

Every Mirror originates from some MirrorSystem.

Fields

final MirrorSystem mirrors

Getters and Setters

MirrorSystem get mirrors

The MirrorSystem that contains this mirror.

Constructors

Mirror()

Class MirrorException implements Exception

Constructors
MirrorException(String _message)
Methods
toString(): String

A MirrorException is used to indicate errors within the mirrors framework.

Constructors

MirrorException(String _message)

Methods

String toString()

Returns a string representation of this object.


Abstract class MirrorSystem

Fields
dynamicType: TypeMirror
isolate: IsolateMirror
libraries: Map
voidType: TypeMirror
Getters and Setters
dynamicType: TypeMirror
isolate: IsolateMirror
libraries: Map<Uri, LibraryMirror>
voidType: TypeMirror
Constructors
MirrorSystem()
Methods
findLibrary(Symbol libraryName): Iterable<LibraryMirror>
getName(Symbol symbol): String

A MirrorSystem is the main interface used to reflect on a set of associated libraries.

At runtime each running isolate has a distinct MirrorSystem.

It is also possible to have a MirrorSystem which represents a set of libraries which are not running -- perhaps at compile-time. In this case, all available reflective functionality would be supported, but runtime functionality (such as invoking a function or inspecting the contents of a variable) would fail dynamically.

Fields

final TypeMirror dynamicType
final IsolateMirror isolate
final Map libraries
final TypeMirror voidType

Getters and Setters

TypeMirror get dynamicType

A mirror on the dynamic type.

IsolateMirror get isolate

A mirror on the isolate associated with this MirrorSystem. This may be null if this mirror system is not running.

Map<Uri, LibraryMirror> get libraries

An immutable map from from library names to mirrors for all libraries known to this mirror system.

TypeMirror get voidType

A mirror on the void type.

Constructors

MirrorSystem()

Methods

Iterable<LibraryMirror> findLibrary(Symbol libraryName)

Returns an iterable of all libraries in the mirror system whose library name is libraryName.

static String getName(Symbol symbol)

Returns the name of symbol.

The following text is non-normative:

Using this method may result in larger output. If possible, use MirrorsUsed to specify which symbols must be retained in clear text.


Class MirroredCompilationError extends MirroredError

Fields
message: String
Constructors
MirroredCompilationError(String message)
Methods
toString(): String

When a compile-time error occurs during the mirrored execution of code, a MirroredCompilationError is thrown.

This exception includes the compile-time error message that would have been displayed to the user, if the function had not been invoked via mirror.

Fields

final String message

Constructors

MirroredCompilationError(String message)

Methods

String toString()

Returns a string representation of this object.


Abstract class MirroredError implements Exception

Constructors
MirroredError()

When an error occurs during the mirrored execution of code, a MirroredError is thrown.

In general, there are three main classes of failure that can happen during mirrored execution of code in some isolate:

- An exception is thrown but not caught. This is caught by the mirrors framework and a MirroredUncaughtExceptionError is created and thrown.

- A compile-time error occurs, such as a syntax error. This is suppressed by the mirrors framework and a MirroredCompilationError is created and thrown.

- A truly fatal error occurs, causing the isolate to be exited. If the reflector and reflectee share the same isolate, then they will both suffer. If the reflector and reflectee are in distinct isolates, then we hope to provide some information about the isolate death, but this has yet to be implemented.

TODO(turnidge): Specify the behavior for remote fatal errors.

Constructors

MirroredError()

Class MirroredUncaughtExceptionError extends MirroredError

Fields
exception_mirror: InstanceMirror
exception_string: String
stacktrace: Object
Constructors
MirroredUncaughtExceptionError(InstanceMirror exception_mirror, String exception_string, Object stacktrace)
Methods
toString(): String

When an uncaught exception occurs during the mirrored execution of code, a MirroredUncaughtExceptionError is thrown.

This exception contains a mirror on the original exception object. It also contains an object which can be used to recover the stacktrace.

Fields

final InstanceMirror exception_mirror

A mirror on the exception object.

final String exception_string

The result of toString() for the exception object.

final Object stacktrace

A stacktrace object for the uncaught exception.

Constructors

MirroredUncaughtExceptionError(InstanceMirror exception_mirror, String exception_string, Object stacktrace)

Methods

String toString()

Returns a string representation of this object.


Class MirrorsUsed

Fields
metaTargets: dynamic
override: dynamic
symbols: dynamic
targets: dynamic
Constructors
MirrorsUsed(dynamic symbols, dynamic targets, dynamic metaTargets, dynamic override)

EXPERIMENTAL API: Description of how "dart:mirrors" is used.

When used as metadata on an import of "dart:mirrors" in library L, this class describes how "dart:mirrors" is used by library L unless overridden. See override.

The following text is non-normative:

In some scenarios, for example, when minifying Dart code, or when generating JavaScript code from a Dart program, the size and performance of the output can suffer from use of reflection. In those cases, telling the compiler what is used, can have a significant impact.

Example usage:

@MirrorsUsed(symbols: 'foo', override: '*')
import 'dart:mirrors';

class Foo {
  noSuchMethod(Invocation invocation) {
    print(Mirrors.getName(invocation.memberName));
  }
}

main() {
  new Foo().foo(); // Prints "foo".
  new Foo().bar(); // Might print an arbitrary (mangled) name, "bar".
}

Fields

final dynamic metaTargets

A list of classes that when used as metadata indicates a reflective target.

See targets.

final dynamic override

A list of library names or "*".

When used as metadata on an import of "dart:mirrors", this metadata does not apply to the library in which the annotation is used, but instead applies to the other libraries (all libraries if "*" is used).

final dynamic symbols

The list of strings passed to new Symbol, and symbols that might be passed to MirrorSystem.getName.

Combined with the names of targets, metaTargets and their members, this forms the complete list of strings passed to new Symbol, and symbols that might be passed to MirrorSystem.getName by the library to which this metadata applies.

The following text is non-normative:

Specifying this option turns off the following warnings emitted by dart2js:

  • Using "MirrorSystem.getName" may result in larger output.
  • Using "new #{name}" may result in larger output.

Use symbols = "*" to turn off the warnings mentioned above.

For example, if using noSuchMethod to interact with a database, extract all the possible column names and include them in this list. Similarly, if using noSuchMethod to interact with another language (JavaScript, for example) extract all the identifiers from API used and include them in this list.

final dynamic targets

A list of reflective targets.

Combined with metaTargets, this provides the complete list of reflective targets used by the library to which this metadata applies.

The following text is non-normative:

For now, there is no formal description of what a reflective target is. Informally, it is a list of things that are expected to have fully functional mirrors.

Constructors

MirrorsUsed(dynamic symbols, dynamic targets, dynamic metaTargets, dynamic override)

Abstract class ObjectMirror implements Mirror

Constructors
ObjectMirror()
Methods
getField(Symbol fieldName): InstanceMirror
getFieldAsync(Symbol fieldName): Future<InstanceMirror>
invoke(Symbol memberName, List<dynamic> positionalArguments, Map<Symbol, dynamic> namedArguments): InstanceMirror
invokeAsync(Symbol memberName, List<dynamic> positionalArguments, Map<Symbol, dynamic> namedArguments): Future<InstanceMirror>
setField(Symbol fieldName, Object value): InstanceMirror
setFieldAsync(Symbol fieldName, Object value): Future<InstanceMirror>

An ObjectMirror is a common superinterface of InstanceMirror, ClassMirror, and LibraryMirror that represents their shared functionality.

For the purposes of the mirrors library, these types are all object-like, in that they support method invocation and field access. Real Dart objects are represented by the InstanceMirror type.

See InstanceMirror, ClassMirror, and LibraryMirror.

Constructors

ObjectMirror()

Methods

InstanceMirror getField(Symbol fieldName)

Invokes a getter and returns a mirror on the result. The getter can be the implicit getter for a field or a user-defined getter method.

Let o be the object reflected by this mirror, let f be the simple name of the getter denoted by fieldName, Then this method will perform the getter invocation o.f in a scope that has access to the private members of o (if o is a class or library) or the private members of the class of o (otherwise). If the invocation returns a result r, this method returns the result of calling reflect(r). If the invocation causes a compilation error this method throws a MirroredCompilationError. If the invocation throws an exception e (that it does not catch) this method throws e.

Future<InstanceMirror> getFieldAsync(Symbol fieldName)

Invokes a getter and returns a mirror on the result. The getter can be the implicit getter for a field or a user-defined getter method.

Let o be the object reflected by this mirror, let f be the simple name of the getter denoted by fieldName, Then this method will perform the getter invocation o.f in a scope that has access to the private members of o (if o is a class or library) or the private members of the class of o(otherwise). The method returns a future k. If the invocation returns a result r, k will be completed with the result of calling reflect(r). If the invocation throws an exception e (that it does not catch) then k is completed with a MirrorError wrapping e.

InstanceMirror invoke(Symbol memberName, List<dynamic> positionalArguments, Map<Symbol, dynamic> namedArguments)

Invokes the named function and returns a mirror on the result.

Let o be the object reflected by this mirror, let f be the simple name of the member denoted by memberName, let a1, ..., an be the elements of positionalArguments let k1, ..., km be the identifiers denoted by the elements of namedArguments.keys and let v1, ..., vm be the elements of namedArguments.values. Then this method will perform the method invocation o.f(a1, ..., an, k1: v1, ..., km: vm) in a scope that has access to the private members of o (if o is a class or library) or the private members of the class of o (otherwise). If the invocation returns a result r, this method returns the result of calling reflect(r). If the invocation causes a compilation error this method throws a MirroredCompilationError. If the invocation throws an exception e (that it does not catch) this method throws e.

Future<InstanceMirror> invokeAsync(Symbol memberName, List<dynamic> positionalArguments, Map<Symbol, dynamic> namedArguments)

Invokes the named function and returns a mirror on the result. The arguments must be instances of InstanceMirror, or of a type that is serializable across isolates (currently num, String, or bool).

Let o be the object reflected by this mirror, let f be the simple name of the member denoted by memberName, let a1, ..., an be the elements of positionalArguments let k1, ..., km be the identifiers denoted by the elements of namedArguments.keys and let v1, ..., vm be the elements of namedArguments.values. For each ai, if ai is an instance of InstanceMirror, let pi be the object reflected by ai; otherwise let pi = ai, i in 1 ...n. Likewise, for each vj, if vj is an instance of InstanceMirror, let qj be the object reflected by vj; otherwise let qj = vj, j in 1 ...m. If any of the pi, qj is not an instance of InstanceMirror and is not serializable across isolates, an exception is thrown. Then this method will perform the method invocation o.f(p1, ..., pn, k1: q1, ..., km: qm) in a scope that has access to the private members of o (if o is a class or library) or the private members of the class of o(otherwise). The method returns a future k. If the invocation returns a result r, k will be completed with the result of calling reflect(r). If the invocation throws an exception e (that it does not catch) then k is completed with a MirrorError wrapping e.

InstanceMirror setField(Symbol fieldName, Object value)

Invokes a setter and returns a mirror on the result. The setter may be either the implicit setter for a non-final field or a user-defined setter method.

Let o be the object reflected by this mirror, let f be the simple name of the getter denoted by fieldName, and let a be the object bound to value. Then this method will perform the setter invocation o.f = a in a scope that has access to the private members of o (if o is a class or library) or the private members of the class of o (otherwise). If the invocation returns a result r, this method returns the result of calling reflect(value). If the invocation causes a compilation error this method throws a MirroredCompilationError. If the invocation throws an exception e (that it does not catch) this method throws e.

Future<InstanceMirror> setFieldAsync(Symbol fieldName, Object value)

Invokes a setter and returns a mirror on the result. The setter may be either the implicit setter for a non-final field or a user-defined setter method. The second argument must be an instance of InstanceMirror, or of a type that is serializable across isolates (currently num, String, or bool).

Let o be the object reflected by this mirror, let f be the simple name of the getter denoted by fieldName, and let a be the object bound to value. If a is an instance of InstanceMirror let p be the object reflected by a, otherwise let p =a. If p is not an instance of InstanceMirror, p must be serializable across isolates or an exception is thrown. Then this method will perform the setter invocation o.f = a in a scope that has access to the private members of o (if o is a class or library) or the private members of the class of o(otherwise). The method returns a future k. If the invocation returns a result r, k will be completed with the result of calling reflect(r). If the invocation throws an exception e (that it does not catch) then k is completed with a [MirrorError} wrapping e.


Abstract class ParameterMirror implements VariableMirror

Fields
defaultValue: InstanceMirror
hasDefaultValue: bool
isNamed: bool
isOptional: bool
type: TypeMirror
Getters and Setters
defaultValue: InstanceMirror
hasDefaultValue: bool
isNamed: bool
isOptional: bool
type: TypeMirror
Constructors
ParameterMirror()

A ParameterMirror reflects a Dart formal parameter declaration.

Fields

final InstanceMirror defaultValue
final bool hasDefaultValue
final bool isNamed
final bool isOptional
final TypeMirror type

Getters and Setters

InstanceMirror get defaultValue

If this is a required parameter, returns null. Otherwise returns a mirror on the default value for this parameter. If no default is declared for an optional parameter, the default is null and a mirror on null is returned.

bool get hasDefaultValue

Returns true if the reflectee has explicitly declared a default value. Otherwise returns false.

bool get isNamed

Returns true if the reflectee is a named parameter. Otherwise returns false.

bool get isOptional

Returns true if the reflectee is an optional parameter. Otherwise returns false.

TypeMirror get type

A mirror on the type of this parameter.

Constructors

ParameterMirror()

Abstract class SourceLocation

Constructors
SourceLocation()

A SourceLocation describes the span of an entity in Dart source code.

Constructors

SourceLocation()

Abstract class TypeMirror implements DeclarationMirror

Constructors
TypeMirror()

A TypeMirror reflects a Dart language class, typedef, or type variable.

Constructors

TypeMirror()

Abstract class TypeVariableMirror extends TypeMirror

Fields
upperBound: TypeMirror
Getters and Setters
upperBound: TypeMirror
Constructors
TypeVariableMirror()
Methods
==(dynamic other): bool

A TypeVariableMirror represents a type parameter of a generic type.

Fields

final TypeMirror upperBound

Getters and Setters

TypeMirror get upperBound

A mirror on the type that is the upper bound of this type variable.

Constructors

TypeVariableMirror()

Methods

bool ==(dynamic other)

Returns true if this mirror is equal to other. Otherwise returns false.

The equality holds if and only if (1) other is a mirror of the same kind and (2) simpleName == other.simpleName and owner == other.owner.


Abstract class TypedefMirror implements ClassMirror

Fields
value: TypeMirror
Getters and Setters
value: TypeMirror
Constructors
TypedefMirror()

A TypedefMirror represents a typedef in a Dart language program.

Fields

final TypeMirror value

Getters and Setters

TypeMirror get value

The defining type for this typedef.

For instance void f(int) is the value for typedef void f(int).

Constructors

TypedefMirror()

Abstract class VariableMirror implements DeclarationMirror

Fields
isFinal: bool
isStatic: bool
type: TypeMirror
Getters and Setters
isFinal: bool
isStatic: bool
type: TypeMirror
Constructors
VariableMirror()
Methods
==(dynamic other): bool

A VariableMirror reflects a Dart language variable declaration.

Fields

final bool isFinal
final bool isStatic
final TypeMirror type

Getters and Setters

bool get isFinal

Returns true if the reflectee is a final variable. Otherwise returns false.

bool get isStatic

Returns true if the reflectee is a static variable. Otherwise returns false.

For the purposes of the mirror library, top-level variables are implicitly declared static.

TypeMirror get type

Returns a mirror on the type of the reflectee.

Constructors

VariableMirror()

Methods

bool ==(dynamic other)

Returns true if this mirror is equal to other.

The equality holds if and only if (1) other is a mirror of the same kind and (2) simpleName == other.simpleName and owner == other.owner.