659 def GenerateInterface(self):
660 interface_name = self._interface_type_info.interface_name()
661
662 implementation_name = self._interface_type_info.implementation_name()
663 self._library_emitter.AddTypeEntry(
664 self._library_name, self._interface.id, implementation_name)
665
666 factory_provider = None
667 if interface_name in interface_factories:
668 factory_provider = interface_factories[interface_name]
669 factory_constructor_name = None
670
671 constructors = []
672 if interface_name in _static_classes:
673 constructor_info = None
674 else:
675 constructor_info = AnalyzeConstructor(self._interface)
676 if constructor_info:
677 constructors.append(constructor_info)
678
679 factory_provider = interface_name
680
681
683 self._interface.id,
684 _element_constructors[self._library_name],
685 factory_provider_name=_factory_ctr_strings[self._library_name]
686 ['provider_name'])
687
688 if infos:
689 factory_constructor_name = _factory_ctr_strings[
690 self._library_name]['constructor_name']
691
692 for info in infos:
693 constructors.append(info.ConstructorInfo(self._interface.id))
694 if factory_provider and factory_provider != info.factory_provider_name:
695 _logger.warn('Conflicting factory provider names: %s != %s' %
696 (factory_provider, info.factory_provider_name))
697 factory_provider = info.factory_provider_name
698
699 implementation_emitter = self._ImplementationEmitter()
700
701 base_type_info = None
702 if self._interface.parents:
703 supertype = self._interface.parents[0].type.id
704 if not IsDartCollectionType(supertype) and not IsPureInterface(
705 supertype, self._database):
706 base_type_info = self._type_registry.TypeInfo(supertype)
707
708 if base_type_info:
709 base_class = base_type_info.implementation_name()
710 else:
711 base_class = self._backend.RootClassName()
712
713 implements = self._backend.AdditionalImplementedInterfaces()
714 for parent in self._interface.parents:
715 parent_type_info = self._type_registry.TypeInfo(parent.type.id)
716 if parent_type_info.interface_name() != base_class and \
717 parent_type_info != base_type_info:
718 implements.append(parent_type_info.interface_name())
719
720 secure_base_name = self._backend.SecureBaseName(interface_name)
721 if secure_base_name:
722 implements.append(secure_base_name)
723
724 implements_str = ''
725 if implements:
726
727 implements = list(OrderedDict([(i, None) for i in implements]))
728 implements_str =
' implements ' +
', '.
join(implements)
729
730 mixins = self._backend.Mixins()
731
732 mixins_str = ''
733 if mixins:
734 mixins_str =
' with ' +
', '.
join(mixins)
735 if not base_class:
736 base_class = 'JavaScriptObject'
737 elif (base_class == 'NativeFieldWrapperClass2' and
738 self._options.dart_js_interop and
739 not (isinstance(self._backend, Dart2JSBackend))):
740 base_class = 'DartHtmlDomObject'
741
742 annotations = self._metadata.GetFormattedMetadata(
743 self._library_name, self._interface, None, '')
744
745 class_modifiers = ''
746 if (self._renamer.ShouldSuppressInterface(self._interface) or
747 IsPureInterface(self._interface.id, self._database)):
748
749
750 if (not (isinstance(self._backend, Dart2JSBackend)) and
751 (self._interface.id == 'XMLHttpRequestProgressEvent' or
752 self._interface.id == 'DOMStringMap')):
753
754
755 class_modifiers = ''
756 else:
757
758
759 if (self._renamer.ShouldSuppressInterface(self._interface) and
760 not (isinstance(self._backend, Dart2JSBackend)) and
761 self._options.dart_js_interop):
762 class_modifiers = ''
763 else:
764 class_modifiers = 'abstract '
765
766 native_spec = ''
767 if not IsPureInterface(self._interface.id, self._database):
768 native_spec = self._backend.NativeSpec()
769
770 class_name = self._interface_type_info.implementation_name()
771
772 js_interop_wrapper = '''
773
774 @Deprecated("Internal Use Only")
775 external static Type get instanceRuntimeType;
776
777 @Deprecated("Internal Use Only")
778 {0}.internal_() : super.internal_();
779
780'''.format(class_name)
781 if base_class == 'NativeFieldWrapperClass2' or base_class == 'DartHtmlDomObject':
782 js_interop_wrapper = '''
783
784 @Deprecated("Internal Use Only")
785 external static Type get instanceRuntimeType;
786
787 @Deprecated("Internal Use Only")
788 {0}.internal_() {{ }}
789'''.format(class_name)
790
791
792
793 if (self._options.templates._conditions['DARTIUM'] and
794 self._options.dart_js_interop and
795 (self._interface.id == 'NamedNodeMap' or
796 self._interface.id == 'CSSStyleDeclaration')):
797 base_class = 'DartHtmlDomObject'
798
799 maplikeKeyType = ''
800 maplikeValueType = ''
801 if self._interface.isMaplike:
802 maplikeKeyType = self._type_registry.\
803 _TypeInfo(self._interface.maplike_key_value[0].id).dart_type()
804 maplikeValueType = 'dynamic'
805 mixins_str = " with MapMixin<%s, %s>" % (maplikeKeyType,
806 maplikeValueType)
807
808 implementation_members_emitter = implementation_emitter.Emit(
809 self._backend.ImplementationTemplate(),
810 LIBRARYNAME='dart.dom.%s' % self._library_name,
811 ANNOTATIONS=annotations,
812 CLASS_MODIFIERS=class_modifiers,
813 CLASSNAME=class_name,
814 EXTENDS=' extends %s' % base_class if base_class else '',
815 IMPLEMENTS=implements_str,
816 MIXINS=mixins_str,
817 DOMNAME=self._interface.doc_js_name,
818 NATIVESPEC=native_spec,
819 KEYTYPE=maplikeKeyType,
820 VALUETYPE=maplikeValueType,
821 NULLABLE='?',
822 NULLSAFECAST=True,
823 NULLASSERT='!')
824 if self._interface.doc_js_name is 'RadioNodeList':
825 print(self._backend.ImplementationTemplate())
826 print(implementation_members_emitter)
827 stream_getter_signatures_emitter = None
828 element_stream_getters_emitter = None
829 class_members_emitter = None
830 if type(implementation_members_emitter) == tuple:
831
832
833
834
835 if (
len(implementation_members_emitter) == 3):
836 stream_getter_signatures_emitter = \
837 implementation_members_emitter[0]
838 element_stream_getters_emitter = implementation_members_emitter[
839 1]
840 implementation_members_emitter = \
841 implementation_members_emitter[2]
842
843
844 elif (
len(implementation_members_emitter) == 2):
845 class_members_emitter = \
846 implementation_members_emitter[0]
847 implementation_members_emitter = \
848 implementation_members_emitter[1]
849 self._backend.StartInterface(implementation_members_emitter)
850 self._backend.EmitHelpers(base_class, class_members_emitter)
851 self._event_generator.EmitStreamProviders(
852 self._interface, self._backend.CustomJSMembers(),
853 implementation_members_emitter, self._library_name)
854 self._prototype_event_generator.CollectStreamProviders(
855 self._interface, self._backend.CustomJSMembers(),
856 self._library_name)
857 self._backend.AddConstructors(constructors, factory_provider,
858 factory_constructor_name,
859 class_members_emitter)
860
861 isElement = False
862 for parent in self._database.Hierarchy(self._interface):
863 if parent.id == 'Element':
864 isElement = True
865
866
867 if (implementation_members_emitter and
868 self._options.templates._conditions['DARTIUM'] and
869 self._options.dart_js_interop and
870 not IsPureInterface(self._interface.id, self._database)):
871 implementation_members_emitter.Emit(js_interop_wrapper)
872
873 if isElement and self._interface.id != 'Element':
874 implementation_members_emitter.Emit(
875 ' /**\n'
876 ' * Constructor instantiated by the DOM when a custom element has been created.\n'
877 ' *\n'
878 ' * This can only be called by subclasses from their created constructor.\n'
879 ' */\n'
880 ' $CLASSNAME.created() : super.created();\n',
881 CLASSNAME=self._interface_type_info.implementation_name())
882
883 self._backend.EmitSupportCheck()
884
885 merged_interface = self._interface_type_info.merged_interface()
886 if merged_interface:
887 self._backend.AddMembers(
888 self._database.GetInterface(merged_interface),
889 not self._backend.ImplementsMergedMembers())
890
891 self._backend.AddMembers(self._interface, False,
892 self._options.dart_js_interop)
893 self._backend.AddSecondaryMembers(self._interface)
894 self._event_generator.EmitStreamGetters(
895 self._interface, [], implementation_members_emitter,
896 self._library_name, stream_getter_signatures_emitter,
897 element_stream_getters_emitter)
898 self._prototype_event_generator.CollectStreamGetters(
899 self._interface, [], self._library_name)
900 self._backend.FinishInterface()
901
def print(*args, **kwargs)
def ElementConstructorInfos(typename, element_constructors, factory_provider_name='_Elements')