| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
| 4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 """This module provides shared functionality for systems to generate | 6 """This module provides shared functionality for systems to generate |
| 7 Dart APIs from the IDL database.""" | 7 Dart APIs from the IDL database.""" |
| 8 | 8 |
| 9 import copy | 9 import copy |
| 10 import json | 10 import json |
| 11 import monitored | 11 import monitored |
| 12 import os | 12 import os |
| 13 import re | 13 import re |
| 14 from htmlrenamer import html_interface_renames, renamed_html_members, \ | 14 from htmlrenamer import html_interface_renames, renamed_html_members, \ |
| 15 typed_array_renames | 15 typed_array_renames |
| 16 | 16 |
| 17 # Set up json file for retrieving comments. | |
| 18 _current_dir = os.path.dirname(__file__) | |
| 19 _json_path = os.path.join(_current_dir, '..', 'docs', 'docs.json') | |
| 20 _dom_json = json.load(open(_json_path)) | |
| 21 | |
| 22 _pure_interfaces = monitored.Set('generator._pure_interfaces', [ | 17 _pure_interfaces = monitored.Set('generator._pure_interfaces', [ |
| 23 # TODO(sra): DOMStringMap should be a class implementing Map<String,String>. | 18 # TODO(sra): DOMStringMap should be a class implementing Map<String,String>. |
| 24 'DOMStringMap', | 19 'DOMStringMap', |
| 25 'ElementTimeControl', | 20 'ElementTimeControl', |
| 26 'ElementTraversal', | 21 'ElementTraversal', |
| 27 'EventListener', | 22 'EventListener', |
| 28 'MediaQueryListListener', | 23 'MediaQueryListListener', |
| 29 'MutationCallback', | 24 'MutationCallback', |
| 30 'SVGExternalResourcesRequired', | 25 'SVGExternalResourcesRequired', |
| 31 'SVGFilterPrimitiveStandardAttributes', | 26 'SVGFilterPrimitiveStandardAttributes', |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 }, dart2jsOnly=True) | 520 }, dart2jsOnly=True) |
| 526 | 521 |
| 527 def FindConversion(idl_type, direction, interface, member): | 522 def FindConversion(idl_type, direction, interface, member): |
| 528 table = dart2js_conversions | 523 table = dart2js_conversions |
| 529 return (table.get('%s %s %s.%s' % (idl_type, direction, interface, member)) or | 524 return (table.get('%s %s %s.%s' % (idl_type, direction, interface, member)) or |
| 530 table.get('* %s %s.%s' % (direction, interface, member)) or | 525 table.get('* %s %s.%s' % (direction, interface, member)) or |
| 531 table.get('%s %s %s.*' % (idl_type, direction, interface)) or | 526 table.get('%s %s %s.*' % (idl_type, direction, interface)) or |
| 532 table.get('%s %s' % (idl_type, direction))) | 527 table.get('%s %s' % (idl_type, direction))) |
| 533 return None | 528 return None |
| 534 | 529 |
| 535 # ------------------------------------------------------------------------------ | |
| 536 | |
| 537 # Annotations to be placed on native members. The table is indexed by the IDL | |
| 538 # interface and member name, and by IDL return or field type name. Both are | |
| 539 # used to assemble the annotations: | |
| 540 # | |
| 541 # INTERFACE.MEMBER: annotations for member. | |
| 542 # +TYPE: add annotations only if there are member annotations. | |
| 543 # -TYPE: add annotations only if there are no member annotations. | |
| 544 # TYPE: add regardless of member annotations. | |
| 545 | |
| 546 dart2js_annotations = monitored.Dict('generator.dart2js_annotations', { | |
| 547 | |
| 548 'ArrayBufferView': [ | |
| 549 "@Creates('TypedData')", | |
| 550 "@Returns('TypedData|Null')", | |
| 551 ], | |
| 552 | |
| 553 'CanvasRenderingContext2D.createImageData': [ | |
| 554 "@Creates('ImageData|=Object')", | |
| 555 ], | |
| 556 | |
| 557 'CanvasRenderingContext2D.getImageData': [ | |
| 558 "@Creates('ImageData|=Object')", | |
| 559 ], | |
| 560 | |
| 561 'CanvasRenderingContext2D.webkitGetImageDataHD': [ | |
| 562 "@Creates('ImageData|=Object')", | |
| 563 ], | |
| 564 | |
| 565 'CanvasRenderingContext2D.fillStyle': [ | |
| 566 "@Creates('String|CanvasGradient|CanvasPattern')", | |
| 567 "@Returns('String|CanvasGradient|CanvasPattern')", | |
| 568 ], | |
| 569 | |
| 570 'CanvasRenderingContext2D.strokeStyle': [ | |
| 571 "@Creates('String|CanvasGradient|CanvasPattern')", | |
| 572 "@Returns('String|CanvasGradient|CanvasPattern')", | |
| 573 ], | |
| 574 | |
| 575 # Methods returning Window can return a local window, or a cross-frame | |
| 576 # window (=Object) that needs wrapping. | |
| 577 'DOMWindow': [ | |
| 578 "@Creates('Window|=Object')", | |
| 579 "@Returns('Window|=Object')", | |
| 580 ], | |
| 581 | |
| 582 'DOMWindow.openDatabase': [ | |
| 583 "@Creates('SqlDatabase')", | |
| 584 ], | |
| 585 | |
| 586 # To be in callback with the browser-created Event, we had to have called | |
| 587 # addEventListener on the target, so we avoid | |
| 588 'Event.currentTarget': [ | |
| 589 "@Creates('Null')", | |
| 590 "@Returns('EventTarget|=Object')", | |
| 591 ], | |
| 592 | |
| 593 # Only nodes in the DOM bubble and have target !== currentTarget. | |
| 594 'Event.target': [ | |
| 595 "@Creates('Node')", | |
| 596 "@Returns('EventTarget|=Object')", | |
| 597 ], | |
| 598 | |
| 599 'MouseEvent.relatedTarget': [ | |
| 600 "@Creates('Node')", | |
| 601 "@Returns('EventTarget|=Object')", | |
| 602 ], | |
| 603 | |
| 604 # Touch targets are Elements in a Document, or the Document. | |
| 605 'Touch.target': [ | |
| 606 "@Creates('Element|Document')", | |
| 607 "@Returns('Element|Document')", | |
| 608 ], | |
| 609 | |
| 610 'FileReader.result': ["@Creates('String|ByteBuffer|Null')"], | |
| 611 | |
| 612 # Rather than have the result of an IDBRequest as a union over all possible | |
| 613 # results, we mark the result as instantiating any classes, and mark | |
| 614 # each operation with the classes that it could cause to be asynchronously | |
| 615 # instantiated. | |
| 616 'IDBRequest.result': ["@Creates('Null')"], | |
| 617 | |
| 618 # The source is usually a participant in the operation that generated the | |
| 619 # IDBRequest. | |
| 620 'IDBRequest.source': ["@Creates('Null')"], | |
| 621 | |
| 622 'IDBFactory.open': ["@Creates('Database')"], | |
| 623 'IDBFactory.webkitGetDatabaseNames': ["@Creates('DomStringList')"], | |
| 624 | |
| 625 'IDBObjectStore.put': ["@_annotation_Creates_IDBKey"], | |
| 626 'IDBObjectStore.add': ["@_annotation_Creates_IDBKey"], | |
| 627 'IDBObjectStore.get': ["@annotation_Creates_SerializedScriptValue"], | |
| 628 'IDBObjectStore.openCursor': ["@Creates('Cursor')"], | |
| 629 | |
| 630 'IDBIndex.get': ["@annotation_Creates_SerializedScriptValue"], | |
| 631 'IDBIndex.getKey': [ | |
| 632 "@annotation_Creates_SerializedScriptValue", | |
| 633 # The source is the object store behind the index. | |
| 634 "@Creates('ObjectStore')", | |
| 635 ], | |
| 636 'IDBIndex.openCursor': ["@Creates('Cursor')"], | |
| 637 'IDBIndex.openKeyCursor': ["@Creates('Cursor')"], | |
| 638 | |
| 639 'IDBCursorWithValue.value': [ | |
| 640 '@annotation_Creates_SerializedScriptValue', | |
| 641 '@annotation_Returns_SerializedScriptValue', | |
| 642 ], | |
| 643 | |
| 644 'IDBCursor.key': [ | |
| 645 "@_annotation_Creates_IDBKey", | |
| 646 "@_annotation_Returns_IDBKey", | |
| 647 ], | |
| 648 | |
| 649 '+IDBRequest': [ | |
| 650 "@Returns('Request')", | |
| 651 "@Creates('Request')", | |
| 652 ], | |
| 653 | |
| 654 '+IDBOpenDBRequest': [ | |
| 655 "@Returns('Request')", | |
| 656 "@Creates('Request')", | |
| 657 ], | |
| 658 | |
| 659 'MessageEvent.ports': ["@Creates('=List')"], | |
| 660 | |
| 661 'MessageEvent.data': [ | |
| 662 "@annotation_Creates_SerializedScriptValue", | |
| 663 "@annotation_Returns_SerializedScriptValue", | |
| 664 ], | |
| 665 'PopStateEvent.state': [ | |
| 666 "@annotation_Creates_SerializedScriptValue", | |
| 667 "@annotation_Returns_SerializedScriptValue", | |
| 668 ], | |
| 669 'SerializedScriptValue': [ | |
| 670 "@annotation_Creates_SerializedScriptValue", | |
| 671 "@annotation_Returns_SerializedScriptValue", | |
| 672 ], | |
| 673 | |
| 674 'SQLResultSetRowList.item': ["@Creates('=Object')"], | |
| 675 | |
| 676 'WebGLRenderingContext.getParameter': [ | |
| 677 # Taken from http://www.khronos.org/registry/webgl/specs/latest/ | |
| 678 # Section 5.14.3 Setting and getting state | |
| 679 "@Creates('Null|num|String|bool|=List|Float32List|Int32List|Uint32List" | |
| 680 "|Framebuffer|Renderbuffer|Texture')", | |
| 681 "@Returns('Null|num|String|bool|=List|Float32List|Int32List|Uint32List" | |
| 682 "|Framebuffer|Renderbuffer|Texture')", | |
| 683 ], | |
| 684 | |
| 685 'XMLHttpRequest.response': [ | |
| 686 "@Creates('ByteBuffer|Blob|Document|=Object|=List|String|num')", | |
| 687 ], | |
| 688 }, dart2jsOnly=True) | |
| 689 | |
| 690 _indexed_db_annotations = [ | |
| 691 "@SupportedBrowser(SupportedBrowser.CHROME)", | |
| 692 "@SupportedBrowser(SupportedBrowser.FIREFOX, '15')", | |
| 693 "@SupportedBrowser(SupportedBrowser.IE, '10')", | |
| 694 "@Experimental", | |
| 695 ] | |
| 696 | |
| 697 _file_system_annotations = [ | |
| 698 "@SupportedBrowser(SupportedBrowser.CHROME)", | |
| 699 "@Experimental", | |
| 700 ] | |
| 701 | |
| 702 _all_but_ie9_annotations = [ | |
| 703 "@SupportedBrowser(SupportedBrowser.CHROME)", | |
| 704 "@SupportedBrowser(SupportedBrowser.FIREFOX)", | |
| 705 "@SupportedBrowser(SupportedBrowser.IE, '10')", | |
| 706 "@SupportedBrowser(SupportedBrowser.SAFARI)", | |
| 707 ] | |
| 708 | |
| 709 _history_annotations = _all_but_ie9_annotations | |
| 710 | |
| 711 _no_ie_annotations = [ | |
| 712 "@SupportedBrowser(SupportedBrowser.CHROME)", | |
| 713 "@SupportedBrowser(SupportedBrowser.FIREFOX)", | |
| 714 "@SupportedBrowser(SupportedBrowser.SAFARI)", | |
| 715 ] | |
| 716 | |
| 717 _performance_annotations = [ | |
| 718 "@SupportedBrowser(SupportedBrowser.CHROME)", | |
| 719 "@SupportedBrowser(SupportedBrowser.FIREFOX)", | |
| 720 "@SupportedBrowser(SupportedBrowser.IE)", | |
| 721 ] | |
| 722 | |
| 723 _rtc_annotations = [ # Note: Firefox nightly builds also support this. | |
| 724 "@SupportedBrowser(SupportedBrowser.CHROME)", | |
| 725 "@Experimental", | |
| 726 ] | |
| 727 | |
| 728 _shadow_dom_annotations = [ | |
| 729 "@SupportedBrowser(SupportedBrowser.CHROME, '26')", | |
| 730 "@Experimental", | |
| 731 ] | |
| 732 | |
| 733 _speech_recognition_annotations = [ | |
| 734 "@SupportedBrowser(SupportedBrowser.CHROME, '25')", | |
| 735 "@Experimental", | |
| 736 ] | |
| 737 | |
| 738 _svg_annotations = _all_but_ie9_annotations; | |
| 739 | |
| 740 _web_sql_annotations = [ | |
| 741 "@SupportedBrowser(SupportedBrowser.CHROME)", | |
| 742 "@SupportedBrowser(SupportedBrowser.SAFARI)", | |
| 743 "@Experimental", | |
| 744 ] | |
| 745 | |
| 746 _webgl_annotations = [ | |
| 747 "@SupportedBrowser(SupportedBrowser.CHROME)", | |
| 748 "@SupportedBrowser(SupportedBrowser.FIREFOX)", | |
| 749 "@Experimental", | |
| 750 ] | |
| 751 | |
| 752 _webkit_experimental_annotations = [ | |
| 753 "@SupportedBrowser(SupportedBrowser.CHROME)", | |
| 754 "@SupportedBrowser(SupportedBrowser.SAFARI)", | |
| 755 "@Experimental", | |
| 756 ] | |
| 757 | |
| 758 # Annotations to be placed on generated members. | |
| 759 # The table is indexed as: | |
| 760 # INTERFACE: annotations to be added to the interface declaration | |
| 761 # INTERFACE.MEMBER: annotation to be added to the member declaration | |
| 762 dart_annotations = monitored.Dict('generator.dart_annotations', { | |
| 763 'CSSHostRule': _shadow_dom_annotations, | |
| 764 'Crypto': _webkit_experimental_annotations, | |
| 765 'Database': _web_sql_annotations, | |
| 766 'DatabaseSync': _web_sql_annotations, | |
| 767 'DOMApplicationCache': [ | |
| 768 "@SupportedBrowser(SupportedBrowser.CHROME)", | |
| 769 "@SupportedBrowser(SupportedBrowser.FIREFOX)", | |
| 770 "@SupportedBrowser(SupportedBrowser.IE, '10')", | |
| 771 "@SupportedBrowser(SupportedBrowser.OPERA)", | |
| 772 "@SupportedBrowser(SupportedBrowser.SAFARI)", | |
| 773 ], | |
| 774 'DOMFileSystem': _file_system_annotations, | |
| 775 'DOMFileSystemSync': _file_system_annotations, | |
| 776 'DOMWindow.webkitConvertPointFromNodeToPage': _webkit_experimental_annotations
, | |
| 777 'DOMWindow.webkitConvertPointFromPageToNode': _webkit_experimental_annotations
, | |
| 778 'DOMWindow.indexedDB': _indexed_db_annotations, | |
| 779 'DOMWindow.openDatabase': _web_sql_annotations, | |
| 780 'DOMWindow.performance': _performance_annotations, | |
| 781 'DOMWindow.webkitNotifications': _webkit_experimental_annotations, | |
| 782 'DOMWindow.webkitRequestFileSystem': _file_system_annotations, | |
| 783 'DOMWindow.webkitResolveLocalFileSystemURL': _file_system_annotations, | |
| 784 'Element.onwebkitTransitionEnd': _all_but_ie9_annotations, | |
| 785 # Placeholder to add experimental flag, implementation for this is | |
| 786 # pending in a separate CL. | |
| 787 'Element.webkitMatchesSelector': ['@Experimental()'], | |
| 788 'Element.webkitCreateShadowRoot': [ | |
| 789 "@SupportedBrowser(SupportedBrowser.CHROME, '25')", | |
| 790 "@Experimental", | |
| 791 ], | |
| 792 'Event.clipboardData': _webkit_experimental_annotations, | |
| 793 'FormData': _all_but_ie9_annotations, | |
| 794 'HashChangeEvent': [ | |
| 795 "@SupportedBrowser(SupportedBrowser.CHROME)", | |
| 796 "@SupportedBrowser(SupportedBrowser.FIREFOX)", | |
| 797 "@SupportedBrowser(SupportedBrowser.SAFARI)", | |
| 798 ], | |
| 799 'History.pushState': _history_annotations, | |
| 800 'History.replaceState': _history_annotations, | |
| 801 'HTMLContentElement': _shadow_dom_annotations, | |
| 802 'HTMLDataListElement': _all_but_ie9_annotations, | |
| 803 'HTMLDetailsElement': _webkit_experimental_annotations, | |
| 804 'HTMLEmbedElement': [ | |
| 805 "@SupportedBrowser(SupportedBrowser.CHROME)", | |
| 806 "@SupportedBrowser(SupportedBrowser.IE)", | |
| 807 "@SupportedBrowser(SupportedBrowser.SAFARI)", | |
| 808 ], | |
| 809 'HTMLKeygenElement': _webkit_experimental_annotations, | |
| 810 'HTMLMeterElement': _no_ie_annotations, | |
| 811 'HTMLObjectElement': [ | |
| 812 "@SupportedBrowser(SupportedBrowser.CHROME)", | |
| 813 "@SupportedBrowser(SupportedBrowser.IE)", | |
| 814 "@SupportedBrowser(SupportedBrowser.SAFARI)", | |
| 815 ], | |
| 816 'HTMLOutputElement': _no_ie_annotations, | |
| 817 'HTMLProgressElement': _all_but_ie9_annotations, | |
| 818 'HTMLShadowElement': _shadow_dom_annotations, | |
| 819 'HTMLTrackElement': [ | |
| 820 "@SupportedBrowser(SupportedBrowser.CHROME)", | |
| 821 "@SupportedBrowser(SupportedBrowser.IE, '10')", | |
| 822 "@SupportedBrowser(SupportedBrowser.SAFARI)", | |
| 823 ], | |
| 824 'IDBFactory': _indexed_db_annotations, | |
| 825 'IDBDatabase': _indexed_db_annotations, | |
| 826 'LocalMediaStream': _rtc_annotations, | |
| 827 'MediaStream': _rtc_annotations, | |
| 828 'MediaStreamEvent': _rtc_annotations, | |
| 829 'MediaStreamTrack': _rtc_annotations, | |
| 830 'MediaStreamTrackEvent': _rtc_annotations, | |
| 831 'MutationObserver': [ | |
| 832 "@SupportedBrowser(SupportedBrowser.CHROME)", | |
| 833 "@SupportedBrowser(SupportedBrowser.FIREFOX)", | |
| 834 "@SupportedBrowser(SupportedBrowser.SAFARI)", | |
| 835 "@Experimental", | |
| 836 ], | |
| 837 'NotificationCenter': _webkit_experimental_annotations, | |
| 838 'Performance': _performance_annotations, | |
| 839 'PopStateEvent': _history_annotations, | |
| 840 'RTCIceCandidate': _rtc_annotations, | |
| 841 'RTCPeerConnection': _rtc_annotations, | |
| 842 'RTCSessionDescription': _rtc_annotations, | |
| 843 'ShadowRoot': _shadow_dom_annotations, | |
| 844 'SpeechRecognition': _speech_recognition_annotations, | |
| 845 'SpeechRecognitionAlternative': _speech_recognition_annotations, | |
| 846 'SpeechRecognitionError': _speech_recognition_annotations, | |
| 847 'SpeechRecognitionEvent': _speech_recognition_annotations, | |
| 848 'SpeechRecognitionResult': _speech_recognition_annotations, | |
| 849 'SVGAltGlyphElement': _no_ie_annotations, | |
| 850 'SVGAnimateElement': _no_ie_annotations, | |
| 851 'SVGAnimateMotionElement': _no_ie_annotations, | |
| 852 'SVGAnimateTransformElement': _no_ie_annotations, | |
| 853 'SVGFEBlendElement': _svg_annotations, | |
| 854 'SVGFEColorMatrixElement': _svg_annotations, | |
| 855 'SVGFEComponentTransferElement': _svg_annotations, | |
| 856 'SVGFEConvolveMatrixElement': _svg_annotations, | |
| 857 'SVGFEDiffuseLightingElement': _svg_annotations, | |
| 858 'SVGFEDisplacementMapElement': _svg_annotations, | |
| 859 'SVGFEDistantLightElement': _svg_annotations, | |
| 860 'SVGFEFloodElement': _svg_annotations, | |
| 861 'SVGFEFuncAElement': _svg_annotations, | |
| 862 'SVGFEFuncBElement': _svg_annotations, | |
| 863 'SVGFEFuncGElement': _svg_annotations, | |
| 864 'SVGFEFuncRElement': _svg_annotations, | |
| 865 'SVGFEGaussianBlurElement': _svg_annotations, | |
| 866 'SVGFEImageElement': _svg_annotations, | |
| 867 'SVGFEMergeElement': _svg_annotations, | |
| 868 'SVGFEMergeNodeElement': _svg_annotations, | |
| 869 'SVGFEMorphologyElement': _svg_annotations, | |
| 870 'SVGFEOffsetElement': _svg_annotations, | |
| 871 'SVGFEPointLightElement': _svg_annotations, | |
| 872 'SVGFESpecularLightingElement': _svg_annotations, | |
| 873 'SVGFESpotLightElement': _svg_annotations, | |
| 874 'SVGFETileElement': _svg_annotations, | |
| 875 'SVGFETurbulenceElement': _svg_annotations, | |
| 876 'SVGFilterElement': _svg_annotations, | |
| 877 'SVGForeignObjectElement': _no_ie_annotations, | |
| 878 'SVGSetElement': _no_ie_annotations, | |
| 879 'SQLTransaction': _web_sql_annotations, | |
| 880 'SQLTransactionSync': _web_sql_annotations, | |
| 881 'WebGLRenderingContext': _webgl_annotations, | |
| 882 'WebKitCSSMatrix': _webkit_experimental_annotations, | |
| 883 'WebKitPoint': _webkit_experimental_annotations, | |
| 884 'WebSocket': _all_but_ie9_annotations, | |
| 885 'Worker': _all_but_ie9_annotations, | |
| 886 'XMLHttpRequest.onloadend': _all_but_ie9_annotations, | |
| 887 'XMLHttpRequest.onprogress': _all_but_ie9_annotations, | |
| 888 'XMLHttpRequest.response': _all_but_ie9_annotations, | |
| 889 'XMLHttpRequestProgressEvent': _webkit_experimental_annotations, | |
| 890 'XSLTProcessor': [ | |
| 891 "@SupportedBrowser(SupportedBrowser.CHROME)", | |
| 892 "@SupportedBrowser(SupportedBrowser.FIREFOX)", | |
| 893 "@SupportedBrowser(SupportedBrowser.SAFARI)", | |
| 894 ], | |
| 895 }) | |
| 896 | |
| 897 def GetComments(library_name, interface_name, member_name=None): | |
| 898 """ Finds all comments for the interface or member and returns a list. """ | |
| 899 | |
| 900 # Add documentation from JSON. | |
| 901 comments = [] | |
| 902 library_name = 'dart.dom.%s' % library_name | |
| 903 if library_name in _dom_json and interface_name in _dom_json[library_name]: | |
| 904 if (member_name and 'members' in _dom_json[library_name][interface_name] and | |
| 905 (member_name in _dom_json[library_name][interface_name]['members'])): | |
| 906 comments = _dom_json[library_name][interface_name]['members'][member_name] | |
| 907 elif (not member_name and 'comment' in | |
| 908 _dom_json[library_name][interface_name]): | |
| 909 comments = _dom_json[library_name][interface_name]['comment'] | |
| 910 | |
| 911 if (len(comments)): | |
| 912 comments = ['\n'.join(comments)] | |
| 913 | |
| 914 return comments | |
| 915 | |
| 916 def GetAnnotationsAndComments(library_name, interface_name, member_name=None): | |
| 917 annotations = GetComments(library_name, interface_name, member_name) | |
| 918 annotations = annotations + (FindCommonAnnotations(library_name, interface_nam
e, | |
| 919 member_name)) | |
| 920 | |
| 921 return annotations | |
| 922 | |
| 923 def FindCommonAnnotations(library_name, interface_name, member_name=None): | |
| 924 """ Finds annotations common between dart2js and dartium. | |
| 925 """ | |
| 926 if member_name: | |
| 927 key = '%s.%s' % (interface_name, member_name) | |
| 928 else: | |
| 929 key = interface_name | |
| 930 | |
| 931 annotations = ["@DomName('" + key + "')"] | |
| 932 | |
| 933 # Only add this for members, so we don't add DocsEditable to templated classes | |
| 934 # (they get it from the default class template) | |
| 935 if member_name: | |
| 936 annotations.append('@DocsEditable'); | |
| 937 | |
| 938 if (dart_annotations.get(key) != None): | |
| 939 annotations.extend(dart_annotations.get(key)) | |
| 940 | |
| 941 if (member_name and member_name.startswith('webkit') and | |
| 942 key not in renamed_html_members): | |
| 943 annotations.extend(_webkit_experimental_annotations) | |
| 944 | |
| 945 return annotations | |
| 946 | |
| 947 def FindDart2JSAnnotationsAndComments(idl_type, library_name, interface_name, | |
| 948 member_name,): | |
| 949 """ Finds all annotations for Dart2JS members- including annotations for | |
| 950 both dart2js and dartium. | |
| 951 """ | |
| 952 annotations = GetAnnotationsAndComments(library_name, interface_name, member_n
ame) | |
| 953 | |
| 954 ann2 = _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name) | |
| 955 if ann2: | |
| 956 if annotations: | |
| 957 annotations.extend(ann2) | |
| 958 else: | |
| 959 annotations = ann2 | |
| 960 return annotations | |
| 961 | |
| 962 def AnyConversionAnnotations(idl_type, interface_name, member_name): | |
| 963 if (dart_annotations.get('%s.%s' % (interface_name, member_name)) or | |
| 964 _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name)): | |
| 965 return True | |
| 966 else: | |
| 967 return False | |
| 968 | |
| 969 def FormatAnnotationsAndComments(annotations, indentation): | |
| 970 if annotations: | |
| 971 | |
| 972 newline = '\n%s' % indentation | |
| 973 result = newline.join(annotations) + newline | |
| 974 return result | |
| 975 return '' | |
| 976 | |
| 977 def _FindDart2JSSpecificAnnotations(idl_type, interface_name, member_name): | |
| 978 """ Finds dart2js-specific annotations. This does not include ones shared with | |
| 979 dartium. | |
| 980 """ | |
| 981 ann1 = dart2js_annotations.get("%s.%s" % (interface_name, member_name)) | |
| 982 if ann1: | |
| 983 ann2 = dart2js_annotations.get('+' + idl_type) | |
| 984 if ann2: | |
| 985 return ann2 + ann1 | |
| 986 ann2 = dart2js_annotations.get(idl_type) | |
| 987 if ann2: | |
| 988 return ann2 + ann1 | |
| 989 return ann1 | |
| 990 | |
| 991 ann2 = dart2js_annotations.get('-' + idl_type) | |
| 992 if ann2: | |
| 993 return ann2 | |
| 994 ann2 = dart2js_annotations.get(idl_type) | |
| 995 return ann2 | |
| 996 | 530 |
| 997 # ------------------------------------------------------------------------------ | 531 # ------------------------------------------------------------------------------ |
| 998 | 532 |
| 999 class IDLTypeInfo(object): | 533 class IDLTypeInfo(object): |
| 1000 def __init__(self, idl_type, data): | 534 def __init__(self, idl_type, data): |
| 1001 self._idl_type = idl_type | 535 self._idl_type = idl_type |
| 1002 self._data = data | 536 self._data = data |
| 1003 | 537 |
| 1004 def idl_type(self): | 538 def idl_type(self): |
| 1005 return self._idl_type | 539 return self._idl_type |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1572 type_name, type_data, dart_interface_name, self) | 1106 type_name, type_data, dart_interface_name, self) |
| 1573 | 1107 |
| 1574 if type_data.clazz == 'BasicTypedList': | 1108 if type_data.clazz == 'BasicTypedList': |
| 1575 dart_interface_name = self._renamer.RenameInterface( | 1109 dart_interface_name = self._renamer.RenameInterface( |
| 1576 self._database.GetInterface(type_name)) | 1110 self._database.GetInterface(type_name)) |
| 1577 return BasicTypedListIDLTypeInfo( | 1111 return BasicTypedListIDLTypeInfo( |
| 1578 type_name, type_data, dart_interface_name, self) | 1112 type_name, type_data, dart_interface_name, self) |
| 1579 | 1113 |
| 1580 class_name = '%sIDLTypeInfo' % type_data.clazz | 1114 class_name = '%sIDLTypeInfo' % type_data.clazz |
| 1581 return globals()[class_name](type_name, type_data) | 1115 return globals()[class_name](type_name, type_data) |
| OLD | NEW |