Example #1
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()))
Example #2
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()))
    def __init__(self,sourcenode, startcoords, endcoords, newname):
        self.sourcenode = sourcenode

        startcoords, endcoords = \
               reverseCoordsIfWrongWayRound(startcoords,endcoords)

        self.startline = startcoords.line
        self.endline = endcoords.line
        self.startcol = startcoords.column
        self.endcol= endcoords.column

        self.newfn = NewFunction(newname)

        self.getLineSeperator()
        self.adjustStartColumnIfLessThanTabwidth()
        self.adjustEndColumnIfStartsANewLine()
        self.fn = self.getFunctionObject()
        self.getRegionToBuffer()
        #print "-"*80
        #print self.extractedLines
        #print "-"*80
        self.deduceIfIsMethodOrFunction()