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

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

Issue 23451052: Mirrors cleanup. No semantic changes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 | « no previous file | no next file » | 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) {
11 return (value == null || value is num || value is String || value is bool); 11 return (value == null || value is num || value is String || value is bool);
12 } 12 }
13 13
14 Map _filterMap(Map<Symbol, dynamic> old_map, bool filter(Symbol key, value)) { 14 Map _filterMap(Map<Symbol, dynamic> old_map, bool filter(Symbol key, value)) {
15 Map new_map = new Map<Symbol, dynamic>(); 15 Map new_map = new Map<Symbol, dynamic>();
16 old_map.forEach((key, value) { 16 old_map.forEach((key, value) {
17 if (filter(key, value)) { 17 if (filter(key, value)) {
18 new_map[key] = value; 18 new_map[key] = value;
19 } 19 }
20 }); 20 });
21 return new_map; 21 return new_map;
22 } 22 }
23 23
24 Map _makeMemberMap(List mirrors) { 24 Map _makeMemberMap(List mirrors) => new Map.fromIterable(
rmacnak 2013/09/12 01:17:31 Give type arguments to the constructor.
Michael Lippautz (Google) 2013/09/12 01:31:15 Done.
25 Map result = new Map<Symbol, dynamic>(); 25 mirrors, key: (e) => e.simpleName);
26 mirrors.forEach((mirror) => result[mirror.simpleName] = mirror);
27 return result;
28 }
29 26
30 String _n(Symbol symbol) => _symbol_dev.Symbol.getName(symbol); 27 String _n(Symbol symbol) => _symbol_dev.Symbol.getName(symbol);
31 28
32 Symbol _s(String name) { 29 Symbol _s(String name) {
33 if (name == null) return null; 30 if (name == null) return null;
34 return new _symbol_dev.Symbol.unvalidated(name); 31 return new _symbol_dev.Symbol.unvalidated(name);
35 } 32 }
36 33
37 Symbol _computeQualifiedName(DeclarationMirror owner, Symbol simpleName) { 34 Symbol _computeQualifiedName(DeclarationMirror owner, Symbol simpleName) {
38 if (owner == null) return simpleName; 35 if (owner == null) return simpleName;
39 return _s('${_n(owner.qualifiedName)}.${_n(simpleName)}'); 36 return _s('${_n(owner.qualifiedName)}.${_n(simpleName)}');
40 } 37 }
41 38
42 Map<Symbol, dynamic> _convertStringToSymbolMap(Map<String, dynamic> map) {
43 if (map == null) return null;
44 Map<Symbol, dynamic> result = new Map<Symbol, dynamic>();
45 map.forEach((name, value) => result[_s(name)] = value);
46 return result;
47 }
48
49 String _makeSignatureString(TypeMirror returnType, 39 String _makeSignatureString(TypeMirror returnType,
50 List<ParameterMirror> parameters) { 40 List<ParameterMirror> parameters) {
51 StringBuffer buf = new StringBuffer(); 41 StringBuffer buf = new StringBuffer();
52 buf.write('('); 42 buf.write('(');
53 bool found_optional_positional = false; 43 bool found_optional_positional = false;
54 bool found_optional_named = false; 44 bool found_optional_named = false;
55 45
56 for (int i = 0; i < parameters.length; i++) { 46 for (int i = 0; i < parameters.length; i++) {
57 var param = parameters[i]; 47 var param = parameters[i];
58 if (param.isOptional && param.isNamed && !found_optional_named) { 48 if (param.isOptional && param.isNamed && !found_optional_named) {
(...skipping 17 matching lines...) Expand all
76 buf.write('}'); 66 buf.write('}');
77 } 67 }
78 if (found_optional_positional) { 68 if (found_optional_positional) {
79 buf.write(']'); 69 buf.write(']');
80 } 70 }
81 buf.write(') -> '); 71 buf.write(') -> ');
82 buf.write(_n(returnType.qualifiedName)); 72 buf.write(_n(returnType.qualifiedName));
83 return buf.toString(); 73 return buf.toString();
84 } 74 }
85 75
86 Map<Uri, LibraryMirror> _createLibrariesMap(List<LibraryMirror> list) {
87 var map = new Map<Uri, LibraryMirror>();
88 list.forEach((LibraryMirror mirror) => map[mirror.uri] = mirror);
89 return map;
90 }
91
92 List _metadata(reflectee) 76 List _metadata(reflectee)
93 native 'DeclarationMirror_metadata'; 77 native 'DeclarationMirror_metadata';
94 78
95 // This will verify the argument types, unwrap them, and ensure we have a fixed 79 // This will verify the argument types, unwrap them, and ensure we have a fixed
96 // array. 80 // array.
97 List _unwarpAsyncPositionals(wrappedArgs) { 81 List _unwrapAsyncPositionals(wrappedArgs) {
98 List unwrappedArgs = new List(wrappedArgs.length); 82 List unwrappedArgs = new List(wrappedArgs.length);
99 for(int i = 0; i < wrappedArgs.length; i++){ 83 for(int i = 0; i < wrappedArgs.length; i++){
100 var wrappedArg = wrappedArgs[i]; 84 var wrappedArg = wrappedArgs[i];
101 if(_isSimpleValue(wrappedArg)) { 85 if(_isSimpleValue(wrappedArg)) {
102 unwrappedArgs[i] = wrappedArg; 86 unwrappedArgs[i] = wrappedArg;
103 } else if(wrappedArg is InstanceMirror) { 87 } else if(wrappedArg is InstanceMirror) {
104 unwrappedArgs[i] = wrappedArg._reflectee; 88 unwrappedArgs[i] = wrappedArg._reflectee;
105 } else { 89 } else {
106 throw "positional argument $i ($wrappedArg) was " 90 throw "positional argument $i ($wrappedArg) was "
107 "not a simple value or InstanceMirror"; 91 "not a simple value or InstanceMirror";
108 } 92 }
109 } 93 }
110 return unwrappedArgs; 94 return unwrappedArgs;
111 } 95 }
112 Map _unwarpAsyncNamed(wrappedArgs) { 96
97 Map _unwrapAsyncNamed(wrappedArgs) {
113 if (wrappedArgs==null) return null; 98 if (wrappedArgs==null) return null;
114 Map unwrappedArgs = new Map(); 99 Map unwrappedArgs = new Map();
115 wrappedArgs.forEach((name, wrappedArg){ 100 wrappedArgs.forEach((name, wrappedArg){
116 if(_isSimpleValue(wrappedArg)) { 101 if(_isSimpleValue(wrappedArg)) {
117 unwrappedArgs[name] = wrappedArg; 102 unwrappedArgs[name] = wrappedArg;
118 } else if(wrappedArg is InstanceMirror) { 103 } else if(wrappedArg is InstanceMirror) {
119 unwrappedArgs[name] = wrappedArg._reflectee; 104 unwrappedArgs[name] = wrappedArg._reflectee;
120 } else { 105 } else {
121 throw "named argument ${_n(name)} ($wrappedArg) was " 106 throw "named argument ${_n(name)} ($wrappedArg) was "
122 "not a simple value or InstanceMirror"; 107 "not a simple value or InstanceMirror";
123 } 108 }
124 }); 109 });
125 return unwrappedArgs; 110 return unwrappedArgs;
126 } 111 }
127 112
128 class _LocalMirrorSystemImpl extends MirrorSystem { 113 class _LocalMirrorSystemImpl extends MirrorSystem {
129 // Change parameter back to "this.libraries" when native code is changed. 114 // Change parameter back to "this.libraries" when native code is changed.
130 _LocalMirrorSystemImpl(List<LibraryMirror> libraries, this.isolate) 115 _LocalMirrorSystemImpl(List<LibraryMirror> libraries, this.isolate)
131 : this.libraries = _createLibrariesMap(libraries); 116 : this.libraries = new Map.fromIterable(libraries, key: (e) => e.uri);
rmacnak 2013/09/12 01:17:31 Ditto.
Michael Lippautz (Google) 2013/09/12 01:31:15 Done.
132 117
133 final Map<Uri, LibraryMirror> libraries; 118 final Map<Uri, LibraryMirror> libraries;
134 final IsolateMirror isolate; 119 final IsolateMirror isolate;
135 120
136 TypeMirror _dynamicType = null; 121 TypeMirror _dynamicType = null;
137
138 TypeMirror get dynamicType { 122 TypeMirror get dynamicType {
139 if (_dynamicType == null) { 123 if (_dynamicType == null) {
140 _dynamicType = new _SpecialTypeMirrorImpl('dynamic'); 124 _dynamicType = new _SpecialTypeMirrorImpl('dynamic');
141 } 125 }
142 return _dynamicType; 126 return _dynamicType;
143 } 127 }
144 128
145 TypeMirror _voidType = null; 129 TypeMirror _voidType = null;
146
147 TypeMirror get voidType { 130 TypeMirror get voidType {
148 if (_voidType == null) { 131 if (_voidType == null) {
149 _voidType = new _SpecialTypeMirrorImpl('void'); 132 _voidType = new _SpecialTypeMirrorImpl('void');
150 } 133 }
151 return _voidType; 134 return _voidType;
152 } 135 }
153 136
154 String toString() => "MirrorSystem for isolate '${isolate.debugName}'"; 137 String toString() => "MirrorSystem for isolate '${isolate.debugName}'";
155 } 138 }
156 139
157 abstract class _LocalMirrorImpl implements Mirror { 140 abstract class _LocalMirrorImpl implements Mirror {
158 int get hashCode { 141 int get hashCode {
159 throw new UnimplementedError('Mirror.hashCode is not implemented'); 142 throw new UnimplementedError('Mirror.hashCode is not implemented');
160 } 143 }
161 144
162 // Local mirrors always return the same MirrorSystem. This field 145 // Local mirrors always return the same MirrorSystem. This field
163 // is more interesting once we implement remote mirrors. 146 // is more interesting once we implement remote mirrors.
164 MirrorSystem get mirrors => _Mirrors.currentMirrorSystem(); 147 MirrorSystem get mirrors => _Mirrors.currentMirrorSystem();
165 } 148 }
166 149
167 class _LocalIsolateMirrorImpl extends _LocalMirrorImpl 150 class _LocalIsolateMirrorImpl extends _LocalMirrorImpl
168 implements IsolateMirror { 151 implements IsolateMirror {
169 _LocalIsolateMirrorImpl(this.debugName, this.rootLibrary) {} 152 _LocalIsolateMirrorImpl(this.debugName, this.rootLibrary);
170 153
171 final String debugName; 154 final String debugName;
172 final bool isCurrent = true; 155 final bool isCurrent = true;
173 final LibraryMirror rootLibrary; 156 final LibraryMirror rootLibrary;
174 157
175 String toString() => "IsolateMirror on '$debugName'"; 158 String toString() => "IsolateMirror on '$debugName'";
176 } 159 }
177 160
178 abstract class _LocalObjectMirrorImpl extends _LocalMirrorImpl 161 abstract class _LocalObjectMirrorImpl extends _LocalMirrorImpl
179 implements ObjectMirror { 162 implements ObjectMirror {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 _n(memberName), 199 _n(memberName),
217 value); 200 value);
218 return reflect(value); 201 return reflect(value);
219 } 202 }
220 203
221 Future<InstanceMirror> invokeAsync(Symbol memberName, 204 Future<InstanceMirror> invokeAsync(Symbol memberName,
222 List positionalArguments, 205 List positionalArguments,
223 [Map<Symbol, dynamic> namedArguments]) { 206 [Map<Symbol, dynamic> namedArguments]) {
224 return new Future(() { 207 return new Future(() {
225 return this.invoke(memberName, 208 return this.invoke(memberName,
226 _unwarpAsyncPositionals(positionalArguments), 209 _unwrapAsyncPositionals(positionalArguments),
227 _unwarpAsyncNamed(namedArguments)); 210 _unwrapAsyncNamed(namedArguments));
228 }); 211 });
229 } 212 }
230 213
231 Future<InstanceMirror> getFieldAsync(Symbol memberName) { 214 Future<InstanceMirror> getFieldAsync(Symbol memberName) {
232 try { 215 try {
233 var result = this._invokeGetter(_reflectee, 216 var result = this._invokeGetter(_reflectee,
234 _n(memberName)); 217 _n(memberName));
235 return new Future.value(reflect(result)); 218 return new Future.value(reflect(result));
236 } catch(e) { 219 } catch(e) {
237 return new Future.error(e); 220 return new Future.error(e);
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 } 392 }
410 393
411 // It is tempting to implement this in terms of Function.apply, but then 394 // It is tempting to implement this in terms of Function.apply, but then
412 // lazy compilation errors would be fatal. 395 // lazy compilation errors would be fatal.
413 return reflect(_apply(_reflectee, arguments, names)); 396 return reflect(_apply(_reflectee, arguments, names));
414 } 397 }
415 398
416 Future<InstanceMirror> applyAsync(List positionalArguments, 399 Future<InstanceMirror> applyAsync(List positionalArguments,
417 [Map<Symbol, dynamic> namedArguments]) { 400 [Map<Symbol, dynamic> namedArguments]) {
418 return new Future(() { 401 return new Future(() {
419 return this.apply(_unwarpAsyncPositionals(positionalArguments), 402 return this.apply(_unwrapAsyncPositionals(positionalArguments),
420 _unwarpAsyncNamed(namedArguments)); 403 _unwrapAsyncNamed(namedArguments));
421 }); 404 });
422 } 405 }
423 406
424 Future<InstanceMirror> findInContext(Symbol name) { 407 Future<InstanceMirror> findInContext(Symbol name) {
425 throw new UnimplementedError( 408 throw new UnimplementedError(
426 'ClosureMirror.findInContext() is not implemented'); 409 'ClosureMirror.findInContext() is not implemented');
427 } 410 }
428 411
429 String toString() => "ClosureMirror on '${Error.safeToString(_reflectee)}'"; 412 String toString() => "ClosureMirror on '${Error.safeToString(_reflectee)}'";
430 413
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 _owner = _library(_reflectee); 466 _owner = _library(_reflectee);
484 } 467 }
485 return _owner; 468 return _owner;
486 } 469 }
487 470
488 bool get isPrivate => _n(simpleName).startsWith('_'); 471 bool get isPrivate => _n(simpleName).startsWith('_');
489 472
490 final bool isTopLevel = true; 473 final bool isTopLevel = true;
491 474
492 SourceLocation get location { 475 SourceLocation get location {
493 throw new UnimplementedError( 476 throw new UnimplementedError('ClassMirror.location is not implemented');
494 'ClassMirror.location is not implemented');
495 } 477 }
496 478
497 // TODO(rmacnak): Remove these left-overs from the days of separate interfaces 479 // TODO(rmacnak): Remove these left-overs from the days of separate interfaces
498 // once we send out a breaking change. 480 // once we send out a breaking change.
499 bool get isClass => true; 481 bool get isClass => true;
500 ClassMirror get defaultFactory => null; 482 ClassMirror get defaultFactory => null;
501 483
502 ClassMirror _trueSuperclassField; 484 ClassMirror _trueSuperclassField;
503 ClassMirror get _trueSuperclass { 485 ClassMirror get _trueSuperclass {
504 if (_trueSuperclassField == null) { 486 if (_trueSuperclassField == null) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 _mixin = this; 531 _mixin = this;
550 } else { 532 } else {
551 _mixin = _Mirrors._reflectType(mixinType); 533 _mixin = _Mirrors._reflectType(mixinType);
552 } 534 }
553 } 535 }
554 } 536 }
555 return _mixin; 537 return _mixin;
556 } 538 }
557 539
558 Map<Symbol, Mirror> _members; 540 Map<Symbol, Mirror> _members;
559
560 Map<Symbol, Mirror> get members { 541 Map<Symbol, Mirror> get members {
561 if (_members == null) { 542 if (_members == null) {
562 var whoseMembers = _isMixinTypedef ? _trueSuperclass : this; 543 var whoseMembers = _isMixinTypedef ? _trueSuperclass : this;
563 _members = _makeMemberMap(mixin._computeMembers(whoseMembers._reflectee)); 544 _members = _makeMemberMap(mixin._computeMembers(whoseMembers._reflectee));
564 } 545 }
565 return _members; 546 return _members;
566 } 547 }
567 548
568 Map<Symbol, MethodMirror> _methods = null; 549 Map<Symbol, MethodMirror> _methods;
569 Map<Symbol, MethodMirror> _getters = null;
570 Map<Symbol, MethodMirror> _setters = null;
571 Map<Symbol, VariableMirror> _variables = null;
572
573 Map<Symbol, MethodMirror> get methods { 550 Map<Symbol, MethodMirror> get methods {
574 if (_methods == null) { 551 if (_methods == null) {
575 _methods = _filterMap( 552 _methods = _filterMap(
576 members, 553 members,
577 (key, value) => (value is MethodMirror && value.isRegularMethod)); 554 (key, value) => (value is MethodMirror && value.isRegularMethod));
578 } 555 }
579 return _methods; 556 return _methods;
580 } 557 }
581 558
559 Map<Symbol, MethodMirror> _getters;
582 Map<Symbol, MethodMirror> get getters { 560 Map<Symbol, MethodMirror> get getters {
583 if (_getters == null) { 561 if (_getters == null) {
584 _getters = _filterMap( 562 _getters = _filterMap(
585 members, 563 members,
586 (key, value) => (value is MethodMirror && value.isGetter)); 564 (key, value) => (value is MethodMirror && value.isGetter));
587 } 565 }
588 return _getters; 566 return _getters;
589 } 567 }
590 568
569 Map<Symbol, MethodMirror> _setters;
591 Map<Symbol, MethodMirror> get setters { 570 Map<Symbol, MethodMirror> get setters {
592 if (_setters == null) { 571 if (_setters == null) {
593 _setters = _filterMap( 572 _setters = _filterMap(
594 members, 573 members,
595 (key, value) => (value is MethodMirror && value.isSetter)); 574 (key, value) => (value is MethodMirror && value.isSetter));
596 } 575 }
597 return _setters; 576 return _setters;
598 } 577 }
599 578
579 Map<Symbol, VariableMirror> _variables;
600 Map<Symbol, VariableMirror> get variables { 580 Map<Symbol, VariableMirror> get variables {
601 if (_variables == null) { 581 if (_variables == null) {
602 _variables = _filterMap( 582 _variables = _filterMap(
603 members, 583 members,
604 (key, value) => (value is VariableMirror)); 584 (key, value) => (value is VariableMirror));
605 } 585 }
606 return _variables; 586 return _variables;
607 } 587 }
608 588
609 Map<Symbol, MethodMirror> _constructors; 589 Map<Symbol, MethodMirror> _constructors;
610
611 Map<Symbol, MethodMirror> get constructors { 590 Map<Symbol, MethodMirror> get constructors {
612 if (_constructors == null) { 591 if (_constructors == null) {
613 var constructorsList = _computeConstructors(_reflectee); 592 var constructorsList = _computeConstructors(_reflectee);
614 var stringName = _n(simpleName); 593 var stringName = _n(simpleName);
615 constructorsList.forEach((c) => c._patchConstructorName(stringName)); 594 constructorsList.forEach((c) => c._patchConstructorName(stringName));
616 _constructors = _makeMemberMap(constructorsList); 595 _constructors = _makeMemberMap(constructorsList);
617 } 596 }
618 return _constructors; 597 return _constructors;
619 } 598 }
620 599
621 Map<Symbol, TypeVariableMirror> _typeVariables = null; 600 Map<Symbol, TypeVariableMirror> _typeVariables = null;
622
623 Map<Symbol, TypeVariableMirror> get typeVariables { 601 Map<Symbol, TypeVariableMirror> get typeVariables {
624 if (_typeVariables == null) { 602 if (_typeVariables == null) {
625 List params = _ClassMirror_type_variables(_reflectee); 603 List params = _ClassMirror_type_variables(_reflectee);
626 _typeVariables = new LinkedHashMap<Symbol, TypeVariableMirror>(); 604 _typeVariables = new LinkedHashMap<Symbol, TypeVariableMirror>();
627 var mirror; 605 var mirror;
628 for (var i = 0; i < params.length; i += 2) { 606 for (var i = 0; i < params.length; i += 2) {
629 mirror = new _LocalTypeVariableMirrorImpl( 607 mirror = new _LocalTypeVariableMirrorImpl(
630 params[i + 1], params[i], this); 608 params[i + 1], params[i], this);
631 _typeVariables[mirror.simpleName] = mirror; 609 _typeVariables[mirror.simpleName] = mirror;
632 } 610 }
633 } 611 }
634 return _typeVariables; 612 return _typeVariables;
635 } 613 }
636 614
637 Map<Symbol, TypeMirror> _typeArguments = null; 615 Map<Symbol, TypeMirror> _typeArguments = null;
638 Map<Symbol, TypeMirror> get typeArguments { 616 Map<Symbol, TypeMirror> get typeArguments {
639 if(_typeArguments == null) { 617 if(_typeArguments == null) {
640 if(_isGenericDeclaration) { 618 if(_isGenericDeclaration) {
641 _typeArguments = new LinkedHashMap<Symbol, TypeMirror>(); 619 _typeArguments = new LinkedHashMap<Symbol, TypeMirror>();
642 } else { 620 } else {
643 _typeArguments = 621 _typeArguments =
644 new LinkedHashMap<Symbol, TypeMirror>.fromIterables(typeVariables.ke ys, 622 new LinkedHashMap<Symbol, TypeMirror>.fromIterables(
645 _computeTypeArgu ments(_reflectedType)); 623 typeVariables.keys, _computeTypeArguments(_reflectedType));
646 } 624 }
647 } 625 }
648 return _typeArguments; 626 return _typeArguments;
649 } 627 }
650 628
651 bool get isOriginalDeclaration { 629 bool get isOriginalDeclaration => !_isGeneric || _isGenericDeclaration;
652 return !_isGeneric || _isGenericDeclaration;
653 }
654 630
655 ClassMirror get originalDeclaration { 631 ClassMirror get originalDeclaration {
656 if (isOriginalDeclaration) { 632 if (isOriginalDeclaration) {
657 return this; 633 return this;
658 } else { 634 } else {
659 return reflectClass(_reflectedType); 635 return reflectClass(_reflectedType);
660 } 636 }
661 } 637 }
662 638
663 String toString() { 639 String toString() => "ClassMirror on '${_n(simpleName)}'";
664 return "ClassMirror on '${_n(simpleName)}'";
665 }
666 640
667 InstanceMirror newInstance(Symbol constructorName, 641 InstanceMirror newInstance(Symbol constructorName,
668 List positionalArguments, 642 List positionalArguments,
669 [Map<Symbol, dynamic> namedArguments]) { 643 [Map<Symbol, dynamic> namedArguments]) {
670 // Native code will add the 1 or 2 implicit arguments depending on whether 644 // Native code will add the 1 or 2 implicit arguments depending on whether
671 // we end up invoking a factory or constructor respectively. 645 // we end up invoking a factory or constructor respectively.
672 int numPositionalArguments = positionalArguments.length; 646 int numPositionalArguments = positionalArguments.length;
673 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; 647 int numNamedArguments = namedArguments != null ? namedArguments.length : 0;
674 int numArguments = numPositionalArguments + numNamedArguments; 648 int numArguments = numPositionalArguments + numNamedArguments;
675 List arguments = new List(numArguments); 649 List arguments = new List(numArguments);
(...skipping 13 matching lines...) Expand all
689 _n(constructorName), 663 _n(constructorName),
690 arguments, 664 arguments,
691 names)); 665 names));
692 } 666 }
693 667
694 Future<InstanceMirror> newInstanceAsync(Symbol constructorName, 668 Future<InstanceMirror> newInstanceAsync(Symbol constructorName,
695 List positionalArguments, 669 List positionalArguments,
696 [Map<Symbol, dynamic> namedArguments]) { 670 [Map<Symbol, dynamic> namedArguments]) {
697 return new Future(() { 671 return new Future(() {
698 return this.newInstance(constructorName, 672 return this.newInstance(constructorName,
699 _unwarpAsyncPositionals(positionalArguments), 673 _unwrapAsyncPositionals(positionalArguments),
700 _unwarpAsyncNamed(namedArguments)); 674 _unwrapAsyncNamed(namedArguments));
701 }); 675 });
702 } 676 }
703 677
704 List<InstanceMirror> get metadata { 678 List<InstanceMirror> get metadata {
705 // Get the metadata objects, convert them into InstanceMirrors using 679 // Get the metadata objects, convert them into InstanceMirrors using
706 // reflect() and then make them into a Dart list. 680 // reflect() and then make them into a Dart list.
707 return _metadata(_reflectee).map(reflect).toList(growable:false); 681 return _metadata(_reflectee).map(reflect).toList(growable:false);
708 } 682 }
709 683
710 bool operator ==(other) { 684 bool operator ==(other) {
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 } 864 }
891 865
892 866
893 class _LocalTypedefMirrorImpl extends _LocalDeclarationMirrorImpl 867 class _LocalTypedefMirrorImpl extends _LocalDeclarationMirrorImpl
894 implements TypedefMirror { 868 implements TypedefMirror {
895 _LocalTypedefMirrorImpl(reflectee, 869 _LocalTypedefMirrorImpl(reflectee,
896 String simpleName, 870 String simpleName,
897 this._owner) 871 this._owner)
898 : super(reflectee, _s(simpleName)); 872 : super(reflectee, _s(simpleName));
899 873
874 final bool isTopLevel = true;
875
900 // TODO(12282): Deal with generic typedefs. 876 // TODO(12282): Deal with generic typedefs.
901 bool get _isGeneric => false; 877 bool get _isGeneric => false;
902 878
879 bool get isPrivate => false;
880
903 DeclarationMirror _owner; 881 DeclarationMirror _owner;
904 DeclarationMirror get owner { 882 DeclarationMirror get owner {
905 if (_owner == null) { 883 if (_owner == null) {
906 _owner = _LocalClassMirrorImpl._library(_reflectee); 884 _owner = _LocalClassMirrorImpl._library(_reflectee);
907 } 885 }
908 return _owner; 886 return _owner;
909 } 887 }
910 888
911 bool get isPrivate => false;
912
913 final bool isTopLevel = true;
914
915 SourceLocation get location { 889 SourceLocation get location {
916 throw new UnimplementedError( 890 throw new UnimplementedError('TypedefMirror.location is not implemented');
917 'TypedefMirror.location is not implemented');
918 } 891 }
919 892
920 TypeMirror _referent = null; 893 TypeMirror _referent = null;
921 TypeMirror get referent { 894 TypeMirror get referent {
922 if (_referent == null) { 895 if (_referent == null) {
923 // TODO(12282): Deal with generic typedef. 896 // TODO(12282): Deal with generic typedef.
924 return new _LocalFunctionTypeMirrorImpl( 897 return new _LocalFunctionTypeMirrorImpl(
925 _TypedefMirror_referent(_reflectee), null); 898 _TypedefMirror_referent(_reflectee), null);
926 } 899 }
927 return _referent; 900 return _referent;
(...skipping 22 matching lines...) Expand all
950 // Always null for libraries. 923 // Always null for libraries.
951 final DeclarationMirror owner = null; 924 final DeclarationMirror owner = null;
952 925
953 // Always false for libraries. 926 // Always false for libraries.
954 final bool isPrivate = false; 927 final bool isPrivate = false;
955 928
956 // Always false for libraries. 929 // Always false for libraries.
957 final bool isTopLevel = false; 930 final bool isTopLevel = false;
958 931
959 SourceLocation get location { 932 SourceLocation get location {
960 throw new UnimplementedError( 933 throw new UnimplementedError('LibraryMirror.location is not implemented');
961 'LibraryMirror.location is not implemented');
962 } 934 }
963 935
964 final Uri uri; 936 final Uri uri;
965 937
966 Map<Symbol, Mirror> _members; 938 Map<Symbol, Mirror> _members;
967
968 Map<Symbol, Mirror> get members { 939 Map<Symbol, Mirror> get members {
969 if (_members == null) { 940 if (_members == null) {
970 _members = _makeMemberMap(_computeMembers(_reflectee)); 941 _members = _makeMemberMap(_computeMembers(_reflectee));
971 } 942 }
972 return _members; 943 return _members;
973 } 944 }
974 945
975 Map<Symbol, ClassMirror> _classes = null; 946 Map<Symbol, ClassMirror> _classes;
976 Map<Symbol, MethodMirror> _functions = null;
977 Map<Symbol, MethodMirror> _getters = null;
978 Map<Symbol, MethodMirror> _setters = null;
979 Map<Symbol, VariableMirror> _variables = null;
980
981 Map<Symbol, ClassMirror> get classes { 947 Map<Symbol, ClassMirror> get classes {
982 if (_classes == null) { 948 if (_classes == null) {
983 _classes = _filterMap(members, 949 _classes = _filterMap(members,
984 (key, value) => (value is ClassMirror)); 950 (key, value) => (value is ClassMirror));
985 } 951 }
986 return _classes; 952 return _classes;
987 } 953 }
988 954
955 Map<Symbol, MethodMirror> _functions;
989 Map<Symbol, MethodMirror> get functions { 956 Map<Symbol, MethodMirror> get functions {
990 if (_functions == null) { 957 if (_functions == null) {
991 _functions = _filterMap(members, 958 _functions = _filterMap(members, (key, value) => (value is MethodMirror));
992 (key, value) => (value is MethodMirror));
993 } 959 }
994 return _functions; 960 return _functions;
995 } 961 }
996 962
963 Map<Symbol, MethodMirror> _getters;
997 Map<Symbol, MethodMirror> get getters { 964 Map<Symbol, MethodMirror> get getters {
998 if (_getters == null) { 965 if (_getters == null) {
999 _getters = _filterMap(functions, 966 _getters = _filterMap(functions, (key, value) => (value.isGetter));
1000 (key, value) => (value.isGetter));
1001 } 967 }
1002 return _getters; 968 return _getters;
1003 } 969 }
1004 970
971 Map<Symbol, MethodMirror> _setters;
1005 Map<Symbol, MethodMirror> get setters { 972 Map<Symbol, MethodMirror> get setters {
1006 if (_setters == null) { 973 if (_setters == null) {
1007 _setters = _filterMap(functions, 974 _setters = _filterMap(functions, (key, value) => (value.isSetter));
1008 (key, value) => (value.isSetter));
1009 } 975 }
1010 return _setters; 976 return _setters;
1011 } 977 }
1012 978
979 Map<Symbol, VariableMirror> _variables;
1013 Map<Symbol, VariableMirror> get variables { 980 Map<Symbol, VariableMirror> get variables {
1014 if (_variables == null) { 981 if (_variables == null) {
1015 _variables = _filterMap(members, 982 _variables = _filterMap(members,
1016 (key, value) => (value is VariableMirror)); 983 (key, value) => (value is VariableMirror));
1017 } 984 }
1018 return _variables; 985 return _variables;
1019 } 986 }
1020 987
1021 List<InstanceMirror> get metadata { 988 List<InstanceMirror> get metadata {
1022 // Get the metadata objects, convert them into InstanceMirrors using 989 // Get the metadata objects, convert them into InstanceMirrors using
1023 // reflect() and then make them into a Dart list. 990 // reflect() and then make them into a Dart list.
1024 return _metadata(_reflectee).map(reflect).toList(growable:false); 991 return _metadata(_reflectee).map(reflect).toList(growable:false);
1025 } 992 }
1026 993
1027 String toString() => "LibraryMirror on '${_n(simpleName)}'";
1028
1029 bool operator ==(other) { 994 bool operator ==(other) {
1030 return this.runtimeType == other.runtimeType && 995 return this.runtimeType == other.runtimeType &&
1031 this._reflectee == other._reflectee; 996 this._reflectee == other._reflectee;
1032 } 997 }
1033 998
1034 int get hashCode => simpleName.hashCode; 999 int get hashCode => simpleName.hashCode;
1035 1000
1001 String toString() => "LibraryMirror on '${_n(simpleName)}'";
1002
1036 _invoke(reflectee, memberName, arguments, argumentNames) 1003 _invoke(reflectee, memberName, arguments, argumentNames)
1037 native 'LibraryMirror_invoke'; 1004 native 'LibraryMirror_invoke';
1038 1005
1039 _invokeGetter(reflectee, getterName) 1006 _invokeGetter(reflectee, getterName)
1040 native 'LibraryMirror_invokeGetter'; 1007 native 'LibraryMirror_invokeGetter';
1041 1008
1042 _invokeSetter(reflectee, setterName, value) 1009 _invokeSetter(reflectee, setterName, value)
1043 native 'LibraryMirror_invokeSetter'; 1010 native 'LibraryMirror_invokeSetter';
1044 1011
1045 _computeMembers(reflectee) 1012 _computeMembers(reflectee)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 DeclarationMirror _owner; 1047 DeclarationMirror _owner;
1081 DeclarationMirror get owner { 1048 DeclarationMirror get owner {
1082 // For nested closures it is possible, that the mirror for the owner has not 1049 // For nested closures it is possible, that the mirror for the owner has not
1083 // been created yet. 1050 // been created yet.
1084 if (_owner == null) { 1051 if (_owner == null) {
1085 _owner = _MethodMirror_owner(_reflectee); 1052 _owner = _MethodMirror_owner(_reflectee);
1086 } 1053 }
1087 return _owner; 1054 return _owner;
1088 } 1055 }
1089 1056
1090 bool get isPrivate { 1057 bool get isPrivate => _n(simpleName).startsWith('_') ||
1091 return _n(simpleName).startsWith('_') || 1058 _n(constructorName).startsWith('_');
1092 _n(constructorName).startsWith('_');
1093 }
1094 1059
1095 bool get isTopLevel => owner is LibraryMirror; 1060 bool get isTopLevel => owner is LibraryMirror;
1096 1061
1097 SourceLocation get location { 1062 SourceLocation get location {
1098 throw new UnimplementedError( 1063 throw new UnimplementedError('MethodMirror.location is not implemented');
1099 'MethodMirror.location is not implemented');
1100 } 1064 }
1101 1065
1102 TypeMirror _returnType = null; 1066 TypeMirror _returnType = null;
1103 TypeMirror get returnType { 1067 TypeMirror get returnType {
1104 if (_returnType == null) { 1068 if (_returnType == null) {
1105 if (isConstructor) { 1069 if (isConstructor) {
1106 _returnType = owner; 1070 _returnType = owner;
1107 } else { 1071 } else {
1108 _returnType = 1072 _returnType =
1109 _Mirrors._reflectType(_MethodMirror_return_type(_reflectee)); 1073 _Mirrors._reflectType(_MethodMirror_return_type(_reflectee));
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 implements VariableMirror { 1144 implements VariableMirror {
1181 _LocalVariableMirrorImpl(reflectee, 1145 _LocalVariableMirrorImpl(reflectee,
1182 String simpleName, 1146 String simpleName,
1183 this.owner, 1147 this.owner,
1184 this._type, 1148 this._type,
1185 this.isStatic, 1149 this.isStatic,
1186 this.isFinal) 1150 this.isFinal)
1187 : super(reflectee, _s(simpleName)); 1151 : super(reflectee, _s(simpleName));
1188 1152
1189 final DeclarationMirror owner; 1153 final DeclarationMirror owner;
1154 final bool isStatic;
1155 final bool isFinal;
1190 1156
1191 bool get isPrivate { 1157 bool get isPrivate => _n(simpleName).startsWith('_');
1192 return _n(simpleName).startsWith('_');
1193 }
1194 1158
1195 bool get isTopLevel { 1159 bool get isTopLevel => owner is LibraryMirror;
1196 return owner is LibraryMirror;
1197 }
1198 1160
1199 SourceLocation get location { 1161 SourceLocation get location {
1200 throw new UnimplementedError( 1162 throw new UnimplementedError('VariableMirror.location is not implemented');
1201 'VariableMirror.location is not implemented');
1202 } 1163 }
1203 1164
1204 TypeMirror _type; 1165 TypeMirror _type;
1205 TypeMirror get type { 1166 TypeMirror get type {
1206 if (_type == null) { 1167 if (_type == null) {
1207 _type = _Mirrors._reflectType(_VariableMirror_type(_reflectee)); 1168 _type = _Mirrors._reflectType(_VariableMirror_type(_reflectee));
1208 } 1169 }
1209 return _type; 1170 return _type;
1210 } 1171 }
1211 1172
1212 final bool isStatic;
1213 final bool isFinal;
1214
1215 String toString() => "VariableMirror on '${_n(simpleName)}'"; 1173 String toString() => "VariableMirror on '${_n(simpleName)}'";
1216 1174
1217 static _VariableMirror_type(reflectee) 1175 static _VariableMirror_type(reflectee)
1218 native "VariableMirror_type"; 1176 native "VariableMirror_type";
1219 } 1177 }
1220 1178
1221 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl 1179 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl
1222 implements ParameterMirror { 1180 implements ParameterMirror {
1223 _LocalParameterMirrorImpl(reflectee, 1181 _LocalParameterMirrorImpl(reflectee,
1224 String simpleName, 1182 String simpleName,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 1231
1274 static Type _ParameterMirror_type(_reflectee, _position) 1232 static Type _ParameterMirror_type(_reflectee, _position)
1275 native "ParameterMirror_type"; 1233 native "ParameterMirror_type";
1276 } 1234 }
1277 1235
1278 class _SpecialTypeMirrorImpl extends _LocalMirrorImpl 1236 class _SpecialTypeMirrorImpl extends _LocalMirrorImpl
1279 implements TypeMirror, DeclarationMirror { 1237 implements TypeMirror, DeclarationMirror {
1280 _SpecialTypeMirrorImpl(String name) : simpleName = _s(name); 1238 _SpecialTypeMirrorImpl(String name) : simpleName = _s(name);
1281 1239
1282 final bool isPrivate = false; 1240 final bool isPrivate = false;
1241 final DeclarationMirror owner = null;
1242 final Symbol simpleName;
1283 final bool isTopLevel = true; 1243 final bool isTopLevel = true;
1284
1285 // Fixed length 0, therefore immutable. 1244 // Fixed length 0, therefore immutable.
1286 final List<InstanceMirror> metadata = new List(0); 1245 final List<InstanceMirror> metadata = new List(0);
1287 1246
1288 final DeclarationMirror owner = null;
1289 final Symbol simpleName;
1290
1291 SourceLocation get location { 1247 SourceLocation get location {
1292 throw new UnimplementedError( 1248 throw new UnimplementedError('TypeMirror.location is not implemented');
1293 'TypeMirror.location is not implemented');
1294 } 1249 }
1295 1250
1296 Symbol get qualifiedName { 1251 Symbol get qualifiedName => simpleName;
1297 return simpleName;
1298 }
1299
1300 String toString() => "TypeMirror on '${_n(simpleName)}'";
1301 1252
1302 // TODO(11955): Remove once dynamicType and voidType are canonical objects in 1253 // TODO(11955): Remove once dynamicType and voidType are canonical objects in
1303 // the object store. 1254 // the object store.
1304 bool operator ==(other) { 1255 bool operator ==(other) {
1305 if (other is! _SpecialTypeMirrorImpl) { 1256 if (other is! _SpecialTypeMirrorImpl) {
1306 return false; 1257 return false;
1307 } 1258 }
1308 return this.simpleName == other.simpleName; 1259 return this.simpleName == other.simpleName;
1309 } 1260 }
1310 1261
1311 int get hashCode => simpleName.hashCode; 1262 int get hashCode => simpleName.hashCode;
1263
1264 String toString() => "TypeMirror on '${_n(simpleName)}'";
1312 } 1265 }
1313 1266
1314 class _Mirrors { 1267 class _Mirrors {
1315 // Does a port refer to our local isolate? 1268 // Does a port refer to our local isolate?
1316 static bool isLocalPort(SendPort port) native 'Mirrors_isLocalPort'; 1269 static bool isLocalPort(SendPort port) native 'Mirrors_isLocalPort';
1317 1270
1318 static MirrorSystem _currentMirrorSystem = null; 1271 static MirrorSystem _currentMirrorSystem = null;
1319 1272
1320 // Creates a new local MirrorSystem. 1273 // Creates a new local MirrorSystem.
1321 static MirrorSystem makeLocalMirrorSystem() 1274 static MirrorSystem makeLocalMirrorSystem()
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 if (typeMirror == null) { 1329 if (typeMirror == null) {
1377 typeMirror = makeLocalTypeMirror(key); 1330 typeMirror = makeLocalTypeMirror(key);
1378 _instanitationCache[key] = typeMirror; 1331 _instanitationCache[key] = typeMirror;
1379 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { 1332 if (typeMirror is ClassMirror && !typeMirror._isGeneric) {
1380 _declarationCache[key] = typeMirror; 1333 _declarationCache[key] = typeMirror;
1381 } 1334 }
1382 } 1335 }
1383 return typeMirror; 1336 return typeMirror;
1384 } 1337 }
1385 } 1338 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698