예제 #1
0
 def visitName(self, node):
     if node.name == self.targetstr:
         potentualMatch = findDefinitionFromASTNode(self.scope, node)
         if  potentualMatch is not None and \
                potentualMatch == self.targetMatch:
             self.appendMatch(node.name)
     self.popWordsUpTo(node.name)
예제 #2
0
 def visitGetattr(self, node):        
     for c in node.getChildNodes():
         self.visit(c)
     if node.attrname == self.targetstr:
         defn = findDefinitionFromASTNode(self.scope, node)
         if defn is not None and defn == self.targetMatch:
             self.appendMatch(node.attrname)
     self.popWordsUpTo(node.attrname)
예제 #3
0
def getDefinitionAndScope(sourcenode,lineno,node,pythonpath):
    scope = getScopeForLine(sourcenode,lineno)
    if scope.getStartLine() == lineno and \
           scope.matchesCompilerNode(node):  # scope is the node
        return scope.getParent(), convertScopeToMatchObject(scope,100)
    defnmatch = findDefinitionFromASTNode(scope,node,pythonpath)
    if defnmatch is None:
        raise CouldntFindDefinitionException("Couldn't find definition")
    scope = getScopeForLine(sourcenode,defnmatch.lineno)
    return scope,defnmatch
예제 #4
0
 def visitImport(self, node):
     for name, alias in node.names:
         if name.split(".")[-1] == self.targetstr:
             getattr = self.createGetattr(name)
             if findDefinitionFromASTNode(self.scope, getattr) == self.targetMatch:
                 self.appendMatch(self.targetstr)
         for nameelem in name.split("."):
             self.popWordsUpTo(nameelem)
         if alias is not None:
             self.popWordsUpTo(alias)
예제 #5
0
 def visitFrom(self, node):
     for elem in node.modname.split("."):
         self.popWordsUpTo(elem)
         
     for name, alias in node.names:
         if name == self.targetstr:
             if alias is not None:
                 pretendNode = Name(alias)
             else:
                 pretendNode = Name(name)
             if findDefinitionFromASTNode(self.scope, pretendNode) \
                                                 == self.targetMatch:
                 self.appendMatch(name)
         self.popWordsUpTo(name)
         if alias is not None:
             self.popWordsUpTo(alias)