OLD | NEW |
1 // Copyright (c) 2015, the Dart Team. All rights reserved. Use of this | 1 // Copyright (c) 2015, the Dart Team. All rights reserved. Use of this |
2 // source code is governed by a BSD-style license that can be found in | 2 // source code is governed by a BSD-style license that can be found in |
3 // the LICENSE file. | 3 // the LICENSE file. |
4 | 4 |
5 // This file defines the same types as sdk/lib/mirrors/mirrors.dart, in | 5 // This file defines the same types as sdk/lib/mirrors/mirrors.dart, in |
6 // order to enable code using [dart:mirrors] to switch to using | 6 // order to enable code using [dart:mirrors] to switch to using |
7 // [Reflectable] based mirrors with the smallest possible change. | 7 // [Reflectable] based mirrors with the smallest possible change. |
8 // The changes are discussed below, under headings on the form | 8 // The changes are discussed below, under headings on the form |
9 // 'API Change: ..'. | 9 // 'API Change: ..'. |
10 | 10 |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 List<Object> get metadata; // TYARG: InstanceMirror | 301 List<Object> get metadata; // TYARG: InstanceMirror |
302 } | 302 } |
303 | 303 |
304 abstract class CombinatorMirror implements Mirror { | 304 abstract class CombinatorMirror implements Mirror { |
305 List<String> get identifiers; | 305 List<String> get identifiers; |
306 bool get isShow; | 306 bool get isShow; |
307 bool get isHide; | 307 bool get isHide; |
308 } | 308 } |
309 | 309 |
310 abstract class TypeMirror implements DeclarationMirror { | 310 abstract class TypeMirror implements DeclarationMirror { |
| 311 |
| 312 /// Returns true if this mirror reflects dynamic, a non-generic class or |
| 313 /// typedef, or an instantiated generic class or typedef with support in |
| 314 /// the execution mode. Otherwise, returns false. |
| 315 /// |
| 316 /// The notion of support in the execution mode reflects temporary |
| 317 /// restrictions arising from the lack of runtime support for certain |
| 318 /// operations. In particular, transformed code cannot produce the reflected |
| 319 /// type for an instantiated generic class when one or more type arguments |
| 320 /// are or contain type variables from an enclosing class. For instance, |
| 321 /// `List<E>` could be used as the type annotation on a variable in the class |
| 322 /// `List` itself, and a variable mirror for that method would then deliver |
| 323 /// a type mirror for the annotation where `hasReflectedType` is false, |
| 324 /// because of the lack of primitives to access the actual type argument of |
| 325 /// that list. |
311 bool get hasReflectedType; | 326 bool get hasReflectedType; |
| 327 |
| 328 /// If [hasReflectedType] returns true, returns the corresponding [Type]. |
| 329 /// Otherwise, an [UnsupportedError] is thrown. |
312 Type get reflectedType; | 330 Type get reflectedType; |
| 331 |
313 List<TypeVariableMirror> get typeVariables; | 332 List<TypeVariableMirror> get typeVariables; |
314 List<TypeMirror> get typeArguments; | 333 List<TypeMirror> get typeArguments; |
315 bool get isOriginalDeclaration; | 334 bool get isOriginalDeclaration; |
316 TypeMirror get originalDeclaration; | 335 TypeMirror get originalDeclaration; |
317 | 336 |
318 // Possible ARG: Type. | 337 // Possible ARG: Type. |
319 // Input from Gilad on this issue: | 338 // Input from Gilad on this issue: |
320 // I think we could consider using Type objects as arguments, because that is | 339 // I think we could consider using Type objects as arguments, because that is |
321 // actually more uniform; in general, the mirror API takes in base level | 340 // actually more uniform; in general, the mirror API takes in base level |
322 // objects and produces meta-level objects. As a practical matter, I'd say we | 341 // objects and produces meta-level objects. As a practical matter, I'd say we |
(...skipping 12 matching lines...) Expand all Loading... |
335 bool get isAbstract; | 354 bool get isAbstract; |
336 bool get isEnum; | 355 bool get isEnum; |
337 | 356 |
338 // The non-abstract members declared in this class. | 357 // The non-abstract members declared in this class. |
339 Map<String, DeclarationMirror> get declarations; | 358 Map<String, DeclarationMirror> get declarations; |
340 Map<String, MethodMirror> get instanceMembers; | 359 Map<String, MethodMirror> get instanceMembers; |
341 Map<String, MethodMirror> get staticMembers; | 360 Map<String, MethodMirror> get staticMembers; |
342 | 361 |
343 ClassMirror get mixin; | 362 ClassMirror get mixin; |
344 | 363 |
| 364 /// Returns true if this mirror reflects dynamic, a non-generic class or |
| 365 /// typedef, or an instantiated generic class or typedef with support in |
| 366 /// the execution mode. Otherwise, returns false. |
| 367 /// |
| 368 /// The notion of support in the execution mode reflects temporary |
| 369 /// restrictions arising from the lack of runtime support for certain |
| 370 /// operations. In particular, untransformed code cannot produce the |
| 371 /// dynamic reflected type for a type mirror on an instantiated generic |
| 372 /// class due to a lack of primitives for navigation among different |
| 373 /// instantiations of the same generic class. For instance, with a given |
| 374 /// [Type] representing `List<int>`, there is no support for obtaining |
| 375 /// `List<dynamic>` because there are no primitives in 'dart:mirrors' |
| 376 /// nor in the core libraries for applying a given generic class to any |
| 377 /// given type arguments. |
| 378 bool get hasDynamicReflectedType; |
| 379 |
| 380 /// If [hasDynamicReflectedType] returns true, returns the [Type] object |
| 381 /// representing the fully dynamic instantiation of this class if it is |
| 382 /// generic, and return the [Type] object representing this class if it is |
| 383 /// not generic. If [hasDynamicReflectedType] returns false it throws an |
| 384 /// [UnsupportedError]. The fully dynamic instantiation of a generic class |
| 385 /// `C` is the application of `C` to a type argument list of the appropriate |
| 386 /// length where every argument is `dynamic`. For instance, the fully dynamic |
| 387 /// instantiation of `List` and `Map` is `List<dynamic>` respectively |
| 388 /// `Map<dynamic, dynamic>`. |
| 389 Type get dynamicReflectedType; |
| 390 |
345 /** | 391 /** |
346 * Invokes the named constructor and returns the result. | 392 * Invokes the named constructor and returns the result. |
347 * | 393 * |
348 * Let *c* be the class reflected by this mirror | 394 * Let *c* be the class reflected by this mirror |
349 * let *a1, ..., an* be the elements of [positionalArguments] | 395 * let *a1, ..., an* be the elements of [positionalArguments] |
350 * let *k1, ..., km* be the identifiers denoted by the elements of | 396 * let *k1, ..., km* be the identifiers denoted by the elements of |
351 * [namedArguments.keys] | 397 * [namedArguments.keys] |
352 * and let *v1, ..., vm* be the elements of [namedArguments.values]. | 398 * and let *v1, ..., vm* be the elements of [namedArguments.values]. |
353 * If [constructorName] was created from the empty string | 399 * If [constructorName] was created from the empty string |
354 * Then this method will execute the instance creation expression | 400 * Then this method will execute the instance creation expression |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 bool get isStatic; | 486 bool get isStatic; |
441 bool operator ==(other); | 487 bool operator ==(other); |
442 } | 488 } |
443 | 489 |
444 abstract class TypedefMirror implements TypeMirror { | 490 abstract class TypedefMirror implements TypeMirror { |
445 FunctionTypeMirror get referent; | 491 FunctionTypeMirror get referent; |
446 } | 492 } |
447 | 493 |
448 abstract class MethodMirror implements DeclarationMirror { | 494 abstract class MethodMirror implements DeclarationMirror { |
449 TypeMirror get returnType; // Possible RET: Type | 495 TypeMirror get returnType; // Possible RET: Type |
| 496 |
| 497 /// Returns the value specified with `hasReflectedType` in [TypeMirror], |
| 498 /// but for the return type given by the annotation of the method modeled |
| 499 /// by this mirror. |
450 bool get hasReflectedReturnType; | 500 bool get hasReflectedReturnType; |
| 501 |
| 502 /// If [hasReflectedReturnType] is true, returns the corresponding [Type]. |
| 503 /// Otherwise, an [UnsupportedError] is thrown. |
451 Type get reflectedReturnType; | 504 Type get reflectedReturnType; |
| 505 |
| 506 /// Returns the value specified with `hasDynamicReflectedType` in |
| 507 /// [ClassMirror], but for the return type given by the annotation of the |
| 508 /// method modeled by this mirror. |
| 509 bool get hasDynamicReflectedReturnType; |
| 510 |
| 511 /// If [hasDynamicReflectedReturnType] is true, returns the corresponding |
| 512 /// [Type] as specified for `dynamicReflectedType` in [ClassMirror]. |
| 513 /// Otherwise, an [UnsupportedError] is thrown. |
| 514 Type get dynamicReflectedReturnType; |
| 515 |
452 String get source; | 516 String get source; |
453 List<ParameterMirror> get parameters; | 517 List<ParameterMirror> get parameters; |
454 bool get isStatic; | 518 bool get isStatic; |
455 bool get isAbstract; | 519 bool get isAbstract; |
456 bool get isSynthetic; | 520 bool get isSynthetic; |
457 bool get isRegularMethod; | 521 bool get isRegularMethod; |
458 bool get isOperator; | 522 bool get isOperator; |
459 bool get isGetter; | 523 bool get isGetter; |
460 bool get isSetter; | 524 bool get isSetter; |
461 bool get isConstructor; | 525 bool get isConstructor; |
462 String get constructorName; | 526 String get constructorName; |
463 bool get isConstConstructor; | 527 bool get isConstConstructor; |
464 bool get isGenerativeConstructor; | 528 bool get isGenerativeConstructor; |
465 bool get isRedirectingConstructor; | 529 bool get isRedirectingConstructor; |
466 bool get isFactoryConstructor; | 530 bool get isFactoryConstructor; |
467 bool operator ==(other); | 531 bool operator ==(other); |
468 } | 532 } |
469 | 533 |
470 abstract class VariableMirror implements DeclarationMirror { | 534 abstract class VariableMirror implements DeclarationMirror { |
471 TypeMirror get type; // Possible RET: Type | 535 TypeMirror get type; // Possible RET: Type |
| 536 |
| 537 /// Returns the value specified with `hasReflectedType` in [TypeMirror], |
| 538 /// but for the type given by the annotation of the variable modeled |
| 539 /// by this mirror. |
472 bool get hasReflectedType; | 540 bool get hasReflectedType; |
| 541 |
| 542 /// If [hasReflectedType] is true, returns the corresponding [Type]. |
| 543 /// Otherwise, an [UnsupportedError] is thrown. |
473 Type get reflectedType; | 544 Type get reflectedType; |
| 545 |
| 546 /// Returns the value specified with `hasDynamicReflectedType` in |
| 547 /// [ClassMirror], but for the type given by the annotation of the |
| 548 /// variable modeled by this mirror. |
| 549 bool get hasDynamicReflectedType; |
| 550 |
| 551 /// If [hasDynamicReflectedType] is true, returns the corresponding |
| 552 /// [Type] as specified for `dynamicReflectedType` in [ClassMirror]. |
| 553 /// Otherwise, an [UnsupportedError] is thrown. |
| 554 Type get dynamicReflectedType; |
| 555 |
474 bool get isStatic; | 556 bool get isStatic; |
475 bool get isFinal; | 557 bool get isFinal; |
476 bool get isConst; | 558 bool get isConst; |
477 bool operator ==(other); | 559 bool operator ==(other); |
478 } | 560 } |
479 | 561 |
480 abstract class ParameterMirror implements VariableMirror { | 562 abstract class ParameterMirror implements VariableMirror { |
481 TypeMirror get type; // Possible RET: Type | |
482 bool get hasReflectedType; | |
483 Type get reflectedType; | |
484 bool get isOptional; | 563 bool get isOptional; |
485 bool get isNamed; | 564 bool get isNamed; |
486 bool get hasDefaultValue; | 565 bool get hasDefaultValue; |
487 Object get defaultValue; // RET: InstanceMirror | 566 Object get defaultValue; // RET: InstanceMirror |
488 } | 567 } |
489 | 568 |
490 abstract class SourceLocation { | 569 abstract class SourceLocation { |
491 int get line; | 570 int get line; |
492 int get column; | 571 int get column; |
493 Uri get sourceUri; | 572 Uri get sourceUri; |
494 } | 573 } |
495 | 574 |
496 class Comment { | 575 class Comment { |
497 final String text; | 576 final String text; |
498 final String trimmedText; | 577 final String trimmedText; |
499 final bool isDocComment; | 578 final bool isDocComment; |
500 const Comment(this.text, this.trimmedText, this.isDocComment); | 579 const Comment(this.text, this.trimmedText, this.isDocComment); |
501 } | 580 } |
| 581 |
| 582 class TypeValue<E> { |
| 583 const TypeValue(); |
| 584 Type get type => E; |
| 585 } |
OLD | NEW |