示例#1
0
    def _getFields(self, xmlClass: Element) -> PyutFields:
        """
        Extracts fields from a DOM element that represents a UML class

        Args:
            xmlClass:
                The DOM version of a UML class

        Returns:
            PyutFields
        """
        pyutFields: PyutFields = cast(PyutFields, [])

        for element in xmlClass.getElementsByTagName(PyutXmlConstants.ELEMENT_MODEL_FIELD):

            xmlField:   Element  = cast(Element, element)
            pyutField: PyutField = PyutField()

            strVis: str                = xmlField.getAttribute(PyutXmlConstants.ATTR_VISIBILITY)
            vis:    PyutVisibilityEnum = PyutVisibilityEnum.toEnum(strVis)

            pyutField.setVisibility(vis)
            xmlParam: Element = xmlField.getElementsByTagName(PyutXmlConstants.ELEMENT_MODEL_PARAM)[0]

            if xmlParam.hasAttribute(PyutXmlConstants.ATTR_DEFAULT_VALUE):
                pyutField.setDefaultValue(xmlParam.getAttribute(PyutXmlConstants.ATTR_DEFAULT_VALUE))
            pyutField.setName(xmlParam.getAttribute(PyutXmlConstants.ATTR_NAME))

            pyutType: PyutType = PyutType(xmlParam.getAttribute(PyutXmlConstants.ATTR_TYPE))
            pyutField.setType(pyutType)

            pyutFields.append(pyutField)

        return pyutFields
示例#2
0
    def _onFieldOk(self, event):
        """
        Activated when button OK from dlgEditField is clicked.

        Args:
            event:  Associated event
        """

        self.fieldToEdit.setName(self._txtFieldName.GetValue().strip())
        from org.pyut.model.PyutType import PyutType

        self.fieldToEdit.setType(
            PyutType(self._txtFieldType.GetValue().strip()))
        visStr: str = self._rdbFieldVisibility.GetStringSelection()
        vis: PyutVisibilityEnum = PyutVisibilityEnum.toEnum(visStr)
        self.fieldToEdit.setVisibility(vis)

        if self._txtFieldDefault.GetValue().strip() != "":
            self.fieldToEdit.setDefaultValue(
                self._txtFieldDefault.GetValue().strip())
        else:
            self.fieldToEdit.setDefaultValue(None)

        # Tell window that its data has been modified
        fileHandling = self._ctrl.getFileHandling()
        project = fileHandling.getCurrentProject()

        if project is not None:
            project.setModified()

        # Close dialog
        self.EndModal(OK)
示例#3
0
    def _xmiVisibility2PyutVisibility(self, visibility: str = "private") -> PyutVisibilityEnum:
        """
        Translates Xmi visibility string to a Pyut visibility enumeration

        Args:
            visibility: the string 'public', 'prviate', or 'protected'

        Returns:  The appropriate enumeration value
        """
        retEnum: PyutVisibilityEnum = PyutVisibilityEnum.toEnum(visibility)
        return retEnum
示例#4
0
    def testGetValues(self):

        enumValueList: List[str] = PyutVisibilityEnum.values()
        self.logger.info(f'{enumValueList}')

        self.assertIn(member=PyutVisibilityEnum.PROTECTED.value,
                      container=enumValueList,
                      msg='Ugh. missing value')
        self.assertIn(member=PyutVisibilityEnum.PRIVATE.value,
                      container=enumValueList,
                      msg='Ugh. missing value')
        self.assertIn(member=PyutVisibilityEnum.PUBLIC.value,
                      container=enumValueList,
                      msg='Ugh. missing value')
示例#5
0
    def _getFields(self, Class):
        """
        To extract fields form Class.

        @since 1.0
        @author Deve Roux <*****@*****.**>
        """
        # for class fields
        allFields = []
        for Field in Class.getElementsByTagName("Field"):

            aField = PyutField()
            # aField.setVisibility(Field.getAttribute('visibility'))
            vis: PyutVisibilityEnum = PyutVisibilityEnum(Field.getAttribute('visibility'))
            aField.setVisibility(vis)
            Param = Field.getElementsByTagName("Param")[0]
            if Param.hasAttribute('defaultValue'):
                aField.setDefaultValue(Param.getAttribute('defaultValue'))
            aField.setName(Param.getAttribute('name'))
            aField.setType(Param.getAttribute('type'))

            allFields.append(aField)
        return allFields
示例#6
0
    def testToEnumPrivateValue(self):

        val: PyutVisibilityEnum = PyutVisibilityEnum.toEnum('-')
        self.assertEqual(PyutVisibilityEnum.PRIVATE, val,
                         'Private to enum value fail')
示例#7
0
    def testToEnumPublicValue(self):

        val: PyutVisibilityEnum = PyutVisibilityEnum.toEnum('+')
        self.assertEqual(PyutVisibilityEnum.PUBLIC, val,
                         'Public to enum value fail')
示例#8
0
    def testToEnumProtectedName(self):

        val: PyutVisibilityEnum = PyutVisibilityEnum.toEnum('protected')
        self.assertEqual(PyutVisibilityEnum.PROTECTED, val,
                         'protected to enum fail')
示例#9
0
    def testToEnumPrivateName(self):

        val: PyutVisibilityEnum = PyutVisibilityEnum.toEnum('private')
        self.assertEqual(PyutVisibilityEnum.PRIVATE, val,
                         'Private to enum fail')
示例#10
0
    def testToEnumPublicName(self):

        val: PyutVisibilityEnum = PyutVisibilityEnum.toEnum('public')
        self.assertEqual(PyutVisibilityEnum.PUBLIC, val,
                         'Public to enum name fail')
示例#11
0
    def deserialize(self, serializedData):
        """
        Deserialize the data needed by the deleted OglCass

        Args:
            serializedData: serialized data needed by the command.
        """
        from org.pyut.model.PyutMethod import PyutMethod
        from org.pyut.model.PyutParam import PyutParam
        from org.pyut.model.PyutField import PyutField

        from org.pyut.model.PyutStereotype import PyutStereotype
        from org.pyut.model.PyutModifier import PyutModifier

        # deserialize the data common to all OglObjects
        DeleteOglLinkedObjectCommand.deserialize(self, serializedData)

        # deserialize properties of the OglClass (first level)
        classDescription = deTokenize("classDescription", serializedData)
        classStereotypeName = deTokenize("classStereotypeName", serializedData)
        classShowStereotype = eval(
            deTokenize("classShowStereotype", serializedData))
        classShowMethods = eval(deTokenize("classShowMethods", serializedData))
        classShowFields = eval(deTokenize("classShowFields", serializedData))

        methods = eval(deTokenize("methods", serializedData))
        fields = eval(deTokenize("fields", serializedData))

        # set up the first level properties of the pyutClass
        pyutClass: PyutClass = self._shape.getPyutObject()
        pyutClass.description = classDescription

        if cmp(classStereotypeName, ""):
            pyutStereo = PyutStereotype(classStereotypeName)
            pyutClass.setStereotype(pyutStereo)

        pyutClass.setShowStereotype(classShowStereotype)
        pyutClass.showMethods = classShowMethods
        pyutClass.showFields = classShowFields

        for field in fields:

            fieldName = field[0]
            fieldType = field[1]
            fieldDefaultValue = field[2]
            fieldVisibility = field[3]
            pyutClass.addField(
                PyutField(fieldName, fieldType, fieldDefaultValue,
                          fieldVisibility))

        methodsList = []
        # deserialize methods of the pyutClass
        for methodProfile in methods:

            # construction of a method
            methodName: str = methodProfile[0]
            methodVisibility: PyutVisibilityEnum = PyutVisibilityEnum.toEnum(
                methodProfile[1])
            methodReturns: PyutType = PyutType(value=methodProfile[2])

            method = PyutMethod(name=methodName,
                                visibility=methodVisibility,
                                returns=methodReturns)

            # deserialize method's params so we get a tuple (name, Type, defaultValue)
            params = eval(methodProfile[3])
            for param in params:
                paramName = param[0]

                # construction of the type of the param
                paramType = param[1]
                # pyutType = PyutType(paramType)   Not used
                paramDefaultValue = param[2]

                # creates and add the param to the method
                method.addParam(
                    PyutParam(paramName, paramType, paramDefaultValue))

            # deserialize method's modifiers so we get a list of names
            # that we have to transform into a list of PyutModifiers.
            modifiersNames = eval(methodProfile[4])
            modifiers = []
            for modifierName in modifiersNames:
                modifiers.append(PyutModifier(modifierName))

            # add the modifiers to the method
            method.setModifiers(modifiers)
            # add the method to the list of methods
            methodsList.append(method)

        # add all the methods to the list
        pyutClass.methods = methodsList