Ejemplo n.º 1
0
def _getTypeFromCoordinates(filepath,lineno,col,pythonpath=[]):
    from bike.query.common import getScopeForLine, translateSourceCoordsIntoASTNode, convertScopeToMatchObject
    from bike.parsing.load import getSourceNode
    node = translateSourceCoordsIntoASTNode(filepath,lineno,col)
    scope = getScopeForLine(getSourceNode(filepath),lineno)
    scope = getTypeOfExpr(scope,node,pythonpath)
    if scope is not None:
        if isinstance(scope,Instance):
            scope = scope.getType()
        return convertScopeToMatchObject(scope)
    else:
        return None
Ejemplo n.º 2
0
def _getTypeFromCoordinates(filepath, lineno, col, pythonpath=[]):
    from bike.query.common import getScopeForLine, translateSourceCoordsIntoASTNode, convertScopeToMatchObject
    from bike.parsing.load import getSourceNode
    node = translateSourceCoordsIntoASTNode(filepath, lineno, col)
    scope = getScopeForLine(getSourceNode(filepath), lineno)
    scope = getTypeOfExpr(scope, node, pythonpath)
    if scope is not None:
        if isinstance(scope, Instance):
            scope = scope.getType()
        return convertScopeToMatchObject(scope)
    else:
        return None
Ejemplo n.º 3
0
def findAllPossibleDefinitionsByCoords(filepath,lineno,col,pythonpath=[]):
    match = findDefinitionByCoords(filepath, lineno, col, pythonpath)
    if match is not None:
        yield match

    if match is None or match.confidence != 100:
        node = translateSourceCoordsIntoASTNode(filepath,lineno,col)
        if isinstance(node,Getattr):
            #print "SCANNING PYTHONPATH ---------------"
            name = node.attrname
            for match in scanPythonPathForMatchingMethodNames(name,filepath,pythonpath):
                yield match
        print >>log.progress,"done"
Ejemplo n.º 4
0
def findReferences(filename,lineno,col,includeDefn=0,pythonpath=[]):
    sourcenode = getSourceNode(filename)
    node = translateSourceCoordsIntoASTNode(filename,lineno,col)
    assert node is not None
    scope,defnmatch = getDefinitionAndScope(sourcenode,lineno,node,pythonpath)
    try:
        for match in findReferencesIncludingDefn_impl(sourcenode,node,
                                                      scope,defnmatch,pythonpath):

            if not includeDefn and match == defnmatch:
                continue        # don't return definition
            else:
                yield match
    except CouldntFindDefinitionException:
        raise CouldntFindDefinitionException("Could not find definition. Please locate manually (maybe using find definition) and find references from that")
Ejemplo n.º 5
0
def generateRefsToAttribute(classobj,attrname,pythonpath):
    rootClasses = getRootClassesOfHierarchy(classobj,pythonpath)
    for sourcenode, linenum, col in _generateCoordsMatchingString(attrname,classobj.filename,pythonpath):
        scope = getScopeForLine(sourcenode, linenum)
        if col != 0 and sourcenode.getLines()[linenum-1][col-1] == '.':  # possible attribute
            expr = translateSourceCoordsIntoASTNode(sourcenode.filename,linenum,col)
            assert isinstance(expr,Getattr) or isinstance(expr,AssAttr)
            exprtype = getTypeOfExpr(scope,expr.expr,pythonpath)
            if isinstance(exprtype,Instance) and \
                   _isAClassInTheSameHierarchy(exprtype.getType(),rootClasses,pythonpath):
                yield createMatchObject(scope,linenum,col,attrname,100)
            elif exprtype is None:
                # can't deduce type of expression - still could be a match
                yield createMatchObject(scope,linenum,col,attrname,50)
        elif scopeIsAMethod(scope) and scope.name == attrname:  # possible method 
            if _isAClassInTheSameHierarchy(scope.getParent(),rootClasses,pythonpath):
                yield convertScopeToMatchObject(scope,100)
Ejemplo n.º 6
0
def findDefinitionByCoords(filepath, lineno, col, pythonpath):
    node = translateSourceCoordsIntoASTNode(filepath,lineno,col)
    if node is None:
        raise "selected node type not supported"
    scope = getScopeForLine(getSourceNode(filepath),lineno)
    if isinstance(node,compiler.ast.Function) or \
             isinstance(node,compiler.ast.Class) or isinstance(node,compiler.ast.Keyword) \
             or isinstance(node,FunctionArg):
        return createMatchObject(scope,lineno,col,node.name,100)
    if isinstance(node,ModuleName):
        module = resolveImportedModuleOrPackage(scope,node.modname,pythonpath)
        return createMatchObject(module,0,0,"")

    if not isinstance(scope, Module) and lineno == scope.linenum:  # looking for defn in fn line
        scope = scope.getParent()
    
    match = findDefinitionFromASTNode(scope,node,pythonpath)
    return match
Ejemplo n.º 7
0
def findAllPossibleDefinitionsByCoords(filepath,lineno,col):
    
    #try:
    node = translateSourceCoordsIntoASTNode(filepath,lineno,col)
    #except:
    #    import traceback
    #    traceback.print_exc()

    if node is None:
        raise "selected node type not supported"
    scope = getScopeForLine(getSourceNode(filepath),lineno)
    match = findDefinitionFromASTNode(scope,node)
    if match is not None:
        yield match
    if isinstance(node,Getattr) and (match is None or match.confidence != 100):
        root = getRoot()
        name = node.attrname
        for match in scanPythonPathForMatchingMethodNames(name,filepath):
            yield match
    log.progress.write("done\n")