OLD | NEW |
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 part of serialization; | 5 part of serialization; |
6 | 6 |
7 // TODO(alanknight): We should have an example and tests for subclassing | 7 // TODO(alanknight): We should have an example and tests for subclassing |
8 // serialization rule rather than using the hard-coded ClosureToMap rule. And | 8 // serialization rule rather than using the hard-coded ClosureToMap rule. And |
9 // possibly an abstract superclass that's designed to be subclassed that way. | 9 // possibly an abstract superclass that's designed to be subclassed that way. |
10 /** | 10 /** |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 var lookup = r.objectNamed(type, (x) => null); | 403 var lookup = r.objectNamed(type, (x) => null); |
404 if (lookup != null) return lookup; | 404 if (lookup != null) return lookup; |
405 var name = qualifiedName.substring(0, separatorIndex); | 405 var name = qualifiedName.substring(0, separatorIndex); |
406 // This is very ugly. The library name for an unnamed library is its URI. | 406 // This is very ugly. The library name for an unnamed library is its URI. |
407 // That can't be constructed as a Symbol, so we can't use findLibrary. | 407 // That can't be constructed as a Symbol, so we can't use findLibrary. |
408 // So follow one or the other path depending if it has a colon, which we | 408 // So follow one or the other path depending if it has a colon, which we |
409 // assume is in any URI and can't be in a Symbol. | 409 // assume is in any URI and can't be in a Symbol. |
410 if (name.contains(":")) { | 410 if (name.contains(":")) { |
411 var uri = Uri.parse(name); | 411 var uri = Uri.parse(name); |
412 var libMirror = currentMirrorSystem().libraries[uri]; | 412 var libMirror = currentMirrorSystem().libraries[uri]; |
413 return libMirror.classes[new Symbol(type)]; | 413 var result = libMirror.declarations[new Symbol(type)]; |
| 414 return result is ClassMirror ? result : null; |
414 } else { | 415 } else { |
415 var symbol = new Symbol(name); | 416 var symbol = new Symbol(name); |
416 var typeSymbol = new Symbol(type); | 417 var typeSymbol = new Symbol(type); |
417 var libMirror = currentMirrorSystem().libraries.values.firstWhere( | 418 var libMirror = currentMirrorSystem().libraries.values.firstWhere((lib) { |
418 (lib) => lib.simpleName == symbol && lib.classes[typeSymbol] != null); | 419 if (lib.simpleName != symbol) return false; |
419 return libMirror.classes[typeSymbol]; | 420 var candidate = lib.declarations[typeSymbol]; |
| 421 return candidate != null && candidate is ClassMirror; |
| 422 }); |
| 423 var result = libMirror.declarations[typeSymbol]; |
| 424 return result is ClassMirror ? result : null; |
420 } | 425 } |
421 } | 426 } |
422 } | 427 } |
423 | 428 |
424 /** | 429 /** |
425 * This provides an abstract superclass for writing your own rules specific to | 430 * This provides an abstract superclass for writing your own rules specific to |
426 * a class. It makes some assumptions about behaviour, and so can have a | 431 * a class. It makes some assumptions about behaviour, and so can have a |
427 * simpler set of methods that need to be implemented in order to subclass it. | 432 * simpler set of methods that need to be implemented in order to subclass it. |
428 * | 433 * |
429 */ | 434 */ |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 int get length => _raw.length; | 573 int get length => _raw.length; |
569 | 574 |
570 void set length(int value) => _throw(); | 575 void set length(int value) => _throw(); |
571 | 576 |
572 void operator []=(int index, value) => _throw(); | 577 void operator []=(int index, value) => _throw(); |
573 | 578 |
574 void _throw() { | 579 void _throw() { |
575 throw new UnsupportedError("Not modifiable"); | 580 throw new UnsupportedError("Not modifiable"); |
576 } | 581 } |
577 } | 582 } |
OLD | NEW |