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:async" show Future; | 5 import "dart:async" show Future; |
6 import "dart:collection" show UnmodifiableListView, UnmodifiableMapView; | 6 import "dart:collection" show UnmodifiableListView, UnmodifiableMapView; |
7 import "dart:_internal" as internal; | 7 import "dart:_internal" as internal; |
8 | 8 |
9 /** | 9 /** |
10 * Returns a [MirrorSystem] for the current isolate. | 10 * Returns a [MirrorSystem] for the current isolate. |
11 */ | 11 */ |
12 @patch | 12 @patch MirrorSystem currentMirrorSystem() { |
13 MirrorSystem currentMirrorSystem() { | |
14 return _Mirrors.currentMirrorSystem(); | 13 return _Mirrors.currentMirrorSystem(); |
15 } | 14 } |
16 | 15 |
17 /** | 16 /** |
18 * Returns an [InstanceMirror] for some Dart language object. | 17 * Returns an [InstanceMirror] for some Dart language object. |
19 * | 18 * |
20 * This only works if this mirror system is associated with the | 19 * This only works if this mirror system is associated with the |
21 * current running isolate. | 20 * current running isolate. |
22 */ | 21 */ |
23 @patch | 22 @patch InstanceMirror reflect(Object reflectee) { |
24 InstanceMirror reflect(Object reflectee) { | |
25 return _Mirrors.reflect(reflectee); | 23 return _Mirrors.reflect(reflectee); |
26 } | 24 } |
27 | 25 |
28 /** | 26 /** |
29 * Returns a [ClassMirror] for the class represented by a Dart | 27 * Returns a [ClassMirror] for the class represented by a Dart |
30 * Type object. | 28 * Type object. |
31 * | 29 * |
32 * This only works with objects local to the current isolate. | 30 * This only works with objects local to the current isolate. |
33 */ | 31 */ |
34 @patch | 32 @patch ClassMirror reflectClass(Type key) { |
35 ClassMirror reflectClass(Type key) { | |
36 return _Mirrors.reflectClass(key); | 33 return _Mirrors.reflectClass(key); |
37 } | 34 } |
38 | 35 |
39 @patch | 36 @patch TypeMirror reflectType(Type key, [List<Type> typeArguments]) { |
40 TypeMirror reflectType(Type key, [List<Type> typeArguments]) { | |
41 return _Mirrors.reflectType(key, typeArguments); | 37 return _Mirrors.reflectType(key, typeArguments); |
42 } | 38 } |
43 | 39 |
44 @patch | 40 @patch class MirrorSystem { |
45 class MirrorSystem { | 41 @patch LibraryMirror findLibrary(Symbol libraryName) { |
46 @patch | |
47 LibraryMirror findLibrary(Symbol libraryName) { | |
48 var candidates = | 42 var candidates = |
49 libraries.values.where((lib) => lib.simpleName == libraryName); | 43 libraries.values.where((lib) => lib.simpleName == libraryName); |
50 if (candidates.length == 1) { | 44 if (candidates.length == 1) { |
51 return candidates.single; | 45 return candidates.single; |
52 } | 46 } |
53 if (candidates.length > 1) { | 47 if (candidates.length > 1) { |
54 var uris = candidates.map((lib) => lib.uri.toString()).toList(); | 48 var uris = candidates.map((lib) => lib.uri.toString()).toList(); |
55 throw new Exception("There are multiple libraries named " | 49 throw new Exception("There are multiple libraries named " |
56 "'${getName(libraryName)}': $uris"); | 50 "'${getName(libraryName)}': $uris"); |
57 } | 51 } |
58 throw new Exception("There is no library named '${getName(libraryName)}'"); | 52 throw new Exception("There is no library named '${getName(libraryName)}'"); |
59 } | 53 } |
60 | 54 |
61 @patch | 55 @patch static String getName(Symbol symbol) { |
62 static String getName(Symbol symbol) { | |
63 return internal.Symbol.getUnmangledName(symbol); | 56 return internal.Symbol.getUnmangledName(symbol); |
64 } | 57 } |
65 | 58 |
66 @patch | 59 @patch static Symbol getSymbol(String name, [LibraryMirror library]) { |
67 static Symbol getSymbol(String name, [LibraryMirror library]) { | |
68 if ((library != null && library is! _LocalLibraryMirror) || | 60 if ((library != null && library is! _LocalLibraryMirror) || |
69 ((name.length > 0) && (name[0] == '_') && (library == null))) { | 61 ((name.length > 0) && (name[0] == '_') && (library == null))) { |
70 throw new ArgumentError(library); | 62 throw new ArgumentError(library); |
71 } | 63 } |
72 if (library != null) name = _mangleName(name, library._reflectee); | 64 if (library != null) name = _mangleName(name, library._reflectee); |
73 return new internal.Symbol.unvalidated(name); | 65 return new internal.Symbol.unvalidated(name); |
74 } | 66 } |
75 | 67 |
76 static _mangleName(String name, _MirrorReference lib) | 68 static _mangleName(String name, _MirrorReference lib) |
77 native "Mirrors_mangleName"; | 69 native "Mirrors_mangleName"; |
78 } | 70 } |
OLD | NEW |