| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library polymer_expressions.src.mirrors; | 5 library polymer_expressions.src.mirrors; |
| 6 | 6 |
| 7 import 'package:observe/observe.dart' show Reflectable, ObservableProperty; | 7 import 'package:observe/observe.dart' show Reflectable, ObservableProperty; |
| 8 | 8 |
| 9 @MirrorsUsed(metaTargets: const [Reflectable, ObservableProperty], | 9 @MirrorsUsed(metaTargets: const [Reflectable, ObservableProperty], |
| 10 override: 'polymer_expressions.src.mirrors') | 10 override: 'polymer_expressions.src.mirrors') |
| 11 import 'dart:mirrors'; | 11 import 'dart:mirrors'; |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * Walks up the class hierarchy to find a method declaration with the given | 14 * Walks up the class hierarchy to find a method declaration with the given |
| 15 * [name]. | 15 * [name]. |
| 16 * | 16 * |
| 17 * Note that it's not possible to tell if there's an implementation via | 17 * Note that it's not possible to tell if there's an implementation via |
| 18 * noSuchMethod(). | 18 * noSuchMethod(). |
| 19 */ | 19 */ |
| 20 Mirror getMemberMirror(ClassMirror classMirror, Symbol name) { | 20 Mirror getMemberMirror(ClassMirror classMirror, Symbol name) { |
| 21 if (classMirror.members.containsKey(name)) { | 21 if (classMirror.declarations.containsKey(name)) { |
| 22 return classMirror.members[name]; | 22 return classMirror.declarations[name]; |
| 23 } | 23 } |
| 24 if (hasSuperclass(classMirror)) { | 24 if (hasSuperclass(classMirror)) { |
| 25 var mirror = getMemberMirror(classMirror.superclass, name); | 25 var mirror = getMemberMirror(classMirror.superclass, name); |
| 26 if (mirror != null) { | 26 if (mirror != null) { |
| 27 return mirror; | 27 return mirror; |
| 28 } | 28 } |
| 29 } | 29 } |
| 30 for (ClassMirror supe in classMirror.superinterfaces) { | 30 for (ClassMirror supe in classMirror.superinterfaces) { |
| 31 var mirror = getMemberMirror(supe, name); | 31 var mirror = getMemberMirror(supe, name); |
| 32 if (mirror != null) { | 32 if (mirror != null) { |
| 33 return mirror; | 33 return mirror; |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 return null; | 36 return null; |
| 37 } | 37 } |
| 38 | 38 |
| 39 /** | 39 /** |
| 40 * Work-around for http://dartbug.com/5794 | 40 * Work-around for http://dartbug.com/5794 |
| 41 */ | 41 */ |
| 42 bool hasSuperclass(ClassMirror classMirror) { | 42 bool hasSuperclass(ClassMirror classMirror) { |
| 43 var superclass = classMirror.superclass; | 43 var superclass = classMirror.superclass; |
| 44 return (superclass != null) && | 44 return (superclass != null) && |
| 45 (superclass.qualifiedName != #dart.core.Object); | 45 (superclass.qualifiedName != #dart.core.Object); |
| 46 } | 46 } |
| OLD | NEW |