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

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: 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(
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) {
Michael Lippautz (Google) 2013/09/11 23:04:11 unused
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) {
Michael Lippautz (Google) 2013/09/11 23:04:11 only 1 caller
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);
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 _owner = _library(_reflectee); 464 _owner = _library(_reflectee);
482 } 465 }
483 return _owner; 466 return _owner;
484 } 467 }
485 468
486 bool get isPrivate => _n(simpleName).startsWith('_'); 469 bool get isPrivate => _n(simpleName).startsWith('_');
487 470
488 final bool isTopLevel = true; 471 final bool isTopLevel = true;
489 472
490 SourceLocation get location { 473 SourceLocation get location {
491 throw new UnimplementedError( 474 throw new UnimplementedError('ClassMirror.location is not implemented');
492 'ClassMirror.location is not implemented');
493 } 475 }
494 476
495 // TODO(rmacnak): Remove these left-overs from the days of separate interfaces 477 // TODO(rmacnak): Remove these left-overs from the days of separate interfaces
496 // once we send out a breaking change. 478 // once we send out a breaking change.
497 bool get isClass => true; 479 bool get isClass => true;
498 ClassMirror get defaultFactory => null; 480 ClassMirror get defaultFactory => null;
499 481
500 ClassMirror _trueSuperclassField; 482 ClassMirror _trueSuperclassField;
501 ClassMirror get _trueSuperclass { 483 ClassMirror get _trueSuperclass {
502 if (_trueSuperclassField == null) { 484 if (_trueSuperclassField == null) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 _mixin = this; 529 _mixin = this;
548 } else { 530 } else {
549 _mixin = _Mirrors._reflectType(mixinType); 531 _mixin = _Mirrors._reflectType(mixinType);
550 } 532 }
551 } 533 }
552 } 534 }
553 return _mixin; 535 return _mixin;
554 } 536 }
555 537
556 Map<Symbol, Mirror> _members; 538 Map<Symbol, Mirror> _members;
557
558 Map<Symbol, Mirror> get members { 539 Map<Symbol, Mirror> get members {
559 if (_members == null) { 540 if (_members == null) {
560 var whoseMembers = _isMixinTypedef ? _trueSuperclass : this; 541 var whoseMembers = _isMixinTypedef ? _trueSuperclass : this;
561 _members = _makeMemberMap(mixin._computeMembers(whoseMembers._reflectee)); 542 _members = _makeMemberMap(mixin._computeMembers(whoseMembers._reflectee));
562 } 543 }
563 return _members; 544 return _members;
564 } 545 }
565 546
566 Map<Symbol, MethodMirror> _methods = null; 547 Map<Symbol, MethodMirror> _methods;
567 Map<Symbol, MethodMirror> _getters = null;
568 Map<Symbol, MethodMirror> _setters = null;
569 Map<Symbol, VariableMirror> _variables = null;
570
571 Map<Symbol, MethodMirror> get methods { 548 Map<Symbol, MethodMirror> get methods {
572 if (_methods == null) { 549 if (_methods == null) {
573 _methods = _filterMap( 550 _methods = _filterMap(
574 members, 551 members,
575 (key, value) => (value is MethodMirror && value.isRegularMethod)); 552 (key, value) => (value is MethodMirror && value.isRegularMethod));
576 } 553 }
577 return _methods; 554 return _methods;
578 } 555 }
579 556
557 Map<Symbol, MethodMirror> _getters;
580 Map<Symbol, MethodMirror> get getters { 558 Map<Symbol, MethodMirror> get getters {
581 if (_getters == null) { 559 if (_getters == null) {
582 _getters = _filterMap( 560 _getters = _filterMap(
583 members, 561 members,
584 (key, value) => (value is MethodMirror && value.isGetter)); 562 (key, value) => (value is MethodMirror && value.isGetter));
585 } 563 }
586 return _getters; 564 return _getters;
587 } 565 }
588 566
567 Map<Symbol, MethodMirror> _setters;
589 Map<Symbol, MethodMirror> get setters { 568 Map<Symbol, MethodMirror> get setters {
590 if (_setters == null) { 569 if (_setters == null) {
591 _setters = _filterMap( 570 _setters = _filterMap(
592 members, 571 members,
593 (key, value) => (value is MethodMirror && value.isSetter)); 572 (key, value) => (value is MethodMirror && value.isSetter));
594 } 573 }
595 return _setters; 574 return _setters;
596 } 575 }
597 576
577 Map<Symbol, VariableMirror> _variables;
598 Map<Symbol, VariableMirror> get variables { 578 Map<Symbol, VariableMirror> get variables {
599 if (_variables == null) { 579 if (_variables == null) {
600 _variables = _filterMap( 580 _variables = _filterMap(
601 members, 581 members,
602 (key, value) => (value is VariableMirror)); 582 (key, value) => (value is VariableMirror));
603 } 583 }
604 return _variables; 584 return _variables;
605 } 585 }
606 586
607 Map<Symbol, MethodMirror> _constructors; 587 Map<Symbol, MethodMirror> _constructors;
608
609 Map<Symbol, MethodMirror> get constructors { 588 Map<Symbol, MethodMirror> get constructors {
610 if (_constructors == null) { 589 if (_constructors == null) {
611 var constructorsList = _computeConstructors(_reflectee); 590 var constructorsList = _computeConstructors(_reflectee);
612 var stringName = _n(simpleName); 591 var stringName = _n(simpleName);
613 constructorsList.forEach((c) => c._patchConstructorName(stringName)); 592 constructorsList.forEach((c) => c._patchConstructorName(stringName));
614 _constructors = _makeMemberMap(constructorsList); 593 _constructors = _makeMemberMap(constructorsList);
615 } 594 }
616 return _constructors; 595 return _constructors;
617 } 596 }
618 597
619 Map<Symbol, TypeVariableMirror> _typeVariables = null; 598 Map<Symbol, TypeVariableMirror> _typeVariables = null;
620
621 Map<Symbol, TypeVariableMirror> get typeVariables { 599 Map<Symbol, TypeVariableMirror> get typeVariables {
622 if (_typeVariables == null) { 600 if (_typeVariables == null) {
623 List params = _ClassMirror_type_variables(_reflectee); 601 List params = _ClassMirror_type_variables(_reflectee);
624 _typeVariables = new LinkedHashMap<Symbol, TypeVariableMirror>(); 602 _typeVariables = new LinkedHashMap<Symbol, TypeVariableMirror>();
625 var mirror; 603 var mirror;
626 for (var i = 0; i < params.length; i += 2) { 604 for (var i = 0; i < params.length; i += 2) {
627 mirror = new _LocalTypeVariableMirrorImpl( 605 mirror = new _LocalTypeVariableMirrorImpl(
628 params[i + 1], params[i], this); 606 params[i + 1], params[i], this);
629 _typeVariables[mirror.simpleName] = mirror; 607 _typeVariables[mirror.simpleName] = mirror;
630 } 608 }
631 } 609 }
632 return _typeVariables; 610 return _typeVariables;
633 } 611 }
634 612
635 Map<Symbol, TypeMirror> _typeArguments = null; 613 Map<Symbol, TypeMirror> _typeArguments = null;
636 Map<Symbol, TypeMirror> get typeArguments { 614 Map<Symbol, TypeMirror> get typeArguments {
637 if(_typeArguments == null) { 615 if(_typeArguments == null) {
638 if(_reflectedType == null) { 616 if(_reflectedType == null) {
639 _typeArguments = new LinkedHashMap<Symbol, TypeMirror>(); 617 _typeArguments = new LinkedHashMap<Symbol, TypeMirror>();
640 } else { 618 } else {
641 _typeArguments = 619 _typeArguments =
642 new LinkedHashMap<Symbol, TypeMirror>.fromIterables(typeVariables.ke ys, 620 new LinkedHashMap<Symbol, TypeMirror>.fromIterables(
643 _computeTypeArgu ments(_reflectedType)); 621 typeVariables.keys, _computeTypeArguments(_reflectedType));
644 } 622 }
645 } 623 }
646 return _typeArguments; 624 return _typeArguments;
647 } 625 }
648 626
649 bool get isOriginalDeclaration { 627 bool get isOriginalDeclaration => !_isGeneric || _reflectedType == null;
650 return !_isGeneric || _reflectedType == null;
651 }
652 628
653 ClassMirror get originalDeclaration { 629 ClassMirror get originalDeclaration {
654 if (isOriginalDeclaration) { 630 if (isOriginalDeclaration) {
655 return this; 631 return this;
656 } else { 632 } else {
657 return reflectClass(_reflectedType); 633 return reflectClass(_reflectedType);
658 } 634 }
659 } 635 }
660 636
661 String toString() { 637 String toString() => "ClassMirror on '${_n(simpleName)}'";
662 return "ClassMirror on '${_n(simpleName)}'";
663 }
664 638
665 InstanceMirror newInstance(Symbol constructorName, 639 InstanceMirror newInstance(Symbol constructorName,
666 List positionalArguments, 640 List positionalArguments,
667 [Map<Symbol, dynamic> namedArguments]) { 641 [Map<Symbol, dynamic> namedArguments]) {
668 // Native code will add the 1 or 2 implicit arguments depending on whether 642 // Native code will add the 1 or 2 implicit arguments depending on whether
669 // we end up invoking a factory or constructor respectively. 643 // we end up invoking a factory or constructor respectively.
670 int numPositionalArguments = positionalArguments.length; 644 int numPositionalArguments = positionalArguments.length;
671 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; 645 int numNamedArguments = namedArguments != null ? namedArguments.length : 0;
672 int numArguments = numPositionalArguments + numNamedArguments; 646 int numArguments = numPositionalArguments + numNamedArguments;
673 List arguments = new List(numArguments); 647 List arguments = new List(numArguments);
(...skipping 12 matching lines...) Expand all
686 _n(constructorName), 660 _n(constructorName),
687 arguments, 661 arguments,
688 names)); 662 names));
689 } 663 }
690 664
691 Future<InstanceMirror> newInstanceAsync(Symbol constructorName, 665 Future<InstanceMirror> newInstanceAsync(Symbol constructorName,
692 List positionalArguments, 666 List positionalArguments,
693 [Map<Symbol, dynamic> namedArguments]) { 667 [Map<Symbol, dynamic> namedArguments]) {
694 return new Future(() { 668 return new Future(() {
695 return this.newInstance(constructorName, 669 return this.newInstance(constructorName,
696 _unwarpAsyncPositionals(positionalArguments), 670 _unwrapAsyncPositionals(positionalArguments),
697 _unwarpAsyncNamed(namedArguments)); 671 _unwrapAsyncNamed(namedArguments));
698 }); 672 });
699 } 673 }
700 674
701 List<InstanceMirror> get metadata { 675 List<InstanceMirror> get metadata {
702 // Get the metadata objects, convert them into InstanceMirrors using 676 // Get the metadata objects, convert them into InstanceMirrors using
703 // reflect() and then make them into a Dart list. 677 // reflect() and then make them into a Dart list.
704 return _metadata(_reflectee).map(reflect).toList(growable:false); 678 return _metadata(_reflectee).map(reflect).toList(growable:false);
705 } 679 }
706 680
707 bool operator ==(other) { 681 bool operator ==(other) {
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 } 860 }
887 861
888 862
889 class _LocalTypedefMirrorImpl extends _LocalDeclarationMirrorImpl 863 class _LocalTypedefMirrorImpl extends _LocalDeclarationMirrorImpl
890 implements TypedefMirror { 864 implements TypedefMirror {
891 _LocalTypedefMirrorImpl(reflectee, 865 _LocalTypedefMirrorImpl(reflectee,
892 String simpleName, 866 String simpleName,
893 this._owner) 867 this._owner)
894 : super(reflectee, _s(simpleName)); 868 : super(reflectee, _s(simpleName));
895 869
870 final bool isTopLevel = true;
871
896 // TODO(12282): Deal with generic typedefs. 872 // TODO(12282): Deal with generic typedefs.
897 bool get _isGeneric => false; 873 bool get _isGeneric => false;
898 874
875 bool get isPrivate => false;
876
899 DeclarationMirror _owner; 877 DeclarationMirror _owner;
900 DeclarationMirror get owner { 878 DeclarationMirror get owner {
901 if (_owner == null) { 879 if (_owner == null) {
902 _owner = _LocalClassMirrorImpl._library(_reflectee); 880 _owner = _LocalClassMirrorImpl._library(_reflectee);
903 } 881 }
904 return _owner; 882 return _owner;
905 } 883 }
906 884
907 bool get isPrivate => false;
908
909 final bool isTopLevel = true;
910
911 SourceLocation get location { 885 SourceLocation get location {
912 throw new UnimplementedError( 886 throw new UnimplementedError('TypedefMirror.location is not implemented');
913 'TypedefMirror.location is not implemented');
914 } 887 }
915 888
916 TypeMirror _referent = null; 889 TypeMirror _referent = null;
917 TypeMirror get referent { 890 TypeMirror get referent {
918 if (_referent == null) { 891 if (_referent == null) {
919 // TODO(12282): Deal with generic typedef. 892 // TODO(12282): Deal with generic typedef.
920 return new _LocalFunctionTypeMirrorImpl( 893 return new _LocalFunctionTypeMirrorImpl(
921 _TypedefMirror_referent(_reflectee), null); 894 _TypedefMirror_referent(_reflectee), null);
922 } 895 }
923 return _referent; 896 return _referent;
(...skipping 22 matching lines...) Expand all
946 // Always null for libraries. 919 // Always null for libraries.
947 final DeclarationMirror owner = null; 920 final DeclarationMirror owner = null;
948 921
949 // Always false for libraries. 922 // Always false for libraries.
950 final bool isPrivate = false; 923 final bool isPrivate = false;
951 924
952 // Always false for libraries. 925 // Always false for libraries.
953 final bool isTopLevel = false; 926 final bool isTopLevel = false;
954 927
955 SourceLocation get location { 928 SourceLocation get location {
956 throw new UnimplementedError( 929 throw new UnimplementedError('LibraryMirror.location is not implemented');
957 'LibraryMirror.location is not implemented');
958 } 930 }
959 931
960 final Uri uri; 932 final Uri uri;
961 933
962 Map<Symbol, Mirror> _members; 934 Map<Symbol, Mirror> _members;
963
964 Map<Symbol, Mirror> get members { 935 Map<Symbol, Mirror> get members {
965 if (_members == null) { 936 if (_members == null) {
966 _members = _makeMemberMap(_computeMembers(_reflectee)); 937 _members = _makeMemberMap(_computeMembers(_reflectee));
967 } 938 }
968 return _members; 939 return _members;
969 } 940 }
970 941
971 Map<Symbol, ClassMirror> _classes = null; 942 Map<Symbol, ClassMirror> _classes;
972 Map<Symbol, MethodMirror> _functions = null;
973 Map<Symbol, MethodMirror> _getters = null;
974 Map<Symbol, MethodMirror> _setters = null;
975 Map<Symbol, VariableMirror> _variables = null;
976
977 Map<Symbol, ClassMirror> get classes { 943 Map<Symbol, ClassMirror> get classes {
978 if (_classes == null) { 944 if (_classes == null) {
979 _classes = _filterMap(members, 945 _classes = _filterMap(members,
980 (key, value) => (value is ClassMirror)); 946 (key, value) => (value is ClassMirror));
981 } 947 }
982 return _classes; 948 return _classes;
983 } 949 }
984 950
951 Map<Symbol, MethodMirror> _functions;
985 Map<Symbol, MethodMirror> get functions { 952 Map<Symbol, MethodMirror> get functions {
986 if (_functions == null) { 953 if (_functions == null) {
987 _functions = _filterMap(members, 954 _functions = _filterMap(members, (key, value) => (value is MethodMirror));
988 (key, value) => (value is MethodMirror));
989 } 955 }
990 return _functions; 956 return _functions;
991 } 957 }
992 958
959 Map<Symbol, MethodMirror> _getters;
993 Map<Symbol, MethodMirror> get getters { 960 Map<Symbol, MethodMirror> get getters {
994 if (_getters == null) { 961 if (_getters == null) {
995 _getters = _filterMap(functions, 962 _getters = _filterMap(functions, (key, value) => (value.isGetter));
996 (key, value) => (value.isGetter));
997 } 963 }
998 return _getters; 964 return _getters;
999 } 965 }
1000 966
967 Map<Symbol, MethodMirror> _setters;
1001 Map<Symbol, MethodMirror> get setters { 968 Map<Symbol, MethodMirror> get setters {
1002 if (_setters == null) { 969 if (_setters == null) {
1003 _setters = _filterMap(functions, 970 _setters = _filterMap(functions, (key, value) => (value.isSetter));
1004 (key, value) => (value.isSetter));
1005 } 971 }
1006 return _setters; 972 return _setters;
1007 } 973 }
1008 974
975 Map<Symbol, VariableMirror> _variables;
1009 Map<Symbol, VariableMirror> get variables { 976 Map<Symbol, VariableMirror> get variables {
1010 if (_variables == null) { 977 if (_variables == null) {
1011 _variables = _filterMap(members, 978 _variables = _filterMap(members,
1012 (key, value) => (value is VariableMirror)); 979 (key, value) => (value is VariableMirror));
1013 } 980 }
1014 return _variables; 981 return _variables;
1015 } 982 }
1016 983
1017 List<InstanceMirror> get metadata { 984 List<InstanceMirror> get metadata {
1018 // Get the metadata objects, convert them into InstanceMirrors using 985 // Get the metadata objects, convert them into InstanceMirrors using
1019 // reflect() and then make them into a Dart list. 986 // reflect() and then make them into a Dart list.
1020 return _metadata(_reflectee).map(reflect).toList(growable:false); 987 return _metadata(_reflectee).map(reflect).toList(growable:false);
1021 } 988 }
1022 989
1023 String toString() => "LibraryMirror on '${_n(simpleName)}'";
1024
1025 bool operator ==(other) { 990 bool operator ==(other) {
1026 return this.runtimeType == other.runtimeType && 991 return this.runtimeType == other.runtimeType &&
1027 this._reflectee == other._reflectee; 992 this._reflectee == other._reflectee;
1028 } 993 }
1029 994
1030 int get hashCode => simpleName.hashCode; 995 int get hashCode => simpleName.hashCode;
1031 996
997 String toString() => "LibraryMirror on '${_n(simpleName)}'";
998
1032 _invoke(reflectee, memberName, arguments, argumentNames) 999 _invoke(reflectee, memberName, arguments, argumentNames)
1033 native 'LibraryMirror_invoke'; 1000 native 'LibraryMirror_invoke';
1034 1001
1035 _invokeGetter(reflectee, getterName) 1002 _invokeGetter(reflectee, getterName)
1036 native 'LibraryMirror_invokeGetter'; 1003 native 'LibraryMirror_invokeGetter';
1037 1004
1038 _invokeSetter(reflectee, setterName, value) 1005 _invokeSetter(reflectee, setterName, value)
1039 native 'LibraryMirror_invokeSetter'; 1006 native 'LibraryMirror_invokeSetter';
1040 1007
1041 _computeMembers(reflectee) 1008 _computeMembers(reflectee)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 DeclarationMirror _owner; 1043 DeclarationMirror _owner;
1077 DeclarationMirror get owner { 1044 DeclarationMirror get owner {
1078 // For nested closures it is possible, that the mirror for the owner has not 1045 // For nested closures it is possible, that the mirror for the owner has not
1079 // been created yet. 1046 // been created yet.
1080 if (_owner == null) { 1047 if (_owner == null) {
1081 _owner = _MethodMirror_owner(_reflectee); 1048 _owner = _MethodMirror_owner(_reflectee);
1082 } 1049 }
1083 return _owner; 1050 return _owner;
1084 } 1051 }
1085 1052
1086 bool get isPrivate { 1053 bool get isPrivate => _n(simpleName).startsWith('_') ||
1087 return _n(simpleName).startsWith('_') || 1054 _n(constructorName).startsWith('_');
1088 _n(constructorName).startsWith('_');
1089 }
1090 1055
1091 bool get isTopLevel => owner is LibraryMirror; 1056 bool get isTopLevel => owner is LibraryMirror;
1092 1057
1093 SourceLocation get location { 1058 SourceLocation get location {
1094 throw new UnimplementedError( 1059 throw new UnimplementedError('MethodMirror.location is not implemented');
1095 'MethodMirror.location is not implemented');
1096 } 1060 }
1097 1061
1098 TypeMirror _returnType = null; 1062 TypeMirror _returnType = null;
1099 TypeMirror get returnType { 1063 TypeMirror get returnType {
1100 if (_returnType == null) { 1064 if (_returnType == null) {
1101 if (isConstructor) { 1065 if (isConstructor) {
1102 _returnType = owner; 1066 _returnType = owner;
1103 } else { 1067 } else {
1104 _returnType = 1068 _returnType =
1105 _Mirrors._reflectType(_MethodMirror_return_type(_reflectee)); 1069 _Mirrors._reflectType(_MethodMirror_return_type(_reflectee));
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 implements VariableMirror { 1140 implements VariableMirror {
1177 _LocalVariableMirrorImpl(reflectee, 1141 _LocalVariableMirrorImpl(reflectee,
1178 String simpleName, 1142 String simpleName,
1179 this.owner, 1143 this.owner,
1180 this._type, 1144 this._type,
1181 this.isStatic, 1145 this.isStatic,
1182 this.isFinal) 1146 this.isFinal)
1183 : super(reflectee, _s(simpleName)); 1147 : super(reflectee, _s(simpleName));
1184 1148
1185 final DeclarationMirror owner; 1149 final DeclarationMirror owner;
1150 final bool isStatic;
1151 final bool isFinal;
1186 1152
1187 bool get isPrivate { 1153 bool get isPrivate => _n(simpleName).startsWith('_');
1188 return _n(simpleName).startsWith('_');
1189 }
1190 1154
1191 bool get isTopLevel { 1155 bool get isTopLevel => owner is LibraryMirror;
1192 return owner is LibraryMirror;
1193 }
1194 1156
1195 SourceLocation get location { 1157 SourceLocation get location {
1196 throw new UnimplementedError( 1158 throw new UnimplementedError('VariableMirror.location is not implemented');
1197 'VariableMirror.location is not implemented');
1198 } 1159 }
1199 1160
1200 TypeMirror _type; 1161 TypeMirror _type;
1201 TypeMirror get type { 1162 TypeMirror get type {
1202 if (_type == null) { 1163 if (_type == null) {
1203 _type = _Mirrors._reflectType(_VariableMirror_type(_reflectee)); 1164 _type = _Mirrors._reflectType(_VariableMirror_type(_reflectee));
1204 } 1165 }
1205 return _type; 1166 return _type;
1206 } 1167 }
1207 1168
1208 final bool isStatic;
1209 final bool isFinal;
1210
1211 String toString() => "VariableMirror on '${_n(simpleName)}'"; 1169 String toString() => "VariableMirror on '${_n(simpleName)}'";
1212 1170
1213 static _VariableMirror_type(reflectee) 1171 static _VariableMirror_type(reflectee)
1214 native "VariableMirror_type"; 1172 native "VariableMirror_type";
1215 } 1173 }
1216 1174
1217 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl 1175 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl
1218 implements ParameterMirror { 1176 implements ParameterMirror {
1219 _LocalParameterMirrorImpl(reflectee, 1177 _LocalParameterMirrorImpl(reflectee,
1220 String simpleName, 1178 String simpleName,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 1227
1270 static Type _ParameterMirror_type(_reflectee, _position) 1228 static Type _ParameterMirror_type(_reflectee, _position)
1271 native "ParameterMirror_type"; 1229 native "ParameterMirror_type";
1272 } 1230 }
1273 1231
1274 class _SpecialTypeMirrorImpl extends _LocalMirrorImpl 1232 class _SpecialTypeMirrorImpl extends _LocalMirrorImpl
1275 implements TypeMirror, DeclarationMirror { 1233 implements TypeMirror, DeclarationMirror {
1276 _SpecialTypeMirrorImpl(String name) : simpleName = _s(name); 1234 _SpecialTypeMirrorImpl(String name) : simpleName = _s(name);
1277 1235
1278 final bool isPrivate = false; 1236 final bool isPrivate = false;
1237 final DeclarationMirror owner = null;
1238 final Symbol simpleName;
1279 final bool isTopLevel = true; 1239 final bool isTopLevel = true;
1280
1281 // Fixed length 0, therefore immutable. 1240 // Fixed length 0, therefore immutable.
1282 final List<InstanceMirror> metadata = new List(0); 1241 final List<InstanceMirror> metadata = new List(0);
1283 1242
1284 final DeclarationMirror owner = null;
1285 final Symbol simpleName;
1286
1287 SourceLocation get location { 1243 SourceLocation get location {
1288 throw new UnimplementedError( 1244 throw new UnimplementedError('TypeMirror.location is not implemented');
1289 'TypeMirror.location is not implemented');
1290 } 1245 }
1291 1246
1292 Symbol get qualifiedName { 1247 Symbol get qualifiedName => simpleName;
1293 return simpleName;
1294 }
1295
1296 String toString() => "TypeMirror on '${_n(simpleName)}'";
1297 1248
1298 // TODO(11955): Remove once dynamicType and voidType are canonical objects in 1249 // TODO(11955): Remove once dynamicType and voidType are canonical objects in
1299 // the object store. 1250 // the object store.
1300 bool operator ==(other) { 1251 bool operator ==(other) {
1301 if (other is! _SpecialTypeMirrorImpl) { 1252 if (other is! _SpecialTypeMirrorImpl) {
1302 return false; 1253 return false;
1303 } 1254 }
1304 return this.simpleName == other.simpleName; 1255 return this.simpleName == other.simpleName;
1305 } 1256 }
1306 1257
1307 int get hashCode => simpleName.hashCode; 1258 int get hashCode => simpleName.hashCode;
1259
1260 String toString() => "TypeMirror on '${_n(simpleName)}'";
1308 } 1261 }
1309 1262
1310 class _Mirrors { 1263 class _Mirrors {
1311 // Does a port refer to our local isolate? 1264 // Does a port refer to our local isolate?
1312 static bool isLocalPort(SendPort port) native 'Mirrors_isLocalPort'; 1265 static bool isLocalPort(SendPort port) native 'Mirrors_isLocalPort';
1313 1266
1314 static MirrorSystem _currentMirrorSystem = null; 1267 static MirrorSystem _currentMirrorSystem = null;
1315 1268
1316 // Creates a new local MirrorSystem. 1269 // Creates a new local MirrorSystem.
1317 static MirrorSystem makeLocalMirrorSystem() 1270 static MirrorSystem makeLocalMirrorSystem()
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 if (typeMirror == null) { 1325 if (typeMirror == null) {
1373 typeMirror = makeLocalTypeMirror(key); 1326 typeMirror = makeLocalTypeMirror(key);
1374 _instanitationCache[key] = typeMirror; 1327 _instanitationCache[key] = typeMirror;
1375 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { 1328 if (typeMirror is ClassMirror && !typeMirror._isGeneric) {
1376 _declarationCache[key] = typeMirror; 1329 _declarationCache[key] = typeMirror;
1377 } 1330 }
1378 } 1331 }
1379 return typeMirror; 1332 return typeMirror;
1380 } 1333 }
1381 } 1334 }
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