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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 } else { | 293 } else { |
294 compilationUnitElement.addMember(patch, listener); | 294 compilationUnitElement.addMember(patch, listener); |
295 } | 295 } |
296 } | 296 } |
297 } | 297 } |
298 | 298 |
299 void patchElement(Compiler compiler, | 299 void patchElement(Compiler compiler, |
300 Element origin, | 300 Element origin, |
301 Element patch) { | 301 Element patch) { |
302 if (origin == null) { | 302 if (origin == null) { |
303 compiler.reportError( | 303 compiler.reportErrorMessage( |
304 patch, MessageKind.PATCH_NON_EXISTING, {'name': patch.name}); | 304 patch, MessageKind.PATCH_NON_EXISTING, {'name': patch.name}); |
305 return; | 305 return; |
306 } | 306 } |
307 if (!(origin.isClass || | 307 if (!(origin.isClass || |
308 origin.isConstructor || | 308 origin.isConstructor || |
309 origin.isFunction || | 309 origin.isFunction || |
310 origin.isAbstractField)) { | 310 origin.isAbstractField)) { |
311 // TODO(ahe): Remove this error when the parser rejects all bad modifiers. | 311 // TODO(ahe): Remove this error when the parser rejects all bad modifiers. |
312 compiler.reportError(origin, MessageKind.PATCH_NONPATCHABLE); | 312 compiler.reportErrorMessage(origin, MessageKind.PATCH_NONPATCHABLE); |
313 return; | 313 return; |
314 } | 314 } |
315 if (patch.isClass) { | 315 if (patch.isClass) { |
316 tryPatchClass(compiler, origin, patch); | 316 tryPatchClass(compiler, origin, patch); |
317 } else if (patch.isGetter) { | 317 } else if (patch.isGetter) { |
318 tryPatchGetter(compiler, origin, patch); | 318 tryPatchGetter(compiler, origin, patch); |
319 } else if (patch.isSetter) { | 319 } else if (patch.isSetter) { |
320 tryPatchSetter(compiler, origin, patch); | 320 tryPatchSetter(compiler, origin, patch); |
321 } else if (patch.isConstructor) { | 321 } else if (patch.isConstructor) { |
322 tryPatchConstructor(compiler, origin, patch); | 322 tryPatchConstructor(compiler, origin, patch); |
323 } else if(patch.isFunction) { | 323 } else if(patch.isFunction) { |
324 tryPatchFunction(compiler, origin, patch); | 324 tryPatchFunction(compiler, origin, patch); |
325 } else { | 325 } else { |
326 // TODO(ahe): Remove this error when the parser rejects all bad modifiers. | 326 // TODO(ahe): Remove this error when the parser rejects all bad modifiers. |
327 compiler.reportError(patch, MessageKind.PATCH_NONPATCHABLE); | 327 compiler.reportErrorMessage(patch, MessageKind.PATCH_NONPATCHABLE); |
328 } | 328 } |
329 } | 329 } |
330 | 330 |
331 void tryPatchClass(Compiler compiler, | 331 void tryPatchClass(Compiler compiler, |
332 Element origin, | 332 Element origin, |
333 ClassElement patch) { | 333 ClassElement patch) { |
334 if (!origin.isClass) { | 334 if (!origin.isClass) { |
335 compiler.reportError( | 335 compiler.reportError( |
336 origin, MessageKind.PATCH_NON_CLASS, {'className': patch.name}); | 336 compiler.createMessage( |
337 compiler.reportInfo( | 337 origin, |
338 patch, MessageKind.PATCH_POINT_TO_CLASS, {'className': patch.name}); | 338 MessageKind.PATCH_NON_CLASS, |
| 339 {'className': patch.name}), |
| 340 <DiagnosticMessage>[ |
| 341 compiler.createMessage( |
| 342 patch, |
| 343 MessageKind.PATCH_POINT_TO_CLASS, |
| 344 {'className': patch.name}), |
| 345 ]); |
339 return; | 346 return; |
340 } | 347 } |
341 patchClass(compiler, origin, patch); | 348 patchClass(compiler, origin, patch); |
342 } | 349 } |
343 | 350 |
344 void patchClass(Compiler compiler, | 351 void patchClass(Compiler compiler, |
345 ClassElementX origin, | 352 ClassElementX origin, |
346 ClassElementX patch) { | 353 ClassElementX patch) { |
347 if (origin.isPatched) { | 354 if (origin.isPatched) { |
348 compiler.internalError(origin, | 355 compiler.internalError(origin, |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 } | 490 } |
484 } | 491 } |
485 } | 492 } |
486 | 493 |
487 | 494 |
488 void tryPatchGetter(DiagnosticListener listener, | 495 void tryPatchGetter(DiagnosticListener listener, |
489 Element origin, | 496 Element origin, |
490 FunctionElement patch) { | 497 FunctionElement patch) { |
491 if (!origin.isAbstractField) { | 498 if (!origin.isAbstractField) { |
492 listener.reportError( | 499 listener.reportError( |
493 origin, MessageKind.PATCH_NON_GETTER, {'name': origin.name}); | 500 listener.createMessage( |
494 listener.reportInfo( | 501 origin, |
495 patch, | 502 MessageKind.PATCH_NON_GETTER, |
496 MessageKind.PATCH_POINT_TO_GETTER, {'getterName': patch.name}); | 503 {'name': origin.name}), |
| 504 <DiagnosticMessage>[ |
| 505 listener.createMessage( |
| 506 patch, |
| 507 MessageKind.PATCH_POINT_TO_GETTER, |
| 508 {'getterName': patch.name}), |
| 509 ]); |
497 return; | 510 return; |
498 } | 511 } |
499 AbstractFieldElement originField = origin; | 512 AbstractFieldElement originField = origin; |
500 if (originField.getter == null) { | 513 if (originField.getter == null) { |
501 listener.reportError( | 514 listener.reportError( |
502 origin, MessageKind.PATCH_NO_GETTER, {'getterName': patch.name}); | 515 listener.createMessage( |
503 listener.reportInfo( | 516 origin, |
504 patch, | 517 MessageKind.PATCH_NO_GETTER, |
505 MessageKind.PATCH_POINT_TO_GETTER, {'getterName': patch.name}); | 518 {'getterName': patch.name}), |
| 519 <DiagnosticMessage>[ |
| 520 listener.createMessage( |
| 521 patch, |
| 522 MessageKind.PATCH_POINT_TO_GETTER, |
| 523 {'getterName': patch.name}), |
| 524 ]); |
506 return; | 525 return; |
507 } | 526 } |
508 GetterElementX getter = originField.getter; | 527 GetterElementX getter = originField.getter; |
509 patchFunction(listener, getter, patch); | 528 patchFunction(listener, getter, patch); |
510 } | 529 } |
511 | 530 |
512 void tryPatchSetter(DiagnosticListener listener, | 531 void tryPatchSetter(DiagnosticListener listener, |
513 Element origin, | 532 Element origin, |
514 FunctionElement patch) { | 533 FunctionElement patch) { |
515 if (!origin.isAbstractField) { | 534 if (!origin.isAbstractField) { |
516 listener.reportError( | 535 listener.reportError( |
517 origin, MessageKind.PATCH_NON_SETTER, {'name': origin.name}); | 536 listener.createMessage( |
518 listener.reportInfo( | 537 origin, |
519 patch, | 538 MessageKind.PATCH_NON_SETTER, |
520 MessageKind.PATCH_POINT_TO_SETTER, {'setterName': patch.name}); | 539 {'name': origin.name}), |
| 540 <DiagnosticMessage>[ |
| 541 listener.createMessage( |
| 542 patch, |
| 543 MessageKind.PATCH_POINT_TO_SETTER, |
| 544 {'setterName': patch.name}), |
| 545 ]); |
521 return; | 546 return; |
522 } | 547 } |
523 AbstractFieldElement originField = origin; | 548 AbstractFieldElement originField = origin; |
524 if (originField.setter == null) { | 549 if (originField.setter == null) { |
525 listener.reportError( | 550 listener.reportError( |
526 origin, MessageKind.PATCH_NO_SETTER, {'setterName': patch.name}); | 551 listener.createMessage( |
527 listener.reportInfo( | 552 origin, |
528 patch, | 553 MessageKind.PATCH_NO_SETTER, |
529 MessageKind.PATCH_POINT_TO_SETTER, {'setterName': patch.name}); | 554 {'setterName': patch.name}), |
| 555 <DiagnosticMessage>[ |
| 556 listener.createMessage( |
| 557 patch, |
| 558 MessageKind.PATCH_POINT_TO_SETTER, |
| 559 {'setterName': patch.name}), |
| 560 ]); |
530 return; | 561 return; |
531 } | 562 } |
532 SetterElementX setter = originField.setter; | 563 SetterElementX setter = originField.setter; |
533 patchFunction(listener, setter, patch); | 564 patchFunction(listener, setter, patch); |
534 } | 565 } |
535 | 566 |
536 void tryPatchConstructor(DiagnosticListener listener, | 567 void tryPatchConstructor(DiagnosticListener listener, |
537 Element origin, | 568 Element origin, |
538 FunctionElement patch) { | 569 FunctionElement patch) { |
539 if (!origin.isConstructor) { | 570 if (!origin.isConstructor) { |
540 listener.reportError( | 571 listener.reportError( |
541 origin, | 572 listener.createMessage( |
542 MessageKind.PATCH_NON_CONSTRUCTOR, {'constructorName': patch.name}); | 573 origin, |
543 listener.reportInfo( | 574 MessageKind.PATCH_NON_CONSTRUCTOR, |
544 patch, | 575 {'constructorName': patch.name}), |
545 MessageKind.PATCH_POINT_TO_CONSTRUCTOR, | 576 <DiagnosticMessage>[ |
546 {'constructorName': patch.name}); | 577 listener.createMessage( |
| 578 patch, |
| 579 MessageKind.PATCH_POINT_TO_CONSTRUCTOR, |
| 580 {'constructorName': patch.name}), |
| 581 ]); |
547 return; | 582 return; |
548 } | 583 } |
549 patchFunction(listener, origin, patch); | 584 patchFunction(listener, origin, patch); |
550 } | 585 } |
551 | 586 |
552 void tryPatchFunction(DiagnosticListener listener, | 587 void tryPatchFunction(DiagnosticListener listener, |
553 Element origin, | 588 Element origin, |
554 FunctionElement patch) { | 589 FunctionElement patch) { |
555 if (!origin.isFunction) { | 590 if (!origin.isFunction) { |
556 listener.reportError( | 591 listener.reportError( |
557 origin, | 592 listener.createMessage( |
558 MessageKind.PATCH_NON_FUNCTION, {'functionName': patch.name}); | 593 origin, |
559 listener.reportInfo( | 594 MessageKind.PATCH_NON_FUNCTION, |
560 patch, | 595 {'functionName': patch.name}), |
561 MessageKind.PATCH_POINT_TO_FUNCTION, {'functionName': patch.name}); | 596 <DiagnosticMessage>[ |
| 597 listener.createMessage( |
| 598 patch, |
| 599 MessageKind.PATCH_POINT_TO_FUNCTION, |
| 600 {'functionName': patch.name}), |
| 601 ]); |
562 return; | 602 return; |
563 } | 603 } |
564 patchFunction(listener, origin, patch); | 604 patchFunction(listener, origin, patch); |
565 } | 605 } |
566 | 606 |
567 void patchFunction(DiagnosticListener listener, | 607 void patchFunction(DiagnosticListener listener, |
568 BaseFunctionElementX origin, | 608 BaseFunctionElementX origin, |
569 BaseFunctionElementX patch) { | 609 BaseFunctionElementX patch) { |
570 if (!origin.modifiers.isExternal) { | 610 if (!origin.modifiers.isExternal) { |
571 listener.reportError(origin, MessageKind.PATCH_NON_EXTERNAL); | 611 listener.reportError( |
572 listener.reportInfo( | 612 listener.createMessage(origin, MessageKind.PATCH_NON_EXTERNAL), |
573 patch, | 613 <DiagnosticMessage>[ |
574 MessageKind.PATCH_POINT_TO_FUNCTION, {'functionName': patch.name}); | 614 listener.createMessage( |
| 615 patch, |
| 616 MessageKind.PATCH_POINT_TO_FUNCTION, |
| 617 {'functionName': patch.name}), |
| 618 ]); |
575 return; | 619 return; |
576 } | 620 } |
577 if (origin.isPatched) { | 621 if (origin.isPatched) { |
578 listener.internalError(origin, | 622 listener.internalError(origin, |
579 "Trying to patch a function more than once."); | 623 "Trying to patch a function more than once."); |
580 } | 624 } |
581 origin.applyPatch(patch); | 625 origin.applyPatch(patch); |
582 } | 626 } |
583 | 627 |
584 PatchVersion getPatchVersion(Compiler compiler, Element element) { | 628 PatchVersion getPatchVersion(Compiler compiler, Element element) { |
585 return EagerAnnotationHandler.checkAnnotation(compiler, element, | 629 return EagerAnnotationHandler.checkAnnotation(compiler, element, |
586 const PatchAnnotationHandler()); | 630 const PatchAnnotationHandler()); |
587 } | 631 } |
588 | 632 |
589 class PatchVersion { | 633 class PatchVersion { |
590 final String tag; | 634 final String tag; |
591 | 635 |
592 const PatchVersion(this.tag); | 636 const PatchVersion(this.tag); |
593 | 637 |
594 bool isActive(String patchTag) => tag == null || tag == patchTag; | 638 bool isActive(String patchTag) => tag == null || tag == patchTag; |
595 | 639 |
596 String toString() => 'PatchVersion($tag)'; | 640 String toString() => 'PatchVersion($tag)'; |
597 } | 641 } |
OLD | NEW |