Ejemplo n.º 1
0
 def getPreceedingLinesInLoop(self,linesbefore,firstLineToExtract):
     if linesbefore == []: return []
     tabwidth = getTabWidthOfLine(firstLineToExtract)
     rootTabwidth = getTabWidthOfLine(linesbefore[0])
     llines = [line for line in generateLogicalLines(linesbefore)]
     startpos = len(llines)-1
     loopTabwidth = tabwidth
     for idx in range(startpos,0,-1):
         line = llines[idx]
         if re.match("(\s+)for",line) is not None or \
            re.match("(\s+)while",line) is not None:
             candidateLoopTabwidth = getTabWidthOfLine(line)
             if candidateLoopTabwidth < loopTabwidth:
                 startpos = idx
     return llines[startpos:]
Ejemplo n.º 2
0
 def getTabwidthOfFunctionBody(self):
     line = self.sourcenode.getLines()[self.fn.getStartLine()]
     tabwidth = getTabWidthOfLine(line)
     parentTabwidth = self.getTabwidthOfParentFunction()
     if tabwidth < parentTabwidth:
         tabwidth = parentTabwidth + DEFAULT_TABSIZE
     if tabwidth < DEFAULT_TABSIZE:
         tabwidth = DEFAULT_TABSIZE
     return tabwidth
Ejemplo n.º 3
0
def extractLocalVariable(filename, startcoords, endcoords, varname):
    sourceobj = getSourceNode(filename)
    if startcoords.line != endcoords.line:
        raise "Can't do multi-line extracts yet"
    startcoords, endcoords = \
                 reverseCoordsIfWrongWayRound(startcoords,endcoords)
    line = sourceobj.getLine(startcoords.line)
    tabwidth = getTabWidthOfLine(line)
    linesep = getLineSeperator(line)
    region = line[startcoords.column:endcoords.column]
    
    getUndoStack().addSource(sourceobj.filename,sourceobj.getSource())
    sourceobj.getLines()[startcoords.line-1] = \
          line[:startcoords.column] + varname + line[endcoords.column:]

    defnline = tabwidth*" " + varname + " = " + region + linesep
    
    sourceobj.getLines().insert(startcoords.line-1,defnline)

    queueFileToSave(sourceobj.filename,"".join(sourceobj.getLines()))
Ejemplo n.º 4
0
 def adjustStartColumnIfLessThanTabwidth(self):
     tabwidth = getTabWidthOfLine(self.sourcenode.getLines()[self.startline-1])
     if self.startcol < tabwidth: self.startcol = tabwidth
Ejemplo n.º 5
0
 def replaceLinesWithFunctionCall(self, srclines, startline, endline, fncall):
     tabwidth = getTabWidthOfLine(srclines[startline-1])
     line = tabwidth*" " + fncall + self.linesep
     srclines[startline-1:endline] = [line]
Ejemplo n.º 6
0
 def getTabwidthOfParentFunction(self):
     line = self.sourcenode.getLines()[self.fn.getStartLine()-1]
     return getTabWidthOfLine(line)