Example #1
0
def getFilterMap(callNode, fileId_):
    global fileId, verbose
    verbose = True
    fileId = fileId_

    result = {}
    if callNode.type != "call":
        return result

    operand = callNode.getChild("operand")
    if operand:
        operand_string, isComplete = treeutil.assembleVariable(operand.getChildByPosition(0))
    if not operand or not isComplete or operand_string != "qx.core.Environment.filter":
        log("Warning", "Can only work on qx.core.Environment.filter call. Ignoring this occurrence.", operand)
        return result

    params = callNode.getChild("params")
    if len(params.children) != 1:
        log("Warning", "Expecting exactly one argument for qx.core.Environment.filter. Ignoring this occurrence.", params)
        return result

    # Get the map from the find call
    firstParam = params.getChildByPosition(0)
    if not firstParam.type == "map":
        log("Warning", "First argument must be a map! Ignoring this occurrence.", firstParam)
        return result
    result = treeutil.mapNodeToMap(firstParam)

    return result
Example #2
0
        def checkPrivate(allVars):

            privateElement = re.compile(r"\b__")

            def findPrivate(allVars):
                variables = []
                for node in allVars:
                    fullName, isComplete = treeutil.assembleVariable(node)
                    if privateElement.search(fullName):
                        variables.append(node)
                return variables

            def isLocalPrivate(var, fullName):
                allIdentifier = fullName.split(".")
                first = second = None
                if len(allIdentifier) > 0:
                    first = allIdentifier[0]
                if len(allIdentifier) > 1:
                    second = allIdentifier[1]
                return first and (first == "this" or first == "that") and second and privateElement.match(second)

            variables = findPrivate(allVars)
            for var in variables:
                fullName = treeutil.assembleVariable(var)[0]
                if (
                    isLocalPrivate(var, fullName) and fullName.split(".")[1] not in restricted
                ):  # local privates are ok, as long as they are declared
                    self.log(
                        var,
                        "Undeclared private data field '%s'. You should list this field in the members section."
                        % fullName,
                    )
            return
Example #3
0
 def findPrivate(allVars):
     variables = []
     for node in allVars:
         fullName, isComplete = treeutil.assembleVariable(node)
         if privateElement.search(fullName):
             variables.append(node)
     return variables
Example #4
0
 def findPrivate(allVars):
     variables = []
     for node in allVars:
         fullName, isComplete = treeutil.assembleVariable(node)
         if privateElement.search(fullName):
             variables.append(node)
     return variables
Example #5
0
        def checkPrivate(allVars):

            privateElement = re.compile(r'\b__')

            def findPrivate(allVars):
                variables = []
                for node in allVars:
                    fullName, isComplete = treeutil.assembleVariable(node)
                    if privateElement.search(fullName):
                        variables.append(node)
                return variables

            def isLocalPrivate(var, fullName):
                allIdentifier = fullName.split('.')
                first = second = None
                if len(allIdentifier) > 0:
                    first = allIdentifier[0]
                if len(allIdentifier) > 1:
                    second = allIdentifier[1]
                return (first and (first == "this" or first == "that")
                        and second and privateElement.match(second))

            variables = findPrivate(allVars)
            for var in variables:
                fullName = treeutil.assembleVariable(var)[0]
                if isLocalPrivate(var, fullName) and fullName.split(
                        '.'
                )[1] not in restricted:  # local privates are ok, as long as they are declared
                    self.log(
                        var,
                        "Undeclared private data field '%s'. You should list this field in the members section."
                        % fullName)
            return
Example #6
0
 def findProtected(allVars):
     variables = []
     for node in allVars:
         # only check protected in lval position
         if (node.hasParent() and node.parent.type == "left" and
             node.parent.hasParent() and node.parent.parent.type == "assignment" and
             protectedElement.search(treeutil.assembleVariable(node)[0])):
             variables.append(node)
     return variables
Example #7
0
 def findProtected(allVars):
     variables = []
     for node in allVars:
         # only check protected in lval position
         if (node.hasParent() and node.parent.type == "left"
                 and node.parent.hasParent()
                 and node.parent.parent.type == "assignment"
                 and protectedElement.search(
                     treeutil.assembleVariable(node)[0])):
             variables.append(node)
     return variables
Example #8
0
        def checkImplicit(allVars):

            def hasUndeclaredMember(fullName):
                allIdentifier = fullName.split('.')
                first = second = None
                if len(allIdentifier) > 0:
                    first  = allIdentifier[0]
                if len(allIdentifier) > 1:
                    second = allIdentifier[1]
                return (first and
                        (first == "this" or first == "that") and 
                        second and
                        second not in restricted)     # <- this is bogus, too narrow
                
            for var in allVars:
                fullName = treeutil.assembleVariable(var)[0]
                if hasUndeclaredMember(fullName):
                    self.log(var, "Undeclared local data field in '%s'! You should list this field in the member section." % fullName)

            return
Example #9
0
        def checkImplicit(allVars):
            def hasUndeclaredMember(fullName):
                allIdentifier = fullName.split('.')
                first = second = None
                if len(allIdentifier) > 0:
                    first = allIdentifier[0]
                if len(allIdentifier) > 1:
                    second = allIdentifier[1]
                return (first and (first == "this" or first == "that")
                        and second and second not in restricted
                        )  # <- this is bogus, too narrow

            for var in allVars:
                fullName = treeutil.assembleVariable(var)[0]
                if hasUndeclaredMember(fullName):
                    self.log(
                        var,
                        "Undeclared local data field in '%s'! You should list this field in the member section."
                        % fullName)

            return
Example #10
0
def getFilterMap(callNode, fileId_):
    global fileId, verbose
    verbose = True
    fileId = fileId_

    result = {}
    if callNode.type != "call":
        return result

    operand = callNode.getChild("operand")
    if operand:
        operand_string, isComplete = treeutil.assembleVariable(
            operand.getChildByPosition(0))
    if not operand or not isComplete or operand_string != "qx.core.Environment.filter":
        log(
            "Warning",
            "Can only work on qx.core.Environment.filter call. Ignoring this occurrence.",
            operand)
        return result

    params = callNode.getChild("params")
    if len(params.children) != 1:
        log(
            "Warning",
            "Expecting exactly one argument for qx.core.Environment.filter. Ignoring this occurrence.",
            params)
        return result

    # Get the map from the find call
    firstParam = params.getChildByPosition(0)
    if not firstParam.type == "map":
        log("Warning",
            "First argument must be a map! Ignoring this occurrence.",
            firstParam)
        return result
    result = treeutil.mapNodeToMap(firstParam)

    return result