def _createProperties( self, propName: str, setterParams: List[str]) -> Tuple[PyutMethod, PyutMethod]: getter: PyutMethod = PyutMethod(name=propName, visibility=PyutVisibilityEnum.PUBLIC) if len(setterParams) == 0: setter: PyutMethod = cast(PyutMethod, None) else: setter = PyutMethod(name=propName, visibility=PyutVisibilityEnum.PUBLIC) if setter is not None: nameType: str = setterParams[0] potentialNameType: List[str] = nameType.split(':') if len(potentialNameType) == 2: param: PyutParam = PyutParam( name=potentialNameType[0], parameterType=PyutType(value=potentialNameType[1])) setter.addParam(param) getter.returnType = PyutType(value=potentialNameType[1]) else: param = PyutParam(name=potentialNameType[0]) setter.addParam(param) return setter, getter
def __addClassMethod(self, className, modifiers, returnType, name, lstFields): """ Add a method to a class Parameters example: ```java static private int getName(int a, long b) - className = name of the class which own this method - static private => modifiers - int => return type - getName => name - int a, long b => lstFields => ["int a", "long b"] ``` Note : Default value can be None. (see names_values) Args: className: Name of the class to add modifiers: Method modifiers returnType: Method returnType name: Method name lstFields: List of string lstFields : Method fields """ self.__logMessage("Adding method %s for class %s" % (name, className)) self.__logMessage("(modifiers=%s; returnType=%s)" % (modifiers, returnType)) # Get class fields po: OglClass = self._classes[className] pc: PyutClass = cast(PyutClass, po.pyutObject) # TODO fix this crazy code to use constructor and catch exception on bad input # Get visibility if "private" in modifiers: visibility: PyutVisibilityEnum = PyutVisibilityEnum.PRIVATE elif "protected" in modifiers: visibility: PyutVisibilityEnum = PyutVisibilityEnum.PROTECTED elif "public" in modifiers: visibility: PyutVisibilityEnum = PyutVisibilityEnum.PUBLIC else: visibility: PyutVisibilityEnum = PyutVisibilityEnum.PUBLIC # Add method methods = pc.methods if returnType == '\n' or returnType == '' or returnType == 'void' or returnType is None: pm = PyutMethod(name, visibility) else: retType: PyutType = PyutType(returnType) pm = PyutMethod(name, visibility, retType) for (paramType, name, defaultValue) in lstFields: param = PyutParam(name, paramType, defaultValue) pm.addParam(param) methods.append(pm)
def _addParameters(self, pyutMethod: PyutMethod) -> PyutMethod: methodName: str = pyutMethod.name if methodName in self.visitor.parameters: parameters: PyutPythonVisitor.Parameters = self.visitor.parameters[methodName] for parameter in parameters: self.logger.debug(f'parameter: {parameter}') paramNameType = parameter.split(':') # # TODO: account for default values # if len(paramNameType) == 2: # Somebody is good and did typing pyutType: PyutType = PyutType(paramNameType[1]) pyutParam: PyutParam = PyutParam(name=paramNameType[0], theParameterType=pyutType) pyutMethod.addParam(pyutParam) return pyutMethod
def deserialize(self, serializedData): """ deserialize the data needed by the destroyed OglLinkedObject. 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 DelOglLinkedObjectCommand.deserialize(self, serializedData) # deserialize properties of the OglClass (first level) classDescription = getTokenValue("classDescription", serializedData) classStereotypeName = getTokenValue("classStereotypeName", serializedData) classShowStereotype = eval( getTokenValue("classShowStereotype", serializedData)) classShowMethods = eval( getTokenValue("classShowMethods", serializedData)) classShowFields = eval(getTokenValue("classShowFields", serializedData)) methods = eval(getTokenValue("methods", serializedData)) fields = eval(getTokenValue("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 = methodProfile[0] methodVisibility = methodProfile[1] methodReturns = methodProfile[2] method = PyutMethod(methodName, methodVisibility, 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