Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 #library('mirrors'); | |
| 6 | |
| 7 #import('dart:uri'); | |
| 8 #import('dart2js_mirror.dart'); | |
| 9 | |
| 10 /** | |
| 11 * [Compilation] encapsulates the compilation of a program. | |
| 12 */ | |
| 13 class Compilation { | |
| 14 /** | |
| 15 * Creates a new compilation which has [script] as its entry point. | |
| 16 */ | |
| 17 factory Compilation(String script, String libraryRoot, | |
| 18 [String packageRoot, List<String> opts = const []]) | |
| 19 { | |
|
Lasse Reichstein Nielsen
2012/07/04 10:58:59
Brace on previous line.
Johnni Winther
2012/07/04 13:19:17
Done.
| |
| 20 return new Dart2jsCompilation(script, libraryRoot, packageRoot, opts); | |
| 21 } | |
| 22 | |
| 23 /** | |
| 24 * Returns the mirror system for this compilation. | |
| 25 */ | |
| 26 abstract MirrorSystem mirrors(); | |
| 27 } | |
| 28 | |
| 29 /** | |
| 30 * The main interface for the whole mirror system. | |
| 31 */ | |
| 32 interface MirrorSystem { | |
| 33 /** | |
| 34 * Returns an unmodifiable map of all libraries in this mirror system. | |
| 35 */ | |
| 36 Map<Object, LibraryMirror> libraries(); | |
| 37 } | |
| 38 | |
| 39 | |
| 40 /** | |
| 41 * An entity in the mirror system. | |
| 42 */ | |
| 43 interface Mirror { | |
| 44 /** | |
| 45 * The simple name of the entity. The simple name is in most cases the | |
| 46 * the declared single identifier name of the entity, such as 'method' for | |
| 47 * a method [:void method() {...}:]. | |
| 48 */ | |
| 49 String simpleName(); | |
| 50 | |
| 51 /** | |
| 52 * Returns the name of this entity qualified by is enclosing context. For | |
| 53 * instance, the qualified name of a method 'method' in class 'Class' in | |
| 54 * library 'library' is 'library.Class.method'. | |
| 55 */ | |
| 56 String qualifiedName(); | |
| 57 } | |
| 58 | |
| 59 /** | |
| 60 * Common interface for interface types and libraries. | |
| 61 */ | |
| 62 interface ObjectMirror extends Mirror { | |
| 63 | |
| 64 /** | |
| 65 * Returns an unmodifiable map of the members of declared in this type or | |
| 66 * library. | |
| 67 */ | |
| 68 Map<Object, MemberMirror> declaredMembers(); | |
| 69 } | |
| 70 | |
| 71 /** | |
| 72 * A library. | |
| 73 */ | |
| 74 interface LibraryMirror extends ObjectMirror { | |
| 75 /** | |
| 76 * The name of the library, as given in #library(). | |
| 77 */ | |
| 78 String simpleName(); | |
| 79 | |
| 80 /** | |
| 81 * Returns an iterable over all types in the library. | |
| 82 */ | |
| 83 Map<Object, InterfaceMirror> types(); | |
| 84 | |
| 85 /** | |
| 86 * Returns the source location for this library. | |
| 87 */ | |
| 88 Location location(); | |
| 89 } | |
| 90 | |
| 91 /** | |
| 92 * Common interface for classes, interfaces, typedefs and type variables. | |
| 93 */ | |
| 94 interface TypeMirror extends Mirror { | |
| 95 /** | |
| 96 * Returns the source location for this type. | |
| 97 */ | |
| 98 Location location(); | |
| 99 | |
| 100 /** | |
| 101 * Returns the library in which this member resides. | |
| 102 */ | |
| 103 LibraryMirror library(); | |
| 104 | |
| 105 /** | |
| 106 * Is [:true:] iff this type is the [:Object:] type. | |
| 107 */ | |
| 108 final bool isObject; | |
| 109 | |
| 110 /** | |
| 111 * Is [:true:] iff this type is the [:Dynamic:] type. | |
| 112 */ | |
| 113 final bool isDynamic; | |
| 114 | |
| 115 /** | |
| 116 * Is [:true:] iff this type is the void type. | |
| 117 */ | |
| 118 final bool isVoid; | |
| 119 | |
| 120 /** | |
| 121 * Is [:true:] iff this type is a type variable. | |
| 122 */ | |
| 123 final bool isTypeVariable; | |
| 124 | |
| 125 /** | |
| 126 * Is [:true:] iff this type is a typedef. | |
| 127 */ | |
| 128 final bool isTypedef; | |
| 129 | |
| 130 /** | |
| 131 * Is [:true:] iff this type is a function type. | |
| 132 */ | |
| 133 final bool isFunction; | |
| 134 } | |
| 135 | |
| 136 /** | |
| 137 * A class or interface type. | |
| 138 */ | |
| 139 interface InterfaceMirror extends TypeMirror, ObjectMirror { | |
| 140 /** | |
| 141 * Returns the defining type, i.e. declaration of a type. | |
| 142 */ | |
| 143 final InterfaceMirror declaration; | |
| 144 | |
| 145 /** | |
| 146 * Returns the super class of this type, or null if this type is [Object] or a | |
| 147 * typedef. | |
| 148 */ | |
| 149 InterfaceMirror superclass(); | |
| 150 | |
| 151 /** | |
| 152 * Returns an iterable over the interfaces directly implemented by this type. | |
| 153 */ | |
| 154 Map<Object, InterfaceMirror> interfaces(); | |
| 155 | |
| 156 /** | |
| 157 * Is [:true:] iff this type is a class. | |
| 158 */ | |
| 159 final bool isClass; | |
| 160 | |
| 161 /** | |
| 162 * Is [:true:] iff this type is an interface. | |
| 163 */ | |
| 164 final bool isInterface; | |
| 165 | |
| 166 /** | |
| 167 * Is [:true:] if this type is private. | |
| 168 */ | |
| 169 final bool isPrivate; | |
| 170 | |
| 171 /** | |
| 172 * Is [:true:] if this type is the declaration of a type. | |
| 173 */ | |
| 174 final bool isDeclaration; | |
| 175 | |
| 176 /** | |
| 177 * Returns a list of the type arguments for this type. | |
| 178 */ | |
| 179 // Return a list instead of a map since the order of type arguments matters. | |
| 180 // Also, there is no clear candidate for the keys, other than the indices, | |
| 181 // which again is an argument for returning a list. | |
| 182 List<TypeMirror> typeArguments(); | |
| 183 | |
| 184 /** | |
| 185 * Returns the list of type variables for this type. | |
| 186 */ | |
| 187 // Return a list instead of a map since the order of type variable matters. | |
| 188 // Even though the type variable name is a candidate for the key, the index | |
| 189 // of a type variable has a more stable semantics, which is an argument for | |
| 190 // returning a list instead of a map. | |
| 191 List<TypeVariableMirror> typeVariables(); | |
| 192 | |
| 193 /** | |
| 194 * Returns an immutable map of the constructors in this interface. | |
| 195 */ | |
| 196 Map<Object, MethodMirror> constructors(); | |
| 197 | |
| 198 /** | |
| 199 * Returns the default type for this interface. | |
| 200 */ | |
| 201 InterfaceMirror defaultType(); | |
| 202 } | |
| 203 | |
| 204 /** | |
| 205 * A type parameter as declared on a generic type. | |
| 206 */ | |
| 207 interface TypeVariableMirror extends TypeMirror { | |
| 208 /** | |
| 209 * Return a mirror on the class, interface, or typedef that declared the | |
| 210 * type variable. | |
| 211 */ | |
| 212 // Should not be called [declaration] as we then would have two [TypeMirror] | |
| 213 // subtypes ([InterfaceMirror] and [TypeVariableMirror]) which have | |
| 214 // [declaration()] methods but with different semantics. | |
| 215 InterfaceMirror declarer(); | |
| 216 | |
| 217 /** | |
| 218 * Returns the bound of the type parameter. | |
| 219 */ | |
| 220 TypeMirror bound(); | |
| 221 } | |
| 222 | |
| 223 /** | |
| 224 * A function type. | |
| 225 */ | |
| 226 interface FunctionTypeMirror extends InterfaceMirror { | |
| 227 /** | |
| 228 * Returns the return type of this function type. | |
| 229 */ | |
| 230 TypeMirror returnType(); | |
| 231 | |
| 232 /** | |
| 233 * Returns the parameters for this function type. | |
| 234 */ | |
| 235 List<ParameterMirror> parameters(); | |
| 236 | |
| 237 /** | |
| 238 * Returns the call method for this function type. | |
| 239 */ | |
| 240 MethodMirror callMethod(); | |
| 241 } | |
| 242 | |
| 243 /** | |
| 244 * A typedef. | |
| 245 */ | |
| 246 interface TypedefMirror extends InterfaceMirror { | |
| 247 /** | |
| 248 * Returns the defining type for this typedef. For instance [:void f(int):] | |
| 249 * for a [:typedef void f(int):]. | |
| 250 */ | |
| 251 TypeMirror definition(); | |
| 252 } | |
| 253 | |
| 254 /** | |
| 255 * A member of a type, i.e. a field, method or constructor. | |
| 256 */ | |
| 257 interface MemberMirror extends Mirror { | |
| 258 /** | |
| 259 * Returns the source location for this member. | |
| 260 */ | |
| 261 Location location(); | |
| 262 | |
| 263 /** | |
| 264 * Returns a mirror on the declaration immediately surrounding the reflectee. | |
| 265 * This could be a class, interface, library or another method or function. | |
| 266 */ | |
| 267 ObjectMirror surroundingDeclaration(); | |
| 268 | |
| 269 /** | |
| 270 * Returns true if this is a top level member, i.e. a member not within a | |
| 271 * type. | |
| 272 */ | |
| 273 final bool isTopLevel; | |
| 274 | |
| 275 /** | |
| 276 * Returns true if this member is a constructor. | |
| 277 */ | |
| 278 final bool isConstructor; | |
| 279 | |
| 280 /** | |
| 281 * Returns true if this member is a field. | |
| 282 */ | |
| 283 final bool isField; | |
| 284 | |
| 285 /** | |
| 286 * Returns true if this member is a method. | |
| 287 */ | |
| 288 final bool isMethod; | |
| 289 | |
| 290 /** | |
| 291 * Returns true if this member is private. | |
| 292 */ | |
| 293 final bool isPrivate; | |
| 294 | |
| 295 /** | |
| 296 * Returns true if this member is static. | |
| 297 */ | |
| 298 final bool isStatic; | |
| 299 } | |
| 300 | |
| 301 /** | |
| 302 * A field. | |
| 303 */ | |
| 304 interface FieldMirror extends MemberMirror { | |
| 305 | |
| 306 /** | |
| 307 * Returns true if this field is final. | |
| 308 */ | |
| 309 final bool isFinal; | |
| 310 | |
| 311 /** | |
| 312 * Returns the type of this field. | |
| 313 */ | |
| 314 TypeMirror type(); | |
| 315 } | |
| 316 | |
| 317 /** | |
| 318 * Common interface constructors and methods, including factories, getters and | |
| 319 * setters. | |
| 320 */ | |
| 321 interface MethodMirror extends MemberMirror { | |
| 322 /** | |
| 323 * Returns the list of parameters for this method. | |
| 324 */ | |
| 325 List<ParameterMirror> parameters(); | |
| 326 | |
| 327 /** | |
| 328 * Returns the return type of this method. | |
| 329 */ | |
| 330 TypeMirror returnType(); | |
| 331 | |
| 332 /** | |
| 333 * Is [:true:] if this method is a constant constructor. | |
| 334 */ | |
| 335 final bool isConst; | |
| 336 | |
| 337 /** | |
| 338 * Is [:true:] if this method is a factory method. | |
| 339 */ | |
| 340 final bool isFactory; | |
| 341 | |
| 342 /** | |
| 343 * Returns the constructor name for named constructors and factory methods, | |
| 344 * e.g. [:'bar':] for constructor [:Foo.bar:] of type [:Foo:]. | |
| 345 */ | |
| 346 final String constructorName; | |
| 347 | |
| 348 /** | |
| 349 * Is [:true:] if this method is a getter method. | |
| 350 */ | |
| 351 final bool isGetter; | |
| 352 | |
| 353 /** | |
| 354 * Is [:true:] if this method is a setter method. | |
| 355 */ | |
| 356 final bool isSetter; | |
| 357 | |
| 358 /** | |
| 359 * Is [:true:] if this method is an operator method. | |
| 360 */ | |
| 361 final bool isOperator; | |
| 362 | |
| 363 /** | |
| 364 * Returns the operator name for operator methods, e.g. [:'<':] for | |
| 365 * [:operator <:] | |
| 366 */ | |
| 367 final String operatorName; | |
| 368 } | |
| 369 | |
| 370 /** | |
| 371 * A formal parameter. | |
| 372 */ | |
| 373 interface ParameterMirror extends Mirror { | |
| 374 /** | |
| 375 * Returns the type of this parameter. | |
| 376 */ | |
| 377 TypeMirror type(); | |
| 378 | |
| 379 /** | |
| 380 * Returns the default value for this parameter. | |
| 381 */ | |
| 382 String defaultValue(); | |
| 383 | |
| 384 /** | |
| 385 * Returns true if this parameter has a default value. | |
| 386 */ | |
| 387 bool hasDefaultValue(); | |
| 388 | |
| 389 /** | |
| 390 * Returns true if this parameter is optional. | |
| 391 */ | |
| 392 bool isOptional(); | |
| 393 } | |
| 394 | |
| 395 /** | |
| 396 * A [Location] describes the span of an entity in Dart source code. | |
| 397 * A [Location] should be the minimum span that encloses the declaration of the | |
| 398 * mirrored entity. | |
| 399 */ | |
| 400 interface Location { | |
| 401 /** | |
| 402 * The character position where the location begins. | |
| 403 */ | |
| 404 int start(); | |
| 405 | |
| 406 /** | |
| 407 * The character position where the location ends. | |
| 408 */ | |
| 409 int end(); | |
| 410 | |
| 411 /** | |
| 412 * Returns the [Source] in which this [Location] indexes. | |
| 413 * If [:loc:] is a location, [:loc.source().text()[loc.start()] is where it | |
| 414 * starts, and [:loc.source().text()[loc.end()] is where it ends. | |
| 415 */ | |
| 416 Source source(); | |
| 417 | |
| 418 /** | |
| 419 * The text of the location span. | |
| 420 */ | |
| 421 String text(); | |
| 422 } | |
| 423 | |
| 424 /** | |
| 425 * A [Source] describes the source code of a compilation unit in Dart source | |
| 426 * code. | |
| 427 */ | |
| 428 interface Source { | |
| 429 /** | |
| 430 * Returns the URI where the source originated. | |
| 431 */ | |
| 432 Uri uri(); | |
| 433 | |
| 434 /** | |
| 435 * Returns the text of this source. | |
| 436 */ | |
| 437 String text(); | |
| 438 } | |
| OLD | NEW |