Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: pkg/dartdoc/lib/src/mirrors/dart2js_mirror.dart

Issue 10985085: Members and comments inherited in dartdoc. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased. Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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('dart:io'); 7 #import('dart:io');
8 #import('dart:uri'); 8 #import('dart:uri');
9 9
10 #import('../../../../../lib/compiler/compiler.dart', prefix: 'diagnostics'); 10 #import('../../../../../lib/compiler/compiler.dart', prefix: 'diagnostics');
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 Future<String> compileToJavaScript() => 377 Future<String> compileToJavaScript() =>
378 new Future<String>.immediate(_compiler.assembledCode); 378 new Future<String>.immediate(_compiler.assembledCode);
379 } 379 }
380 380
381 381
382 //------------------------------------------------------------------------------ 382 //------------------------------------------------------------------------------
383 // Dart2Js specific extensions of mirror interfaces 383 // Dart2Js specific extensions of mirror interfaces
384 //------------------------------------------------------------------------------ 384 //------------------------------------------------------------------------------
385 385
386 abstract class Dart2JsMirror implements Mirror { 386 abstract class Dart2JsMirror implements Mirror {
387 /**
388 * A unique name used as the key in maps.
389 */
390 String get canonicalName;
391 Dart2JsMirrorSystem get system; 387 Dart2JsMirrorSystem get system;
392 } 388 }
393 389
394 abstract class Dart2JsMemberMirror implements Dart2JsMirror, MemberMirror { 390 abstract class Dart2JsMemberMirror implements Dart2JsMirror, MemberMirror {
395 391
396 } 392 }
397 393
398 abstract class Dart2JsTypeMirror implements Dart2JsMirror, TypeMirror { 394 abstract class Dart2JsTypeMirror implements Dart2JsMirror, TypeMirror {
399 395
400 } 396 }
401 397
402 abstract class Dart2JsElementMirror implements Dart2JsMirror { 398 abstract class Dart2JsElementMirror implements Dart2JsMirror {
403 final Dart2JsMirrorSystem system; 399 final Dart2JsMirrorSystem system;
404 final Element _element; 400 final Element _element;
405 401
406 Dart2JsElementMirror(this.system, this._element) { 402 Dart2JsElementMirror(this.system, this._element) {
407 assert (system !== null); 403 assert (system !== null);
408 assert (_element !== null); 404 assert (_element !== null);
409 } 405 }
410 406
411 String get simpleName => _element.name.slowToString(); 407 String get simpleName => _element.name.slowToString();
412 408
409 String get displayName => simpleName;
410
413 Location get location => new Dart2JsLocation( 411 Location get location => new Dart2JsLocation(
414 _element.getCompilationUnit().script, 412 _element.getCompilationUnit().script,
415 system.compiler.spanFromElement(_element)); 413 system.compiler.spanFromElement(_element));
416 414
417 String toString() => _element.toString(); 415 String toString() => _element.toString();
418 416
419 int hashCode() => qualifiedName.hashCode(); 417 int hashCode() => qualifiedName.hashCode();
420 } 418 }
421 419
422 abstract class Dart2JsProxyMirror implements Dart2JsMirror { 420 abstract class Dart2JsProxyMirror implements Dart2JsMirror {
423 final Dart2JsMirrorSystem system; 421 final Dart2JsMirrorSystem system;
424 422
425 Dart2JsProxyMirror(this.system); 423 Dart2JsProxyMirror(this.system);
426 424
425 String get displayName => simpleName;
426
427 int hashCode() => qualifiedName.hashCode(); 427 int hashCode() => qualifiedName.hashCode();
428 } 428 }
429 429
430 //------------------------------------------------------------------------------ 430 //------------------------------------------------------------------------------
431 // Mirror system implementation. 431 // Mirror system implementation.
432 //------------------------------------------------------------------------------ 432 //------------------------------------------------------------------------------
433 433
434 class Dart2JsMirrorSystem implements MirrorSystem, Dart2JsMirror { 434 class Dart2JsMirrorSystem implements MirrorSystem, Dart2JsMirror {
435 final api.Compiler compiler; 435 final api.Compiler compiler;
436 Map<String, Dart2JsLibraryMirror> _libraries; 436 Map<String, Dart2JsLibraryMirror> _libraries;
437 Map<LibraryElement, Dart2JsLibraryMirror> _libraryMap; 437 Map<LibraryElement, Dart2JsLibraryMirror> _libraryMap;
438 438
439 Dart2JsMirrorSystem(this.compiler) 439 Dart2JsMirrorSystem(this.compiler)
440 : _libraryMap = new Map<LibraryElement, Dart2JsLibraryMirror>(); 440 : _libraryMap = new Map<LibraryElement, Dart2JsLibraryMirror>();
441 441
442 void _ensureLibraries() { 442 void _ensureLibraries() {
443 if (_libraries == null) { 443 if (_libraries == null) {
444 _libraries = <String, Dart2JsLibraryMirror>{}; 444 _libraries = <String, Dart2JsLibraryMirror>{};
445 compiler.libraries.forEach((_, LibraryElement v) { 445 compiler.libraries.forEach((_, LibraryElement v) {
446 var mirror = new Dart2JsLibraryMirror(system, v); 446 var mirror = new Dart2JsLibraryMirror(system, v);
447 _libraries[mirror.canonicalName] = mirror; 447 _libraries[mirror.simpleName] = mirror;
448 _libraryMap[v] = mirror; 448 _libraryMap[v] = mirror;
449 }); 449 });
450 } 450 }
451 } 451 }
452 452
453 Map<Object, LibraryMirror> get libraries { 453 Map<String, LibraryMirror> get libraries {
454 _ensureLibraries(); 454 _ensureLibraries();
455 return new ImmutableMapWrapper<Object, LibraryMirror>(_libraries); 455 return new ImmutableMapWrapper<String, LibraryMirror>(_libraries);
456 } 456 }
457 457
458 Dart2JsLibraryMirror getLibrary(LibraryElement element) { 458 Dart2JsLibraryMirror getLibrary(LibraryElement element) {
459 return _libraryMap[element]; 459 return _libraryMap[element];
460 } 460 }
461 461
462 Dart2JsMirrorSystem get system => this; 462 Dart2JsMirrorSystem get system => this;
463 463
464 String get simpleName => "mirror"; 464 String get simpleName => "mirror";
465 String get displayName => simpleName;
465 String get qualifiedName => simpleName; 466 String get qualifiedName => simpleName;
466 467
467 String get canonicalName => simpleName;
468
469 // TODO(johnniwinther): Hack! Dart2JsMirrorSystem need not be a Mirror. 468 // TODO(johnniwinther): Hack! Dart2JsMirrorSystem need not be a Mirror.
470 int hashCode() => qualifiedName.hashCode(); 469 int hashCode() => qualifiedName.hashCode();
471 } 470 }
472 471
473 abstract class Dart2JsObjectMirror extends Dart2JsElementMirror 472 abstract class Dart2JsObjectMirror extends Dart2JsElementMirror
474 implements ObjectMirror { 473 implements ObjectMirror {
475 Dart2JsObjectMirror(Dart2JsMirrorSystem system, Element element) 474 Dart2JsObjectMirror(Dart2JsMirrorSystem system, Element element)
476 : super(system, element); 475 : super(system, element);
477 } 476 }
478 477
479 class Dart2JsLibraryMirror extends Dart2JsObjectMirror 478 class Dart2JsLibraryMirror extends Dart2JsObjectMirror
480 implements LibraryMirror { 479 implements LibraryMirror {
481 Map<String, InterfaceMirror> _types; 480 Map<String, InterfaceMirror> _types;
482 Map<String, MemberMirror> _members; 481 Map<String, MemberMirror> _members;
483 482
484 Dart2JsLibraryMirror(Dart2JsMirrorSystem system, LibraryElement library) 483 Dart2JsLibraryMirror(Dart2JsMirrorSystem system, LibraryElement library)
485 : super(system, library); 484 : super(system, library);
486 485
487 LibraryElement get _library => _element; 486 LibraryElement get _library => _element;
488 487
489 LibraryMirror library() => this; 488 LibraryMirror library() => this;
490 489
491 String get canonicalName => simpleName;
492
493 /** 490 /**
494 * Returns the library name (for libraries with a #library tag) or the script 491 * Returns the library name (for libraries with a #library tag) or the script
495 * file name (for scripts without a #library tag). The latter case is used to 492 * file name (for scripts without a #library tag). The latter case is used to
496 * provide a 'library name' for scripts, to use for instance in dartdoc. 493 * provide a 'library name' for scripts, to use for instance in dartdoc.
497 */ 494 */
498 String get simpleName { 495 String get simpleName {
499 if (_library.libraryTag !== null) { 496 if (_library.libraryTag !== null) {
500 // TODO(ahe): Remove StringNode check when old syntax is removed. 497 // TODO(ahe): Remove StringNode check when old syntax is removed.
501 StringNode name = _library.libraryTag.name.asStringNode(); 498 StringNode name = _library.libraryTag.name.asStringNode();
502 if (name !== null) { 499 if (name !== null) {
(...skipping 11 matching lines...) Expand all
514 String get qualifiedName => simpleName; 511 String get qualifiedName => simpleName;
515 512
516 void _ensureTypes() { 513 void _ensureTypes() {
517 if (_types == null) { 514 if (_types == null) {
518 _types = <String, InterfaceMirror>{}; 515 _types = <String, InterfaceMirror>{};
519 _library.forEachExport((Element e) { 516 _library.forEachExport((Element e) {
520 if (e.getLibrary() == _library) { 517 if (e.getLibrary() == _library) {
521 if (e.isClass()) { 518 if (e.isClass()) {
522 e.ensureResolved(system.compiler); 519 e.ensureResolved(system.compiler);
523 var type = new Dart2JsInterfaceMirror.fromLibrary(this, e); 520 var type = new Dart2JsInterfaceMirror.fromLibrary(this, e);
524 _types[type.canonicalName] = type; 521 assert(!_types.containsKey(type.simpleName));
522 _types[type.simpleName] = type;
525 } else if (e.isTypedef()) { 523 } else if (e.isTypedef()) {
526 var type = new Dart2JsTypedefMirror.fromLibrary(this, 524 var type = new Dart2JsTypedefMirror.fromLibrary(this,
527 e.computeType(system.compiler)); 525 e.computeType(system.compiler));
528 _types[type.canonicalName] = type; 526 assert(!_types.containsKey(type.simpleName));
527 _types[type.simpleName] = type;
529 } 528 }
530 } 529 }
531 }); 530 });
532 } 531 }
533 } 532 }
534 533
535 void _ensureMembers() { 534 void _ensureMembers() {
536 if (_members == null) { 535 if (_members == null) {
537 _members = <String, MemberMirror>{}; 536 _members = <String, MemberMirror>{};
538 _library.forEachExport((Element e) { 537 _library.forEachExport((Element e) {
539 if (!e.isClass() && !e.isTypedef()) { 538 if (!e.isClass() && !e.isTypedef()) {
540 for (var member in _convertElementMemberToMemberMirrors(this, e)) { 539 for (var member in _convertElementMemberToMemberMirrors(this, e)) {
541 _members[member.canonicalName] = member; 540 assert(!_members.containsKey(member.simpleName));
541 _members[member.simpleName] = member;
542 } 542 }
543 } 543 }
544 }); 544 });
545 } 545 }
546 } 546 }
547 547
548 Map<Object, MemberMirror> get declaredMembers { 548 Map<String, MemberMirror> get declaredMembers {
549 _ensureMembers(); 549 _ensureMembers();
550 return new ImmutableMapWrapper<Object, MemberMirror>(_members); 550 return new ImmutableMapWrapper<String, MemberMirror>(_members);
551 } 551 }
552 552
553 Map<Object, InterfaceMirror> get types { 553 Map<String, InterfaceMirror> get types {
554 _ensureTypes(); 554 _ensureTypes();
555 return new ImmutableMapWrapper<Object, InterfaceMirror>(_types); 555 return new ImmutableMapWrapper<String, InterfaceMirror>(_types);
556 } 556 }
557 557
558 Location get location { 558 Location get location {
559 var script = _library.getCompilationUnit().script; 559 var script = _library.getCompilationUnit().script;
560 return new Dart2JsLocation( 560 return new Dart2JsLocation(
561 script, 561 script,
562 new SourceSpan(script.uri, 0, script.text.length)); 562 new SourceSpan(script.uri, 0, script.text.length));
563 } 563 }
564 } 564 }
565 565
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 } 606 }
607 607
608 Dart2JsParameterMirror._normal(Dart2JsMirrorSystem system, 608 Dart2JsParameterMirror._normal(Dart2JsMirrorSystem system,
609 this._method, 609 this._method,
610 VariableElement element, 610 VariableElement element,
611 this.isOptional) 611 this.isOptional)
612 : super(system, element); 612 : super(system, element);
613 613
614 VariableElement get _variableElement => _element; 614 VariableElement get _variableElement => _element;
615 615
616 String get canonicalName => simpleName;
617
618 String get qualifiedName => '${_method.qualifiedName}#${simpleName}'; 616 String get qualifiedName => '${_method.qualifiedName}#${simpleName}';
619 617
620 TypeMirror get type => _convertTypeToTypeMirror(system, 618 TypeMirror get type => _convertTypeToTypeMirror(system,
621 _variableElement.computeType(system.compiler), 619 _variableElement.computeType(system.compiler),
622 system.compiler.types.dynamicType, 620 system.compiler.types.dynamicType,
623 _variableElement.variables.functionSignature); 621 _variableElement.variables.functionSignature);
624 622
625 String get defaultValue { 623 String get defaultValue {
626 if (hasDefaultValue) { 624 if (hasDefaultValue) {
627 SendSet expression = _variableElement.cachedNode.asSendSet(); 625 SendSet expression = _variableElement.cachedNode.asSendSet();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 : this.library = system.getLibrary(_class.getLibrary()), 676 : this.library = system.getLibrary(_class.getLibrary()),
679 super(system, _class); 677 super(system, _class);
680 678
681 ClassElement get _class => _element; 679 ClassElement get _class => _element;
682 680
683 Dart2JsInterfaceMirror.fromLibrary(Dart2JsLibraryMirror library, 681 Dart2JsInterfaceMirror.fromLibrary(Dart2JsLibraryMirror library,
684 ClassElement _class) 682 ClassElement _class)
685 : this.library = library, 683 : this.library = library,
686 super(library.system, _class); 684 super(library.system, _class);
687 685
688 String get canonicalName => simpleName;
689
690 String get qualifiedName => '${library.qualifiedName}.${simpleName}'; 686 String get qualifiedName => '${library.qualifiedName}.${simpleName}';
691 687
692 Location get location { 688 Location get location {
693 if (_class is PartialClassElement) { 689 if (_class is PartialClassElement) {
694 var node = _class.parseNode(_diagnosticListener); 690 var node = _class.parseNode(system.compiler);
695 if (node !== null) { 691 if (node !== null) {
696 var script = _class.getCompilationUnit().script; 692 var script = _class.getCompilationUnit().script;
697 var span = system.compiler.spanFromNode(node, script.uri); 693 var span = system.compiler.spanFromNode(node, script.uri);
698 return new Dart2JsLocation(script, span); 694 return new Dart2JsLocation(script, span);
699 } 695 }
700 } 696 }
701 return super.location; 697 return super.location;
702 } 698 }
703 699
704 void _ensureMembers() { 700 void _ensureMembers() {
705 if (_members == null) { 701 if (_members == null) {
706 _members = <String, Dart2JsMemberMirror>{}; 702 _members = <String, Dart2JsMemberMirror>{};
707 _class.localMembers.forEach((e) { 703 _class.localMembers.forEach((e) {
708 for (var member in _convertElementMemberToMemberMirrors(this, e)) { 704 for (var member in _convertElementMemberToMemberMirrors(this, e)) {
709 _members[member.canonicalName] = member; 705 assert(!_members.containsKey(member.simpleName));
706 _members[member.simpleName] = member;
710 } 707 }
711 }); 708 });
712 } 709 }
713 } 710 }
714 711
715 Map<Object, MemberMirror> get declaredMembers { 712 Map<String, MemberMirror> get declaredMembers {
716 _ensureMembers(); 713 _ensureMembers();
717 return new ImmutableMapWrapper<Object, MemberMirror>(_members); 714 return new ImmutableMapWrapper<String, MemberMirror>(_members);
718 } 715 }
719 716
720 bool get isObject => _class == system.compiler.objectClass; 717 bool get isObject => _class == system.compiler.objectClass;
721 718
722 bool get isDynamic => false; 719 bool get isDynamic => false;
723 720
724 bool get isVoid => false; 721 bool get isVoid => false;
725 722
726 bool get isTypeVariable => false; 723 bool get isTypeVariable => false;
727 724
728 bool get isTypedef => false; 725 bool get isTypedef => false;
729 726
730 bool get isFunction => false; 727 bool get isFunction => false;
731 728
732 InterfaceMirror get declaration => this; 729 InterfaceMirror get declaration => this;
733 730
734 InterfaceMirror get superclass { 731 InterfaceMirror get superclass {
735 if (_class.supertype != null) { 732 if (_class.supertype != null) {
736 return new Dart2JsInterfaceTypeMirror(system, _class.supertype); 733 return new Dart2JsInterfaceTypeMirror(system, _class.supertype);
737 } 734 }
738 return null; 735 return null;
739 } 736 }
740 737
741 Map<Object, InterfaceMirror> get interfaces { 738 List<InterfaceMirror> get interfaces {
742 var map = new Map<String, InterfaceMirror>(); 739 var list = <InterfaceMirror>[];
743 Link<DartType> link = _class.interfaces; 740 Link<DartType> link = _class.interfaces;
744 while (!link.isEmpty()) { 741 while (!link.isEmpty()) {
745 var type = _convertTypeToTypeMirror(system, link.head, 742 var type = _convertTypeToTypeMirror(system, link.head,
746 system.compiler.types.dynamicType); 743 system.compiler.types.dynamicType);
747 map[type.canonicalName] = type; 744 list.add(type);
748 link = link.tail; 745 link = link.tail;
749 } 746 }
750 return new ImmutableMapWrapper<Object, InterfaceMirror>(map); 747 return list;
751 } 748 }
752 749
753 bool get isClass => !_class.isInterface(); 750 bool get isClass => !_class.isInterface();
754 751
755 bool get isInterface => _class.isInterface(); 752 bool get isInterface => _class.isInterface();
756 753
757 bool get isAbstract => _class.modifiers.isAbstract(); 754 bool get isAbstract => _class.modifiers.isAbstract();
758 755
759 bool get isPrivate => _isPrivate(simpleName); 756 bool get isPrivate => _isPrivate(simpleName);
760 757
761 bool get isDeclaration => true; 758 bool get isDeclaration => true;
762 759
763 List<TypeMirror> get typeArguments { 760 List<TypeMirror> get typeArguments {
764 throw new UnsupportedOperationException( 761 throw new UnsupportedOperationException(
765 'Declarations do not have type arguments'); 762 'Declarations do not have type arguments');
766 } 763 }
767 764
768 List<TypeVariableMirror> get typeVariables { 765 List<TypeVariableMirror> get typeVariables {
769 if (_typeVariables == null) { 766 if (_typeVariables == null) {
770 _typeVariables = <TypeVariableMirror>[]; 767 _typeVariables = <TypeVariableMirror>[];
771 _class.ensureResolved(system.compiler); 768 _class.ensureResolved(system.compiler);
772 for (TypeVariableType typeVariable in _class.typeVariables) { 769 for (TypeVariableType typeVariable in _class.typeVariables) {
773 _typeVariables.add( 770 _typeVariables.add(
774 new Dart2JsTypeVariableMirror(system, typeVariable)); 771 new Dart2JsTypeVariableMirror(system, typeVariable));
775 } 772 }
776 } 773 }
777 return _typeVariables; 774 return _typeVariables;
778 } 775 }
779 776
780 Map<Object, MethodMirror> get constructors { 777 Map<String, MethodMirror> get constructors {
781 _ensureMembers(); 778 _ensureMembers();
782 return new AsFilteredImmutableMap<Object, MemberMirror, MethodMirror>( 779 return new AsFilteredImmutableMap<String, MemberMirror, MethodMirror>(
783 _members, (m) => m.isConstructor ? m : null); 780 _members, (m) => m.isConstructor ? m : null);
784 } 781 }
785 782
786 /** 783 /**
787 * Returns the default type for this interface. 784 * Returns the default type for this interface.
788 */ 785 */
789 InterfaceMirror get defaultType { 786 InterfaceMirror get defaultType {
790 if (_class.defaultClass != null) { 787 if (_class.defaultClass != null) {
791 return new Dart2JsInterfaceTypeMirror(system, _class.defaultClass); 788 return new Dart2JsInterfaceTypeMirror(system, _class.defaultClass);
792 } 789 }
(...skipping 27 matching lines...) Expand all
820 : this._library = system.getLibrary(_typedef.element.getLibrary()), 817 : this._library = system.getLibrary(_typedef.element.getLibrary()),
821 super(system, _typedef); 818 super(system, _typedef);
822 819
823 Dart2JsTypedefMirror.fromLibrary(Dart2JsLibraryMirror library, 820 Dart2JsTypedefMirror.fromLibrary(Dart2JsLibraryMirror library,
824 TypedefType _typedef) 821 TypedefType _typedef)
825 : this._library = library, 822 : this._library = library,
826 super(library.system, _typedef); 823 super(library.system, _typedef);
827 824
828 TypedefType get _typedef => _type; 825 TypedefType get _typedef => _type;
829 826
830 String get canonicalName => simpleName;
831
832 String get qualifiedName => '${library.qualifiedName}.${simpleName}'; 827 String get qualifiedName => '${library.qualifiedName}.${simpleName}';
833 828
834 Location get location { 829 Location get location {
835 var node = _typedef.element.parseNode(_diagnosticListener); 830 var node = _typedef.element.parseNode(_diagnosticListener);
836 if (node !== null) { 831 if (node !== null) {
837 var script = _typedef.element.getCompilationUnit().script; 832 var script = _typedef.element.getCompilationUnit().script;
838 var span = system.compiler.spanFromNode(node, script.uri); 833 var span = system.compiler.spanFromNode(node, script.uri);
839 return new Dart2JsLocation(script, span); 834 return new Dart2JsLocation(script, span);
840 } 835 }
841 return super.location; 836 return super.location;
(...skipping 25 matching lines...) Expand all
867 system.compiler.resolveTypedef(_typedef.element); 862 system.compiler.resolveTypedef(_typedef.element);
868 _definition = _convertTypeToTypeMirror( 863 _definition = _convertTypeToTypeMirror(
869 system, 864 system,
870 _typedef.element.alias, 865 _typedef.element.alias,
871 system.compiler.types.dynamicType, 866 system.compiler.types.dynamicType,
872 _typedef.element.functionSignature); 867 _typedef.element.functionSignature);
873 } 868 }
874 return _definition; 869 return _definition;
875 } 870 }
876 871
877 Map<Object, MemberMirror> get declaredMembers => 872 Map<String, MemberMirror> get declaredMembers =>
878 const <String, MemberMirror>{}; 873 const <String, MemberMirror>{};
879 874
880 InterfaceMirror get declaration => this; 875 InterfaceMirror get declaration => this;
881 876
882 // TODO(johnniwinther): How should a typedef respond to these? 877 // TODO(johnniwinther): How should a typedef respond to these?
883 InterfaceMirror get superclass => null; 878 InterfaceMirror get superclass => null;
884 879
885 Map<Object, InterfaceMirror> get interfaces => 880 List<InterfaceMirror> get interfaces => const <InterfaceMirror>[];
886 const <String, InterfaceMirror>{};
887 881
888 bool get isClass => false; 882 bool get isClass => false;
889 883
890 bool get isInterface => false; 884 bool get isInterface => false;
891 885
892 bool get isPrivate => _isPrivate(simpleName); 886 bool get isPrivate => _isPrivate(simpleName);
893 887
894 bool get isDeclaration => true; 888 bool get isDeclaration => true;
895 889
896 Map<Object, MethodMirror> get constructors => 890 bool get isAbstract => false;
891
892 Map<String, MethodMirror> get constructors =>
897 const <String, MethodMirror>{}; 893 const <String, MethodMirror>{};
898 894
899 InterfaceMirror get defaultType => null; 895 InterfaceMirror get defaultType => null;
900 } 896 }
901 897
902 class Dart2JsTypeVariableMirror extends Dart2JsTypeElementMirror 898 class Dart2JsTypeVariableMirror extends Dart2JsTypeElementMirror
903 implements TypeVariableMirror { 899 implements TypeVariableMirror {
904 final TypeVariableType _typeVariableType; 900 final TypeVariableType _typeVariableType;
905 InterfaceMirror _declarer; 901 InterfaceMirror _declarer;
906 902
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 954
959 abstract class Dart2JsTypeElementMirror extends Dart2JsProxyMirror 955 abstract class Dart2JsTypeElementMirror extends Dart2JsProxyMirror
960 implements Dart2JsTypeMirror { 956 implements Dart2JsTypeMirror {
961 final DartType _type; 957 final DartType _type;
962 958
963 Dart2JsTypeElementMirror(Dart2JsMirrorSystem system, this._type) 959 Dart2JsTypeElementMirror(Dart2JsMirrorSystem system, this._type)
964 : super(system); 960 : super(system);
965 961
966 String get simpleName => _type.name.slowToString(); 962 String get simpleName => _type.name.slowToString();
967 963
968 String get canonicalName => simpleName;
969
970 Location get location { 964 Location get location {
971 var script = _type.element.getCompilationUnit().script; 965 var script = _type.element.getCompilationUnit().script;
972 return new Dart2JsLocation(script, 966 return new Dart2JsLocation(script,
973 system.compiler.spanFromElement(_type.element)); 967 system.compiler.spanFromElement(_type.element));
974 } 968 }
975 969
976 LibraryMirror get library { 970 LibraryMirror get library {
977 return system.getLibrary(_type.element.getLibrary()); 971 return system.getLibrary(_type.element.getLibrary());
978 } 972 }
979 973
(...skipping 18 matching lines...) Expand all
998 992
999 Dart2JsInterfaceTypeMirror(Dart2JsMirrorSystem system, 993 Dart2JsInterfaceTypeMirror(Dart2JsMirrorSystem system,
1000 InterfaceType interfaceType) 994 InterfaceType interfaceType)
1001 : super(system, interfaceType); 995 : super(system, interfaceType);
1002 996
1003 InterfaceType get _interfaceType => _type; 997 InterfaceType get _interfaceType => _type;
1004 998
1005 String get qualifiedName => declaration.qualifiedName; 999 String get qualifiedName => declaration.qualifiedName;
1006 1000
1007 // TODO(johnniwinther): Substitute type arguments for type variables. 1001 // TODO(johnniwinther): Substitute type arguments for type variables.
1008 Map<Object, MemberMirror> get declaredMembers => declaration.declaredMembers; 1002 Map<String, MemberMirror> get declaredMembers => declaration.declaredMembers;
1009 1003
1010 bool get isObject => system.compiler.objectClass == _type.element; 1004 bool get isObject => system.compiler.objectClass == _type.element;
1011 1005
1012 bool get isDynamic => system.compiler.dynamicClass == _type.element; 1006 bool get isDynamic => system.compiler.dynamicClass == _type.element;
1013 1007
1014 InterfaceMirror get declaration 1008 InterfaceMirror get declaration
1015 => new Dart2JsInterfaceMirror(system, _type.element); 1009 => new Dart2JsInterfaceMirror(system, _type.element);
1016 1010
1017 // TODO(johnniwinther): Substitute type arguments for type variables. 1011 // TODO(johnniwinther): Substitute type arguments for type variables.
1018 InterfaceMirror get superclass => declaration.superclass; 1012 InterfaceMirror get superclass => declaration.superclass;
1019 1013
1020 // TODO(johnniwinther): Substitute type arguments for type variables. 1014 // TODO(johnniwinther): Substitute type arguments for type variables.
1021 Map<Object, InterfaceMirror> get interfaces => declaration.interfaces; 1015 List<InterfaceMirror> get interfaces => declaration.interfaces;
1022 1016
1023 bool get isClass => declaration.isClass; 1017 bool get isClass => declaration.isClass;
1024 1018
1025 bool get isInterface => declaration.isInterface; 1019 bool get isInterface => declaration.isInterface;
1026 1020
1027 bool get isAbstract => declaration.isAbstract; 1021 bool get isAbstract => declaration.isAbstract;
1028 1022
1029 bool get isPrivate => declaration.isPrivate; 1023 bool get isPrivate => declaration.isPrivate;
1030 1024
1031 bool get isDeclaration => false; 1025 bool get isDeclaration => false;
1032 1026
1033 List<TypeMirror> get typeArguments { 1027 List<TypeMirror> get typeArguments {
1034 if (_typeArguments == null) { 1028 if (_typeArguments == null) {
1035 _typeArguments = <TypeMirror>[]; 1029 _typeArguments = <TypeMirror>[];
1036 Link<DartType> type = _interfaceType.arguments; 1030 Link<DartType> type = _interfaceType.arguments;
1037 while (type != null && type.head != null) { 1031 while (type != null && type.head != null) {
1038 _typeArguments.add(_convertTypeToTypeMirror(system, type.head, 1032 _typeArguments.add(_convertTypeToTypeMirror(system, type.head,
1039 system.compiler.types.dynamicType)); 1033 system.compiler.types.dynamicType));
1040 type = type.tail; 1034 type = type.tail;
1041 } 1035 }
1042 } 1036 }
1043 return _typeArguments; 1037 return _typeArguments;
1044 } 1038 }
1045 1039
1046 List<TypeVariableMirror> get typeVariables => declaration.typeVariables; 1040 List<TypeVariableMirror> get typeVariables => declaration.typeVariables;
1047 1041
1048 // TODO(johnniwinther): Substitute type arguments for type variables. 1042 // TODO(johnniwinther): Substitute type arguments for type variables.
1049 Map<Object, MethodMirror> get constructors => declaration.constructors; 1043 Map<String, MethodMirror> get constructors => declaration.constructors;
1050 1044
1051 // TODO(johnniwinther): Substitute type arguments for type variables? 1045 // TODO(johnniwinther): Substitute type arguments for type variables?
1052 InterfaceMirror get defaultType => declaration.defaultType; 1046 InterfaceMirror get defaultType => declaration.defaultType;
1053 1047
1054 bool operator ==(Object other) { 1048 bool operator ==(Object other) {
1055 if (this === other) { 1049 if (this === other) {
1056 return true; 1050 return true;
1057 } 1051 }
1058 if (other is! InterfaceMirror) { 1052 if (other is! InterfaceMirror) {
1059 return false; 1053 return false;
(...skipping 26 matching lines...) Expand all
1086 : super(system, functionType) { 1080 : super(system, functionType) {
1087 assert (_functionSignature !== null); 1081 assert (_functionSignature !== null);
1088 } 1082 }
1089 1083
1090 FunctionType get _functionType => _type; 1084 FunctionType get _functionType => _type;
1091 1085
1092 // TODO(johnniwinther): Is this the qualified name of a function type? 1086 // TODO(johnniwinther): Is this the qualified name of a function type?
1093 String get qualifiedName => declaration.qualifiedName; 1087 String get qualifiedName => declaration.qualifiedName;
1094 1088
1095 // TODO(johnniwinther): Substitute type arguments for type variables. 1089 // TODO(johnniwinther): Substitute type arguments for type variables.
1096 Map<Object, MemberMirror> get declaredMembers { 1090 Map<String, MemberMirror> get declaredMembers {
1097 var method = callMethod; 1091 var method = callMethod;
1098 if (method !== null) { 1092 if (method !== null) {
1099 var map = new Map<String, MemberMirror>.from( 1093 var map = new Map<String, MemberMirror>.from(
1100 declaration.declaredMembers); 1094 declaration.declaredMembers);
1101 var name = method.qualifiedName; 1095 var name = method.qualifiedName;
1096 assert(!map.containsKey(name));
1102 map[name] = method; 1097 map[name] = method;
1103 Function func = null; 1098 return new ImmutableMapWrapper<String, MemberMirror>(map);
1104 return new ImmutableMapWrapper<Object, MemberMirror>(map);
1105 } 1099 }
1106 return declaration.declaredMembers; 1100 return declaration.declaredMembers;
1107 } 1101 }
1108 1102
1109 bool get isFunction => true; 1103 bool get isFunction => true;
1110 1104
1111 MethodMirror get callMethod => _convertElementMethodToMethodMirror( 1105 MethodMirror get callMethod => _convertElementMethodToMethodMirror(
1112 system.getLibrary(_functionType.element.getLibrary()), 1106 system.getLibrary(_functionType.element.getLibrary()),
1113 _functionType.element); 1107 _functionType.element);
1114 1108
1115 InterfaceMirror get declaration 1109 InterfaceMirror get declaration
1116 => new Dart2JsInterfaceMirror(system, system.compiler.functionClass); 1110 => new Dart2JsInterfaceMirror(system, system.compiler.functionClass);
1117 1111
1118 // TODO(johnniwinther): Substitute type arguments for type variables. 1112 // TODO(johnniwinther): Substitute type arguments for type variables.
1119 InterfaceMirror get superclass => declaration.superclass; 1113 InterfaceMirror get superclass => declaration.superclass;
1120 1114
1121 // TODO(johnniwinther): Substitute type arguments for type variables. 1115 // TODO(johnniwinther): Substitute type arguments for type variables.
1122 Map<Object, InterfaceMirror> get interfaces => declaration.interfaces; 1116 List<InterfaceMirror> get interfaces => declaration.interfaces;
1123 1117
1124 bool get isClass => declaration.isClass; 1118 bool get isClass => declaration.isClass;
1125 1119
1126 bool get isInterface => declaration.isInterface; 1120 bool get isInterface => declaration.isInterface;
1127 1121
1128 bool get isPrivate => declaration.isPrivate; 1122 bool get isPrivate => declaration.isPrivate;
1129 1123
1130 bool get isDeclaration => false; 1124 bool get isDeclaration => false;
1131 1125
1126 bool get isAbstract => false;
1127
1132 List<TypeMirror> get typeArguments => const <TypeMirror>[]; 1128 List<TypeMirror> get typeArguments => const <TypeMirror>[];
1133 1129
1134 List<TypeVariableMirror> get typeVariables => declaration.typeVariables; 1130 List<TypeVariableMirror> get typeVariables => declaration.typeVariables;
1135 1131
1136 Map<Object, MethodMirror> get constructors => 1132 Map<String, MethodMirror> get constructors => <String, MethodMirror>{};
1137 <String, MethodMirror>{};
1138 1133
1139 InterfaceMirror get defaultType => null; 1134 InterfaceMirror get defaultType => null;
1140 1135
1141 TypeMirror get returnType { 1136 TypeMirror get returnType {
1142 return _convertTypeToTypeMirror(system, _functionType.returnType, 1137 return _convertTypeToTypeMirror(system, _functionType.returnType,
1143 system.compiler.types.dynamicType); 1138 system.compiler.types.dynamicType);
1144 } 1139 }
1145 1140
1146 List<ParameterMirror> get parameters { 1141 List<ParameterMirror> get parameters {
1147 if (_parameters === null) { 1142 if (_parameters === null) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 } 1211 }
1217 } 1212 }
1218 1213
1219 //------------------------------------------------------------------------------ 1214 //------------------------------------------------------------------------------
1220 // Member mirrors implementation. 1215 // Member mirrors implementation.
1221 //------------------------------------------------------------------------------ 1216 //------------------------------------------------------------------------------
1222 1217
1223 class Dart2JsMethodMirror extends Dart2JsElementMirror 1218 class Dart2JsMethodMirror extends Dart2JsElementMirror
1224 implements Dart2JsMemberMirror, MethodMirror { 1219 implements Dart2JsMemberMirror, MethodMirror {
1225 final Dart2JsObjectMirror _objectMirror; 1220 final Dart2JsObjectMirror _objectMirror;
1226 String _name; 1221 String _simpleName;
1222 String _displayName;
1227 String _constructorName; 1223 String _constructorName;
1228 String _operatorName; 1224 String _operatorName;
1229 Dart2JsMethodKind _kind; 1225 Dart2JsMethodKind _kind;
1230 String _canonicalName;
1231 1226
1232 Dart2JsMethodMirror(Dart2JsObjectMirror objectMirror, 1227 Dart2JsMethodMirror(Dart2JsObjectMirror objectMirror,
1233 FunctionElement function) 1228 FunctionElement function)
1234 : this._objectMirror = objectMirror, 1229 : this._objectMirror = objectMirror,
1235 super(objectMirror.system, function) { 1230 super(objectMirror.system, function) {
1236 _name = _element.name.slowToString(); 1231 _simpleName = _element.name.slowToString();
1237 if (_function.kind == ElementKind.GETTER) { 1232 if (_function.kind == ElementKind.GETTER) {
1238 _kind = Dart2JsMethodKind.GETTER; 1233 _kind = Dart2JsMethodKind.GETTER;
1239 _canonicalName = _name; 1234 _displayName = _simpleName;
1240 } else if (_function.kind == ElementKind.SETTER) { 1235 } else if (_function.kind == ElementKind.SETTER) {
1241 _kind = Dart2JsMethodKind.SETTER; 1236 _kind = Dart2JsMethodKind.SETTER;
1242 _canonicalName = '$_name='; 1237 _displayName = _simpleName;
1238 _simpleName = '$_simpleName=';
1243 } else if (_function.kind == ElementKind.GENERATIVE_CONSTRUCTOR) { 1239 } else if (_function.kind == ElementKind.GENERATIVE_CONSTRUCTOR) {
1244 _constructorName = ''; 1240 _constructorName = '';
1245 int dollarPos = _name.indexOf('\$'); 1241 int dollarPos = _simpleName.indexOf('\$');
1246 if (dollarPos != -1) { 1242 if (dollarPos != -1) {
1247 _constructorName = _name.substring(dollarPos + 1); 1243 _constructorName = _simpleName.substring(dollarPos + 1);
1248 _name = _name.substring(0, dollarPos); 1244 _simpleName = _simpleName.substring(0, dollarPos);
1249 // canonical name is TypeName.constructorName 1245 // Simple name is TypeName.constructorName.
1250 _canonicalName = '$_name.$_constructorName'; 1246 _simpleName = '$_simpleName.$_constructorName';
1251 } else { 1247 } else {
1252 // canonical name is TypeName 1248 // Simple name is TypeName.
1253 _canonicalName = _name;
1254 } 1249 }
1255 if (_function.modifiers.isConst()) { 1250 if (_function.modifiers.isConst()) {
1256 _kind = Dart2JsMethodKind.CONST; 1251 _kind = Dart2JsMethodKind.CONST;
1257 } else { 1252 } else {
1258 _kind = Dart2JsMethodKind.CONSTRUCTOR; 1253 _kind = Dart2JsMethodKind.CONSTRUCTOR;
1259 } 1254 }
1255 _displayName = _simpleName;
1260 } else if (_function.modifiers.isFactory()) { 1256 } else if (_function.modifiers.isFactory()) {
1261 _kind = Dart2JsMethodKind.FACTORY; 1257 _kind = Dart2JsMethodKind.FACTORY;
1262 _constructorName = ''; 1258 _constructorName = '';
1263 int dollarPos = _name.indexOf('\$'); 1259 int dollarPos = _simpleName.indexOf('\$');
1264 if (dollarPos != -1) { 1260 if (dollarPos != -1) {
1265 _constructorName = _name.substring(dollarPos+1); 1261 _constructorName = _simpleName.substring(dollarPos+1);
1266 _name = _name.substring(0, dollarPos); 1262 _simpleName = _simpleName.substring(0, dollarPos);
1263 _simpleName = '$_simpleName.$_constructorName';
1267 } 1264 }
1268 // canonical name is TypeName.constructorName 1265 // Simple name is TypeName.constructorName.
1269 _canonicalName = '$_name.$_constructorName'; 1266 _displayName = _simpleName;
1270 } else if (_name == 'negate') { 1267 } else if (_simpleName == 'negate') {
1271 _operatorName = _name;
1272 _name = 'operator';
1273 _kind = Dart2JsMethodKind.OPERATOR; 1268 _kind = Dart2JsMethodKind.OPERATOR;
1274 // canonical name is 'operator operatorName' 1269 _operatorName = '-';
1275 _canonicalName = 'operator $_operatorName'; 1270 // Simple name is 'operator operatorName'.
1276 } else if (_name.startsWith('operator\$')) { 1271 _simpleName = Mirror.UNARY_MINUS;
1277 String str = _name.substring(9); 1272 // Display name is 'operator operatorName'.
1278 _name = 'operator'; 1273 _displayName = 'operator -';
1274 } else if (_simpleName.startsWith('operator\$')) {
1275 String str = _simpleName.substring(9);
1276 _simpleName = 'operator';
1279 _kind = Dart2JsMethodKind.OPERATOR; 1277 _kind = Dart2JsMethodKind.OPERATOR;
1280 _operatorName = _getOperatorFromOperatorName(str); 1278 _operatorName = _getOperatorFromOperatorName(str);
1281 // canonical name is 'operator operatorName' 1279 // Simple name is 'operator operatorName'.
1282 _canonicalName = 'operator $_operatorName'; 1280 _simpleName = _operatorName;
1281 // Display name is 'operator operatorName'.
1282 _displayName = 'operator $_operatorName';
1283 } else { 1283 } else {
1284 _kind = Dart2JsMethodKind.NORMAL; 1284 _kind = Dart2JsMethodKind.NORMAL;
1285 _canonicalName = _name; 1285 _displayName = _simpleName;
1286 } 1286 }
1287 } 1287 }
1288 1288
1289 FunctionElement get _function => _element; 1289 FunctionElement get _function => _element;
1290 1290
1291 String get simpleName => _name; 1291 String get simpleName => _simpleName;
1292
1293 String get displayName => _displayName;
1292 1294
1293 String get qualifiedName 1295 String get qualifiedName
1294 => '${surroundingDeclaration.qualifiedName}.$canonicalName'; 1296 => '${surroundingDeclaration.qualifiedName}.$simpleName';
1295
1296 String get canonicalName => _canonicalName;
1297 1297
1298 ObjectMirror get surroundingDeclaration => _objectMirror; 1298 ObjectMirror get surroundingDeclaration => _objectMirror;
1299 1299
1300 bool get isTopLevel => _objectMirror is LibraryMirror; 1300 bool get isTopLevel => _objectMirror is LibraryMirror;
1301 1301
1302 bool get isConstructor 1302 bool get isConstructor
1303 => _kind == Dart2JsMethodKind.CONSTRUCTOR || isConst || isFactory; 1303 => _kind == Dart2JsMethodKind.CONSTRUCTOR || isConst || isFactory;
1304 1304
1305 bool get isField => false; 1305 bool get isField => false;
1306 1306
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1357 Dart2JsObjectMirror _objectMirror; 1357 Dart2JsObjectMirror _objectMirror;
1358 VariableElement _variable; 1358 VariableElement _variable;
1359 1359
1360 Dart2JsFieldMirror(Dart2JsObjectMirror objectMirror, 1360 Dart2JsFieldMirror(Dart2JsObjectMirror objectMirror,
1361 VariableElement variable) 1361 VariableElement variable)
1362 : this._objectMirror = objectMirror, 1362 : this._objectMirror = objectMirror,
1363 this._variable = variable, 1363 this._variable = variable,
1364 super(objectMirror.system, variable); 1364 super(objectMirror.system, variable);
1365 1365
1366 String get qualifiedName 1366 String get qualifiedName
1367 => '${surroundingDeclaration.qualifiedName}.$canonicalName'; 1367 => '${surroundingDeclaration.qualifiedName}.$simpleName';
1368
1369 String get canonicalName => simpleName;
1370 1368
1371 ObjectMirror get surroundingDeclaration => _objectMirror; 1369 ObjectMirror get surroundingDeclaration => _objectMirror;
1372 1370
1373 bool get isTopLevel => _objectMirror is LibraryMirror; 1371 bool get isTopLevel => _objectMirror is LibraryMirror;
1374 1372
1375 bool get isConstructor => false; 1373 bool get isConstructor => false;
1376 1374
1377 bool get isField => true; 1375 bool get isField => true;
1378 1376
1379 bool get isMethod => false; 1377 bool get isMethod => false;
(...skipping 15 matching lines...) Expand all
1395 if (node !== null) { 1393 if (node !== null) {
1396 var span = system.compiler.spanFromNode(node, script.uri); 1394 var span = system.compiler.spanFromNode(node, script.uri);
1397 return new Dart2JsLocation(script, span); 1395 return new Dart2JsLocation(script, span);
1398 } else { 1396 } else {
1399 var span = system.compiler.spanFromElement(_variable); 1397 var span = system.compiler.spanFromElement(_variable);
1400 return new Dart2JsLocation(script, span); 1398 return new Dart2JsLocation(script, span);
1401 } 1399 }
1402 } 1400 }
1403 } 1401 }
1404 1402
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698