| 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 #import('dart:io'); | 7 #import('dart:io'); |
| 8 #import('dart:uri'); | 8 #import('dart:uri'); |
| 9 #import('dart2js_mirror.dart'); | 9 #import('dart2js_mirror.dart'); |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 Path libraryRoot, | 31 Path libraryRoot, |
| 32 [Path packageRoot, | 32 [Path packageRoot, |
| 33 List<String> opts = const []]) { | 33 List<String> opts = const []]) { |
| 34 return new Dart2JsCompilation.library(libraries, libraryRoot, | 34 return new Dart2JsCompilation.library(libraries, libraryRoot, |
| 35 packageRoot, opts); | 35 packageRoot, opts); |
| 36 } | 36 } |
| 37 | 37 |
| 38 /** | 38 /** |
| 39 * Returns the mirror system for this compilation. | 39 * Returns the mirror system for this compilation. |
| 40 */ | 40 */ |
| 41 abstract MirrorSystem mirrors(); | 41 final MirrorSystem mirrors; |
| 42 | 42 |
| 43 /** | 43 /** |
| 44 * Returns a future for the compiled JavaScript code. | 44 * Returns a future for the compiled JavaScript code. |
| 45 */ | 45 */ |
| 46 abstract Future<String> compileToJavaScript(); | 46 abstract Future<String> compileToJavaScript(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 /** | 49 /** |
| 50 * The main interface for the whole mirror system. | 50 * The main interface for the whole mirror system. |
| 51 */ | 51 */ |
| 52 interface MirrorSystem { | 52 interface MirrorSystem { |
| 53 /** | 53 /** |
| 54 * Returns an unmodifiable map of all libraries in this mirror system. | 54 * Returns an unmodifiable map of all libraries in this mirror system. |
| 55 */ | 55 */ |
| 56 Map<Object, LibraryMirror> libraries(); | 56 final Map<Object, LibraryMirror> libraries; |
| 57 } | 57 } |
| 58 | 58 |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * An entity in the mirror system. | 61 * An entity in the mirror system. |
| 62 */ | 62 */ |
| 63 interface Mirror extends Hashable { | 63 interface Mirror extends Hashable { |
| 64 /** | 64 /** |
| 65 * The simple name of the entity. The simple name is in most cases the | 65 * The simple name of the entity. The simple name is in most cases the |
| 66 * the declared single identifier name of the entity, such as 'method' for | 66 * the declared single identifier name of the entity, such as 'method' for |
| 67 * a method [:void method() {...}:]. | 67 * a method [:void method() {...}:]. |
| 68 */ | 68 */ |
| 69 String simpleName(); | 69 final String simpleName; |
| 70 | 70 |
| 71 /** | 71 /** |
| 72 * Returns the name of this entity qualified by is enclosing context. For | 72 * Returns the name of this entity qualified by is enclosing context. For |
| 73 * instance, the qualified name of a method 'method' in class 'Class' in | 73 * instance, the qualified name of a method 'method' in class 'Class' in |
| 74 * library 'library' is 'library.Class.method'. | 74 * library 'library' is 'library.Class.method'. |
| 75 */ | 75 */ |
| 76 String qualifiedName(); | 76 final String qualifiedName; |
| 77 | 77 |
| 78 /** | 78 /** |
| 79 * Returns the mirror system which contains this mirror. | 79 * Returns the mirror system which contains this mirror. |
| 80 */ | 80 */ |
| 81 final MirrorSystem system; | 81 final MirrorSystem system; |
| 82 } | 82 } |
| 83 | 83 |
| 84 /** | 84 /** |
| 85 * Common interface for interface types and libraries. | 85 * Common interface for interface types and libraries. |
| 86 */ | 86 */ |
| 87 interface ObjectMirror extends Mirror { | 87 interface ObjectMirror extends Mirror { |
| 88 | 88 |
| 89 /** | 89 /** |
| 90 * Returns an unmodifiable map of the members of declared in this type or | 90 * Returns an unmodifiable map of the members of declared in this type or |
| 91 * library. | 91 * library. |
| 92 */ | 92 */ |
| 93 Map<Object, MemberMirror> declaredMembers(); | 93 final Map<Object, MemberMirror> declaredMembers; |
| 94 } | 94 } |
| 95 | 95 |
| 96 /** | 96 /** |
| 97 * A library. | 97 * A library. |
| 98 */ | 98 */ |
| 99 interface LibraryMirror extends ObjectMirror { | 99 interface LibraryMirror extends ObjectMirror { |
| 100 /** | 100 /** |
| 101 * The name of the library, as given in #library(). | 101 * The name of the library, as given in #library(). |
| 102 */ | 102 */ |
| 103 String simpleName(); | 103 final String simpleName; |
| 104 | 104 |
| 105 /** | 105 /** |
| 106 * Returns an iterable over all types in the library. | 106 * Returns an iterable over all types in the library. |
| 107 */ | 107 */ |
| 108 Map<Object, InterfaceMirror> types(); | 108 final Map<Object, InterfaceMirror> types; |
| 109 | 109 |
| 110 /** | 110 /** |
| 111 * Returns the source location for this library. | 111 * Returns the source location for this library. |
| 112 */ | 112 */ |
| 113 Location location(); | 113 final Location location; |
| 114 } | 114 } |
| 115 | 115 |
| 116 /** | 116 /** |
| 117 * Common interface for classes, interfaces, typedefs and type variables. | 117 * Common interface for classes, interfaces, typedefs and type variables. |
| 118 */ | 118 */ |
| 119 interface TypeMirror extends Mirror { | 119 interface TypeMirror extends Mirror { |
| 120 /** | 120 /** |
| 121 * Returns the source location for this type. | 121 * Returns the source location for this type. |
| 122 */ | 122 */ |
| 123 Location location(); | 123 final Location location; |
| 124 | 124 |
| 125 /** | 125 /** |
| 126 * Returns the library in which this member resides. | 126 * Returns the library in which this member resides. |
| 127 */ | 127 */ |
| 128 LibraryMirror library(); | 128 final LibraryMirror library; |
| 129 | 129 |
| 130 /** | 130 /** |
| 131 * Is [:true:] iff this type is the [:Object:] type. | 131 * Is [:true:] iff this type is the [:Object:] type. |
| 132 */ | 132 */ |
| 133 final bool isObject; | 133 final bool isObject; |
| 134 | 134 |
| 135 /** | 135 /** |
| 136 * Is [:true:] iff this type is the [:Dynamic:] type. | 136 * Is [:true:] iff this type is the [:Dynamic:] type. |
| 137 */ | 137 */ |
| 138 final bool isDynamic; | 138 final bool isDynamic; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 164 interface InterfaceMirror extends TypeMirror, ObjectMirror { | 164 interface InterfaceMirror extends TypeMirror, ObjectMirror { |
| 165 /** | 165 /** |
| 166 * Returns the defining type, i.e. declaration of a type. | 166 * Returns the defining type, i.e. declaration of a type. |
| 167 */ | 167 */ |
| 168 final InterfaceMirror declaration; | 168 final InterfaceMirror declaration; |
| 169 | 169 |
| 170 /** | 170 /** |
| 171 * Returns the super class of this type, or null if this type is [Object] or a | 171 * Returns the super class of this type, or null if this type is [Object] or a |
| 172 * typedef. | 172 * typedef. |
| 173 */ | 173 */ |
| 174 InterfaceMirror superclass(); | 174 final InterfaceMirror superclass; |
| 175 | 175 |
| 176 /** | 176 /** |
| 177 * Returns an iterable over the interfaces directly implemented by this type. | 177 * Returns an iterable over the interfaces directly implemented by this type. |
| 178 */ | 178 */ |
| 179 Map<Object, InterfaceMirror> interfaces(); | 179 final Map<Object, InterfaceMirror> interfaces; |
| 180 | 180 |
| 181 /** | 181 /** |
| 182 * Is [:true:] iff this type is a class. | 182 * Is [:true:] iff this type is a class. |
| 183 */ | 183 */ |
| 184 final bool isClass; | 184 final bool isClass; |
| 185 | 185 |
| 186 /** | 186 /** |
| 187 * Is [:true:] iff this type is an interface. | 187 * Is [:true:] iff this type is an interface. |
| 188 */ | 188 */ |
| 189 final bool isInterface; | 189 final bool isInterface; |
| 190 | 190 |
| 191 /** | 191 /** |
| 192 * Is [:true:] if this type is private. | 192 * Is [:true:] if this type is private. |
| 193 */ | 193 */ |
| 194 final bool isPrivate; | 194 final bool isPrivate; |
| 195 | 195 |
| 196 /** | 196 /** |
| 197 * Is [:true:] if this type is the declaration of a type. | 197 * Is [:true:] if this type is the declaration of a type. |
| 198 */ | 198 */ |
| 199 final bool isDeclaration; | 199 final bool isDeclaration; |
| 200 | 200 |
| 201 /** | 201 /** |
| 202 * Returns a list of the type arguments for this type. | 202 * Returns a list of the type arguments for this type. |
| 203 */ | 203 */ |
| 204 // Return a list instead of a map since the order of type arguments matters. | 204 final List<TypeMirror> typeArguments; |
| 205 // Also, there is no clear candidate for the keys, other than the indices, | |
| 206 // which again is an argument for returning a list. | |
| 207 List<TypeMirror> typeArguments(); | |
| 208 | 205 |
| 209 /** | 206 /** |
| 210 * Returns the list of type variables for this type. | 207 * Returns the list of type variables for this type. |
| 211 */ | 208 */ |
| 212 // Return a list instead of a map since the order of type variable matters. | 209 final List<TypeVariableMirror> typeVariables; |
| 213 // Even though the type variable name is a candidate for the key, the index | |
| 214 // of a type variable has a more stable semantics, which is an argument for | |
| 215 // returning a list instead of a map. | |
| 216 List<TypeVariableMirror> typeVariables(); | |
| 217 | 210 |
| 218 /** | 211 /** |
| 219 * Returns an immutable map of the constructors in this interface. | 212 * Returns an immutable map of the constructors in this interface. |
| 220 */ | 213 */ |
| 221 Map<Object, MethodMirror> constructors(); | 214 final Map<Object, MethodMirror> constructors; |
| 222 | 215 |
| 223 /** | 216 /** |
| 224 * Returns the default type for this interface. | 217 * Returns the default type for this interface. |
| 225 */ | 218 */ |
| 226 InterfaceMirror defaultType(); | 219 final InterfaceMirror defaultType; |
| 227 } | 220 } |
| 228 | 221 |
| 229 /** | 222 /** |
| 230 * A type parameter as declared on a generic type. | 223 * A type parameter as declared on a generic type. |
| 231 */ | 224 */ |
| 232 interface TypeVariableMirror extends TypeMirror { | 225 interface TypeVariableMirror extends TypeMirror { |
| 233 /** | 226 /** |
| 234 * Return a mirror on the class, interface, or typedef that declared the | 227 * Return a mirror on the class, interface, or typedef that declared the |
| 235 * type variable. | 228 * type variable. |
| 236 */ | 229 */ |
| 237 // Should not be called [declaration] as we then would have two [TypeMirror] | 230 // Should not be called [declaration] as we then would have two [TypeMirror] |
| 238 // subtypes ([InterfaceMirror] and [TypeVariableMirror]) which have | 231 // subtypes ([InterfaceMirror] and [TypeVariableMirror]) which have |
| 239 // [declaration()] methods but with different semantics. | 232 // [declaration()] methods but with different semantics. |
| 240 InterfaceMirror declarer(); | 233 final InterfaceMirror declarer; |
| 241 | 234 |
| 242 /** | 235 /** |
| 243 * Returns the bound of the type parameter. | 236 * Returns the bound of the type parameter. |
| 244 */ | 237 */ |
| 245 TypeMirror bound(); | 238 final TypeMirror bound; |
| 246 } | 239 } |
| 247 | 240 |
| 248 /** | 241 /** |
| 249 * A function type. | 242 * A function type. |
| 250 */ | 243 */ |
| 251 interface FunctionTypeMirror extends InterfaceMirror { | 244 interface FunctionTypeMirror extends InterfaceMirror { |
| 252 /** | 245 /** |
| 253 * Returns the return type of this function type. | 246 * Returns the return type of this function type. |
| 254 */ | 247 */ |
| 255 TypeMirror returnType(); | 248 final TypeMirror returnType; |
| 256 | 249 |
| 257 /** | 250 /** |
| 258 * Returns the parameters for this function type. | 251 * Returns the parameters for this function type. |
| 259 */ | 252 */ |
| 260 List<ParameterMirror> parameters(); | 253 final List<ParameterMirror> parameters; |
| 261 | 254 |
| 262 /** | 255 /** |
| 263 * Returns the call method for this function type. | 256 * Returns the call method for this function type. |
| 264 */ | 257 */ |
| 265 MethodMirror callMethod(); | 258 final MethodMirror callMethod; |
| 266 } | 259 } |
| 267 | 260 |
| 268 /** | 261 /** |
| 269 * A typedef. | 262 * A typedef. |
| 270 */ | 263 */ |
| 271 interface TypedefMirror extends InterfaceMirror { | 264 interface TypedefMirror extends InterfaceMirror { |
| 272 /** | 265 /** |
| 273 * Returns the defining type for this typedef. For instance [:void f(int):] | 266 * Returns the defining type for this typedef. For instance [:void f(int):] |
| 274 * for a [:typedef void f(int):]. | 267 * for a [:typedef void f(int):]. |
| 275 */ | 268 */ |
| 276 TypeMirror definition(); | 269 final TypeMirror definition; |
| 277 } | 270 } |
| 278 | 271 |
| 279 /** | 272 /** |
| 280 * A member of a type, i.e. a field, method or constructor. | 273 * A member of a type, i.e. a field, method or constructor. |
| 281 */ | 274 */ |
| 282 interface MemberMirror extends Mirror { | 275 interface MemberMirror extends Mirror { |
| 283 /** | 276 /** |
| 284 * Returns the source location for this member. | 277 * Returns the source location for this member. |
| 285 */ | 278 */ |
| 286 Location location(); | 279 final Location location; |
| 287 | 280 |
| 288 /** | 281 /** |
| 289 * Returns a mirror on the declaration immediately surrounding the reflectee. | 282 * Returns a mirror on the declaration immediately surrounding the reflectee. |
| 290 * This could be a class, interface, library or another method or function. | 283 * This could be a class, interface, library or another method or function. |
| 291 */ | 284 */ |
| 292 ObjectMirror surroundingDeclaration(); | 285 final ObjectMirror surroundingDeclaration; |
| 293 | 286 |
| 294 /** | 287 /** |
| 295 * Returns true if this is a top level member, i.e. a member not within a | 288 * Returns true if this is a top level member, i.e. a member not within a |
| 296 * type. | 289 * type. |
| 297 */ | 290 */ |
| 298 final bool isTopLevel; | 291 final bool isTopLevel; |
| 299 | 292 |
| 300 /** | 293 /** |
| 301 * Returns true if this member is a constructor. | 294 * Returns true if this member is a constructor. |
| 302 */ | 295 */ |
| (...skipping 26 matching lines...) Expand all Loading... |
| 329 interface FieldMirror extends MemberMirror { | 322 interface FieldMirror extends MemberMirror { |
| 330 | 323 |
| 331 /** | 324 /** |
| 332 * Returns true if this field is final. | 325 * Returns true if this field is final. |
| 333 */ | 326 */ |
| 334 final bool isFinal; | 327 final bool isFinal; |
| 335 | 328 |
| 336 /** | 329 /** |
| 337 * Returns the type of this field. | 330 * Returns the type of this field. |
| 338 */ | 331 */ |
| 339 TypeMirror type(); | 332 final TypeMirror type; |
| 340 } | 333 } |
| 341 | 334 |
| 342 /** | 335 /** |
| 343 * Common interface constructors and methods, including factories, getters and | 336 * Common interface constructors and methods, including factories, getters and |
| 344 * setters. | 337 * setters. |
| 345 */ | 338 */ |
| 346 interface MethodMirror extends MemberMirror { | 339 interface MethodMirror extends MemberMirror { |
| 347 /** | 340 /** |
| 348 * Returns the list of parameters for this method. | 341 * Returns the list of parameters for this method. |
| 349 */ | 342 */ |
| 350 List<ParameterMirror> parameters(); | 343 final List<ParameterMirror> parameters; |
| 351 | 344 |
| 352 /** | 345 /** |
| 353 * Returns the return type of this method. | 346 * Returns the return type of this method. |
| 354 */ | 347 */ |
| 355 TypeMirror returnType(); | 348 final TypeMirror returnType; |
| 356 | 349 |
| 357 /** | 350 /** |
| 358 * Is [:true:] if this method is a constant constructor. | 351 * Is [:true:] if this method is a constant constructor. |
| 359 */ | 352 */ |
| 360 final bool isConst; | 353 final bool isConst; |
| 361 | 354 |
| 362 /** | 355 /** |
| 363 * Is [:true:] if this method is a factory method. | 356 * Is [:true:] if this method is a factory method. |
| 364 */ | 357 */ |
| 365 final bool isFactory; | 358 final bool isFactory; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 392 final String operatorName; | 385 final String operatorName; |
| 393 } | 386 } |
| 394 | 387 |
| 395 /** | 388 /** |
| 396 * A formal parameter. | 389 * A formal parameter. |
| 397 */ | 390 */ |
| 398 interface ParameterMirror extends Mirror { | 391 interface ParameterMirror extends Mirror { |
| 399 /** | 392 /** |
| 400 * Returns the type of this parameter. | 393 * Returns the type of this parameter. |
| 401 */ | 394 */ |
| 402 TypeMirror type(); | 395 final TypeMirror type; |
| 403 | 396 |
| 404 /** | 397 /** |
| 405 * Returns the default value for this parameter. | 398 * Returns the default value for this parameter. |
| 406 */ | 399 */ |
| 407 String defaultValue(); | 400 final String defaultValue; |
| 408 | 401 |
| 409 /** | 402 /** |
| 410 * Returns true if this parameter has a default value. | 403 * Returns true if this parameter has a default value. |
| 411 */ | 404 */ |
| 412 bool hasDefaultValue(); | 405 final bool hasDefaultValue; |
| 413 | 406 |
| 414 /** | 407 /** |
| 415 * Returns true if this parameter is optional. | 408 * Returns true if this parameter is optional. |
| 416 */ | 409 */ |
| 417 bool isOptional(); | 410 final bool isOptional; |
| 418 | 411 |
| 419 /** | 412 /** |
| 420 * Returns [:true:] iff this parameter is an initializing formal of a | 413 * Returns [:true:] iff this parameter is an initializing formal of a |
| 421 * constructor. That is, if it is of the form [:this.x:] where [:x:] is a | 414 * constructor. That is, if it is of the form [:this.x:] where [:x:] is a |
| 422 * field. | 415 * field. |
| 423 */ | 416 */ |
| 424 bool isInitializingFormal(); | 417 final bool isInitializingFormal; |
| 425 | 418 |
| 426 /** | 419 /** |
| 427 * Returns the initialized field, if this parameter is an initializing formal. | 420 * Returns the initialized field, if this parameter is an initializing formal. |
| 428 */ | 421 */ |
| 429 FieldMirror initializedField(); | 422 final FieldMirror initializedField; |
| 430 } | 423 } |
| 431 | 424 |
| 432 /** | 425 /** |
| 433 * A [Location] describes the span of an entity in Dart source code. | 426 * A [Location] describes the span of an entity in Dart source code. |
| 434 * A [Location] should be the minimum span that encloses the declaration of the | 427 * A [Location] should be the minimum span that encloses the declaration of the |
| 435 * mirrored entity. | 428 * mirrored entity. |
| 436 */ | 429 */ |
| 437 interface Location { | 430 interface Location { |
| 438 /** | 431 /** |
| 439 * The character position where the location begins. | 432 * The character position where the location begins. |
| 440 */ | 433 */ |
| 441 int start(); | 434 final int start; |
| 442 | 435 |
| 443 /** | 436 /** |
| 444 * The character position where the location ends. | 437 * The character position where the location ends. |
| 445 */ | 438 */ |
| 446 int end(); | 439 final int end; |
| 447 | 440 |
| 448 /** | 441 /** |
| 449 * Returns the [Source] in which this [Location] indexes. | 442 * Returns the [Source] in which this [Location] indexes. |
| 450 * If [:loc:] is a location, [:loc.source().text()[loc.start()] is where it | 443 * If [:loc:] is a location, [:loc.source().text()[loc.start()] is where it |
| 451 * starts, and [:loc.source().text()[loc.end()] is where it ends. | 444 * starts, and [:loc.source().text()[loc.end()] is where it ends. |
| 452 */ | 445 */ |
| 453 Source source(); | 446 final Source source; |
| 454 | 447 |
| 455 /** | 448 /** |
| 456 * The text of the location span. | 449 * The text of the location span. |
| 457 */ | 450 */ |
| 458 String text(); | 451 final String text; |
| 459 } | 452 } |
| 460 | 453 |
| 461 /** | 454 /** |
| 462 * A [Source] describes the source code of a compilation unit in Dart source | 455 * A [Source] describes the source code of a compilation unit in Dart source |
| 463 * code. | 456 * code. |
| 464 */ | 457 */ |
| 465 interface Source { | 458 interface Source { |
| 466 /** | 459 /** |
| 467 * Returns the URI where the source originated. | 460 * Returns the URI where the source originated. |
| 468 */ | 461 */ |
| 469 Uri uri(); | 462 final Uri uri; |
| 470 | 463 |
| 471 /** | 464 /** |
| 472 * Returns the text of this source. | 465 * Returns the text of this source. |
| 473 */ | 466 */ |
| 474 String text(); | 467 final String text; |
| 475 } | 468 } |
| OLD | NEW |