<commit_before>from autosar.writer.writer_base import ElementWriter
import autosar.base
import autosar.workspace
import autosar.constant
import autosar.mode
from autosar.writer.behavior_writer import XMLBehaviorWriter

class XMLComponentTypeWriter(ElementWriter):
    def __init__(self,version, patch):
        super().__init__(version, patch)
        if version >= 4.0:
            self.behavior_writer=XMLBehaviorWriter(version, patch)

        if self.version >= 3.0 and self.version < 4.0:
            self.switcher = {
                              'ApplicationSoftwareComponent': self.writeApplicationSoftwareComponentXML,
                              'ComplexDeviceDriverComponent': self.writeComplexDeviceDriverComponentXML,
                              'ServiceComponent': self.writeServiceComponentXML,
                              'SwcImplementation': self.writeSwcImplementationXML,
                              'CompositionComponent': self.writeCompositionComponentXML
            }
        elif self.version >= 4.0:
            self.switcher = {
                              'ApplicationSoftwareComponent': self.writeApplicationSoftwareComponentXML,
                              'ComplexDeviceDriverComponent': self.writeComplexDeviceDriverComponentXML,
                              'ServiceComponent': self.writeServiceComponentXML,
                              'SwcImplementation': self.writeSwcImplementationXML,
                              'CompositionComponent': self.writeCompositionComponentXML,
                              'ParameterComponent': self.writeParameterComponentXML,
                              'NvBlockComponent': self.writeNvBlockComponentXML
            }
        else:
            switch.keys = {}

    def getSupportedXML(self):
        return self.switcher.keys()

    def getSupportedCode(self):
        return []

    def writeElementXML(self, elem):
        xmlWriteFunc = self.switcher.get(type(elem).__name__)
        if xmlWriteFunc is not None:
            return xmlWriteFunc(elem)
        else:
            return None

    def writeElementCode(self, elem, localvars):
        raise NotImplementedError('writeElementCode')

    def writeApplicationSoftwareComponentXML(self,swc):
        assert(isinstance(swc,autosar.component.ApplicationSoftwareComponent))
        return self._writeComponentXML(swc)

    def writeComplexDeviceDriverComponentXML(self,swc):
        assert(isinstance(swc,autosar.component.ComplexDeviceDriverComponent))
        return self._writeComponentXML(swc)

    def writeCompositionComponentXML(self,swc):
        assert(isinstance(swc,autosar.component.CompositionComponent))
        return self._writeComponentXML(swc)

    def writeServiceComponentXML(self,swc):
        assert(isinstance(swc,autosar.component.ServiceComponent))
        return self._writeComponentXML(swc)

    def writeParameterComponentXML(self, swc):
        assert(isinstance(swc,autosar.component.ParameterComponent))
        return self._writeComponentXML(swc)

    def writeNvBlockComponentXML(self, swc):
        assert(isinstance(swc,autosar.component.NvBlockComponent))
        return self._writeComponentXML(swc)

    def _writeComponentXML(self, swc):
        lines=[]
        ws = swc.rootWS()
        assert(ws is not None)
        lines=[]
        lines.append('<%s>'%swc.tag(self.version))
        lines.append(self.indent('<SHORT-NAME>%s</SHORT-NAME>'%swc.name,1))
        if isinstance(swc, autosar.component.ServiceComponent):
            lines.append(self.indent('<CATEGORY>ServiceComponent</CATEGORY>',1))
        descLines = self.writeDescXML(swc)
        if descLines is not None:
            lines.extend(self.indent(descLines,1))
        lines.append(self.indent('<PORTS>',1))
        for port in swc.providePorts:
            lines.extend(self.indent(self._writeProvidePortXML(port),2))
        for port in swc.requirePorts:
            lines.extend(self.indent(self._writeRequirePortXML(port),2))
        lines.append(self.indent('</PORTS>',1))
        if (self.version >= 4.0) and (isinstance(swc, autosar.component.AtomicSoftwareComponent)) and (swc.behavior is not None):
            lines.append(self.indent('<INTERNAL-BEHAVIORS>',1))
            lines.extend(self.indent(self.behavior_writer.writeInternalBehaviorXML(swc.behavior),2))
            lines.append(self.indent('</INTERNAL-BEHAVIORS>',1))
        if isinstance(swc, autosar.component.CompositionComponent):<commit_msg>Update SWC writer function to write admin data<commit_after>from autosar.writer.writer_base import ElementWriter
import autosar.base
import autosar.workspace
import autosar.constant
import autosar.mode
from autosar.writer.behavior_writer import XMLBehaviorWriter

class XMLComponentTypeWriter(ElementWriter):
    def __init__(self,version, patch):
        super().__init__(version, patch)
        if version >= 4.0:
            self.behavior_writer=XMLBehaviorWriter(version, patch)

        if self.version >= 3.0 and self.version < 4.0:
            self.switcher = {
                              'ApplicationSoftwareComponent': self.writeApplicationSoftwareComponentXML,
                              'ComplexDeviceDriverComponent': self.writeComplexDeviceDriverComponentXML,
                              'ServiceComponent': self.writeServiceComponentXML,
                              'SwcImplementation': self.writeSwcImplementationXML,
                              'CompositionComponent': self.writeCompositionComponentXML
            }
        elif self.version >= 4.0:
            self.switcher = {
                              'ApplicationSoftwareComponent': self.writeApplicationSoftwareComponentXML,
                              'ComplexDeviceDriverComponent': self.writeComplexDeviceDriverComponentXML,
                              'ServiceComponent': self.writeServiceComponentXML,
                              'SwcImplementation': self.writeSwcImplementationXML,
                              'CompositionComponent': self.writeCompositionComponentXML,
                              'ParameterComponent': self.writeParameterComponentXML,
                              'NvBlockComponent': self.writeNvBlockComponentXML
            }
        else:
            switch.keys = {}

    def getSupportedXML(self):
        return self.switcher.keys()

    def getSupportedCode(self):
        return []

    def writeElementXML(self, elem):
        xmlWriteFunc = self.switcher.get(type(elem).__name__)
        if xmlWriteFunc is not None:
            return xmlWriteFunc(elem)
        else:
            return None

    def writeElementCode(self, elem, localvars):
        raise NotImplementedError('writeElementCode')

    def writeApplicationSoftwareComponentXML(self,swc):
        assert(isinstance(swc,autosar.component.ApplicationSoftwareComponent))
        return self._writeComponentXML(swc)

    def writeComplexDeviceDriverComponentXML(self,swc):
        assert(isinstance(swc,autosar.component.ComplexDeviceDriverComponent))
        return self._writeComponentXML(swc)

    def writeCompositionComponentXML(self,swc):
        assert(isinstance(swc,autosar.component.CompositionComponent))
        return self._writeComponentXML(swc)

    def writeServiceComponentXML(self,swc):
        assert(isinstance(swc,autosar.component.ServiceComponent))
        return self._writeComponentXML(swc)

    def writeParameterComponentXML(self, swc):
        assert(isinstance(swc,autosar.component.ParameterComponent))
        return self._writeComponentXML(swc)

    def writeNvBlockComponentXML(self, swc):
        assert(isinstance(swc,autosar.component.NvBlockComponent))
        return self._writeComponentXML(swc)

    def _writeComponentXML(self, swc):
        lines=[]
        ws = swc.rootWS()
        assert(ws is not None)
        lines=[]
        lines.append('<%s>'%swc.tag(self.version))
        lines.append(self.indent('<SHORT-NAME>%s</SHORT-NAME>'%swc.name,1))
        if isinstance(swc, autosar.component.ServiceComponent):
            lines.append(self.indent('<CATEGORY>ServiceComponent</CATEGORY>',1))
        if swc.adminData is not None:
            lines.extend(self.indent(self.writeAdminDataXML(swc.adminData),1))
        descLines = self.writeDescXML(swc)
        if descLines is not None:
            lines.extend(self.indent(descLines,1))
        lines.append(self.indent('<PORTS>',1))
        for port in swc.providePorts:
            lines.extend(self.indent(self._writeProvidePortXML(port),2))
        for port in swc.requirePorts:
            lines.extend(self.indent(self._writeRequirePortXML(port),2))
        lines.append(self.indent('</PORTS>',1))
        if (self.version >= 4.0) and (isinstance(swc, autosar.component.AtomicSoftwareComponent)) and (swc.behavior is not None):
            lines.append(self.indent('<INTERNAL-BEHAVIORS>',1))
            lines.extend(self.indent(self.behavior_writer.writeInternalBehaviorXML(swc.behavior),2))
            lines.append(self.indent('</INTERNAL-BEHAVIORS>',1))
        if isinstance(swc, autosar.component.CompositionComponent):
{'fraction_non_alphanumeric': 0.09515951595159516, 'fraction_numerical': 0.004510451045104511, 'mean_word_length': 2.712127398938342, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2344299', 'n_tokens_mistral': 2452, 'n_tokens_neox': 2405, 'n_words': 370}