| 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 |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 Element patch) { | 394 Element patch) { |
| 395 if (origin == null) { | 395 if (origin == null) { |
| 396 listener.reportError( | 396 listener.reportError( |
| 397 patch, leg.MessageKind.PATCH_NON_EXISTING, {'name': patch.name}); | 397 patch, leg.MessageKind.PATCH_NON_EXISTING, {'name': patch.name}); |
| 398 return; | 398 return; |
| 399 } | 399 } |
| 400 if (!(origin.isClass() || | 400 if (!(origin.isClass() || |
| 401 origin.isConstructor() || | 401 origin.isConstructor() || |
| 402 origin.isFunction() || | 402 origin.isFunction() || |
| 403 origin.isAbstractField())) { | 403 origin.isAbstractField())) { |
| 404 // TODO(ahe): Remove this error when the parser rejects all bad modifiers. |
| 404 listener.reportError(origin, leg.MessageKind.PATCH_NONPATCHABLE); | 405 listener.reportError(origin, leg.MessageKind.PATCH_NONPATCHABLE); |
| 405 return; | 406 return; |
| 406 } | 407 } |
| 407 if (patch.isClass()) { | 408 if (patch.isClass()) { |
| 408 tryPatchClass(listener, origin, patch); | 409 tryPatchClass(listener, origin, patch); |
| 409 } else if (patch.isGetter()) { | 410 } else if (patch.isGetter()) { |
| 410 tryPatchGetter(listener, origin, patch); | 411 tryPatchGetter(listener, origin, patch); |
| 411 } else if (patch.isSetter()) { | 412 } else if (patch.isSetter()) { |
| 412 tryPatchSetter(listener, origin, patch); | 413 tryPatchSetter(listener, origin, patch); |
| 413 } else if (patch.isConstructor()) { | 414 } else if (patch.isConstructor()) { |
| 414 tryPatchConstructor(listener, origin, patch); | 415 tryPatchConstructor(listener, origin, patch); |
| 415 } else if(patch.isFunction()) { | 416 } else if(patch.isFunction()) { |
| 416 tryPatchFunction(listener, origin, patch); | 417 tryPatchFunction(listener, origin, patch); |
| 417 } else { | 418 } else { |
| 419 // TODO(ahe): Remove this error when the parser rejects all bad modifiers. |
| 418 listener.reportError(patch, leg.MessageKind.PATCH_NONPATCHABLE); | 420 listener.reportError(patch, leg.MessageKind.PATCH_NONPATCHABLE); |
| 419 } | 421 } |
| 420 } | 422 } |
| 421 | 423 |
| 422 void tryPatchClass(leg.DiagnosticListener listener, | 424 void tryPatchClass(leg.DiagnosticListener listener, |
| 423 Element origin, | 425 Element origin, |
| 424 ClassElement patch) { | 426 ClassElement patch) { |
| 425 if (!origin.isClass()) { | 427 if (!origin.isClass()) { |
| 426 listener.reportError( | 428 listener.reportError( |
| 427 origin, leg.MessageKind.PATCH_NON_CLASS, {'className': patch.name}); | 429 origin, leg.MessageKind.PATCH_NON_CLASS, {'className': patch.name}); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 | 549 |
| 548 // TODO(johnniwinther): Add unittest when patch is (real) metadata. | 550 // TODO(johnniwinther): Add unittest when patch is (real) metadata. |
| 549 bool isPatchElement(Element element) { | 551 bool isPatchElement(Element element) { |
| 550 // TODO(lrn): More checks needed if we introduce metadata for real. | 552 // TODO(lrn): More checks needed if we introduce metadata for real. |
| 551 // In that case, it must have the identifier "native" as metadata. | 553 // In that case, it must have the identifier "native" as metadata. |
| 552 for (Link link = element.metadata; !link.isEmpty; link = link.tail) { | 554 for (Link link = element.metadata; !link.isEmpty; link = link.tail) { |
| 553 if (link.head is PatchMetadataAnnotation) return true; | 555 if (link.head is PatchMetadataAnnotation) return true; |
| 554 } | 556 } |
| 555 return false; | 557 return false; |
| 556 } | 558 } |
| OLD | NEW |