| 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 observe.src.path_observer; | 5 library observe.src.path_observer; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 @MirrorsUsed(metaTargets: const [Reflectable, ObservableProperty], | 8 @MirrorsUsed(metaTargets: const [Reflectable, ObservableProperty], |
| 9 override: 'observe.src.path_observer') | 9 override: 'observe.src.path_observer') |
| 10 import 'dart:mirrors'; | 10 import 'dart:mirrors'; |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 final member = type.declarations[name]; | 327 final member = type.declarations[name]; |
| 328 if (member is MethodMirror && member.isRegularMethod) return true; | 328 if (member is MethodMirror && member.isRegularMethod) return true; |
| 329 type = _safeSuperclass(type); | 329 type = _safeSuperclass(type); |
| 330 } | 330 } |
| 331 return false; | 331 return false; |
| 332 } | 332 } |
| 333 | 333 |
| 334 ClassMirror _safeSuperclass(ClassMirror type) { | 334 ClassMirror _safeSuperclass(ClassMirror type) { |
| 335 try { | 335 try { |
| 336 return type.superclass; | 336 return type.superclass; |
| 337 } on UnsupportedError catch (e) { | 337 } /*on UnsupportedError*/ catch (e) { |
| 338 // TODO(jmesserly): dart2js throws this error when the type is not | 338 // Note: dart2js throws UnsupportedError when the type is not |
| 339 // reflectable. | 339 // reflectable. |
| 340 // TODO(jmesserly): dart2js also throws a NoSuchMethodError if the `type` is |
| 341 // a bound generic, because they are not fully implemented. See |
| 342 // https://code.google.com/p/dart/issues/detail?id=15573 |
| 340 return objectType; | 343 return objectType; |
| 341 } | 344 } |
| 342 } | 345 } |
| 343 | 346 |
| 344 // From: https://github.com/rafaelw/ChangeSummary/blob/master/change_summary.js | 347 // From: https://github.com/rafaelw/ChangeSummary/blob/master/change_summary.js |
| 345 | 348 |
| 346 final _pathRegExp = () { | 349 final _pathRegExp = () { |
| 347 const identStart = '[\$_a-zA-Z]'; | 350 const identStart = '[\$_a-zA-Z]'; |
| 348 const identPart = '[\$_a-zA-Z0-9]'; | 351 const identPart = '[\$_a-zA-Z0-9]'; |
| 349 const ident = '$identStart+$identPart*'; | 352 const ident = '$identStart+$identPart*'; |
| 350 const elementIndex = '(?:[0-9]|[1-9]+[0-9]+)'; | 353 const elementIndex = '(?:[0-9]|[1-9]+[0-9]+)'; |
| 351 const identOrElementIndex = '(?:$ident|$elementIndex)'; | 354 const identOrElementIndex = '(?:$ident|$elementIndex)'; |
| 352 const path = '(?:$identOrElementIndex)(?:\\.$identOrElementIndex)*'; | 355 const path = '(?:$identOrElementIndex)(?:\\.$identOrElementIndex)*'; |
| 353 return new RegExp('^$path\$'); | 356 return new RegExp('^$path\$'); |
| 354 }(); | 357 }(); |
| 355 | 358 |
| 356 final _spacesRegExp = new RegExp(r'\s'); | 359 final _spacesRegExp = new RegExp(r'\s'); |
| 357 | 360 |
| 358 bool _isPathValid(String s) { | 361 bool _isPathValid(String s) { |
| 359 s = s.replaceAll(_spacesRegExp, ''); | 362 s = s.replaceAll(_spacesRegExp, ''); |
| 360 | 363 |
| 361 if (s == '') return true; | 364 if (s == '') return true; |
| 362 if (s[0] == '.') return false; | 365 if (s[0] == '.') return false; |
| 363 return _pathRegExp.hasMatch(s); | 366 return _pathRegExp.hasMatch(s); |
| 364 } | 367 } |
| 365 | 368 |
| 366 final Logger _logger = new Logger('observe.PathObserver'); | 369 final Logger _logger = new Logger('observe.PathObserver'); |
| OLD | NEW |