def getReferencesToModule(root, fqn): modulename = fqn.split(".")[-1] moduleobj = getTypeOf(root, fqn) moduleRefFinder = ModuleRefFinder(moduleobj) for ref in globalScanForMatches(moduleRefFinder, modulename): yield ref
def generateRefsToName(name,scope,sourcenode,defnmatch): assert scope is not None if isinstance(scope,Function): # search can be limited to scope return scanScopeForMatches(sourcenode,scope, NameRefFinder(name,defnmatch), name) else: return globalScanForMatches(sourcenode.filename, NameRefFinder(name,defnmatch), name)
def findReferencesIncludingDefn_impl(sourcenode,node,scope,defnmatch): if isinstance(node,Name) or isinstance(node,AssName): return generateRefsToName(node.name,scope,sourcenode,defnmatch) elif isinstance(node,Getattr) or isinstance(node,AssAttr): exprtype = getTypeOfExpr(scope,node.expr) if exprtype is None or isinstance(exprtype,UnfoundType): raise CouldntFindDefinitionException() if isinstance(exprtype,Instance): exprtype = exprtype.getType() return generateRefsToAttribute(exprtype,node.attrname) else: targetname = node.attrname return globalScanForMatches(sourcenode.filename, NameRefFinder(targetname, defnmatch), targetname, ) elif isinstance(node,compiler.ast.Function) or \ isinstance(node,compiler.ast.Class): return handleClassOrFunctionRefs(scope, node, defnmatch) else: assert 0,"Seed to references must be Name,Getattr,Function or Class"
def generateRefsToAttribute(classobj,attrname): rootClasses = getRootClassesOfHierarchy(classobj) attrRefFinder = AttrbuteRefFinder(rootClasses,attrname) for ref in globalScanForMatches(classobj.filename, attrRefFinder, attrname): yield ref print >>log.progress,"Done"