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

Side by Side Diff: runtime/lib/mirrors_impl.dart

Issue 23983026: Fill in type arguments when creating an object from the mirrors or embedding API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: const, rebase Created 7 years, 3 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
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // VM-specific implementation of the dart:mirrors library. 5 // VM-specific implementation of the dart:mirrors library.
6 6
7 import "dart:collection"; 7 import "dart:collection";
8 8
9 // These values are allowed to be passed directly over the wire. 9 // These values are allowed to be passed directly over the wire.
10 bool _isSimpleValue(var value) { 10 bool _isSimpleValue(var value) {
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 static _computeFunction(reflectee) 434 static _computeFunction(reflectee)
435 native 'ClosureMirror_function'; 435 native 'ClosureMirror_function';
436 } 436 }
437 437
438 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl 438 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl
439 implements ClassMirror { 439 implements ClassMirror {
440 _LocalClassMirrorImpl(reflectee, 440 _LocalClassMirrorImpl(reflectee,
441 this._reflectedType, 441 this._reflectedType,
442 String simpleName, 442 String simpleName,
443 this._isGeneric, 443 this._isGeneric,
444 this._isMixinTypedef) 444 this._isMixinTypedef,
445 this._isGenericDeclaration)
445 : this._simpleName = _s(simpleName), 446 : this._simpleName = _s(simpleName),
446 super(reflectee); 447 super(reflectee);
447 448
448 final Type _reflectedType; 449 final Type _reflectedType;
449 final bool _isGeneric; 450 final bool _isGeneric;
450 final bool _isMixinTypedef; 451 final bool _isMixinTypedef;
452 final bool _isGenericDeclaration;
451 453
452 bool get hasReflectedType => _reflectedType != null; 454 bool get hasReflectedType => !_isGenericDeclaration;
453 Type get reflectedType { 455 Type get reflectedType {
454 if (!hasReflectedType) { 456 if (!hasReflectedType) {
455 throw new UnsupportedError( 457 throw new UnsupportedError(
456 "Declarations of generics have no reflected type"); 458 "Declarations of generics have no reflected type");
457 } 459 }
458 return _reflectedType; 460 return _reflectedType;
459 } 461 }
460 462
461 Symbol _simpleName; 463 Symbol _simpleName;
462 Symbol get simpleName { 464 Symbol get simpleName {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 params[i + 1], params[i], this); 630 params[i + 1], params[i], this);
629 _typeVariables[mirror.simpleName] = mirror; 631 _typeVariables[mirror.simpleName] = mirror;
630 } 632 }
631 } 633 }
632 return _typeVariables; 634 return _typeVariables;
633 } 635 }
634 636
635 Map<Symbol, TypeMirror> _typeArguments = null; 637 Map<Symbol, TypeMirror> _typeArguments = null;
636 Map<Symbol, TypeMirror> get typeArguments { 638 Map<Symbol, TypeMirror> get typeArguments {
637 if(_typeArguments == null) { 639 if(_typeArguments == null) {
638 if(_reflectedType == null) { 640 if(_isGenericDeclaration) {
639 _typeArguments = new LinkedHashMap<Symbol, TypeMirror>(); 641 _typeArguments = new LinkedHashMap<Symbol, TypeMirror>();
640 } else { 642 } else {
641 _typeArguments = 643 _typeArguments =
642 new LinkedHashMap<Symbol, TypeMirror>.fromIterables(typeVariables.ke ys, 644 new LinkedHashMap<Symbol, TypeMirror>.fromIterables(typeVariables.ke ys,
643 _computeTypeArgu ments(_reflectedType)); 645 _computeTypeArgu ments(_reflectedType));
644 } 646 }
645 } 647 }
646 return _typeArguments; 648 return _typeArguments;
647 } 649 }
648 650
649 bool get isOriginalDeclaration { 651 bool get isOriginalDeclaration {
650 return !_isGeneric || _reflectedType == null; 652 return !_isGeneric || _isGenericDeclaration;
651 } 653 }
652 654
653 ClassMirror get originalDeclaration { 655 ClassMirror get originalDeclaration {
654 if (isOriginalDeclaration) { 656 if (isOriginalDeclaration) {
655 return this; 657 return this;
656 } else { 658 } else {
657 return reflectClass(_reflectedType); 659 return reflectClass(_reflectedType);
658 } 660 }
659 } 661 }
660 662
(...skipping 15 matching lines...) Expand all
676 int argumentIndex = numPositionalArguments; 678 int argumentIndex = numPositionalArguments;
677 int nameIndex = 0; 679 int nameIndex = 0;
678 if (numNamedArguments > 0) { 680 if (numNamedArguments > 0) {
679 namedArguments.forEach((name, value) { 681 namedArguments.forEach((name, value) {
680 arguments[argumentIndex++] = value; 682 arguments[argumentIndex++] = value;
681 names[nameIndex++] = _n(name); 683 names[nameIndex++] = _n(name);
682 }); 684 });
683 } 685 }
684 686
685 return reflect(_invokeConstructor(_reflectee, 687 return reflect(_invokeConstructor(_reflectee,
688 _reflectedType,
686 _n(constructorName), 689 _n(constructorName),
687 arguments, 690 arguments,
688 names)); 691 names));
689 } 692 }
690 693
691 Future<InstanceMirror> newInstanceAsync(Symbol constructorName, 694 Future<InstanceMirror> newInstanceAsync(Symbol constructorName,
692 List positionalArguments, 695 List positionalArguments,
693 [Map<Symbol, dynamic> namedArguments]) { 696 [Map<Symbol, dynamic> namedArguments]) {
694 return new Future(() { 697 return new Future(() {
695 return this.newInstance(constructorName, 698 return this.newInstance(constructorName,
696 _unwarpAsyncPositionals(positionalArguments), 699 _unwarpAsyncPositionals(positionalArguments),
697 _unwarpAsyncNamed(namedArguments)); 700 _unwarpAsyncNamed(namedArguments));
698 }); 701 });
699 } 702 }
700 703
701 List<InstanceMirror> get metadata { 704 List<InstanceMirror> get metadata {
702 // Get the metadata objects, convert them into InstanceMirrors using 705 // Get the metadata objects, convert them into InstanceMirrors using
703 // reflect() and then make them into a Dart list. 706 // reflect() and then make them into a Dart list.
704 return _metadata(_reflectee).map(reflect).toList(growable:false); 707 return _metadata(_reflectee).map(reflect).toList(growable:false);
705 } 708 }
706 709
707 bool operator ==(other) { 710 bool operator ==(other) {
708 return this.runtimeType == other.runtimeType && 711 return this.runtimeType == other.runtimeType &&
709 this._reflectee == other._reflectee && 712 this._reflectee == other._reflectee &&
710 this._reflectedType == other._reflectedType; 713 this._reflectedType == other._reflectedType &&
714 this._isGenericDeclaration == other._isGenericDeclaration;
711 } 715 }
712 716
713 int get hashCode => simpleName.hashCode; 717 int get hashCode => simpleName.hashCode;
714 718
715 static _library(reflectee) 719 static _library(reflectee)
716 native "ClassMirror_library"; 720 native "ClassMirror_library";
717 721
718 static _supertype(reflectee) 722 static _supertype(reflectee)
719 native "ClassMirror_supertype"; 723 native "ClassMirror_supertype";
720 724
(...skipping 11 matching lines...) Expand all
732 736
733 _invoke(reflectee, memberName, arguments, argumentNames) 737 _invoke(reflectee, memberName, arguments, argumentNames)
734 native 'ClassMirror_invoke'; 738 native 'ClassMirror_invoke';
735 739
736 _invokeGetter(reflectee, getterName) 740 _invokeGetter(reflectee, getterName)
737 native 'ClassMirror_invokeGetter'; 741 native 'ClassMirror_invokeGetter';
738 742
739 _invokeSetter(reflectee, setterName, value) 743 _invokeSetter(reflectee, setterName, value)
740 native 'ClassMirror_invokeSetter'; 744 native 'ClassMirror_invokeSetter';
741 745
742 static _invokeConstructor(reflectee, constructorName, arguments, argumentNames ) 746 static _invokeConstructor(reflectee, type, constructorName, arguments, argumen tNames)
743 native 'ClassMirror_invokeConstructor'; 747 native 'ClassMirror_invokeConstructor';
744 748
745 static _ClassMirror_type_variables(reflectee) 749 static _ClassMirror_type_variables(reflectee)
746 native "ClassMirror_type_variables"; 750 native "ClassMirror_type_variables";
747 751
748 static _computeTypeArguments(reflectee) 752 static _computeTypeArguments(reflectee)
749 native "ClassMirror_type_arguments"; 753 native "ClassMirror_type_arguments";
750 } 754 }
751 755
752 class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl 756 class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl
753 implements FunctionTypeMirror { 757 implements FunctionTypeMirror {
754 _LocalFunctionTypeMirrorImpl(reflectee, reflectedType) 758 _LocalFunctionTypeMirrorImpl(reflectee, reflectedType)
755 : super(reflectee, reflectedType, null, false, false); 759 : super(reflectee, reflectedType, null, false, false, false);
756 760
757 // FunctionTypeMirrors have a simpleName generated from their signature. 761 // FunctionTypeMirrors have a simpleName generated from their signature.
758 Symbol _simpleName = null; 762 Symbol _simpleName = null;
759 Symbol get simpleName { 763 Symbol get simpleName {
760 if (_simpleName == null) { 764 if (_simpleName == null) {
761 _simpleName = _s(_makeSignatureString(returnType, parameters)); 765 _simpleName = _s(_makeSignatureString(returnType, parameters));
762 } 766 }
763 return _simpleName; 767 return _simpleName;
764 } 768 }
765 769
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 if (typeMirror == null) { 1376 if (typeMirror == null) {
1373 typeMirror = makeLocalTypeMirror(key); 1377 typeMirror = makeLocalTypeMirror(key);
1374 _instanitationCache[key] = typeMirror; 1378 _instanitationCache[key] = typeMirror;
1375 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { 1379 if (typeMirror is ClassMirror && !typeMirror._isGeneric) {
1376 _declarationCache[key] = typeMirror; 1380 _declarationCache[key] = typeMirror;
1377 } 1381 }
1378 } 1382 }
1379 return typeMirror; 1383 return typeMirror;
1380 } 1384 }
1381 } 1385 }
OLDNEW
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698