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() { |
(...skipping 18 matching lines...) Expand all Loading... |
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 |