| 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 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 MetadataAnnotation annotation, | 458 MetadataAnnotation annotation, |
| 459 ConstantValue constant) { | 459 ConstantValue constant) { |
| 460 DartType annotationType = constant.getType(compiler.coreTypes); | 460 DartType annotationType = constant.getType(compiler.coreTypes); |
| 461 if (annotationType.element != compiler.nativeAnnotationClass) { | 461 if (annotationType.element != compiler.nativeAnnotationClass) { |
| 462 DiagnosticReporter reporter = compiler.reporter; | 462 DiagnosticReporter reporter = compiler.reporter; |
| 463 reporter.internalError(annotation, 'Invalid @Native(...) annotation.'); | 463 reporter.internalError(annotation, 'Invalid @Native(...) annotation.'); |
| 464 } | 464 } |
| 465 } | 465 } |
| 466 } | 466 } |
| 467 | 467 |
| 468 /// Annotation handler for pre-resolution detection of `@Js(...)` | 468 /// Annotation handler for pre-resolution detection of `@JS(...)` |
| 469 /// annotations. | 469 /// annotations. |
| 470 class JsInteropAnnotationHandler implements EagerAnnotationHandler<bool> { | 470 class JsInteropAnnotationHandler implements EagerAnnotationHandler<bool> { |
| 471 const JsInteropAnnotationHandler(); | 471 const JsInteropAnnotationHandler(); |
| 472 | 472 |
| 473 bool hasJsNameAnnotation(MetadataAnnotation annotation) => | 473 bool hasJsNameAnnotation(MetadataAnnotation annotation) => |
| 474 annotation.beginToken != null && annotation.beginToken.next.value == 'Js'; | 474 annotation.beginToken != null && annotation.beginToken.next.value == 'JS'; |
| 475 | 475 |
| 476 bool apply(Compiler compiler, | 476 bool apply(Compiler compiler, |
| 477 Element element, | 477 Element element, |
| 478 MetadataAnnotation annotation) { | 478 MetadataAnnotation annotation) { |
| 479 bool hasJsInterop = hasJsNameAnnotation(annotation); | 479 bool hasJsInterop = hasJsNameAnnotation(annotation); |
| 480 if (hasJsInterop) { | 480 if (hasJsInterop) { |
| 481 element.markAsJsInterop(); | 481 element.markAsJsInterop(); |
| 482 } | 482 } |
| 483 // Due to semantics of apply in the baseclass we have to return null to | 483 // Due to semantics of apply in the baseclass we have to return null to |
| 484 // indicate that no match was found. | 484 // indicate that no match was found. |
| 485 return hasJsInterop ? true : null; | 485 return hasJsInterop ? true : null; |
| 486 } | 486 } |
| 487 | 487 |
| 488 @override | 488 @override |
| 489 void validate(Compiler compiler, | 489 void validate(Compiler compiler, |
| 490 Element element, | 490 Element element, |
| 491 MetadataAnnotation annotation, | 491 MetadataAnnotation annotation, |
| 492 ConstantValue constant) { | 492 ConstantValue constant) { |
| 493 JavaScriptBackend backend = compiler.backend; | 493 JavaScriptBackend backend = compiler.backend; |
| 494 if (constant.getType(compiler.coreTypes).element != | 494 if (constant.getType(compiler.coreTypes).element != |
| 495 backend.jsAnnotationClass) { | 495 backend.jsAnnotationClass) { |
| 496 compiler.reporter.internalError(annotation, 'Invalid @Js(...) annotation.'
); | 496 compiler.reporter.internalError(annotation, 'Invalid @JS(...) annotation.'
); |
| 497 } | 497 } |
| 498 } | 498 } |
| 499 } | 499 } |
| 500 | 500 |
| 501 /// Annotation handler for pre-resolution detection of `@patch` annotations. | 501 /// Annotation handler for pre-resolution detection of `@patch` annotations. |
| 502 class PatchAnnotationHandler implements EagerAnnotationHandler<PatchVersion> { | 502 class PatchAnnotationHandler implements EagerAnnotationHandler<PatchVersion> { |
| 503 const PatchAnnotationHandler(); | 503 const PatchAnnotationHandler(); |
| 504 | 504 |
| 505 PatchVersion getPatchVersion(MetadataAnnotation annotation) { | 505 PatchVersion getPatchVersion(MetadataAnnotation annotation) { |
| 506 if (annotation.beginToken != null) { | 506 if (annotation.beginToken != null) { |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 | 678 |
| 679 class PatchVersion { | 679 class PatchVersion { |
| 680 final String tag; | 680 final String tag; |
| 681 | 681 |
| 682 const PatchVersion(this.tag); | 682 const PatchVersion(this.tag); |
| 683 | 683 |
| 684 bool isActive(String patchTag) => tag == null || tag == patchTag; | 684 bool isActive(String patchTag) => tag == null || tag == patchTag; |
| 685 | 685 |
| 686 String toString() => 'PatchVersion($tag)'; | 686 String toString() => 'PatchVersion($tag)'; |
| 687 } | 687 } |
| OLD | NEW |