| OLD | NEW |
| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 final visitParent = options.includeInherited && cls.superclass != null && | 145 final visitParent = options.includeInherited && cls.superclass != null && |
| 146 // TODO(sigmund): use _toType(cls.superclass) != options.includeUpTo | 146 // TODO(sigmund): use _toType(cls.superclass) != options.includeUpTo |
| 147 // when dartbug.com/16925 gets fixed (_toType fails in dart2js if | 147 // when dartbug.com/16925 gets fixed (_toType fails in dart2js if |
| 148 // applied to classes with type-arguments). | 148 // applied to classes with type-arguments). |
| 149 cls.superclass != reflectClass(options.includeUpTo); | 149 cls.superclass != reflectClass(options.includeUpTo); |
| 150 var result = visitParent ? _query(cls.superclass, options) : []; | 150 var result = visitParent ? _query(cls.superclass, options) : []; |
| 151 for (var member in cls.declarations.values) { | 151 for (var member in cls.declarations.values) { |
| 152 if (member is! VariableMirror && member is! MethodMirror) continue; | 152 if (member is! VariableMirror && member is! MethodMirror) continue; |
| 153 if (member.isStatic || member.isPrivate) continue; | 153 if (member.isStatic || member.isPrivate) continue; |
| 154 var name = member.simpleName; | 154 var name = member.simpleName; |
| 155 bool isMethod = false; | |
| 156 if (member is VariableMirror) { | 155 if (member is VariableMirror) { |
| 157 if (!options.includeFields) continue; | 156 if (!options.includeFields) continue; |
| 158 if (options.excludeFinal && member.isFinal) continue; | 157 if (options.excludeFinal && member.isFinal) continue; |
| 159 } | 158 } |
| 160 | 159 |
| 161 // TODO(sigmund): what if we have a setter but no getter? | 160 // TODO(sigmund): what if we have a setter but no getter? |
| 162 if (member is MethodMirror && member.isSetter) continue; | 161 if (member is MethodMirror && member.isSetter) continue; |
| 163 if (member is MethodMirror && member.isConstructor) continue; | 162 if (member is MethodMirror && member.isConstructor) continue; |
| 164 | 163 |
| 165 if (member is MethodMirror && member.isGetter) { | 164 if (member is MethodMirror && member.isGetter) { |
| 166 if (!options.includeProperties) continue; | 165 if (!options.includeProperties) continue; |
| 167 if (options.excludeFinal && !_hasSetter(cls, member)) continue; | 166 if (options.excludeFinal && !_hasSetter(cls, member)) continue; |
| 168 } | 167 } |
| 169 | 168 |
| 170 if (member is MethodMirror && member.isRegularMethod) { | 169 if (member is MethodMirror && member.isRegularMethod) { |
| 171 if (!options.includeMethods) continue; | 170 if (!options.includeMethods) continue; |
| 172 isMethod = true; | |
| 173 } | 171 } |
| 174 | 172 |
| 175 if (options.matches != null && !options.matches(name)) continue; | 173 if (options.matches != null && !options.matches(name)) continue; |
| 176 | 174 |
| 177 var annotations = | 175 var annotations = |
| 178 member.metadata.map((m) => m.reflectee).toList(); | 176 member.metadata.map((m) => m.reflectee).toList(); |
| 179 if (options.withAnnotations != null && | 177 if (options.withAnnotations != null && |
| 180 !matchesAnnotation(annotations, options.withAnnotations)) { | 178 !matchesAnnotation(annotations, options.withAnnotations)) { |
| 181 continue; | 179 continue; |
| 182 } | 180 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 return _objectType; | 225 return _objectType; |
| 228 } | 226 } |
| 229 } | 227 } |
| 230 | 228 |
| 231 MethodMirror _findMethod(ClassMirror type, Symbol name) { | 229 MethodMirror _findMethod(ClassMirror type, Symbol name) { |
| 232 do { | 230 do { |
| 233 var member = type.declarations[name]; | 231 var member = type.declarations[name]; |
| 234 if (member is MethodMirror) return member; | 232 if (member is MethodMirror) return member; |
| 235 type = type.superclass; | 233 type = type.superclass; |
| 236 } while (type != null); | 234 } while (type != null); |
| 235 return null; |
| 237 } | 236 } |
| 238 | 237 |
| 239 // When recursively looking for symbols up the type-hierarchy it's generally a | 238 // When recursively looking for symbols up the type-hierarchy it's generally a |
| 240 // good idea to stop at Object, since we know it doesn't have what we want. | 239 // good idea to stop at Object, since we know it doesn't have what we want. |
| 241 // TODO(jmesserly): This is also a workaround for what appears to be a V8 | 240 // TODO(jmesserly): This is also a workaround for what appears to be a V8 |
| 242 // bug introduced between Chrome 31 and 32. After 32 | 241 // bug introduced between Chrome 31 and 32. After 32 |
| 243 // JsClassMirror.declarations on Object calls | 242 // JsClassMirror.declarations on Object calls |
| 244 // JsClassMirror.typeVariables, which tries to get the _jsConstructor's | 243 // JsClassMirror.typeVariables, which tries to get the _jsConstructor's |
| 245 // .prototype["<>"]. This ends up getting the "" property instead, maybe | 244 // .prototype["<>"]. This ends up getting the "" property instead, maybe |
| 246 // because "<>" doesn't exist, and gets ";" which then blows up because | 245 // because "<>" doesn't exist, and gets ";" which then blows up because |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 String toString() => (new StringBuffer() | 310 String toString() => (new StringBuffer() |
| 312 ..write('(mirror-based-declaration ') | 311 ..write('(mirror-based-declaration ') |
| 313 ..write(name) | 312 ..write(name) |
| 314 ..write(isField ? ' (field) ' | 313 ..write(isField ? ' (field) ' |
| 315 : (isProperty ? ' (property) ' : ' (method) ')) | 314 : (isProperty ? ' (property) ' : ' (method) ')) |
| 316 ..write(isFinal ? 'final ' : '') | 315 ..write(isFinal ? 'final ' : '') |
| 317 ..write(isStatic ? 'static ' : '') | 316 ..write(isStatic ? 'static ' : '') |
| 318 ..write(annotations) | 317 ..write(annotations) |
| 319 ..write(')')).toString(); | 318 ..write(')')).toString(); |
| 320 } | 319 } |
| OLD | NEW |