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 // #library("mirrors"); | 5 // #library("mirrors"); |
6 | 6 |
7 // The dart:mirrors library provides reflective access for Dart program. | 7 // The dart:mirrors library provides reflective access for Dart program. |
8 // | 8 // |
9 // TODO(turnidge): Complete this api. This is a placeholder. | 9 // TODO(turnidge): Finish implementing this api. |
10 | 10 |
11 interface IsolateMirror { | 11 /** |
12 // A name used to refer to an isolate in debugging messages. | 12 * Creates an [IsolateMirror] on the isolate which is listening on |
13 final String debugName; | 13 * the [SendPort]. |
14 } | 14 */ |
15 | |
16 Future<IsolateMirror> isolateMirrorOf(SendPort port) { | 15 Future<IsolateMirror> isolateMirrorOf(SendPort port) { |
17 return _Mirrors.isolateMirrorOf(port); | 16 return _Mirrors.isolateMirrorOf(port); |
18 } | 17 } |
| 18 |
| 19 /** |
| 20 * A [Mirror] reflects some Dart language entity. |
| 21 * |
| 22 * Every [Mirror] originates from some [IsolateMirror]. |
| 23 */ |
| 24 interface Mirror { |
| 25 /** |
| 26 * The isolate of orgin for this [Mirror]. |
| 27 */ |
| 28 final IsolateMirror isolate; |
| 29 } |
| 30 |
| 31 /** |
| 32 * An [IsolateMirror] reflects an isolate. |
| 33 */ |
| 34 interface IsolateMirror extends Mirror { |
| 35 /** |
| 36 * A unique name used to refer to an isolate in debugging messages. |
| 37 */ |
| 38 final String debugName; |
| 39 |
| 40 /** |
| 41 * A mirror on the root library of the reflectee. |
| 42 */ |
| 43 final LibraryMirror rootLibrary; |
| 44 |
| 45 /** |
| 46 * An immutable map from from library names to mirrors for all |
| 47 * libraries loaded in the reflectee. |
| 48 */ |
| 49 final Map<String, LibraryMirror> libraries; |
| 50 } |
| 51 |
| 52 |
| 53 /** |
| 54 * An [ObjectMirror] is a common superinterface of [InstanceMirror], |
| 55 * [InterfaceMirror], and [LibraryMirror] that represents their shared |
| 56 * functionality. |
| 57 * |
| 58 * For the purposes of the mirrors api, these types are all |
| 59 * object-like, in that they support method invocation and field |
| 60 * access. Real Dart objects are represented by the [InstanceMirror] |
| 61 * type. |
| 62 * |
| 63 * See [InstanceMirror], [InterfaceMirror], and [LibraryMirror]. |
| 64 */ |
| 65 interface ObjectMirror extends Mirror { |
| 66 /** |
| 67 * Invokes the named function and returns a mirror on the result. |
| 68 * |
| 69 * TODO(turnidge): Properly document. |
| 70 * |
| 71 * TODO(turnidge): what to do if invoke causes the death of the reflectee? |
| 72 */ |
| 73 Future<InstanceMirror> invoke(String memberName, |
| 74 List<Object> positionalArguments, |
| 75 [Map<String,Object> namedArguments]); |
| 76 } |
| 77 |
| 78 /** |
| 79 * An [InstanceMirror] reflects an instance of a Dart language object. |
| 80 */ |
| 81 interface InstanceMirror extends ObjectMirror { |
| 82 /** |
| 83 * If the [InstanceMirror] refers to a simple type, we provide |
| 84 * access to the actual value here. Simple types are... |
| 85 * |
| 86 * TODO(turnidge): Properly document. |
| 87 * |
| 88 * TODO(turnidge): How best to represent a null simple value versus |
| 89 * the absence of a simple value? |
| 90 */ |
| 91 final simpleValue; |
| 92 } |
| 93 |
| 94 /** |
| 95 * An [InterfaceMirror] reflects a Dart language class or interface. |
| 96 */ |
| 97 interface InterfaceMirror extends ObjectMirror { |
| 98 } |
| 99 |
| 100 /** |
| 101 * A [LibraryMirror] reflects a Dart language library, providing |
| 102 * access to the variables, functions, classes, and interfaces of the |
| 103 * library. |
| 104 */ |
| 105 interface LibraryMirror extends ObjectMirror { |
| 106 /** |
| 107 * The name of the library, as provided in the [#library] declaration. |
| 108 */ |
| 109 final String simpleName; |
| 110 |
| 111 /** |
| 112 * The url of the library. |
| 113 * |
| 114 * TODO(turnidge): Document where this url comes from. Will this |
| 115 * value be sensible? |
| 116 */ |
| 117 final String url; |
| 118 } |
| 119 |
| 120 /** |
| 121 * A [MirrorException] is used to indicate errors within the mirrors |
| 122 * framework. |
| 123 */ |
| 124 class MirrorException implements Exception { |
| 125 const MirrorException(String this._message); |
| 126 String toString() => "MirrorException: '$_message'"; |
| 127 final String _message; |
| 128 } |
OLD | NEW |