2012-12-19 12:45:46 +00:00
|
|
|
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
2015-04-24 17:49:58 +00:00
|
|
|
import "dart:_internal" as internal;
|
2013-02-25 23:25:29 +00:00
|
|
|
|
2012-12-19 12:45:46 +00:00
|
|
|
/**
|
|
|
|
* Returns a [MirrorSystem] for the current isolate.
|
|
|
|
*/
|
|
|
|
patch MirrorSystem currentMirrorSystem() {
|
|
|
|
return _Mirrors.currentMirrorSystem();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an [InstanceMirror] for some Dart language object.
|
|
|
|
*
|
|
|
|
* This only works if this mirror system is associated with the
|
|
|
|
* current running isolate.
|
|
|
|
*/
|
|
|
|
patch InstanceMirror reflect(Object reflectee) {
|
|
|
|
return _Mirrors.reflect(reflectee);
|
|
|
|
}
|
2013-04-15 15:00:45 +00:00
|
|
|
|
2013-04-17 10:11:21 +00:00
|
|
|
/**
|
|
|
|
* Returns a [ClassMirror] for the class represented by a Dart
|
|
|
|
* Type object.
|
|
|
|
*
|
|
|
|
* This only works with objects local to the current isolate.
|
|
|
|
*/
|
|
|
|
patch ClassMirror reflectClass(Type key) {
|
|
|
|
return _Mirrors.reflectClass(key);
|
|
|
|
}
|
|
|
|
|
2013-10-18 16:59:55 +00:00
|
|
|
patch TypeMirror reflectType(Type key) {
|
|
|
|
return _Mirrors.reflectType(key);
|
|
|
|
}
|
|
|
|
|
2013-04-15 15:00:45 +00:00
|
|
|
patch class MirrorSystem {
|
2014-05-13 17:20:08 +00:00
|
|
|
/* patch */ LibraryMirror findLibrary(Symbol libraryName) {
|
|
|
|
var candidates =
|
|
|
|
libraries.values.where((lib) => lib.simpleName == libraryName);
|
|
|
|
if (candidates.length == 1) {
|
|
|
|
return candidates.single;
|
|
|
|
}
|
|
|
|
if (candidates.length > 1) {
|
|
|
|
var uris = candidates.map((lib) => lib.uri.toString()).toList();
|
|
|
|
throw new Exception("There are multiple libraries named "
|
|
|
|
"'${getName(libraryName)}': $uris");
|
|
|
|
}
|
|
|
|
throw new Exception("There is no library named '${getName(libraryName)}'");
|
|
|
|
}
|
|
|
|
|
2013-04-15 15:00:45 +00:00
|
|
|
/* patch */ static String getName(Symbol symbol) {
|
2015-04-24 17:49:58 +00:00
|
|
|
return internal.Symbol.getUnmangledName(symbol);
|
2013-04-15 15:00:45 +00:00
|
|
|
}
|
2013-11-11 23:08:38 +00:00
|
|
|
|
2013-10-11 20:56:14 +00:00
|
|
|
/* patch */ static Symbol getSymbol(String name, [LibraryMirror library]) {
|
2013-11-20 01:33:24 +00:00
|
|
|
if ((library != null && library is! _LocalLibraryMirror) ||
|
2013-11-11 23:08:38 +00:00
|
|
|
((name.length > 0) && (name[0] == '_') && (library == null))) {
|
2013-10-11 20:56:14 +00:00
|
|
|
throw new ArgumentError(library);
|
|
|
|
}
|
|
|
|
if (library != null) name = _mangleName(name, library._reflectee);
|
2015-04-24 17:49:58 +00:00
|
|
|
return new internal.Symbol.unvalidated(name);
|
2013-10-11 20:56:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static _mangleName(String name, _MirrorReference lib)
|
|
|
|
native "Mirrors_mangleName";
|
2013-04-15 15:00:45 +00:00
|
|
|
}
|