示例#1
0
    def _getMethods(self, Class):
        """
        To extract methods from interface.
        """
        # class methods for this current class
        allMethods = []
        for Method in Class.getElementsByTagName("Method"):

            # method name
            aMethod = PyutMethod(Method.getAttribute('name'))

            # method visibility
            aMethod.setVisibility(Method.getAttribute('visibility'))

            # for method return type
            Return = Method.getElementsByTagName("Return")[0]
            aMethod.setReturns(Return.getAttribute('type'))

            # for methods param
            allParams = []
            for Param in Method.getElementsByTagName("Param"):
                allParams.append(self._getParam(Param))

            # setting the params for this method
            aMethod.setParams(allParams)
            # adding this method in all class methods
            allMethods.append(aMethod)

        return allMethods
示例#2
0
文件: PyutXmi.py 项目: hasii2011/PyUt
    def _getMethods(self, Class):
        """
        Extract a method from a Xmi file from Class part.

        Args:
            Class:  An XML Class

        Returns:  A PyutMethod
        """
        # class methods for this current class
        allMethods = []

        for Method in Class.getElementsByTagName("Foundation.Core.Operation"):

            self.logger.debug(f'_getMethods - Method: {Method}')
            # name = Method.getElementsByTagName("Foundation.Core.ModelElement.name")[0].firstChild
            methodElements: NodeList = Method.getElementsByTagName(
                "Foundation.Core.ModelElement.name")

            self.logger.debug(
                f'_getMethods - {methodElements=}  {methodElements.length=}  type(methodElements): {type(methodElements)}'
            )
            if methodElements.length == 0:
                continue
            elt = methodElements.item(0)
            self.logger.debug(f'_getMethods - elt: {elt}')
            name = elt.firstChild

            if name.nodeType == name.TEXT_NODE:
                aMethod = PyutMethod(name.data)
                self.logger.debug(f'Method name: {name.data}')
                # method visibility
                visibility = Method.getElementsByTagName(
                    "Foundation.Core.ModelElement.visibility")[0]
                # aMethod.setVisibility(self._xmiVisibility2PyutVisibility (visibility.getAttribute('xmi.value')))
                visStr: str = visibility.getAttribute('xmi.value')
                vis: PyutVisibilityEnum = self._xmiVisibility2PyutVisibility(
                    visStr)
                self.logger.debug(f'Method visibility: {vis}')
                aMethod.setVisibility(vis)
                allParams = []
                for Param in Method.getElementsByTagName(
                        "Foundation.Core.Parameter"):
                    pyutParam = self._getParam(Param, aMethod)
                    if pyutParam is not None:
                        allParams.append(pyutParam)

                aMethod.setParams(allParams)

                # adding this method in all class methods
                allMethods.append(aMethod)

        return allMethods