| 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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 | 380 |
| 381 /** Return the name for this object in the Writer. */ | 381 /** Return the name for this object in the Writer. */ |
| 382 nameFor(object, Writer writer) => writer.nameFor(object); | 382 nameFor(object, Writer writer) => writer.nameFor(object); |
| 383 } | 383 } |
| 384 | 384 |
| 385 /** | 385 /** |
| 386 * This rule handles the special case of Mirrors. It stores the mirror by its | 386 * This rule handles the special case of Mirrors. It stores the mirror by its |
| 387 * qualifiedName and attempts to look it up in both the namedObjects | 387 * qualifiedName and attempts to look it up in both the namedObjects |
| 388 * collection, or if it's not found there, by looking it up in the mirror | 388 * collection, or if it's not found there, by looking it up in the mirror |
| 389 * system. When reading, the user is responsible for supplying the appropriate | 389 * system. When reading, the user is responsible for supplying the appropriate |
| 390 * values in [namedObjects] or in the [externals] paramter to | 390 * values in [Serialization.namedObjects] or in the [externals] paramter to |
| 391 * [Serialization.read]. | 391 * [Serialization.read]. |
| 392 */ | 392 */ |
| 393 class MirrorRule extends NamedObjectRule { | 393 class MirrorRule extends NamedObjectRule { |
| 394 bool appliesTo(object, Writer writer) => object is DeclarationMirror; | 394 bool appliesTo(object, Writer writer) => object is DeclarationMirror; |
| 395 nameFor(DeclarationMirror object, Writer writer) => | 395 nameFor(DeclarationMirror object, Writer writer) => |
| 396 MirrorSystem.getName(object.qualifiedName); | 396 MirrorSystem.getName(object.qualifiedName); |
| 397 | 397 |
| 398 inflateEssential(state, Reader r) { | 398 inflateEssential(state, Reader r) { |
| 399 var qualifiedName = r.resolveReference(state.first); | 399 var qualifiedName = r.resolveReference(state.first); |
| 400 var lookupFull = r.objectNamed(qualifiedName, (x) => null); | 400 var lookupFull = r.objectNamed(qualifiedName, (x) => null); |
| 401 if (lookupFull != null) return lookupFull; | 401 if (lookupFull != null) return lookupFull; |
| 402 var separatorIndex = qualifiedName.lastIndexOf("."); | 402 var separatorIndex = qualifiedName.lastIndexOf("."); |
| 403 var lib = new Symbol(qualifiedName.substring(0, separatorIndex)); | 403 var lib = new Symbol(qualifiedName.substring(0, separatorIndex)); |
| 404 var type = qualifiedName.substring(separatorIndex + 1); | 404 var type = qualifiedName.substring(separatorIndex + 1); |
| 405 var lookup = r.objectNamed(type, (x) => null); | 405 var lookup = r.objectNamed(type, (x) => null); |
| 406 if (lookup != null) return lookup; | 406 if (lookup != null) return lookup; |
| 407 var libMirror = currentMirrorSystem().libraries[lib]; | 407 var libMirror = currentMirrorSystem().findLibrary(lib).first; |
| 408 return libMirror.classes[new Symbol(type)]; | 408 return libMirror.classes[new Symbol(type)]; |
| 409 } | 409 } |
| 410 } | 410 } |
| 411 | 411 |
| 412 /** | 412 /** |
| 413 * This provides an abstract superclass for writing your own rules specific to | 413 * This provides an abstract superclass for writing your own rules specific to |
| 414 * a class. It makes some assumptions about behaviour, and so can have a | 414 * a class. It makes some assumptions about behaviour, and so can have a |
| 415 * simpler set of methods that need to be implemented in order to subclass it. | 415 * simpler set of methods that need to be implemented in order to subclass it. |
| 416 * | 416 * |
| 417 */ | 417 */ |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 removeAll(x) => _throw(); | 573 removeAll(x) => _throw(); |
| 574 retainAll(x) => _throw(); | 574 retainAll(x) => _throw(); |
| 575 removeWhere(x) => _throw(); | 575 removeWhere(x) => _throw(); |
| 576 retainWhere(x) => _throw(); | 576 retainWhere(x) => _throw(); |
| 577 getRange(x, y) => _throw(); | 577 getRange(x, y) => _throw(); |
| 578 setRange(x, y, z, [a]) => _throw(); | 578 setRange(x, y, z, [a]) => _throw(); |
| 579 removeRange(x, y) => _throw(); | 579 removeRange(x, y) => _throw(); |
| 580 get reversed => _throw(); | 580 get reversed => _throw(); |
| 581 void set length(x) => _throw(); | 581 void set length(x) => _throw(); |
| 582 } | 582 } |
| OLD | NEW |