コード例 #1
0
ファイル: test_relationships.py プロジェクト: tillwf/artub
 def helper(self,src,classname):
     try:
         createPackageStructure(src,testdata.TheClass)
         classobj = getTypeOf(getModule(pkgstructureFile1),classname,[pkgstructureRootDir])
         return getRootClassesOfHierarchy(classobj,[pkgstructureRootDir])
     finally:
         removePackageStructure()
コード例 #2
0
 def _isAClassInTheSameHierarchy(self,classobj):
     #return classobj in self.targetClasses
     targetRootClasses = getRootClassesOfHierarchy(classobj)
     for rootclass in self.rootClasses:
         if rootclass in targetRootClasses:
             return True
     return False
コード例 #3
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)
コード例 #4
0
def _isAClassInTheSameHierarchy(classobj,rootclasses,pythonpath):
    targetRootClasses = getRootClassesOfHierarchy(classobj,pythonpath)
    for rootclass in rootclasses:
        if rootclass in targetRootClasses:
            return True
    return False
コード例 #5
0
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"