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

Side by Side Diff: pkg/smoke/lib/mirrors.dart

Issue 180273004: Fixes in smoke, which in turn should fix todomvc. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 /// Implementation of the smoke services using mirrors. 5 /// Implementation of the smoke services using mirrors.
6 library smoke.mirrors; 6 library smoke.mirrors;
7 7
8 import 'dart:mirrors'; 8 import 'dart:mirrors';
9 import 'package:smoke/smoke.dart'; 9 import 'package:smoke/smoke.dart';
10 import 'package:logging/logging.dart'; 10 import 'package:logging/logging.dart';
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } 60 }
61 } 61 }
62 args = adjustList(args, required, required + optional); 62 args = adjustList(args, required, required + optional);
63 } 63 }
64 return receiverMirror.invoke(methodName, args, namedArgs).reflectee; 64 return receiverMirror.invoke(methodName, args, namedArgs).reflectee;
65 } 65 }
66 } 66 }
67 67
68 /// Implements [TypeInspectorService] using mirrors. 68 /// Implements [TypeInspectorService] using mirrors.
69 class ReflectiveTypeInspectorService implements TypeInspectorService { 69 class ReflectiveTypeInspectorService implements TypeInspectorService {
70 bool isSubclassOf(Type type, Type supertype) {
71 if (type == supertype || supertype == Object) return true;
72 // TODO(sigmund): change to mirror.isSubclassOf when it gets implemented in
73 // dart2js. (dartbug.com/12439)
74 var mirror = reflectClass(type);
75 var top = reflectClass(supertype);
76 while (mirror != _objectType) {
77 mirror = _safeSuperclass(mirror);
78 if (mirror == top) return true;
79 }
80 return false;
81 }
82
70 bool hasGetter(Type type, Symbol name) { 83 bool hasGetter(Type type, Symbol name) {
71 var mirror = reflectType(type); 84 var mirror = reflectType(type);
72 if (mirror is! ClassMirror) return false; 85 if (mirror is! ClassMirror) return false;
73 while (mirror != _objectType) { 86 while (mirror != _objectType) {
74 final members = mirror.declarations; 87 final members = mirror.declarations;
75 if (members.containsKey(name)) return true; 88 if (members.containsKey(name)) return true;
76 mirror = _safeSuperclass(mirror); 89 mirror = _safeSuperclass(mirror);
77 } 90 }
78 return false; 91 return false;
79 } 92 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 return new _MirrorDeclaration(mirror, declaration); 143 return new _MirrorDeclaration(mirror, declaration);
131 } 144 }
132 145
133 List<Declaration> query(Type type, QueryOptions options) { 146 List<Declaration> query(Type type, QueryOptions options) {
134 var mirror = reflectType(type); 147 var mirror = reflectType(type);
135 if (mirror is! ClassMirror) return null; 148 if (mirror is! ClassMirror) return null;
136 return _query(mirror, options); 149 return _query(mirror, options);
137 } 150 }
138 151
139 List<Declaration> _query(ClassMirror cls, QueryOptions options) { 152 List<Declaration> _query(ClassMirror cls, QueryOptions options) {
140 var result = (!options.includeInherited || cls.superclass == _objectType) 153 final visitParent = options.includeInherited && cls.superclass != null &&
141 ? [] : _query(cls.superclass, options); 154 cls.superclass != reflectClass(options.includeUpTo);
Siggi Cherem (dart-lang) 2014/02/25 23:23:23 note that for the same reasons than below (classes
Jennifer Messerly 2014/02/25 23:50:09 might be worth adding this comment (it can refer t
Siggi Cherem (dart-lang) 2014/02/26 00:09:50 Done.
155 var result = visitParent ? _query(cls.superclass, options) : [];
142 for (var member in cls.declarations.values) { 156 for (var member in cls.declarations.values) {
143 if (member is! VariableMirror && member is! MethodMirror) continue; 157 if (member is! VariableMirror && member is! MethodMirror) continue;
144 if (member.isStatic || member.isPrivate) continue; 158 if (member.isStatic || member.isPrivate) continue;
145 var name = member.simpleName; 159 var name = member.simpleName;
146 bool isMethod = false; 160 bool isMethod = false;
147 if (member is VariableMirror) { 161 if (member is VariableMirror) {
148 if (!options.includeFields) continue; 162 if (!options.includeFields) continue;
149 if (options.excludeFinal && member.isFinal) continue; 163 if (options.excludeFinal && member.isFinal) continue;
150 } 164 }
151 165
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 // dartbug.com/16078). 321 // dartbug.com/16078).
308 // * having [call] also allows `is` checks to work for functions of 0 322 // * having [call] also allows `is` checks to work for functions of 0
309 // through 3 arguments. We depend on this in 323 // through 3 arguments. We depend on this in
310 // `polymer_expressions/lib/eval.dart` to check whether a function is a 324 // `polymer_expressions/lib/eval.dart` to check whether a function is a
311 // filter (takes a single argument). (Note that it's possible to include 325 // filter (takes a single argument). (Note that it's possible to include
312 // both [call] and [noSuchMethod], which would make instance-of checks 326 // both [call] and [noSuchMethod], which would make instance-of checks
313 // work with the signature of [call], but will allow invoking the function 327 // work with the signature of [call], but will allow invoking the function
314 // using [noSuchMethod]. 328 // using [noSuchMethod].
315 call([a, b, c]) => invoke(receiver, methodName, [a, b, c], adjust: true); 329 call([a, b, c]) => invoke(receiver, methodName, [a, b, c], adjust: true);
316 } 330 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698