Пример #1
0
    def _writeMethod(self, file: int, method: PyutMethod):
        """
        Writing a method in file : name(param, param, ...).

        Args:
            file:       File descriptor
            method:     method object
        """
        name:       str = method.getName()
        visibility: str = self.__visibility[str(method.getVisibility())]
        returnType: str = str(method.getReturns())
        if returnType == "":
            returnType = "void"

        write(file, f'{self.__tab}{visibility} {returnType} {name}('.encode())

        # for all param
        nbParam = len(method.getParams())
        self.logger.info(f'# params: {nbParam}')
        for param in method.getParams():
            # writing param
            self._writeParam(file, param)

            # comma between param
            nbParam = nbParam - 1
            if nbParam > 0:
                write(file, ' , '.encode())

        write(file, f') {{\n{self.__tab}}}\n\n'.encode())
Пример #2
0
    def _writeMethodComment(self, file: int, method: PyutMethod, tab=""):
        """
        Write method comment with doxygen organization.

        Args:
            file:   file descriptor
            method: pyutMethod
            tab:    tab character(s) to use

        """
        write(file, f'{tab}/**\n'.encode())
        write(file, f'{tab} * method {method.getName()}\n'.encode())
        write(file, f'{tab} * More info here.\n'.encode())

        for param in method.getParams():
            write(
                file,
                f'{tab} * @param {param.getName()} : {str(param.getType())}\n'.
                encode())

        if str(method.getReturns()) != '':
            write(file,
                  f'{tab} * @return {str(method.getReturns())}\n'.encode())

        write(file, f'{tab} */\n'.encode())
Пример #3
0
    def generateASingleMethodsCode(self, pyutMethod: PyutMethod, writePass: bool = True) -> List[str]:
        """
        Generate the Python code for the input method

        Args:
            pyutMethod:    The PyutMethod for which we will generate code
            writePass:  If `True` write `pass` in the code

        Returns:
            A list that is the generated code
        """
        methodCode:  List[str] = []

        currentCode: str = self._generateMethodDefinitionStanza(pyutMethod)
        # Add parameters (parameter, parameter, parameter, ...)
        params = pyutMethod.getParams()
        currentCode = self._generateParametersCode(currentCode, params)
        currentCode = f'{currentCode})'

        returnType: PyutType = pyutMethod.getReturns()
        if returnType is not None and returnType.value != '':
            currentCode = f'{currentCode} -> {returnType.value}'

        currentCode = f'{currentCode}:\n'

        # Add to the method code
        methodCode.append(currentCode)

        # Add comments
        methodCode.append(self.__indentStr('"""\n'))
        methodCode = self._generateMethodComments(methodCode, pyutMethod)
        methodCode.append(self.__indentStr('"""\n'))

        if writePass:
            methodCode.append(self.__indentStr('pass\n'))

        methodCode.append('\n')
        return methodCode