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.dart2js'); | 5 #library('mirrors.dart2js'); |
6 | 6 |
7 #import('../../../lib/compiler/compiler.dart', prefix: 'diagnostics'); | 7 #import('../../../lib/compiler/compiler.dart', prefix: 'diagnostics'); |
8 #import('../../../lib/compiler/implementation/elements/elements.dart'); | 8 #import('../../../lib/compiler/implementation/elements/elements.dart'); |
9 #import('../../../lib/compiler/implementation/apiimpl.dart', prefix: 'api'); | 9 #import('../../../lib/compiler/implementation/apiimpl.dart', prefix: 'api'); |
10 #import('../../../lib/compiler/implementation/scanner/scannerlib.dart'); | 10 #import('../../../lib/compiler/implementation/scanner/scannerlib.dart'); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 'xor': '^', | 141 'xor': '^', |
142 'or': '|', | 142 'or': '|', |
143 }; | 143 }; |
144 String newName = mapping[name]; | 144 String newName = mapping[name]; |
145 if (newName === null) { | 145 if (newName === null) { |
146 throw new Exception('Unhandled operator name: $name'); | 146 throw new Exception('Unhandled operator name: $name'); |
147 } | 147 } |
148 return newName; | 148 return newName; |
149 } | 149 } |
150 | 150 |
151 DiagnosticListener get _diagnosticListener() { | 151 DiagnosticListener get _diagnosticListener { |
152 return const Dart2JsDiagnosticListener(); | 152 return const Dart2JsDiagnosticListener(); |
153 } | 153 } |
154 | 154 |
155 class Dart2JsDiagnosticListener implements DiagnosticListener { | 155 class Dart2JsDiagnosticListener implements DiagnosticListener { |
156 const Dart2JsDiagnosticListener(); | 156 const Dart2JsDiagnosticListener(); |
157 | 157 |
158 void cancel([String reason, node, token, instruction, element]) { | 158 void cancel([String reason, node, token, instruction, element]) { |
159 print(reason); | 159 print(reason); |
160 } | 160 } |
161 | 161 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 // TODO(johnniwinther): Detect file not found | 358 // TODO(johnniwinther): Detect file not found |
359 } | 359 } |
360 _compiler.runList(librariesUri); | 360 _compiler.runList(librariesUri); |
361 } | 361 } |
362 | 362 |
363 void addLibrary(String path) { | 363 void addLibrary(String path) { |
364 var uri = cwd.resolve(nativeToUriPath(path)); | 364 var uri = cwd.resolve(nativeToUriPath(path)); |
365 _compiler.scanner.loadLibrary(uri, null); | 365 _compiler.scanner.loadLibrary(uri, null); |
366 } | 366 } |
367 | 367 |
368 MirrorSystem get mirrors() => new Dart2JsMirrorSystem(_compiler); | 368 MirrorSystem get mirrors => new Dart2JsMirrorSystem(_compiler); |
369 | 369 |
370 Future<String> compileToJavaScript() => | 370 Future<String> compileToJavaScript() => |
371 new Future<String>.immediate(_compiler.assembledCode); | 371 new Future<String>.immediate(_compiler.assembledCode); |
372 } | 372 } |
373 | 373 |
374 | 374 |
375 //------------------------------------------------------------------------------ | 375 //------------------------------------------------------------------------------ |
376 // Dart2Js specific extensions of mirror interfaces | 376 // Dart2Js specific extensions of mirror interfaces |
377 //------------------------------------------------------------------------------ | 377 //------------------------------------------------------------------------------ |
378 | 378 |
(...skipping 15 matching lines...) Expand all Loading... |
394 | 394 |
395 abstract class Dart2JsElementMirror implements Dart2JsMirror { | 395 abstract class Dart2JsElementMirror implements Dart2JsMirror { |
396 final Dart2JsMirrorSystem system; | 396 final Dart2JsMirrorSystem system; |
397 final Element _element; | 397 final Element _element; |
398 | 398 |
399 Dart2JsElementMirror(this.system, this._element) { | 399 Dart2JsElementMirror(this.system, this._element) { |
400 assert (system !== null); | 400 assert (system !== null); |
401 assert (_element !== null); | 401 assert (_element !== null); |
402 } | 402 } |
403 | 403 |
404 String get simpleName() => _element.name.slowToString(); | 404 String get simpleName => _element.name.slowToString(); |
405 | 405 |
406 Location get location() => new Dart2JsLocation( | 406 Location get location => new Dart2JsLocation( |
407 _element.getCompilationUnit().script, | 407 _element.getCompilationUnit().script, |
408 system.compiler.spanFromElement(_element)); | 408 system.compiler.spanFromElement(_element)); |
409 | 409 |
410 String toString() => _element.toString(); | 410 String toString() => _element.toString(); |
411 | 411 |
412 int hashCode() => qualifiedName.hashCode(); | 412 int hashCode() => qualifiedName.hashCode(); |
413 } | 413 } |
414 | 414 |
415 abstract class Dart2JsProxyMirror implements Dart2JsMirror { | 415 abstract class Dart2JsProxyMirror implements Dart2JsMirror { |
416 final Dart2JsMirrorSystem system; | 416 final Dart2JsMirrorSystem system; |
(...skipping 19 matching lines...) Expand all Loading... |
436 if (_libraries == null) { | 436 if (_libraries == null) { |
437 _libraries = <String, Dart2JsLibraryMirror>{}; | 437 _libraries = <String, Dart2JsLibraryMirror>{}; |
438 compiler.libraries.forEach((_, LibraryElement v) { | 438 compiler.libraries.forEach((_, LibraryElement v) { |
439 var mirror = new Dart2JsLibraryMirror(system, v); | 439 var mirror = new Dart2JsLibraryMirror(system, v); |
440 _libraries[mirror.canonicalName] = mirror; | 440 _libraries[mirror.canonicalName] = mirror; |
441 _libraryMap[v] = mirror; | 441 _libraryMap[v] = mirror; |
442 }); | 442 }); |
443 } | 443 } |
444 } | 444 } |
445 | 445 |
446 Map<Object, LibraryMirror> get libraries() { | 446 Map<Object, LibraryMirror> get libraries { |
447 _ensureLibraries(); | 447 _ensureLibraries(); |
448 return new ImmutableMapWrapper<Object, LibraryMirror>(_libraries); | 448 return new ImmutableMapWrapper<Object, LibraryMirror>(_libraries); |
449 } | 449 } |
450 | 450 |
451 Dart2JsLibraryMirror getLibrary(LibraryElement element) { | 451 Dart2JsLibraryMirror getLibrary(LibraryElement element) { |
452 return _libraryMap[element]; | 452 return _libraryMap[element]; |
453 } | 453 } |
454 | 454 |
455 Dart2JsMirrorSystem get system() => this; | 455 Dart2JsMirrorSystem get system => this; |
456 | 456 |
457 String get simpleName() => "mirror"; | 457 String get simpleName => "mirror"; |
458 String get qualifiedName() => simpleName; | 458 String get qualifiedName => simpleName; |
459 | 459 |
460 String get canonicalName() => simpleName; | 460 String get canonicalName => simpleName; |
461 | 461 |
462 // TODO(johnniwinther): Hack! Dart2JsMirrorSystem need not be a Mirror. | 462 // TODO(johnniwinther): Hack! Dart2JsMirrorSystem need not be a Mirror. |
463 int hashCode() => qualifiedName.hashCode(); | 463 int hashCode() => qualifiedName.hashCode(); |
464 } | 464 } |
465 | 465 |
466 abstract class Dart2JsObjectMirror extends Dart2JsElementMirror | 466 abstract class Dart2JsObjectMirror extends Dart2JsElementMirror |
467 implements ObjectMirror { | 467 implements ObjectMirror { |
468 Dart2JsObjectMirror(Dart2JsMirrorSystem system, Element element) | 468 Dart2JsObjectMirror(Dart2JsMirrorSystem system, Element element) |
469 : super(system, element); | 469 : super(system, element); |
470 } | 470 } |
471 | 471 |
472 class Dart2JsLibraryMirror extends Dart2JsObjectMirror | 472 class Dart2JsLibraryMirror extends Dart2JsObjectMirror |
473 implements LibraryMirror { | 473 implements LibraryMirror { |
474 Map<String, InterfaceMirror> _types; | 474 Map<String, InterfaceMirror> _types; |
475 Map<String, MemberMirror> _members; | 475 Map<String, MemberMirror> _members; |
476 | 476 |
477 Dart2JsLibraryMirror(Dart2JsMirrorSystem system, LibraryElement library) | 477 Dart2JsLibraryMirror(Dart2JsMirrorSystem system, LibraryElement library) |
478 : super(system, library); | 478 : super(system, library); |
479 | 479 |
480 LibraryElement get _library() => _element; | 480 LibraryElement get _library => _element; |
481 | 481 |
482 LibraryMirror library() => this; | 482 LibraryMirror library() => this; |
483 | 483 |
484 String get canonicalName() => simpleName; | 484 String get canonicalName => simpleName; |
485 | 485 |
486 /** | 486 /** |
487 * Returns the library name (for libraries with a #library tag) or the script | 487 * Returns the library name (for libraries with a #library tag) or the script |
488 * file name (for scripts without a #library tag). The latter case is used to | 488 * file name (for scripts without a #library tag). The latter case is used to |
489 * provide a 'library name' for scripts, to use for instance in dartdoc. | 489 * provide a 'library name' for scripts, to use for instance in dartdoc. |
490 */ | 490 */ |
491 String get simpleName() { | 491 String get simpleName { |
492 if (_library.libraryTag !== null) { | 492 if (_library.libraryTag !== null) { |
493 return _library.libraryTag.argument.dartString.slowToString(); | 493 return _library.libraryTag.argument.dartString.slowToString(); |
494 } else { | 494 } else { |
495 // Use the file name as script name. | 495 // Use the file name as script name. |
496 String path = _library.uri.path; | 496 String path = _library.uri.path; |
497 return path.substring(path.lastIndexOf('/') + 1); | 497 return path.substring(path.lastIndexOf('/') + 1); |
498 } | 498 } |
499 } | 499 } |
500 | 500 |
501 String get qualifiedName() => simpleName; | 501 String get qualifiedName => simpleName; |
502 | 502 |
503 void _ensureTypes() { | 503 void _ensureTypes() { |
504 if (_types == null) { | 504 if (_types == null) { |
505 _types = <String, InterfaceMirror>{}; | 505 _types = <String, InterfaceMirror>{}; |
506 _library.forEachExport((Element e) { | 506 _library.forEachExport((Element e) { |
507 if (e.getLibrary() == _library) { | 507 if (e.getLibrary() == _library) { |
508 if (e.isClass()) { | 508 if (e.isClass()) { |
509 e.ensureResolved(system.compiler); | 509 e.ensureResolved(system.compiler); |
510 var type = new Dart2JsInterfaceMirror.fromLibrary(this, e); | 510 var type = new Dart2JsInterfaceMirror.fromLibrary(this, e); |
511 _types[type.canonicalName] = type; | 511 _types[type.canonicalName] = type; |
(...skipping 13 matching lines...) Expand all Loading... |
525 _library.forEachExport((Element e) { | 525 _library.forEachExport((Element e) { |
526 if (!e.isClass() && !e.isTypedef()) { | 526 if (!e.isClass() && !e.isTypedef()) { |
527 for (var member in _convertElementMemberToMemberMirrors(this, e)) { | 527 for (var member in _convertElementMemberToMemberMirrors(this, e)) { |
528 _members[member.canonicalName] = member; | 528 _members[member.canonicalName] = member; |
529 } | 529 } |
530 } | 530 } |
531 }); | 531 }); |
532 } | 532 } |
533 } | 533 } |
534 | 534 |
535 Map<Object, MemberMirror> get declaredMembers() { | 535 Map<Object, MemberMirror> get declaredMembers { |
536 _ensureMembers(); | 536 _ensureMembers(); |
537 return new ImmutableMapWrapper<Object, MemberMirror>(_members); | 537 return new ImmutableMapWrapper<Object, MemberMirror>(_members); |
538 } | 538 } |
539 | 539 |
540 Map<Object, InterfaceMirror> get types() { | 540 Map<Object, InterfaceMirror> get types { |
541 _ensureTypes(); | 541 _ensureTypes(); |
542 return new ImmutableMapWrapper<Object, InterfaceMirror>(_types); | 542 return new ImmutableMapWrapper<Object, InterfaceMirror>(_types); |
543 } | 543 } |
544 | 544 |
545 Location get location() { | 545 Location get location { |
546 var script = _library.getCompilationUnit().script; | 546 var script = _library.getCompilationUnit().script; |
547 return new Dart2JsLocation( | 547 return new Dart2JsLocation( |
548 script, | 548 script, |
549 new SourceSpan(script.uri, 0, script.text.length)); | 549 new SourceSpan(script.uri, 0, script.text.length)); |
550 } | 550 } |
551 } | 551 } |
552 | 552 |
553 class Dart2JsLocation implements Location { | 553 class Dart2JsLocation implements Location { |
554 Script _script; | 554 Script _script; |
555 SourceSpan _span; | 555 SourceSpan _span; |
556 | 556 |
557 Dart2JsLocation(this._script, this._span); | 557 Dart2JsLocation(this._script, this._span); |
558 | 558 |
559 int get start() => _span.begin; | 559 int get start => _span.begin; |
560 | 560 |
561 int get end() => _span.end; | 561 int get end => _span.end; |
562 | 562 |
563 Source get source() => new Dart2JsSource(_script); | 563 Source get source => new Dart2JsSource(_script); |
564 | 564 |
565 String get text() => _script.text.substring(start, end); | 565 String get text => _script.text.substring(start, end); |
566 } | 566 } |
567 | 567 |
568 class Dart2JsSource implements Source { | 568 class Dart2JsSource implements Source { |
569 Script _script; | 569 Script _script; |
570 | 570 |
571 Dart2JsSource(this._script); | 571 Dart2JsSource(this._script); |
572 | 572 |
573 Uri get uri() => _script.uri; | 573 Uri get uri => _script.uri; |
574 | 574 |
575 String get text() => _script.text; | 575 String get text => _script.text; |
576 } | 576 } |
577 | 577 |
578 class Dart2JsParameterMirror extends Dart2JsElementMirror | 578 class Dart2JsParameterMirror extends Dart2JsElementMirror |
579 implements ParameterMirror { | 579 implements ParameterMirror { |
580 final MethodMirror _method; | 580 final MethodMirror _method; |
581 final bool isOptional; | 581 final bool isOptional; |
582 | 582 |
583 factory Dart2JsParameterMirror(Dart2JsMirrorSystem system, | 583 factory Dart2JsParameterMirror(Dart2JsMirrorSystem system, |
584 MethodMirror method, | 584 MethodMirror method, |
585 VariableElement element, | 585 VariableElement element, |
586 bool isOptional) { | 586 bool isOptional) { |
587 if (element is FieldParameterElement) { | 587 if (element is FieldParameterElement) { |
588 return new Dart2JsFieldParameterMirror(system, | 588 return new Dart2JsFieldParameterMirror(system, |
589 method, element, isOptional); | 589 method, element, isOptional); |
590 } | 590 } |
591 return new Dart2JsParameterMirror._normal(system, | 591 return new Dart2JsParameterMirror._normal(system, |
592 method, element, isOptional); | 592 method, element, isOptional); |
593 } | 593 } |
594 | 594 |
595 Dart2JsParameterMirror._normal(Dart2JsMirrorSystem system, | 595 Dart2JsParameterMirror._normal(Dart2JsMirrorSystem system, |
596 this._method, | 596 this._method, |
597 VariableElement element, | 597 VariableElement element, |
598 this.isOptional) | 598 this.isOptional) |
599 : super(system, element); | 599 : super(system, element); |
600 | 600 |
601 VariableElement get _variableElement() => _element; | 601 VariableElement get _variableElement => _element; |
602 | 602 |
603 String get canonicalName() => simpleName; | 603 String get canonicalName => simpleName; |
604 | 604 |
605 String get qualifiedName() => '${_method.qualifiedName}#${simpleName}'; | 605 String get qualifiedName => '${_method.qualifiedName}#${simpleName}'; |
606 | 606 |
607 TypeMirror get type() => _convertTypeToTypeMirror(system, | 607 TypeMirror get type => _convertTypeToTypeMirror(system, |
608 _variableElement.computeType(system.compiler), | 608 _variableElement.computeType(system.compiler), |
609 system.compiler.types.dynamicType, | 609 system.compiler.types.dynamicType, |
610 _variableElement.variables.functionSignature); | 610 _variableElement.variables.functionSignature); |
611 | 611 |
612 String get defaultValue() { | 612 String get defaultValue { |
613 if (hasDefaultValue) { | 613 if (hasDefaultValue) { |
614 SendSet expression = _variableElement.cachedNode.asSendSet(); | 614 SendSet expression = _variableElement.cachedNode.asSendSet(); |
615 return unparse(expression.arguments.head); | 615 return unparse(expression.arguments.head); |
616 } | 616 } |
617 return null; | 617 return null; |
618 } | 618 } |
619 bool get hasDefaultValue() { | 619 bool get hasDefaultValue { |
620 return _variableElement.cachedNode !== null && | 620 return _variableElement.cachedNode !== null && |
621 _variableElement.cachedNode is SendSet; | 621 _variableElement.cachedNode is SendSet; |
622 } | 622 } |
623 | 623 |
624 bool get isInitializingFormal() => false; | 624 bool get isInitializingFormal => false; |
625 | 625 |
626 FieldMirror get initializedField() => null; | 626 FieldMirror get initializedField => null; |
627 } | 627 } |
628 | 628 |
629 class Dart2JsFieldParameterMirror extends Dart2JsParameterMirror { | 629 class Dart2JsFieldParameterMirror extends Dart2JsParameterMirror { |
630 | 630 |
631 Dart2JsFieldParameterMirror(Dart2JsMirrorSystem system, | 631 Dart2JsFieldParameterMirror(Dart2JsMirrorSystem system, |
632 MethodMirror method, | 632 MethodMirror method, |
633 FieldParameterElement element, | 633 FieldParameterElement element, |
634 bool isOptional) | 634 bool isOptional) |
635 : super._normal(system, method, element, isOptional); | 635 : super._normal(system, method, element, isOptional); |
636 | 636 |
637 FieldParameterElement get _fieldParameterElement() => _element; | 637 FieldParameterElement get _fieldParameterElement => _element; |
638 | 638 |
639 TypeMirror get type() { | 639 TypeMirror get type { |
640 if (_fieldParameterElement.variables.cachedNode.type !== null) { | 640 if (_fieldParameterElement.variables.cachedNode.type !== null) { |
641 return super.type; | 641 return super.type; |
642 } | 642 } |
643 return _convertTypeToTypeMirror(system, | 643 return _convertTypeToTypeMirror(system, |
644 _fieldParameterElement.fieldElement.computeType(system.compiler), | 644 _fieldParameterElement.fieldElement.computeType(system.compiler), |
645 system.compiler.types.dynamicType, | 645 system.compiler.types.dynamicType, |
646 _variableElement.variables.functionSignature); | 646 _variableElement.variables.functionSignature); |
647 } | 647 } |
648 | 648 |
649 bool get isInitializingFormal() => true; | 649 bool get isInitializingFormal => true; |
650 | 650 |
651 FieldMirror get initializedField() => new Dart2JsFieldMirror( | 651 FieldMirror get initializedField => new Dart2JsFieldMirror( |
652 _method.surroundingDeclaration, _fieldParameterElement.fieldElement); | 652 _method.surroundingDeclaration, _fieldParameterElement.fieldElement); |
653 } | 653 } |
654 | 654 |
655 //------------------------------------------------------------------------------ | 655 //------------------------------------------------------------------------------ |
656 // Declarations | 656 // Declarations |
657 //------------------------------------------------------------------------------ | 657 //------------------------------------------------------------------------------ |
658 class Dart2JsInterfaceMirror extends Dart2JsObjectMirror | 658 class Dart2JsInterfaceMirror extends Dart2JsObjectMirror |
659 implements Dart2JsTypeMirror, InterfaceMirror { | 659 implements Dart2JsTypeMirror, InterfaceMirror { |
660 final Dart2JsLibraryMirror library; | 660 final Dart2JsLibraryMirror library; |
661 Map<String, Dart2JsMemberMirror> _members; | 661 Map<String, Dart2JsMemberMirror> _members; |
662 List<TypeVariableMirror> _typeVariables; | 662 List<TypeVariableMirror> _typeVariables; |
663 | 663 |
664 Dart2JsInterfaceMirror(Dart2JsMirrorSystem system, ClassElement _class) | 664 Dart2JsInterfaceMirror(Dart2JsMirrorSystem system, ClassElement _class) |
665 : this.library = system.getLibrary(_class.getLibrary()), | 665 : this.library = system.getLibrary(_class.getLibrary()), |
666 super(system, _class); | 666 super(system, _class); |
667 | 667 |
668 ClassElement get _class() => _element; | 668 ClassElement get _class => _element; |
669 | 669 |
670 | 670 |
671 Dart2JsInterfaceMirror.fromLibrary(Dart2JsLibraryMirror library, | 671 Dart2JsInterfaceMirror.fromLibrary(Dart2JsLibraryMirror library, |
672 ClassElement _class) | 672 ClassElement _class) |
673 : this.library = library, | 673 : this.library = library, |
674 super(library.system, _class); | 674 super(library.system, _class); |
675 | 675 |
676 String get canonicalName() => simpleName; | 676 String get canonicalName => simpleName; |
677 | 677 |
678 String get qualifiedName() => '${library.qualifiedName}.${simpleName}'; | 678 String get qualifiedName => '${library.qualifiedName}.${simpleName}'; |
679 | 679 |
680 Location get location() { | 680 Location get location { |
681 if (_class is PartialClassElement) { | 681 if (_class is PartialClassElement) { |
682 var node = _class.parseNode(_diagnosticListener); | 682 var node = _class.parseNode(_diagnosticListener); |
683 if (node !== null) { | 683 if (node !== null) { |
684 var script = _class.getCompilationUnit().script; | 684 var script = _class.getCompilationUnit().script; |
685 var span = system.compiler.spanFromNode(node, script.uri); | 685 var span = system.compiler.spanFromNode(node, script.uri); |
686 return new Dart2JsLocation(script, span); | 686 return new Dart2JsLocation(script, span); |
687 } | 687 } |
688 } | 688 } |
689 return super.location; | 689 return super.location; |
690 } | 690 } |
691 | 691 |
692 void _ensureMembers() { | 692 void _ensureMembers() { |
693 if (_members == null) { | 693 if (_members == null) { |
694 _members = <String, Dart2JsMemberMirror>{}; | 694 _members = <String, Dart2JsMemberMirror>{}; |
695 _class.localMembers.forEach((e) { | 695 _class.localMembers.forEach((e) { |
696 for (var member in _convertElementMemberToMemberMirrors(this, e)) { | 696 for (var member in _convertElementMemberToMemberMirrors(this, e)) { |
697 _members[member.canonicalName] = member; | 697 _members[member.canonicalName] = member; |
698 } | 698 } |
699 }); | 699 }); |
700 } | 700 } |
701 } | 701 } |
702 | 702 |
703 Map<Object, MemberMirror> get declaredMembers() { | 703 Map<Object, MemberMirror> get declaredMembers { |
704 _ensureMembers(); | 704 _ensureMembers(); |
705 return new ImmutableMapWrapper<Object, MemberMirror>(_members); | 705 return new ImmutableMapWrapper<Object, MemberMirror>(_members); |
706 } | 706 } |
707 | 707 |
708 bool get isObject() => _class == system.compiler.objectClass; | 708 bool get isObject => _class == system.compiler.objectClass; |
709 | 709 |
710 bool get isDynamic() => _class == system.compiler.dynamicClass; | 710 bool get isDynamic => _class == system.compiler.dynamicClass; |
711 | 711 |
712 bool get isVoid() => false; | 712 bool get isVoid => false; |
713 | 713 |
714 bool get isTypeVariable() => false; | 714 bool get isTypeVariable => false; |
715 | 715 |
716 bool get isTypedef() => false; | 716 bool get isTypedef => false; |
717 | 717 |
718 bool get isFunction() => false; | 718 bool get isFunction => false; |
719 | 719 |
720 InterfaceMirror get declaration() => this; | 720 InterfaceMirror get declaration => this; |
721 | 721 |
722 InterfaceMirror get superclass() { | 722 InterfaceMirror get superclass { |
723 if (_class.supertype != null) { | 723 if (_class.supertype != null) { |
724 return new Dart2JsInterfaceTypeMirror(system, _class.supertype); | 724 return new Dart2JsInterfaceTypeMirror(system, _class.supertype); |
725 } | 725 } |
726 return null; | 726 return null; |
727 } | 727 } |
728 | 728 |
729 Map<Object, InterfaceMirror> get interfaces() { | 729 Map<Object, InterfaceMirror> get interfaces { |
730 var map = new Map<String, InterfaceMirror>(); | 730 var map = new Map<String, InterfaceMirror>(); |
731 Link<DartType> link = _class.interfaces; | 731 Link<DartType> link = _class.interfaces; |
732 while (!link.isEmpty()) { | 732 while (!link.isEmpty()) { |
733 var type = _convertTypeToTypeMirror(system, link.head, | 733 var type = _convertTypeToTypeMirror(system, link.head, |
734 system.compiler.types.dynamicType); | 734 system.compiler.types.dynamicType); |
735 map[type.canonicalName] = type; | 735 map[type.canonicalName] = type; |
736 link = link.tail; | 736 link = link.tail; |
737 } | 737 } |
738 return new ImmutableMapWrapper<Object, InterfaceMirror>(map); | 738 return new ImmutableMapWrapper<Object, InterfaceMirror>(map); |
739 } | 739 } |
740 | 740 |
741 bool get isClass() => !_class.isInterface(); | 741 bool get isClass => !_class.isInterface(); |
742 | 742 |
743 bool get isInterface() => _class.isInterface(); | 743 bool get isInterface => _class.isInterface(); |
744 | 744 |
745 bool get isPrivate() => _isPrivate(simpleName); | 745 bool get isPrivate => _isPrivate(simpleName); |
746 | 746 |
747 bool get isDeclaration() => true; | 747 bool get isDeclaration => true; |
748 | 748 |
749 List<TypeMirror> get typeArguments() { | 749 List<TypeMirror> get typeArguments { |
750 throw new UnsupportedOperationException( | 750 throw new UnsupportedOperationException( |
751 'Declarations do not have type arguments'); | 751 'Declarations do not have type arguments'); |
752 } | 752 } |
753 | 753 |
754 List<TypeVariableMirror> get typeVariables() { | 754 List<TypeVariableMirror> get typeVariables { |
755 if (_typeVariables == null) { | 755 if (_typeVariables == null) { |
756 _typeVariables = <TypeVariableMirror>[]; | 756 _typeVariables = <TypeVariableMirror>[]; |
757 _class.ensureResolved(system.compiler); | 757 _class.ensureResolved(system.compiler); |
758 for (TypeVariableType typeVariable in _class.typeVariables) { | 758 for (TypeVariableType typeVariable in _class.typeVariables) { |
759 _typeVariables.add( | 759 _typeVariables.add( |
760 new Dart2JsTypeVariableMirror(system, typeVariable)); | 760 new Dart2JsTypeVariableMirror(system, typeVariable)); |
761 } | 761 } |
762 } | 762 } |
763 return _typeVariables; | 763 return _typeVariables; |
764 } | 764 } |
765 | 765 |
766 Map<Object, MethodMirror> get constructors() { | 766 Map<Object, MethodMirror> get constructors { |
767 _ensureMembers(); | 767 _ensureMembers(); |
768 return new AsFilteredImmutableMap<Object, MemberMirror, MethodMirror>( | 768 return new AsFilteredImmutableMap<Object, MemberMirror, MethodMirror>( |
769 _members, (m) => m.isConstructor ? m : null); | 769 _members, (m) => m.isConstructor ? m : null); |
770 } | 770 } |
771 | 771 |
772 /** | 772 /** |
773 * Returns the default type for this interface. | 773 * Returns the default type for this interface. |
774 */ | 774 */ |
775 InterfaceMirror get defaultType() { | 775 InterfaceMirror get defaultType { |
776 if (_class.defaultClass != null) { | 776 if (_class.defaultClass != null) { |
777 return new Dart2JsInterfaceTypeMirror(system, _class.defaultClass); | 777 return new Dart2JsInterfaceTypeMirror(system, _class.defaultClass); |
778 } | 778 } |
779 return null; | 779 return null; |
780 } | 780 } |
781 | 781 |
782 bool operator ==(Object other) { | 782 bool operator ==(Object other) { |
783 if (this === other) { | 783 if (this === other) { |
784 return true; | 784 return true; |
785 } | 785 } |
(...skipping 18 matching lines...) Expand all Loading... |
804 | 804 |
805 Dart2JsTypedefMirror(Dart2JsMirrorSystem system, TypedefType _typedef) | 805 Dart2JsTypedefMirror(Dart2JsMirrorSystem system, TypedefType _typedef) |
806 : this._library = system.getLibrary(_typedef.element.getLibrary()), | 806 : this._library = system.getLibrary(_typedef.element.getLibrary()), |
807 super(system, _typedef); | 807 super(system, _typedef); |
808 | 808 |
809 Dart2JsTypedefMirror.fromLibrary(Dart2JsLibraryMirror library, | 809 Dart2JsTypedefMirror.fromLibrary(Dart2JsLibraryMirror library, |
810 TypedefType _typedef) | 810 TypedefType _typedef) |
811 : this._library = library, | 811 : this._library = library, |
812 super(library.system, _typedef); | 812 super(library.system, _typedef); |
813 | 813 |
814 TypedefType get _typedef() => _type; | 814 TypedefType get _typedef => _type; |
815 | 815 |
816 String get canonicalName() => simpleName; | 816 String get canonicalName => simpleName; |
817 | 817 |
818 String get qualifiedName() => '${library.qualifiedName}.${simpleName}'; | 818 String get qualifiedName => '${library.qualifiedName}.${simpleName}'; |
819 | 819 |
820 Location get location() { | 820 Location get location { |
821 var node = _typedef.element.parseNode(_diagnosticListener); | 821 var node = _typedef.element.parseNode(_diagnosticListener); |
822 if (node !== null) { | 822 if (node !== null) { |
823 var script = _typedef.element.getCompilationUnit().script; | 823 var script = _typedef.element.getCompilationUnit().script; |
824 var span = system.compiler.spanFromNode(node, script.uri); | 824 var span = system.compiler.spanFromNode(node, script.uri); |
825 return new Dart2JsLocation(script, span); | 825 return new Dart2JsLocation(script, span); |
826 } | 826 } |
827 return super.location; | 827 return super.location; |
828 } | 828 } |
829 | 829 |
830 LibraryMirror get library() => _library; | 830 LibraryMirror get library => _library; |
831 | 831 |
832 bool get isObject() => false; | 832 bool get isObject => false; |
833 | 833 |
834 bool get isDynamic() => false; | 834 bool get isDynamic => false; |
835 | 835 |
836 bool get isVoid() => false; | 836 bool get isVoid => false; |
837 | 837 |
838 bool get isTypeVariable() => false; | 838 bool get isTypeVariable => false; |
839 | 839 |
840 bool get isTypedef() => true; | 840 bool get isTypedef => true; |
841 | 841 |
842 bool get isFunction() => false; | 842 bool get isFunction => false; |
843 | 843 |
844 List<TypeMirror> get typeArguments() { | 844 List<TypeMirror> get typeArguments { |
845 throw new UnsupportedOperationException( | 845 throw new UnsupportedOperationException( |
846 'Declarations do not have type arguments'); | 846 'Declarations do not have type arguments'); |
847 } | 847 } |
848 | 848 |
849 List<TypeVariableMirror> get typeVariables() { | 849 List<TypeVariableMirror> get typeVariables { |
850 if (_typeVariables == null) { | 850 if (_typeVariables == null) { |
851 _typeVariables = <TypeVariableMirror>[]; | 851 _typeVariables = <TypeVariableMirror>[]; |
852 for (TypeVariableType typeVariable in _typedef.typeArguments) { | 852 for (TypeVariableType typeVariable in _typedef.typeArguments) { |
853 _typeVariables.add( | 853 _typeVariables.add( |
854 new Dart2JsTypeVariableMirror(system, typeVariable)); | 854 new Dart2JsTypeVariableMirror(system, typeVariable)); |
855 } | 855 } |
856 } | 856 } |
857 return _typeVariables; | 857 return _typeVariables; |
858 } | 858 } |
859 | 859 |
860 TypeMirror get definition() { | 860 TypeMirror get definition { |
861 if (_definition === null) { | 861 if (_definition === null) { |
862 // TODO(johnniwinther): Should be [ensureResolved]. | 862 // TODO(johnniwinther): Should be [ensureResolved]. |
863 system.compiler.resolveTypedef(_typedef.element); | 863 system.compiler.resolveTypedef(_typedef.element); |
864 _definition = _convertTypeToTypeMirror( | 864 _definition = _convertTypeToTypeMirror( |
865 system, | 865 system, |
866 _typedef.element.alias, | 866 _typedef.element.alias, |
867 system.compiler.types.dynamicType, | 867 system.compiler.types.dynamicType, |
868 _typedef.element.functionSignature); | 868 _typedef.element.functionSignature); |
869 } | 869 } |
870 return _definition; | 870 return _definition; |
871 } | 871 } |
872 | 872 |
873 Map<Object, MemberMirror> get declaredMembers() => | 873 Map<Object, MemberMirror> get declaredMembers => |
874 const <String, MemberMirror>{}; | 874 const <String, MemberMirror>{}; |
875 | 875 |
876 InterfaceMirror get declaration() => this; | 876 InterfaceMirror get declaration => this; |
877 | 877 |
878 // TODO(johnniwinther): How should a typedef respond to these? | 878 // TODO(johnniwinther): How should a typedef respond to these? |
879 InterfaceMirror get superclass() => null; | 879 InterfaceMirror get superclass => null; |
880 | 880 |
881 Map<Object, InterfaceMirror> get interfaces() => | 881 Map<Object, InterfaceMirror> get interfaces => |
882 const <String, InterfaceMirror>{}; | 882 const <String, InterfaceMirror>{}; |
883 | 883 |
884 bool get isClass() => false; | 884 bool get isClass => false; |
885 | 885 |
886 bool get isInterface() => false; | 886 bool get isInterface => false; |
887 | 887 |
888 bool get isPrivate() => _isPrivate(simpleName); | 888 bool get isPrivate => _isPrivate(simpleName); |
889 | 889 |
890 bool get isDeclaration() => true; | 890 bool get isDeclaration => true; |
891 | 891 |
892 Map<Object, MethodMirror> get constructors() => | 892 Map<Object, MethodMirror> get constructors => |
893 const <String, MethodMirror>{}; | 893 const <String, MethodMirror>{}; |
894 | 894 |
895 InterfaceMirror get defaultType() => null; | 895 InterfaceMirror get defaultType => null; |
896 } | 896 } |
897 | 897 |
898 class Dart2JsTypeVariableMirror extends Dart2JsTypeElementMirror | 898 class Dart2JsTypeVariableMirror extends Dart2JsTypeElementMirror |
899 implements TypeVariableMirror { | 899 implements TypeVariableMirror { |
900 final TypeVariableType _typeVariableType; | 900 final TypeVariableType _typeVariableType; |
901 InterfaceMirror _declarer; | 901 InterfaceMirror _declarer; |
902 | 902 |
903 Dart2JsTypeVariableMirror(Dart2JsMirrorSystem system, | 903 Dart2JsTypeVariableMirror(Dart2JsMirrorSystem system, |
904 TypeVariableType typeVariableType) | 904 TypeVariableType typeVariableType) |
905 : this._typeVariableType = typeVariableType, | 905 : this._typeVariableType = typeVariableType, |
906 super(system, typeVariableType) { | 906 super(system, typeVariableType) { |
907 assert(_typeVariableType !== null); | 907 assert(_typeVariableType !== null); |
908 } | 908 } |
909 | 909 |
910 | 910 |
911 String get qualifiedName() => '${declarer.qualifiedName}.${simpleName}'; | 911 String get qualifiedName => '${declarer.qualifiedName}.${simpleName}'; |
912 | 912 |
913 InterfaceMirror get declarer() { | 913 InterfaceMirror get declarer { |
914 if (_declarer === null) { | 914 if (_declarer === null) { |
915 if (_typeVariableType.element.enclosingElement.isClass()) { | 915 if (_typeVariableType.element.enclosingElement.isClass()) { |
916 _declarer = new Dart2JsInterfaceMirror(system, | 916 _declarer = new Dart2JsInterfaceMirror(system, |
917 _typeVariableType.element.enclosingElement); | 917 _typeVariableType.element.enclosingElement); |
918 } else if (_typeVariableType.element.enclosingElement.isTypedef()) { | 918 } else if (_typeVariableType.element.enclosingElement.isTypedef()) { |
919 _declarer = new Dart2JsTypedefMirror(system, | 919 _declarer = new Dart2JsTypedefMirror(system, |
920 _typeVariableType.element.enclosingElement.computeType( | 920 _typeVariableType.element.enclosingElement.computeType( |
921 system.compiler)); | 921 system.compiler)); |
922 } | 922 } |
923 } | 923 } |
924 return _declarer; | 924 return _declarer; |
925 } | 925 } |
926 | 926 |
927 LibraryMirror get library() => declarer.library; | 927 LibraryMirror get library => declarer.library; |
928 | 928 |
929 bool get isObject() => false; | 929 bool get isObject => false; |
930 | 930 |
931 bool get isDynamic() => false; | 931 bool get isDynamic => false; |
932 | 932 |
933 bool get isVoid() => false; | 933 bool get isVoid => false; |
934 | 934 |
935 bool get isTypeVariable() => true; | 935 bool get isTypeVariable => true; |
936 | 936 |
937 bool get isTypedef() => false; | 937 bool get isTypedef => false; |
938 | 938 |
939 bool get isFunction() => false; | 939 bool get isFunction => false; |
940 | 940 |
941 TypeMirror get bound() => _convertTypeToTypeMirror( | 941 TypeMirror get bound => _convertTypeToTypeMirror( |
942 system, | 942 system, |
943 _typeVariableType.element.bound, | 943 _typeVariableType.element.bound, |
944 system.compiler.objectClass.computeType(system.compiler)); | 944 system.compiler.objectClass.computeType(system.compiler)); |
945 | 945 |
946 bool operator ==(Object other) { | 946 bool operator ==(Object other) { |
947 if (this === other) { | 947 if (this === other) { |
948 return true; | 948 return true; |
949 } | 949 } |
950 if (other is! TypeVariableMirror) { | 950 if (other is! TypeVariableMirror) { |
951 return false; | 951 return false; |
(...skipping 10 matching lines...) Expand all Loading... |
962 // Types | 962 // Types |
963 //------------------------------------------------------------------------------ | 963 //------------------------------------------------------------------------------ |
964 | 964 |
965 abstract class Dart2JsTypeElementMirror extends Dart2JsProxyMirror | 965 abstract class Dart2JsTypeElementMirror extends Dart2JsProxyMirror |
966 implements Dart2JsTypeMirror { | 966 implements Dart2JsTypeMirror { |
967 final DartType _type; | 967 final DartType _type; |
968 | 968 |
969 Dart2JsTypeElementMirror(Dart2JsMirrorSystem system, this._type) | 969 Dart2JsTypeElementMirror(Dart2JsMirrorSystem system, this._type) |
970 : super(system); | 970 : super(system); |
971 | 971 |
972 String get simpleName() => _type.name.slowToString(); | 972 String get simpleName => _type.name.slowToString(); |
973 | 973 |
974 String get canonicalName() => simpleName; | 974 String get canonicalName => simpleName; |
975 | 975 |
976 Location get location() { | 976 Location get location { |
977 var script = _type.element.getCompilationUnit().script; | 977 var script = _type.element.getCompilationUnit().script; |
978 return new Dart2JsLocation(script, | 978 return new Dart2JsLocation(script, |
979 system.compiler.spanFromElement(_type.element)); | 979 system.compiler.spanFromElement(_type.element)); |
980 } | 980 } |
981 | 981 |
982 LibraryMirror get library() { | 982 LibraryMirror get library { |
983 return system.getLibrary(_type.element.getLibrary()); | 983 return system.getLibrary(_type.element.getLibrary()); |
984 } | 984 } |
985 | 985 |
986 String toString() => _type.element.toString(); | 986 String toString() => _type.element.toString(); |
987 } | 987 } |
988 | 988 |
989 class Dart2JsInterfaceTypeMirror extends Dart2JsTypeElementMirror | 989 class Dart2JsInterfaceTypeMirror extends Dart2JsTypeElementMirror |
990 implements InterfaceMirror { | 990 implements InterfaceMirror { |
991 List<TypeMirror> _typeArguments; | 991 List<TypeMirror> _typeArguments; |
992 | 992 |
993 Dart2JsInterfaceTypeMirror(Dart2JsMirrorSystem system, | 993 Dart2JsInterfaceTypeMirror(Dart2JsMirrorSystem system, |
994 InterfaceType interfaceType) | 994 InterfaceType interfaceType) |
995 : super(system, interfaceType); | 995 : super(system, interfaceType); |
996 | 996 |
997 InterfaceType get _interfaceType() => _type; | 997 InterfaceType get _interfaceType => _type; |
998 | 998 |
999 String get qualifiedName() => declaration.qualifiedName; | 999 String get qualifiedName => declaration.qualifiedName; |
1000 | 1000 |
1001 // TODO(johnniwinther): Substitute type arguments for type variables. | 1001 // TODO(johnniwinther): Substitute type arguments for type variables. |
1002 Map<Object, MemberMirror> get declaredMembers() => declaration.declaredMembers
; | 1002 Map<Object, MemberMirror> get declaredMembers => declaration.declaredMembers; |
1003 | 1003 |
1004 bool get isObject() => system.compiler.objectClass == _type.element; | 1004 bool get isObject => system.compiler.objectClass == _type.element; |
1005 | 1005 |
1006 bool get isDynamic() => system.compiler.dynamicClass == _type.element; | 1006 bool get isDynamic => system.compiler.dynamicClass == _type.element; |
1007 | 1007 |
1008 bool get isTypeVariable() => false; | 1008 bool get isTypeVariable => false; |
1009 | 1009 |
1010 bool get isVoid() => false; | 1010 bool get isVoid => false; |
1011 | 1011 |
1012 bool get isTypedef() => false; | 1012 bool get isTypedef => false; |
1013 | 1013 |
1014 bool get isFunction() => false; | 1014 bool get isFunction => false; |
1015 | 1015 |
1016 InterfaceMirror get declaration() | 1016 InterfaceMirror get declaration |
1017 => new Dart2JsInterfaceMirror(system, _type.element); | 1017 => new Dart2JsInterfaceMirror(system, _type.element); |
1018 | 1018 |
1019 // TODO(johnniwinther): Substitute type arguments for type variables. | 1019 // TODO(johnniwinther): Substitute type arguments for type variables. |
1020 InterfaceMirror get superclass() => declaration.superclass; | 1020 InterfaceMirror get superclass => declaration.superclass; |
1021 | 1021 |
1022 // TODO(johnniwinther): Substitute type arguments for type variables. | 1022 // TODO(johnniwinther): Substitute type arguments for type variables. |
1023 Map<Object, InterfaceMirror> get interfaces() => declaration.interfaces; | 1023 Map<Object, InterfaceMirror> get interfaces => declaration.interfaces; |
1024 | 1024 |
1025 bool get isClass() => declaration.isClass; | 1025 bool get isClass => declaration.isClass; |
1026 | 1026 |
1027 bool get isInterface() => declaration.isInterface; | 1027 bool get isInterface => declaration.isInterface; |
1028 | 1028 |
1029 bool get isPrivate() => declaration.isPrivate; | 1029 bool get isPrivate => declaration.isPrivate; |
1030 | 1030 |
1031 bool get isDeclaration() => false; | 1031 bool get isDeclaration => false; |
1032 | 1032 |
1033 List<TypeMirror> get typeArguments() { | 1033 List<TypeMirror> get typeArguments { |
1034 if (_typeArguments == null) { | 1034 if (_typeArguments == null) { |
1035 _typeArguments = <TypeMirror>[]; | 1035 _typeArguments = <TypeMirror>[]; |
1036 Link<DartType> type = _interfaceType.arguments; | 1036 Link<DartType> type = _interfaceType.arguments; |
1037 while (type != null && type.head != null) { | 1037 while (type != null && type.head != null) { |
1038 _typeArguments.add(_convertTypeToTypeMirror(system, type.head, | 1038 _typeArguments.add(_convertTypeToTypeMirror(system, type.head, |
1039 system.compiler.types.dynamicType)); | 1039 system.compiler.types.dynamicType)); |
1040 type = type.tail; | 1040 type = type.tail; |
1041 } | 1041 } |
1042 } | 1042 } |
1043 return _typeArguments; | 1043 return _typeArguments; |
1044 } | 1044 } |
1045 | 1045 |
1046 List<TypeVariableMirror> get typeVariables() => declaration.typeVariables; | 1046 List<TypeVariableMirror> get typeVariables => declaration.typeVariables; |
1047 | 1047 |
1048 // TODO(johnniwinther): Substitute type arguments for type variables. | 1048 // TODO(johnniwinther): Substitute type arguments for type variables. |
1049 Map<Object, MethodMirror> get constructors() => declaration.constructors; | 1049 Map<Object, MethodMirror> get constructors => declaration.constructors; |
1050 | 1050 |
1051 // TODO(johnniwinther): Substitute type arguments for type variables? | 1051 // TODO(johnniwinther): Substitute type arguments for type variables? |
1052 InterfaceMirror get defaultType() => declaration.defaultType; | 1052 InterfaceMirror get defaultType => declaration.defaultType; |
1053 | 1053 |
1054 bool operator ==(Object other) { | 1054 bool operator ==(Object other) { |
1055 if (this === other) { | 1055 if (this === other) { |
1056 return true; | 1056 return true; |
1057 } | 1057 } |
1058 if (other is! InterfaceMirror) { | 1058 if (other is! InterfaceMirror) { |
1059 return false; | 1059 return false; |
1060 } | 1060 } |
1061 if (other.isDeclaration) { | 1061 if (other.isDeclaration) { |
1062 return false; | 1062 return false; |
(...skipping 17 matching lines...) Expand all Loading... |
1080 implements FunctionTypeMirror { | 1080 implements FunctionTypeMirror { |
1081 final FunctionSignature _functionSignature; | 1081 final FunctionSignature _functionSignature; |
1082 List<ParameterMirror> _parameters; | 1082 List<ParameterMirror> _parameters; |
1083 | 1083 |
1084 Dart2JsFunctionTypeMirror(Dart2JsMirrorSystem system, | 1084 Dart2JsFunctionTypeMirror(Dart2JsMirrorSystem system, |
1085 FunctionType functionType, this._functionSignature) | 1085 FunctionType functionType, this._functionSignature) |
1086 : super(system, functionType) { | 1086 : super(system, functionType) { |
1087 assert (_functionSignature !== null); | 1087 assert (_functionSignature !== null); |
1088 } | 1088 } |
1089 | 1089 |
1090 FunctionType get _functionType() => _type; | 1090 FunctionType get _functionType => _type; |
1091 | 1091 |
1092 // TODO(johnniwinther): Is this the qualified name of a function type? | 1092 // TODO(johnniwinther): Is this the qualified name of a function type? |
1093 String get qualifiedName() => declaration.qualifiedName; | 1093 String get qualifiedName => declaration.qualifiedName; |
1094 | 1094 |
1095 // TODO(johnniwinther): Substitute type arguments for type variables. | 1095 // TODO(johnniwinther): Substitute type arguments for type variables. |
1096 Map<Object, MemberMirror> get declaredMembers() { | 1096 Map<Object, MemberMirror> get declaredMembers { |
1097 var method = callMethod; | 1097 var method = callMethod; |
1098 if (method !== null) { | 1098 if (method !== null) { |
1099 var map = new Map<String, MemberMirror>.from( | 1099 var map = new Map<String, MemberMirror>.from( |
1100 declaration.declaredMembers); | 1100 declaration.declaredMembers); |
1101 var name = method.qualifiedName; | 1101 var name = method.qualifiedName; |
1102 map[name] = method; | 1102 map[name] = method; |
1103 Function func = null; | 1103 Function func = null; |
1104 return new ImmutableMapWrapper<Object, MemberMirror>(map); | 1104 return new ImmutableMapWrapper<Object, MemberMirror>(map); |
1105 } | 1105 } |
1106 return declaration.declaredMembers; | 1106 return declaration.declaredMembers; |
1107 } | 1107 } |
1108 | 1108 |
1109 bool get isObject() => system.compiler.objectClass == _type.element; | 1109 bool get isObject => system.compiler.objectClass == _type.element; |
1110 | 1110 |
1111 bool get isDynamic() => system.compiler.dynamicClass == _type.element; | 1111 bool get isDynamic => system.compiler.dynamicClass == _type.element; |
1112 | 1112 |
1113 bool get isVoid() => false; | 1113 bool get isVoid => false; |
1114 | 1114 |
1115 bool get isTypeVariable() => false; | 1115 bool get isTypeVariable => false; |
1116 | 1116 |
1117 bool get isTypedef() => false; | 1117 bool get isTypedef => false; |
1118 | 1118 |
1119 bool get isFunction() => true; | 1119 bool get isFunction => true; |
1120 | 1120 |
1121 MethodMirror get callMethod() => _convertElementMethodToMethodMirror( | 1121 MethodMirror get callMethod => _convertElementMethodToMethodMirror( |
1122 system.getLibrary(_functionType.element.getLibrary()), | 1122 system.getLibrary(_functionType.element.getLibrary()), |
1123 _functionType.element); | 1123 _functionType.element); |
1124 | 1124 |
1125 InterfaceMirror get declaration() | 1125 InterfaceMirror get declaration |
1126 => new Dart2JsInterfaceMirror(system, system.compiler.functionClass); | 1126 => new Dart2JsInterfaceMirror(system, system.compiler.functionClass); |
1127 | 1127 |
1128 // TODO(johnniwinther): Substitute type arguments for type variables. | 1128 // TODO(johnniwinther): Substitute type arguments for type variables. |
1129 InterfaceMirror get superclass() => declaration.superclass; | 1129 InterfaceMirror get superclass => declaration.superclass; |
1130 | 1130 |
1131 // TODO(johnniwinther): Substitute type arguments for type variables. | 1131 // TODO(johnniwinther): Substitute type arguments for type variables. |
1132 Map<Object, InterfaceMirror> get interfaces() => declaration.interfaces; | 1132 Map<Object, InterfaceMirror> get interfaces => declaration.interfaces; |
1133 | 1133 |
1134 bool get isClass() => declaration.isClass; | 1134 bool get isClass => declaration.isClass; |
1135 | 1135 |
1136 bool get isInterface() => declaration.isInterface; | 1136 bool get isInterface => declaration.isInterface; |
1137 | 1137 |
1138 bool get isPrivate() => declaration.isPrivate; | 1138 bool get isPrivate => declaration.isPrivate; |
1139 | 1139 |
1140 bool get isDeclaration() => false; | 1140 bool get isDeclaration => false; |
1141 | 1141 |
1142 List<TypeMirror> get typeArguments() => const <TypeMirror>[]; | 1142 List<TypeMirror> get typeArguments => const <TypeMirror>[]; |
1143 | 1143 |
1144 List<TypeVariableMirror> get typeVariables() => declaration.typeVariables; | 1144 List<TypeVariableMirror> get typeVariables => declaration.typeVariables; |
1145 | 1145 |
1146 Map<Object, MethodMirror> get constructors() => | 1146 Map<Object, MethodMirror> get constructors => |
1147 <String, MethodMirror>{}; | 1147 <String, MethodMirror>{}; |
1148 | 1148 |
1149 InterfaceMirror get defaultType() => null; | 1149 InterfaceMirror get defaultType => null; |
1150 | 1150 |
1151 TypeMirror get returnType() { | 1151 TypeMirror get returnType { |
1152 return _convertTypeToTypeMirror(system, _functionType.returnType, | 1152 return _convertTypeToTypeMirror(system, _functionType.returnType, |
1153 system.compiler.types.dynamicType); | 1153 system.compiler.types.dynamicType); |
1154 } | 1154 } |
1155 | 1155 |
1156 List<ParameterMirror> get parameters() { | 1156 List<ParameterMirror> get parameters { |
1157 if (_parameters === null) { | 1157 if (_parameters === null) { |
1158 _parameters = _parametersFromFunctionSignature(system, callMethod, | 1158 _parameters = _parametersFromFunctionSignature(system, callMethod, |
1159 _functionSignature); | 1159 _functionSignature); |
1160 } | 1160 } |
1161 return _parameters; | 1161 return _parameters; |
1162 } | 1162 } |
1163 } | 1163 } |
1164 | 1164 |
1165 class Dart2JsVoidMirror extends Dart2JsTypeElementMirror { | 1165 class Dart2JsVoidMirror extends Dart2JsTypeElementMirror { |
1166 | 1166 |
1167 Dart2JsVoidMirror(Dart2JsMirrorSystem system, VoidType voidType) | 1167 Dart2JsVoidMirror(Dart2JsMirrorSystem system, VoidType voidType) |
1168 : super(system, voidType); | 1168 : super(system, voidType); |
1169 | 1169 |
1170 VoidType get _voidType() => _type; | 1170 VoidType get _voidType => _type; |
1171 | 1171 |
1172 String get qualifiedName() => simpleName; | 1172 String get qualifiedName => simpleName; |
1173 | 1173 |
1174 /** | 1174 /** |
1175 * The void type has no location. | 1175 * The void type has no location. |
1176 */ | 1176 */ |
1177 Location get location() => null; | 1177 Location get location => null; |
1178 | 1178 |
1179 /** | 1179 /** |
1180 * The void type has no library. | 1180 * The void type has no library. |
1181 */ | 1181 */ |
1182 LibraryMirror get library() => null; | 1182 LibraryMirror get library => null; |
1183 | 1183 |
1184 bool get isObject() => false; | 1184 bool get isObject => false; |
1185 | 1185 |
1186 bool get isVoid() => true; | 1186 bool get isVoid => true; |
1187 | 1187 |
1188 bool get isDynamic() => false; | 1188 bool get isDynamic => false; |
1189 | 1189 |
1190 bool get isTypeVariable() => false; | 1190 bool get isTypeVariable => false; |
1191 | 1191 |
1192 bool get isTypedef() => false; | 1192 bool get isTypedef => false; |
1193 | 1193 |
1194 bool get isFunction() => false; | 1194 bool get isFunction => false; |
1195 | 1195 |
1196 bool operator ==(Object other) { | 1196 bool operator ==(Object other) { |
1197 if (this === other) { | 1197 if (this === other) { |
1198 return true; | 1198 return true; |
1199 } | 1199 } |
1200 if (other is! TypeMirror) { | 1200 if (other is! TypeMirror) { |
1201 return false; | 1201 return false; |
1202 } | 1202 } |
1203 return other.isVoid; | 1203 return other.isVoid; |
1204 } | 1204 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1268 _kind = Dart2JsMethodKind.OPERATOR; | 1268 _kind = Dart2JsMethodKind.OPERATOR; |
1269 _operatorName = _getOperatorFromOperatorName(str); | 1269 _operatorName = _getOperatorFromOperatorName(str); |
1270 // canonical name is 'operator operatorName' | 1270 // canonical name is 'operator operatorName' |
1271 _canonicalName = 'operator $_operatorName'; | 1271 _canonicalName = 'operator $_operatorName'; |
1272 } else { | 1272 } else { |
1273 _kind = Dart2JsMethodKind.NORMAL; | 1273 _kind = Dart2JsMethodKind.NORMAL; |
1274 _canonicalName = _name; | 1274 _canonicalName = _name; |
1275 } | 1275 } |
1276 } | 1276 } |
1277 | 1277 |
1278 FunctionElement get _function() => _element; | 1278 FunctionElement get _function => _element; |
1279 | 1279 |
1280 String get simpleName() => _name; | 1280 String get simpleName => _name; |
1281 | 1281 |
1282 String get qualifiedName() | 1282 String get qualifiedName |
1283 => '${surroundingDeclaration.qualifiedName}.$canonicalName'; | 1283 => '${surroundingDeclaration.qualifiedName}.$canonicalName'; |
1284 | 1284 |
1285 String get canonicalName() => _canonicalName; | 1285 String get canonicalName => _canonicalName; |
1286 | 1286 |
1287 ObjectMirror get surroundingDeclaration() => _objectMirror; | 1287 ObjectMirror get surroundingDeclaration => _objectMirror; |
1288 | 1288 |
1289 bool get isTopLevel() => _objectMirror is LibraryMirror; | 1289 bool get isTopLevel => _objectMirror is LibraryMirror; |
1290 | 1290 |
1291 bool get isConstructor() | 1291 bool get isConstructor |
1292 => _kind == Dart2JsMethodKind.CONSTRUCTOR || isConst || isFactory; | 1292 => _kind == Dart2JsMethodKind.CONSTRUCTOR || isConst || isFactory; |
1293 | 1293 |
1294 bool get isField() => false; | 1294 bool get isField => false; |
1295 | 1295 |
1296 bool get isMethod() => !isConstructor; | 1296 bool get isMethod => !isConstructor; |
1297 | 1297 |
1298 bool get isPrivate() => _isPrivate(simpleName); | 1298 bool get isPrivate => _isPrivate(simpleName); |
1299 | 1299 |
1300 bool get isStatic() => | 1300 bool get isStatic => |
1301 _function.modifiers !== null && _function.modifiers.isStatic(); | 1301 _function.modifiers !== null && _function.modifiers.isStatic(); |
1302 | 1302 |
1303 List<ParameterMirror> get parameters() { | 1303 List<ParameterMirror> get parameters { |
1304 return _parametersFromFunctionSignature(system, this, | 1304 return _parametersFromFunctionSignature(system, this, |
1305 _function.computeSignature(system.compiler)); | 1305 _function.computeSignature(system.compiler)); |
1306 } | 1306 } |
1307 | 1307 |
1308 TypeMirror get returnType() => _convertTypeToTypeMirror( | 1308 TypeMirror get returnType => _convertTypeToTypeMirror( |
1309 system, _function.computeSignature(system.compiler).returnType, | 1309 system, _function.computeSignature(system.compiler).returnType, |
1310 system.compiler.types.dynamicType); | 1310 system.compiler.types.dynamicType); |
1311 | 1311 |
1312 bool get isConst() => _kind == Dart2JsMethodKind.CONST; | 1312 bool get isConst => _kind == Dart2JsMethodKind.CONST; |
1313 | 1313 |
1314 bool get isFactory() => _kind == Dart2JsMethodKind.FACTORY; | 1314 bool get isFactory => _kind == Dart2JsMethodKind.FACTORY; |
1315 | 1315 |
1316 String get constructorName() => _constructorName; | 1316 String get constructorName => _constructorName; |
1317 | 1317 |
1318 bool get isGetter() => _kind == Dart2JsMethodKind.GETTER; | 1318 bool get isGetter => _kind == Dart2JsMethodKind.GETTER; |
1319 | 1319 |
1320 bool get isSetter() => _kind == Dart2JsMethodKind.SETTER; | 1320 bool get isSetter => _kind == Dart2JsMethodKind.SETTER; |
1321 | 1321 |
1322 bool get isOperator() => _kind == Dart2JsMethodKind.OPERATOR; | 1322 bool get isOperator => _kind == Dart2JsMethodKind.OPERATOR; |
1323 | 1323 |
1324 String get operatorName() => _operatorName; | 1324 String get operatorName => _operatorName; |
1325 | 1325 |
1326 Location get location() { | 1326 Location get location { |
1327 var node = _function.parseNode(_diagnosticListener); | 1327 var node = _function.parseNode(_diagnosticListener); |
1328 if (node !== null) { | 1328 if (node !== null) { |
1329 var script = _function.getCompilationUnit().script; | 1329 var script = _function.getCompilationUnit().script; |
1330 if (_function.isPatched) { | 1330 if (_function.isPatched) { |
1331 // TODO(ager): This should not be necessary when patch | 1331 // TODO(ager): This should not be necessary when patch |
1332 // support has been reworked. | 1332 // support has been reworked. |
1333 script = _function.patch.getCompilationUnit().script; | 1333 script = _function.patch.getCompilationUnit().script; |
1334 } | 1334 } |
1335 var span = system.compiler.spanFromNode(node, script.uri); | 1335 var span = system.compiler.spanFromNode(node, script.uri); |
1336 return new Dart2JsLocation(script, span); | 1336 return new Dart2JsLocation(script, span); |
1337 } | 1337 } |
1338 return super.location; | 1338 return super.location; |
1339 } | 1339 } |
1340 | 1340 |
1341 } | 1341 } |
1342 | 1342 |
1343 class Dart2JsFieldMirror extends Dart2JsElementMirror | 1343 class Dart2JsFieldMirror extends Dart2JsElementMirror |
1344 implements Dart2JsMemberMirror, FieldMirror { | 1344 implements Dart2JsMemberMirror, FieldMirror { |
1345 Dart2JsObjectMirror _objectMirror; | 1345 Dart2JsObjectMirror _objectMirror; |
1346 VariableElement _variable; | 1346 VariableElement _variable; |
1347 | 1347 |
1348 Dart2JsFieldMirror(Dart2JsObjectMirror objectMirror, | 1348 Dart2JsFieldMirror(Dart2JsObjectMirror objectMirror, |
1349 VariableElement variable) | 1349 VariableElement variable) |
1350 : this._objectMirror = objectMirror, | 1350 : this._objectMirror = objectMirror, |
1351 this._variable = variable, | 1351 this._variable = variable, |
1352 super(objectMirror.system, variable); | 1352 super(objectMirror.system, variable); |
1353 | 1353 |
1354 String get qualifiedName() | 1354 String get qualifiedName |
1355 => '${surroundingDeclaration.qualifiedName}.$canonicalName'; | 1355 => '${surroundingDeclaration.qualifiedName}.$canonicalName'; |
1356 | 1356 |
1357 String get canonicalName() => simpleName; | 1357 String get canonicalName => simpleName; |
1358 | 1358 |
1359 ObjectMirror get surroundingDeclaration() => _objectMirror; | 1359 ObjectMirror get surroundingDeclaration => _objectMirror; |
1360 | 1360 |
1361 bool get isTopLevel() => _objectMirror is LibraryMirror; | 1361 bool get isTopLevel => _objectMirror is LibraryMirror; |
1362 | 1362 |
1363 bool get isConstructor() => false; | 1363 bool get isConstructor => false; |
1364 | 1364 |
1365 bool get isField() => true; | 1365 bool get isField => true; |
1366 | 1366 |
1367 bool get isMethod() => false; | 1367 bool get isMethod => false; |
1368 | 1368 |
1369 bool get isPrivate() => _isPrivate(simpleName); | 1369 bool get isPrivate => _isPrivate(simpleName); |
1370 | 1370 |
1371 bool get isStatic() => _variable.modifiers.isStatic(); | 1371 bool get isStatic => _variable.modifiers.isStatic(); |
1372 | 1372 |
1373 // TODO(johnniwinther): Should this return true on const as well? | 1373 // TODO(johnniwinther): Should this return true on const as well? |
1374 bool get isFinal() => _variable.modifiers.isFinal(); | 1374 bool get isFinal => _variable.modifiers.isFinal(); |
1375 | 1375 |
1376 TypeMirror get type() => _convertTypeToTypeMirror(system, | 1376 TypeMirror get type => _convertTypeToTypeMirror(system, |
1377 _variable.computeType(system.compiler), | 1377 _variable.computeType(system.compiler), |
1378 system.compiler.types.dynamicType); | 1378 system.compiler.types.dynamicType); |
1379 | 1379 |
1380 Location get location() { | 1380 Location get location { |
1381 var script = _variable.getCompilationUnit().script; | 1381 var script = _variable.getCompilationUnit().script; |
1382 var node = _variable.variables.parseNode(_diagnosticListener); | 1382 var node = _variable.variables.parseNode(_diagnosticListener); |
1383 if (node !== null) { | 1383 if (node !== null) { |
1384 var span = system.compiler.spanFromNode(node, script.uri); | 1384 var span = system.compiler.spanFromNode(node, script.uri); |
1385 return new Dart2JsLocation(script, span); | 1385 return new Dart2JsLocation(script, span); |
1386 } else { | 1386 } else { |
1387 var span = system.compiler.spanFromElement(_variable); | 1387 var span = system.compiler.spanFromElement(_variable); |
1388 return new Dart2JsLocation(script, span); | 1388 return new Dart2JsLocation(script, span); |
1389 } | 1389 } |
1390 } | 1390 } |
1391 } | 1391 } |
1392 | 1392 |
OLD | NEW |