W3cubDocs

/Dart 2

MirrorsUsed class

Annotation describing how "dart:mirrors" is used (EXPERIMENTAL).

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')
import 'dart:mirrors';

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

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

For a detailed description of the parameters to the MirrorsUsed constructor see the comments for symbols, targets, metaTargets and override.

An import of dart:mirrors may have multiple MirrorsUsed annotations. This is particularly helpful to specify overrides for specific libraries. For example:

@MirrorsUsed(targets: 'foo.Bar', override: 'foo')
@MirrorsUsed(targets: 'Bar')
import 'dart:mirrors';

will ensure that the target Bar from the current library and from library foo is available for reflection. See also override.

Annotations
  • @Deprecated("No longer has any effect. Will be removed in a later release.")

Constructors

MirrorsUsed({dynamic symbols, dynamic targets, dynamic metaTargets, dynamic override })
const
See the documentation for MirrorsUsed.symbols, MirrorsUsed.targets, MirrorsUsed.metaTargets and MirrorsUsed.override for documentation of the parameters.

Properties

metaTargets → dynamic
final
A list of classes that when used as metadata indicates a reflective target. See also targets. [...]
override → dynamic
final
A list of library names or "*". [...]
symbols → dynamic
final
The list of strings passed to new Symbol, and symbols that might be passed to MirrorSystem.getName. [...]
targets → dynamic
final
A list of reflective targets. [...]
hashCodeint
read-only, inherited
The hash code for this object. [...]
runtimeTypeType
read-only, inherited
A representation of the runtime type of the object.

Methods

noSuchMethod(Invocation invocation) → dynamic
inherited
Invoked when a non-existent method or property is accessed. [...]
toString() → String
inherited
Returns a string representation of this object.

Operators

operator ==(dynamic other) → bool
inherited
The equality operator. [...]

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.5.0/dart-mirrors/MirrorsUsed-class.html