def cmpBarycenter(theNode: SugiyamaNode) -> int: """ Comparison function on barycenter value Args: theNode Returns: The return value from cmp() """ xNode: SugiyamaNode = theNode.getLeftNode() yNode: SugiyamaNode = theNode.getRightNode() if xNode is None or yNode is None: return 0 else: return cmp(xNode.getBarycenter(), yNode.getBarycenter())
def deTokenize(tokenId: str, serializedData: str) -> str: """ The token has to be created by the `tokenize()` method. Used in the deserialize method of a command to get back a value. Args: tokenId: name of the token serializedData: string which contains the information needed to deserialize a command Returns: The value (string) of the specified token extracted from the specified string. """ # to not to work on the original -- hasii note, is this true? value = serializedData hLogger.info(f'tokenId: `{tokenId}`') hLogger.debug(f'value: {value}') # find a char that is not present in the value tempEscape = chr(1) while value.find(tempEscape) > -1: tempEscape = chr(ord(tempEscape + str(1))) # replace the double escape sequences by a char that is not # present in the original value value = value.replace(TOKEN_ESCAPE + TOKEN_ESCAPE, tempEscape) # find the start position of the value which is just after the end # of the token name followed by the assignment token. startPos = value.find(tokenId) startPos = startPos + len(tokenId) + len(TOKEN_ASSIGN) # value = value[startPos : len(value)] # find the end position which is just before TOKEN_ASSIGN endPos = value.find(TOKEN_END, startPos) # check if there isn't a escape token before TOKEN_END what # would means that the TOKEN_END sequence is a part of the # value, so we check for the next TOKEN_END. while cmp(value[endPos - len(TOKEN_ESCAPE):endPos], TOKEN_ESCAPE) == 0: endPos = value.find(TOKEN_END, endPos + 1) value = value[startPos:endPos] # remove all the escape sequences value = value.replace(TOKEN_ESCAPE, "") # add simple escape sequences where they where double value = value.replace(tempEscape, TOKEN_ESCAPE) hLogger.info(f'return value: {value}') return value
def cmpIndex(aTuple: Tuple): """ Internal comparison function for sorting list of parents or children by index. Args: aTuple: Returns: """ sugiyamaNode: SugiyamaNode = aTuple[0] l: SugiyamaNode = sugiyamaNode.getLeftNode() r: SugiyamaNode = sugiyamaNode.getRightNode() if l is None or r is None: return 0 else: SugiyamaGlobals.clsLogger.info( f' l.getIndex(): {l.getIndex()} r.getIndex(): {r.getIndex()}') return cmp(l.getIndex(), r.getIndex())
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