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 var result = libMirror.declarations[new Symbol(type)]; | 413 return libMirror.classes[new Symbol(type)]; |
414 return result is ClassMirror ? result : null; | |
415 } else { | 414 } else { |
416 var symbol = new Symbol(name); | 415 var symbol = new Symbol(name); |
417 var typeSymbol = new Symbol(type); | 416 var typeSymbol = new Symbol(type); |
418 var libMirror = currentMirrorSystem().libraries.values.firstWhere((lib) { | 417 var libMirror = currentMirrorSystem().libraries.values.firstWhere( |
419 if (lib.simpleName != symbol) return false; | 418 (lib) => lib.simpleName == symbol && lib.classes[typeSymbol] != null); |
420 var candidate = lib.declarations[typeSymbol]; | 419 return libMirror.classes[typeSymbol]; |
421 return candidate != null && candidate is ClassMirror; | |
422 }); | |
423 var result = libMirror.declarations[typeSymbol]; | |
424 return result is ClassMirror ? result : null; | |
425 } | 420 } |
426 } | 421 } |
427 } | 422 } |
428 | 423 |
429 /** | 424 /** |
430 * This provides an abstract superclass for writing your own rules specific to | 425 * This provides an abstract superclass for writing your own rules specific to |
431 * a class. It makes some assumptions about behaviour, and so can have a | 426 * a class. It makes some assumptions about behaviour, and so can have a |
432 * simpler set of methods that need to be implemented in order to subclass it. | 427 * simpler set of methods that need to be implemented in order to subclass it. |
433 * | 428 * |
434 */ | 429 */ |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 int get length => _raw.length; | 568 int get length => _raw.length; |
574 | 569 |
575 void set length(int value) => _throw(); | 570 void set length(int value) => _throw(); |
576 | 571 |
577 void operator []=(int index, value) => _throw(); | 572 void operator []=(int index, value) => _throw(); |
578 | 573 |
579 void _throw() { | 574 void _throw() { |
580 throw new UnsupportedError("Not modifiable"); | 575 throw new UnsupportedError("Not modifiable"); |
581 } | 576 } |
582 } | 577 } |
OLD | NEW |