ClosureMirror abstract#
A ClosureMirror reflects a closure.
A ClosureMirror provides the ability to execute its reflectee and introspect its function.
Implemented types
Constructors#
ClosureMirror()#
Properties#
function no setter#
A mirror on the function associated with this closure.
The function associated with an implicit closure of a function is that function.
The function associated with an instance of a class that has a call
method is that call method.
A Dart implementation might choose to create a class for each closure
expression, in which case function would be the same as
type.declarations[#call]. But the Dart language model does not require
this. A more typical implementation involves a single closure class for
each type signature, where the call method dispatches to a function held
in the closure rather the call method
directly implementing the closure body. So one cannot rely on closures from
distinct closure expressions having distinct classes (type), but one
can rely on them having distinct functions (function).
Implementation
MethodMirror get function;
hashCode no setter inherited#
The hash code for this object.
A hash code is a single integer which represents the state of the object that affects operator == comparisons.
All objects have hash codes. The default hash code implemented by Object represents only the identity of the object, the same way as the default operator == implementation only considers objects equal if they are identical (see identityHashCode).
If operator == is overridden to use the object state instead, the hash code must also be changed to represent that state, otherwise the object cannot be used in hash based data structures like the default Set and Map implementations.
Hash codes must be the same for objects that are equal to each other according to operator ==. The hash code of an object should only change if the object changes in a way that affects equality. There are no further requirements for the hash codes. They need not be consistent between executions of the same program and there are no distribution guarantees.
Objects that are not equal are allowed to have the same hash code. It is even technically allowed that all instances have the same hash code, but if clashes happen too often, it may reduce the efficiency of hash-based data structures like HashSet or HashMap.
If a subclass overrides hashCode, it should override the operator == operator as well to maintain consistency.
Inherited from Object.
Implementation
external int get hashCode;
hasReflectee no setter inherited#
Whether reflectee will return 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:
Inherited from InstanceMirror.
Implementation
bool get hasReflectee;
reflectee no setter inherited#
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.
Inherited from InstanceMirror.
Implementation
dynamic get reflectee;
runtimeType no setter inherited#
A representation of the runtime type of the object.
Inherited from Object.
Implementation
external Type get runtimeType;
type no setter inherited#
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.
Inherited from InstanceMirror.
Implementation
ClassMirror get type;
Methods#
apply()#
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, the effect is the same as if a non-reflective compilation error had been encountered.
If the invocation throws an exception e (that it does not catch), this method throws e.
Implementation
InstanceMirror apply(
List<dynamic> positionalArguments, [
Map<Symbol, dynamic> namedArguments = const <Symbol, dynamic>{},
]);
delegate() inherited#
Performs invocation on the reflectee of this ObjectMirror.
Equivalent to
if (invocation.isGetter) {
return this.getField(invocation.memberName).reflectee;
} else if (invocation.isSetter) {
return this.setField(invocation.memberName,
invocation.positionalArguments[0]).reflectee;
} else {
return this.invoke(invocation.memberName,
invocation.positionalArguments,
invocation.namedArguments).reflectee;
}
Inherited from ObjectMirror.
Implementation
delegate(Invocation invocation);
getField() inherited#
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 this mirror is an InstanceMirror, and
fieldName denotes an instance
method on its reflectee, the result of the invocation is an instance
mirror on a closure corresponding to that method.
If this mirror is a LibraryMirror, and
fieldName denotes a top-level
method in the corresponding library, the result of the invocation is an
instance mirror on a closure corresponding to that method.
If this mirror is a ClassMirror, and
fieldName denotes a static method
in the corresponding class, the result of the invocation is an instance
mirror on a closure corresponding to that method.
If the invocation returns a result r, this method returns the result of calling reflect(r).
If the invocation causes a compilation error, the effect is the same as if a non-reflective compilation error had been encountered.
If the invocation throws an exception e (that it does not catch), this method throws e.
Inherited from ObjectMirror.
Implementation
// TODO(ahe): Remove stuff about scope and private members. [fieldName] is a
// capability giving access to private members.
InstanceMirror getField(Symbol fieldName);
invoke() inherited#
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 the effect is the same as if a non-reflective compilation error had been encountered.
If the invocation throws an exception e (that it does not catch), this method throws e.
Inherited from ObjectMirror.
Implementation
InstanceMirror invoke(
Symbol memberName,
List<dynamic> positionalArguments, [
Map<Symbol, dynamic> namedArguments = const <Symbol, dynamic>{},
]);
noSuchMethod() inherited#
Invoked when a nonexistent method or property is accessed.
A dynamic member invocation can attempt to call a member which doesn't exist on the receiving object. Example:
dynamic object = 1;
object.add(42); // Statically allowed, run-time error
This invalid code will invoke the noSuchMethod method
of the integer 1 with an Invocation
representing the
.add(42) call and arguments (which then throws).
Classes can override noSuchMethod to provide custom behavior for such invalid dynamic invocations.
A class with a non-default noSuchMethod invocation can also omit implementations for members of its interface. Example:
class MockList<T> implements List<T> {
noSuchMethod(Invocation invocation) {
log(invocation);
super.noSuchMethod(invocation); // Will throw.
}
}
void main() {
MockList().add(42);
}
This code has no compile-time warnings or errors even though
the MockList class has no concrete implementation of
any of the List interface methods.
Calls to List methods are forwarded to noSuchMethod,
so this code will log an invocation similar to
Invocation.method(#add, [42])
and then throw.
If a value is returned from noSuchMethod,
it becomes the result of the original invocation.
If the value is not of a type that can be returned by the original
invocation, a type error occurs at the invocation.
The default behavior is to throw a NoSuchMethodError.
Inherited from Object.
Implementation
@pragma("vm:entry-point")
@pragma("wasm:entry-point")
external dynamic noSuchMethod(Invocation invocation);
setField() inherited#
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, the effect is the same as if a non-reflective compilation error had been encountered.
If the invocation throws an exception e (that it does not catch) this method throws e.
Inherited from ObjectMirror.
Implementation
InstanceMirror setField(Symbol fieldName, dynamic value);
toString() inherited#
A string representation of this object.
Some classes have a default textual representation,
often paired with a static parse function (like int.parse).
These classes will provide the textual representation as
their string representation.
Other classes have no meaningful textual representation
that a program will care about.
Such classes will typically override toString to provide
useful information when inspecting the object,
mainly for debugging or logging.
Inherited from Object.
Implementation
external String toString();
Operators#
operator ==() inherited#
The equality operator.
The default behavior for all Objects is to return true if and
only if this object and other are the same object.
Override this method to specify a different equality relation on a class. The overriding method must still be an equivalence relation. That is, it must be:
Total: It must return a boolean for all arguments. It should never throw.
Reflexive: For all objects
o,o == omust be true.-
Symmetric: For all objects
o1ando2,o1 == o2ando2 == o1must either both be true, or both be false. -
Transitive: For all objects
o1,o2, ando3, ifo1 == o2ando2 == o3are true, theno1 == o3must be true.
The method should also be consistent over time, so whether two objects are equal should only change if at least one of the objects was modified.
If a subclass overrides the equality operator, it should override the hashCode method as well to maintain consistency.
Inherited from Object.
Implementation
external bool operator ==(Object other);