Example #1
0
    def __generateParameter(self, currentParamNumber: int, numberOfParameters: int, pyutParam: PyutParam) -> str:
        """

        Args:
            currentParamNumber: The current parameter #
            numberOfParameters: The number of parameters the method has
            pyutParam:          What we are generating code from

        Returns:
            Python code for a single parameter
        """

        paramCode: str = ""

        paramCode = f'{paramCode}{pyutParam.getName()}'

        paramType: PyutType = pyutParam.getType()
        if paramType is not None and paramType.value != '':
            paramCode = f'{paramCode}: {paramType.value}'
        if pyutParam.getDefaultValue() is not None:
            paramCode = f'{paramCode} = {pyutParam.getDefaultValue()}'
        if currentParamNumber < numberOfParameters - 1:
            paramCode = f'{paramCode}, '

        return paramCode
Example #2
0
    def _writeParam(self, file: int, param: PyutParam):
        """
        Writing params to file.

        Args:
            file:   file descriptor
            param:  pyut parameter object to write
        """
        paramType: str = param.getType().__str__()
        paramName: str = param.getName()
        write(file, f'{paramType} {paramName}'.encode())
Example #3
0
    def _pyutParamToXml(self, pyutParam: PyutParam,
                        xmlDoc: Document) -> Element:
        """
        Export a PyutParam to a miniDom Element

        Args:
            pyutParam:  Parameter to save
            xmlDoc:     XML Node

        Returns:
            The new updated element
        """
        root: Element = xmlDoc.createElement(
            PyutXmlConstants.ELEMENT_MODEL_PARAM)

        root.setAttribute(PyutXmlConstants.ATTR_NAME, pyutParam.getName())
        root.setAttribute(PyutXmlConstants.ATTR_TYPE, str(pyutParam.getType()))

        defaultValue = pyutParam.getDefaultValue()
        if defaultValue is not None:
            root.setAttribute(PyutXmlConstants.ATTR_DEFAULT_VALUE,
                              defaultValue)

        return root