Chromium Code Reviews| 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 && annotation.beginToken.next.lexeme == 'JS' ; |
|
ahe
2017/03/10 07:26:11
Long line.
danrubel
2017/03/11 22:10:38
Reformatted.
| |
| 438 | 438 |
| 439 bool apply( | 439 bool apply( |
| 440 Compiler compiler, Element element, MetadataAnnotation annotation) { | 440 Compiler compiler, Element element, MetadataAnnotation annotation) { |
| 441 bool hasJsInterop = hasJsNameAnnotation(annotation); | 441 bool hasJsInterop = hasJsNameAnnotation(annotation); |
| 442 if (hasJsInterop) { | 442 if (hasJsInterop) { |
| 443 JavaScriptBackend backend = compiler.backend; | 443 JavaScriptBackend backend = compiler.backend; |
| 444 backend.nativeData.markAsJsInterop(element); | 444 backend.nativeData.markAsJsInterop(element); |
| 445 } | 445 } |
| 446 // Due to semantics of apply in the baseclass we have to return null to | 446 // Due to semantics of apply in the baseclass we have to return null to |
| 447 // indicate that no match was found. | 447 // indicate that no match was found. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 459 } | 459 } |
| 460 } | 460 } |
| 461 } | 461 } |
| 462 | 462 |
| 463 /// Annotation handler for pre-resolution detection of `@patch` annotations. | 463 /// Annotation handler for pre-resolution detection of `@patch` annotations. |
| 464 class PatchAnnotationHandler implements EagerAnnotationHandler<PatchVersion> { | 464 class PatchAnnotationHandler implements EagerAnnotationHandler<PatchVersion> { |
| 465 const PatchAnnotationHandler(); | 465 const PatchAnnotationHandler(); |
| 466 | 466 |
| 467 PatchVersion getPatchVersion(MetadataAnnotationX annotation) { | 467 PatchVersion getPatchVersion(MetadataAnnotationX annotation) { |
| 468 if (annotation.beginToken != null) { | 468 if (annotation.beginToken != null) { |
| 469 if (annotation.beginToken.next.value == 'patch') { | 469 if (annotation.beginToken.next.lexeme == 'patch') { |
| 470 return const PatchVersion(null); | 470 return const PatchVersion(null); |
| 471 } else if (annotation.beginToken.next.value == 'patch_full') { | 471 } else if (annotation.beginToken.next.lexeme == 'patch_full') { |
| 472 return const PatchVersion('full'); | 472 return const PatchVersion('full'); |
| 473 } else if (annotation.beginToken.next.value == 'patch_lazy') { | 473 } else if (annotation.beginToken.next.lexeme == 'patch_lazy') { |
| 474 return const PatchVersion('lazy'); | 474 return const PatchVersion('lazy'); |
| 475 } else if (annotation.beginToken.next.value == 'patch_startup') { | 475 } else if (annotation.beginToken.next.lexeme == 'patch_startup') { |
| 476 return const PatchVersion('startup'); | 476 return const PatchVersion('startup'); |
| 477 } | 477 } |
| 478 } | 478 } |
| 479 return null; | 479 return null; |
| 480 } | 480 } |
| 481 | 481 |
| 482 @override | 482 @override |
| 483 PatchVersion apply( | 483 PatchVersion apply( |
| 484 Compiler compiler, Element element, MetadataAnnotation annotation) { | 484 Compiler compiler, Element element, MetadataAnnotation annotation) { |
| 485 return getPatchVersion(annotation); | 485 return getPatchVersion(annotation); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 607 | 607 |
| 608 class PatchVersion { | 608 class PatchVersion { |
| 609 final String tag; | 609 final String tag; |
| 610 | 610 |
| 611 const PatchVersion(this.tag); | 611 const PatchVersion(this.tag); |
| 612 | 612 |
| 613 bool isActive(String patchTag) => tag == null || tag == patchTag; | 613 bool isActive(String patchTag) => tag == null || tag == patchTag; |
| 614 | 614 |
| 615 String toString() => 'PatchVersion($tag)'; | 615 String toString() => 'PatchVersion($tag)'; |
| 616 } | 616 } |
| OLD | NEW |