| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import "dart:_internal" as internal; | 5 import "dart:_internal" as internal; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Returns a [MirrorSystem] for the current isolate. | 8 * Returns a [MirrorSystem] for the current isolate. |
| 9 */ | 9 */ |
| 10 patch MirrorSystem currentMirrorSystem() { | 10 @patch MirrorSystem currentMirrorSystem() { |
| 11 return _Mirrors.currentMirrorSystem(); | 11 return _Mirrors.currentMirrorSystem(); |
| 12 } | 12 } |
| 13 | 13 |
| 14 /** | 14 /** |
| 15 * Returns an [InstanceMirror] for some Dart language object. | 15 * Returns an [InstanceMirror] for some Dart language object. |
| 16 * | 16 * |
| 17 * This only works if this mirror system is associated with the | 17 * This only works if this mirror system is associated with the |
| 18 * current running isolate. | 18 * current running isolate. |
| 19 */ | 19 */ |
| 20 patch InstanceMirror reflect(Object reflectee) { | 20 @patch InstanceMirror reflect(Object reflectee) { |
| 21 return _Mirrors.reflect(reflectee); | 21 return _Mirrors.reflect(reflectee); |
| 22 } | 22 } |
| 23 | 23 |
| 24 /** | 24 /** |
| 25 * Returns a [ClassMirror] for the class represented by a Dart | 25 * Returns a [ClassMirror] for the class represented by a Dart |
| 26 * Type object. | 26 * Type object. |
| 27 * | 27 * |
| 28 * This only works with objects local to the current isolate. | 28 * This only works with objects local to the current isolate. |
| 29 */ | 29 */ |
| 30 patch ClassMirror reflectClass(Type key) { | 30 @patch ClassMirror reflectClass(Type key) { |
| 31 return _Mirrors.reflectClass(key); | 31 return _Mirrors.reflectClass(key); |
| 32 } | 32 } |
| 33 | 33 |
| 34 patch TypeMirror reflectType(Type key) { | 34 @patch TypeMirror reflectType(Type key) { |
| 35 return _Mirrors.reflectType(key); | 35 return _Mirrors.reflectType(key); |
| 36 } | 36 } |
| 37 | 37 |
| 38 patch class MirrorSystem { | 38 @patch class MirrorSystem { |
| 39 /* patch */ LibraryMirror findLibrary(Symbol libraryName) { | 39 /* @patch */ LibraryMirror findLibrary(Symbol libraryName) { |
| 40 var candidates = | 40 var candidates = |
| 41 libraries.values.where((lib) => lib.simpleName == libraryName); | 41 libraries.values.where((lib) => lib.simpleName == libraryName); |
| 42 if (candidates.length == 1) { | 42 if (candidates.length == 1) { |
| 43 return candidates.single; | 43 return candidates.single; |
| 44 } | 44 } |
| 45 if (candidates.length > 1) { | 45 if (candidates.length > 1) { |
| 46 var uris = candidates.map((lib) => lib.uri.toString()).toList(); | 46 var uris = candidates.map((lib) => lib.uri.toString()).toList(); |
| 47 throw new Exception("There are multiple libraries named " | 47 throw new Exception("There are multiple libraries named " |
| 48 "'${getName(libraryName)}': $uris"); | 48 "'${getName(libraryName)}': $uris"); |
| 49 } | 49 } |
| 50 throw new Exception("There is no library named '${getName(libraryName)}'"); | 50 throw new Exception("There is no library named '${getName(libraryName)}'"); |
| 51 } | 51 } |
| 52 | 52 |
| 53 /* patch */ static String getName(Symbol symbol) { | 53 /* @patch */ static String getName(Symbol symbol) { |
| 54 return internal.Symbol.getUnmangledName(symbol); | 54 return internal.Symbol.getUnmangledName(symbol); |
| 55 } | 55 } |
| 56 | 56 |
| 57 /* patch */ static Symbol getSymbol(String name, [LibraryMirror library]) { | 57 /* @patch */ static Symbol getSymbol(String name, [LibraryMirror library]) { |
| 58 if ((library != null && library is! _LocalLibraryMirror) || | 58 if ((library != null && library is! _LocalLibraryMirror) || |
| 59 ((name.length > 0) && (name[0] == '_') && (library == null))) { | 59 ((name.length > 0) && (name[0] == '_') && (library == null))) { |
| 60 throw new ArgumentError(library); | 60 throw new ArgumentError(library); |
| 61 } | 61 } |
| 62 if (library != null) name = _mangleName(name, library._reflectee); | 62 if (library != null) name = _mangleName(name, library._reflectee); |
| 63 return new internal.Symbol.unvalidated(name); | 63 return new internal.Symbol.unvalidated(name); |
| 64 } | 64 } |
| 65 | 65 |
| 66 static _mangleName(String name, _MirrorReference lib) | 66 static _mangleName(String name, _MirrorReference lib) |
| 67 native "Mirrors_mangleName"; | 67 native "Mirrors_mangleName"; |
| 68 } | 68 } |
| OLD | NEW |