def docMethod(self):

                #print 'doc: ', self.document, self.document.getClass().getName()
                #print 'editor: ', self.editor, self.editor.getClass().getName()
                #line = self.selection.getCursorLine()
                lineStartScopeObj = self.selection.getPreviousLineThatStartsScope(
                )
                # the number of the line that starts the scope.
                print 'start of scope is:', lineStartScopeObj.iLineStartingScope
                parser = FastParser.parseToKnowGloballyAccessiblePath(
                    self.document, lineStartScopeObj.iLineStartingScope)
                for stmt in parser:
                    print 'stmt', stmt
                    if isinstance(stmt, FunctionDef):
                        #print 'begin line?', stmt.beginLine
                        # now get the return values and the args sent to the function
                        grammarVersion = self.editor.getGrammarVersion()
                        parseInfoObj = PyParser.ParserInfo(
                            self.document, grammarVersion)
                        parseOut = PyParser.reparseDocument(parseInfoObj)
                        body = NodeUtils.getBody(parseOut.ast)
                        funcDef = self.searchFuncs(body, stmt.beginLine)
                        argList = self.parseFunc(funcDef)
                        returnState = self.hasReturn(funcDef)
                        #lineOffset = self.document.getLineOffset(stmt.beginLine)
                        #startLine = self.selection.getLine(self.document, stmt.beginLine-1)
                        prevLine = self.selection.getLine(
                            self.document, stmt.beginLine)
                        indentation = self.selection.getIndentationFromLine(
                            prevLine)
                        docString = self.prepOutputMethodString2(
                            indentation, argList, returnState)
                        self.selection.addLine(indentation + docString,
                                               stmt.beginLine - 1)
                        return docString
 def docMethod(self):
     
     #print 'doc: ', self.document, self.document.getClass().getName()
     #print 'editor: ', self.editor, self.editor.getClass().getName()
     #line = self.selection.getCursorLine()
     lineStartScopeObj = self.selection.getPreviousLineThatStartsScope()
     # the number of the line that starts the scope.
     print 'start of scope is:', lineStartScopeObj.iLineStartingScope
     parser = FastParser.parseToKnowGloballyAccessiblePath(self.document, lineStartScopeObj.iLineStartingScope)
     for stmt in parser:
         print 'stmt', stmt
         if isinstance(stmt, FunctionDef):
             #print 'begin line?', stmt.beginLine
             # now get the return values and the args sent to the function
             grammarVersion = self.editor.getGrammarVersion()
             parseInfoObj = PyParser.ParserInfo(self.document, grammarVersion)
             parseOut = PyParser.reparseDocument(parseInfoObj)
             body = NodeUtils.getBody(parseOut.ast)
             funcDef = self.searchFuncs(body, stmt.beginLine)
             argList = self.parseFunc(funcDef)
             returnState = self.hasReturn(funcDef)
             #lineOffset = self.document.getLineOffset(stmt.beginLine)
             #startLine = self.selection.getLine(self.document, stmt.beginLine-1)
             prevLine = self.selection.getLine(self.document, stmt.beginLine)
             indentation = self.selection.getIndentationFromLine(prevLine)
             docString = self.prepOutputMethodString2(indentation, argList, returnState)
             self.selection.addLine(indentation + docString, stmt.beginLine-1)
             return docString
Пример #3
0
def GetCurrentMethod(context):
    from org.python.pydev.parser.visitors import NodeUtils
    from org.python.pydev.parser.jython.ast import FunctionDef
    
    for stmt in _GetCurrentASTPath(context, True):
        if isinstance(stmt, FunctionDef):
            return NodeUtils.getRepresentationString(stmt)
    return ''
Пример #4
0
def GetCurrentMethod(context):
    from org.python.pydev.parser.visitors import NodeUtils
    from org.python.pydev.parser.jython.ast import FunctionDef

    for stmt in _GetCurrentASTPath(context, True):
        if isinstance(stmt, FunctionDef):
            return NodeUtils.getRepresentationString(stmt)
    return ''
Пример #5
0
def GetCurrentClass(context):
    from org.python.pydev.parser.visitors import NodeUtils
    from org.python.pydev.parser.jython.ast import ClassDef
    
    stmt = _GetCurrentClassStmt(context)
    if stmt is not None:
        return NodeUtils.getRepresentationString(stmt)
    
    return ''
Пример #6
0
def GetQualifiedNameScope(context):
    from org.python.pydev.parser.visitors import NodeUtils
    
    ret = ''
    for stmt in _GetCurrentASTPath(context):
        if ret:
            ret += '.'
        ret += NodeUtils.getRepresentationString(stmt)
    return ret
Пример #7
0
def GetCurrentClass(context):
    from org.python.pydev.parser.visitors import NodeUtils
    from org.python.pydev.parser.jython.ast import ClassDef

    stmt = _GetCurrentClassStmt(context)
    if stmt is not None:
        return NodeUtils.getRepresentationString(stmt)

    return ''
Пример #8
0
def GetQualifiedNameScope(context):
    from org.python.pydev.parser.visitors import NodeUtils

    ret = ''
    for stmt in _GetCurrentASTPath(context):
        if ret:
            ret += '.'
        ret += NodeUtils.getRepresentationString(stmt)
    return ret
Пример #9
0
def _GetPreviousOrNextClassOrMethod(context, searchForward):
    from org.python.pydev.parser.visitors import NodeUtils
    from org.python.pydev.parser.fastparser import FastParser
    doc = context.getDocument()
    selection = _CreateSelection(context)
    startLine = selection.getStartLineIndex()
    
    found = FastParser.firstClassOrFunction(doc, startLine, searchForward, context.isCythonFile())
    if found:
        return NodeUtils.getRepresentationString(found)
    return ''
Пример #10
0
def _GetPreviousOrNextClassOrMethod(context, searchForward):
    from org.python.pydev.parser.visitors import NodeUtils
    from org.python.pydev.parser.fastparser import FastParser
    doc = context.getDocument()
    selection = _CreateSelection(context)
    startLine = selection.getStartLineIndex()

    found = FastParser.firstClassOrFunction(doc, startLine, searchForward)
    if found:
        return NodeUtils.getRepresentationString(found)
    return ''
Пример #11
0
def getClassArgs(idocument, selObj, beginLine):
    '''
    This method recieves a selection object and the start and end 
    lines of a class definition.  It will then scan through the code
    looking for class variables.  It stuffs the class variables 
    into a list and returns them.

        
    :param  selObj: The selection object, used to access the document
    :type selObj: org.python.pydev.core.docutils.PySelection
    :param  beginLine: an integer indicating the first line of the class
    :type beginLine: integer
    :param  endLine: (Optional) If null then assumes that this is the last 
                      class in the module and therefor all subsequent lines
                      are from the class.
    :type endLine: integer
    
    :return: a list containing the names of all the class variables
    :rtype: list
    '''
    print 'getClassArgs called' 
#    from org.python.pydev.core.docutils import PySelection
    from org.python.pydev.parser import PyParser
    from org.python.pydev.parser.visitors import NodeUtils
    from org.python.pydev.parser.jython.ast import ClassDef
    from org.python.pydev.parser.jython.ast import Assign
    from org.python.pydev.parser.jython.ast import FunctionDef
    
    doc = selObj.getDoc()
    #parseInfoObj = PyParser.ParserInfo(doc, 12)
    print 'here'
    grammarVersion = idocument.getGrammarVersion()
    print 'grammarVersion', grammarVersion
    parseInfoObj = PyParser.ParserInfo(doc, grammarVersion)
    
    nodes = PyParser.reparseDocument(parseInfoObj)
    body = NodeUtils.getBody(nodes.ast)
    
    print 'body', body
    classVarList = []
    for stmt in body:
        if isinstance(stmt, ClassDef):
            print 'class start', stmt.beginLine, beginLine
            print 'classname', stmt.name.id
            # the class we are looking for!
            #if stmt.name.id == 'test':
            if stmt.beginLine == beginLine:
                for j in stmt.body:
                    if isinstance(j, Assign ):
                        print 'Class Name: ', j.targets[0].id
                        classVarList.append(str(j.targets[0].id))
                        print 'j', j 
                    if isinstance(j, FunctionDef):
                        print 'func full', j.name.id
                        for inFunc in j.body:
                            classVarList = searchAssignments(classVarList, inFunc)
                            print 'classVarList', classVarList
    # remove duplicates from the list
    import sets
    classVarList = list(sets.Set(classVarList))
    classVarList.sort()
    return classVarList
Пример #12
0
def getFuncArgs(idocument, beginLine):
    '''
    This method recieves a document object and the start  
    lines of a function definition who's args we want to 
    retrieve. 
    
    It then creates an AST parsed document structure, which 
    gets worked through until a method is found that occurs 
    on the same line as the beginLine that was sent as an 
    arg to this method.
    
    Once this is found it searches for the args in that method 
    and also whether the method has return value.  It then
    sends this information to prepOutputMethodString2 method
    that will convert this into a nicely formatted docstring.
        
    :param  idocument: input context object
    :type idocument: org.python.pydev.editor.codecompletion.templates.PyDocumentTemplateContext
    :param  beginLine: the integer that the function starts on.
    :type beginLine: int
    
    :returns: a sphinx restructured text docstring template for 
              method from which the method was called.
    :rtype: string
    '''
    
    print 'getClassArgs called' 
#    from org.python.pydev.core.docutils import PySelection
    from org.python.pydev.parser import PyParser
    from org.python.pydev.parser.visitors import NodeUtils
    from org.python.pydev.core.docutils import PySelection
    doc = idocument.getDocument()
    
    # creating a parser object.  The 12 is a constant that
    # defines python syntax.  See org.python.pydev.core.IGrammarVersionProvider
    # different numbers are:
    #    2.4    10
    #    2.5    11
    #    2.6    12
    #    2.7    13
    #    etc...
    grammarVersion = idocument.getGrammarVersion()
    print 'grammarVersion:', grammarVersion
    parseInfoObj = PyParser.ParserInfo(doc, grammarVersion)
    # parsign the document into the different node types
    # from the root node you can access all elements of the
    # doc.  (hierarchical parser)
    # nodes is a Tuple object of type:
    #  com.aptana.shared_core.structure.Tuple
    nodes = PyParser.reparseDocument(parseInfoObj)
    print 'node type:', nodes.getClass().getName()
    # nodes.01 contains SimpleNode
    #x = nodes.o1
    #print 'xtype ', x.getClass().getName()
    
    # getting the document body
    body = NodeUtils.getBody(nodes.ast)
    print 'body', body
    # getting the function that starts on the line: begtinLine
    funcDef = searchFuncs(body, beginLine)
    print 'funcDef', funcDef
    argList = parseFunc(funcDef)
    returnState = hasReturn(funcDef)
    #doc = idocument.getDocument()
#    doc = idocument.getDocument()
    # 2 - get a selection object for the current line
    selection = PySelection(idocument.getDocument(), idocument.getStart())
    startLineNumber = doc.getLineOfOffset(idocument.getStart())
    startLineContents = selection.getLine(startLineNumber)
    indentation = selection.getIndentationFromLine(startLineContents)
    
    docString = prepOutputMethodString2(indentation, argList, returnState)
    print 'return: ', returnState
    return docString