| 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 /** | 5 /** |
| 6 * This library contains the infrastructure to parse and integrate patch files. | 6 * This library contains the infrastructure to parse and integrate patch files. |
| 7 * | 7 * |
| 8 * Three types of elements can be patched: [LibraryElement], [ClassElement], | 8 * Three types of elements can be patched: [LibraryElement], [ClassElement], |
| 9 * [FunctionElement]. Patches are introduced in patch libraries which are loaded | 9 * [FunctionElement]. Patches are introduced in patch libraries which are loaded |
| 10 * together with the corresponding origin library. Which libraries that are | 10 * together with the corresponding origin library. Which libraries that are |
| 11 * patched is determined by the dart2jsPatchPath field of LibraryInfo found | 11 * patched is determined by the dart2jsPatchPath field of LibraryInfo found |
| 12 * in [:lib/_internal/libraries.dart:]. | 12 * in [:lib/_internal/libraries.dart:]. |
| 13 * | 13 * |
| 14 * Patch libraries are parsed like regular library and thus provided with their | 14 * Patch libraries are parsed like regular library and thus provided with their |
| 15 * own elements. These elements which are distinct from the elements from the | 15 * own elements. These elements which are distinct from the elements from the |
| 16 * patched library and the relation between patched and patch elements is | 16 * patched library and the relation between patched and patch elements is |
| 17 * established through the [:patch:] and [:origin:] fields found on | 17 * established through the [:patch:] and [:origin:] fields found on |
| 18 * [LibraryElement], [ClassElement] and [FunctionElement]. The [:patch:] fields | 18 * [LibraryElement], [ClassElement] and [FunctionElement]. The [:patch:] fields |
| 19 * are set on the patched elements to point to their corresponding patch | 19 * are set on the patched elements to point to their corresponding patch |
| 20 * element, and the [:origin:] elements are set on the patch elements to point | 20 * element, and the [:origin:] elements are set on the patch elements to point |
| 21 * their corresponding patched elements. | 21 * their corresponding patched elements. |
| 22 * | 22 * |
| 23 * The fields [Element.isPatched] and [Element.isPatch] can be used to determine | 23 * The fields [Element.isPatched] and [Element.isPatch] can be used to determine |
| 24 * whether the [:patch:] or [:origin:] field, respectively, has been set on an | 24 * whether the [:patch:] or [:origin:] field, respectively, has been set on an |
| 25 * element, regardless of whether the element is one of the three patchable | 25 * element, regardless of whether the element is one of the three patchable |
| 26 * element types or not. | 26 * element types or not. |
| 27 * | 27 * |
| 28 * ## Variants of Classes and Functions ## | 28 * ## Variants of classes and functions ## |
| 29 * | 29 * |
| 30 * With patches there are four variants of classes and function: | 30 * With patches there are four variants of classes and function: |
| 31 * | 31 * |
| 32 * Regular: A class or function which is not declared in a patch library and | 32 * Regular: A class or function which is not declared in a patch library and |
| 33 * which has no corresponding patch. | 33 * which has no corresponding patch. |
| 34 * Origin: A class or function which is not declared in a patch library and | 34 * Origin: A class or function which is not declared in a patch library and |
| 35 * which has a corresponding patch. Origin functions must use the [:external:] | 35 * which has a corresponding patch. Origin functions must use the [:external:] |
| 36 * modifier and can have no body. Origin classes and functions are also | 36 * modifier and can have no body. Origin classes and functions are also |
| 37 * called 'patched'. | 37 * called 'patched'. |
| 38 * Patch: A class or function which is declared in a patch library and which | 38 * Patch: A class or function which is declared in a patch library and which |
| (...skipping 21 matching lines...) Expand all Loading... |
| 60 * // In the patch library: | 60 * // In the patch library: |
| 61 * class _InjectedClass { // An injected class. | 61 * class _InjectedClass { // An injected class. |
| 62 * void _injectedMethod() {} // An injected method. | 62 * void _injectedMethod() {} // An injected method. |
| 63 * } | 63 * } |
| 64 * patch class PatchedClass { // A patch class. | 64 * patch class PatchedClass { // A patch class. |
| 65 * int _injectedField; { // An injected field. | 65 * int _injectedField; { // An injected field. |
| 66 * patch void patchedMethod() {} // A patch method. | 66 * patch void patchedMethod() {} // A patch method. |
| 67 * } | 67 * } |
| 68 * | 68 * |
| 69 * | 69 * |
| 70 * ## Declaration and Implementation ## | 70 * ## Declaration and implementation ## |
| 71 * | 71 * |
| 72 * With patches we have two views on elements: as the 'declaration' which | 72 * With patches we have two views on elements: as the 'declaration' which |
| 73 * introduces the entity and defines its interface, and as the 'implementation' | 73 * introduces the entity and defines its interface, and as the 'implementation' |
| 74 * which defines the actual implementation of the entity. | 74 * which defines the actual implementation of the entity. |
| 75 * | 75 * |
| 76 * Every element has a 'declaration' and an 'implementation' element. For | 76 * Every element has a 'declaration' and an 'implementation' element. For |
| 77 * regular and injected elements these are the same. For origin elements the | 77 * regular and injected elements these are the same. For origin elements the |
| 78 * declaration is the element itself and the implementation is the patch element | 78 * declaration is the element itself and the implementation is the patch element |
| 79 * found through its [:patch:] field. For patch elements the implementation is | 79 * found through its [:patch:] field. For patch elements the implementation is |
| 80 * the element itself and the declaration is the origin element found through | 80 * the element itself and the declaration is the origin element found through |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 | 549 |
| 550 // TODO(johnniwinther): Add unittest when patch is (real) metadata. | 550 // TODO(johnniwinther): Add unittest when patch is (real) metadata. |
| 551 bool isPatchElement(Element element) { | 551 bool isPatchElement(Element element) { |
| 552 // TODO(lrn): More checks needed if we introduce metadata for real. | 552 // TODO(lrn): More checks needed if we introduce metadata for real. |
| 553 // In that case, it must have the identifier "native" as metadata. | 553 // In that case, it must have the identifier "native" as metadata. |
| 554 for (Link link = element.metadata; !link.isEmpty; link = link.tail) { | 554 for (Link link = element.metadata; !link.isEmpty; link = link.tail) { |
| 555 if (link.head is PatchMetadataAnnotation) return true; | 555 if (link.head is PatchMetadataAnnotation) return true; |
| 556 } | 556 } |
| 557 return false; | 557 return false; |
| 558 } | 558 } |
| OLD | NEW |