示例#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
示例#3
0
    def read(self, umlObject, file):
        """
        Read data from file

        format:
        ```Python
        class name
        <<stereotype_optional>>
        +method([param[:type]]*)[:type_return]
        +field[:type][=value_initial]
        ```

        for example:

        ParentClass
        +strMethod(strParam : str = bogus) : str
        +intMethod(intParam = 1) : int
        +floatField : float = 1.0
        +booleanField : bool = True

        Args:
            umlObject:
            file:
        """
        className: str = file.readline().strip()
        pyutClass: PyutClass = umlObject.getPyutObject()
        pyutClass.setName(className)

        # process stereotype if present
        nextStereoType: str = file.readline().strip()
        if nextStereoType[0:2] == "<<":
            pyutClass.setStereotype(nextStereoType[2:-2].strip())
            nextStereoType = file.readline().strip()

        methods = []
        fields = []
        pyutClass.methods = methods
        pyutClass.fields = fields

        # process methods and fields
        visValues: List[str] = PyutVisibilityEnum.values()
        while True:
            if nextStereoType == "":
                break

            # search visibility

            if nextStereoType[0] in visValues:
                visStr = nextStereoType[0]
                vis: PyutVisibilityEnum = PyutVisibilityEnum.toEnum(visStr)
                nextStereoType = nextStereoType[1:]
            else:
                vis: PyutVisibilityEnum = PyutVisibilityEnum.PUBLIC

            pos = nextStereoType.find("(")
            params = []
            if pos != -1:
                # process method
                name = nextStereoType[0:pos].strip()
                nextStereoType = nextStereoType[pos + 1:]
                pos = nextStereoType.find(")")

                # TODO return typ should be PyutType
                returnType: str = ""
                if pos != -1:
                    params = self._findParams(nextStereoType[:pos])
                    nextStereoType = nextStereoType[pos + 1:]
                    pos = nextStereoType.find(":")

                    if pos != -1:
                        returnType = nextStereoType[pos + 1:].strip()
                    else:
                        returnType = ""
                method = PyutMethod(name, vis, returnType)

                method.setParams([PyutParam(x[0], x[1]) for x in params])
                methods.append(method)
            else:
                # process field
                field = self._findParams(nextStereoType)[0]
                if field:
                    fields.append(PyutField(field[0], field[1],
                                            visibility=vis))

            nextStereoType = file.readline().strip()