| 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 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 } | 386 } |
| 387 } | 387 } |
| 388 | 388 |
| 389 /// Annotation handler for pre-resolution detection of `@Native(...)` | 389 /// Annotation handler for pre-resolution detection of `@Native(...)` |
| 390 /// annotations. | 390 /// annotations. |
| 391 class NativeAnnotationHandler implements EagerAnnotationHandler<String> { | 391 class NativeAnnotationHandler implements EagerAnnotationHandler<String> { |
| 392 const NativeAnnotationHandler(); | 392 const NativeAnnotationHandler(); |
| 393 | 393 |
| 394 String getNativeAnnotation(MetadataAnnotationX annotation) { | 394 String getNativeAnnotation(MetadataAnnotationX annotation) { |
| 395 if (annotation.beginToken != null && | 395 if (annotation.beginToken != null && |
| 396 annotation.beginToken.next.value == 'Native') { | 396 annotation.beginToken.next.lexeme == 'Native') { |
| 397 // Skipping '@', 'Native', and '('. | 397 // Skipping '@', 'Native', and '('. |
| 398 Token argument = annotation.beginToken.next.next.next; | 398 Token argument = annotation.beginToken.next.next.next; |
| 399 if (argument is StringToken) { | 399 if (argument is StringToken) { |
| 400 return argument.value; | 400 return argument.lexeme; |
| 401 } | 401 } |
| 402 } | 402 } |
| 403 return null; | 403 return null; |
| 404 } | 404 } |
| 405 | 405 |
| 406 String apply( | 406 String apply( |
| 407 Compiler compiler, Element element, MetadataAnnotation annotation) { | 407 Compiler compiler, Element element, MetadataAnnotation annotation) { |
| 408 if (element.isClass) { | 408 if (element.isClass) { |
| 409 String native = getNativeAnnotation(annotation); | 409 String native = getNativeAnnotation(annotation); |
| 410 if (native != null) { | 410 if (native != null) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 427 } | 427 } |
| 428 } | 428 } |
| 429 } | 429 } |
| 430 | 430 |
| 431 /// Annotation handler for pre-resolution detection of `@JS(...)` | 431 /// Annotation handler for pre-resolution detection of `@JS(...)` |
| 432 /// annotations. | 432 /// annotations. |
| 433 class JsInteropAnnotationHandler implements EagerAnnotationHandler<bool> { | 433 class JsInteropAnnotationHandler implements EagerAnnotationHandler<bool> { |
| 434 const JsInteropAnnotationHandler(); | 434 const JsInteropAnnotationHandler(); |
| 435 | 435 |
| 436 bool hasJsNameAnnotation(MetadataAnnotationX annotation) => | 436 bool hasJsNameAnnotation(MetadataAnnotationX annotation) => |
| 437 annotation.beginToken != null && annotation.beginToken.next.value == 'JS'; | 437 annotation.beginToken != null && |
| 438 annotation.beginToken.next.lexeme == 'JS'; |
| 438 | 439 |
| 439 bool apply( | 440 bool apply( |
| 440 Compiler compiler, Element element, MetadataAnnotation annotation) { | 441 Compiler compiler, Element element, MetadataAnnotation annotation) { |
| 441 bool hasJsInterop = hasJsNameAnnotation(annotation); | 442 bool hasJsInterop = hasJsNameAnnotation(annotation); |
| 442 if (hasJsInterop) { | 443 if (hasJsInterop) { |
| 443 JavaScriptBackend backend = compiler.backend; | 444 JavaScriptBackend backend = compiler.backend; |
| 444 backend.nativeData.markAsJsInterop(element); | 445 backend.nativeData.markAsJsInterop(element); |
| 445 } | 446 } |
| 446 // Due to semantics of apply in the baseclass we have to return null to | 447 // Due to semantics of apply in the baseclass we have to return null to |
| 447 // indicate that no match was found. | 448 // indicate that no match was found. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 459 } | 460 } |
| 460 } | 461 } |
| 461 } | 462 } |
| 462 | 463 |
| 463 /// Annotation handler for pre-resolution detection of `@patch` annotations. | 464 /// Annotation handler for pre-resolution detection of `@patch` annotations. |
| 464 class PatchAnnotationHandler implements EagerAnnotationHandler<PatchVersion> { | 465 class PatchAnnotationHandler implements EagerAnnotationHandler<PatchVersion> { |
| 465 const PatchAnnotationHandler(); | 466 const PatchAnnotationHandler(); |
| 466 | 467 |
| 467 PatchVersion getPatchVersion(MetadataAnnotationX annotation) { | 468 PatchVersion getPatchVersion(MetadataAnnotationX annotation) { |
| 468 if (annotation.beginToken != null) { | 469 if (annotation.beginToken != null) { |
| 469 if (annotation.beginToken.next.value == 'patch') { | 470 if (annotation.beginToken.next.lexeme == 'patch') { |
| 470 return const PatchVersion(null); | 471 return const PatchVersion(null); |
| 471 } else if (annotation.beginToken.next.value == 'patch_full') { | 472 } else if (annotation.beginToken.next.lexeme == 'patch_full') { |
| 472 return const PatchVersion('full'); | 473 return const PatchVersion('full'); |
| 473 } else if (annotation.beginToken.next.value == 'patch_lazy') { | 474 } else if (annotation.beginToken.next.lexeme == 'patch_lazy') { |
| 474 return const PatchVersion('lazy'); | 475 return const PatchVersion('lazy'); |
| 475 } else if (annotation.beginToken.next.value == 'patch_startup') { | 476 } else if (annotation.beginToken.next.lexeme == 'patch_startup') { |
| 476 return const PatchVersion('startup'); | 477 return const PatchVersion('startup'); |
| 477 } | 478 } |
| 478 } | 479 } |
| 479 return null; | 480 return null; |
| 480 } | 481 } |
| 481 | 482 |
| 482 @override | 483 @override |
| 483 PatchVersion apply( | 484 PatchVersion apply( |
| 484 Compiler compiler, Element element, MetadataAnnotation annotation) { | 485 Compiler compiler, Element element, MetadataAnnotation annotation) { |
| 485 return getPatchVersion(annotation); | 486 return getPatchVersion(annotation); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 | 608 |
| 608 class PatchVersion { | 609 class PatchVersion { |
| 609 final String tag; | 610 final String tag; |
| 610 | 611 |
| 611 const PatchVersion(this.tag); | 612 const PatchVersion(this.tag); |
| 612 | 613 |
| 613 bool isActive(String patchTag) => tag == null || tag == patchTag; | 614 bool isActive(String patchTag) => tag == null || tag == patchTag; |
| 614 | 615 |
| 615 String toString() => 'PatchVersion($tag)'; | 616 String toString() => 'PatchVersion($tag)'; |
| 616 } | 617 } |
| OLD | NEW |