Example #1
0
    def checkFields(self):
        define = treeutil.findQxDefine(self.tree)
        if not define:
            return

        classMapNode = treeutil.selectNode(define, "params/2")
        if classMapNode is None:
            return

        classMap = treeutil.mapNodeToMap(classMapNode)
        if not classMap.has_key("members"):
            return

        members = treeutil.mapNodeToMap(classMap["members"].children[0])
        restricted = [key for key in members if key.startswith("_")]

        assignNodes = [
            node for node in nodeIterator(classMap["members"], "assignment")
        ]
        if classMap.has_key("construct"):
            for node in nodeIterator(classMap["construct"], "assignment"):
                assignNodes.append(node)

        for node in assignNodes:
            this = treeutil.selectNode(node,
                                       "left/variable/identifier[1]/@name")
            if this != "this":
                continue

            field = treeutil.selectNode(node,
                                        "left/variable/identifier[2]/@name")
            if field is None:
                continue

            if field[0] != "_":
                continue
            elif field[1] == "_":
                prot = "private"
            else:
                prot = "protected"

            if prot == "protected":
                self.log(
                    node,
                    "Protected data field '%s'. Protected fields are deprecated. Better use private fileds in combination with getter and setter methods."
                    % field)
            elif not field in restricted:
                self.log(
                    node,
                    "Implicit declaration of %s field '%s'. You should list this field in the members section."
                    % (prot, field))
Example #2
0
 def _variantsFromTree(self, node):
     console = self.context['console']
     #config  = self.context['jobconf'] - TODO: this can yield job 'apiconf::build-resources' when running 'apiconf::build-data'!?
     config = Context.jobconf
     warn_non_literal_keys = "non-literal-keys" not in config.get(
         "config-warnings/environment", [])
     classvariants = set()
     for variantNode in variantoptimizer.findVariantNodes(node):
         firstParam = treeutil.selectNode(variantNode, "../../params/1")
         if firstParam:
             if treeutil.isStringLiteral(firstParam):
                 classvariants.add(firstParam.get("value"))
             elif firstParam.isVar():
                 if warn_non_literal_keys:
                     console.warn(
                         "qx.core.Environment call with non-literal key (%s:%s)"
                         % (self.id, variantNode.get("line", False)))
             elif firstParam.type == "map":  # e.g. .filter() method
                 mapMap = treeutil.mapNodeToMap(firstParam)
                 classvariants.update(mapMap.keys())
             else:
                 console.warn(
                     "qx.core.Environment call with alien first argument (%s:%s)"
                     % (self.id, variantNode.get("line", False)))
     return classvariants
Example #3
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("arguments")
    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 #4
0
    def _getMembersMap(self):
        classMap = self._getClassMap()
        if not "members" in classMap:
            return {}

        members = treeutil.mapNodeToMap(classMap["members"].children[0])
        return members
Example #5
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 #6
0
 def _variantsFromTree(self, node):
     console = self.context["console"]
     config = self.context["jobconf"]
     warn_non_literal_keys = "non-literal-keys" not in config.get("config-warnings/environment", [])
     classvariants = set()
     for variantNode in variantoptimizer.findVariantNodes(node):
         firstParam = treeutil.selectNode(variantNode, "../../params/1")
         if firstParam:
             if treeutil.isStringLiteral(firstParam):
                 classvariants.add(firstParam.get("value"))
             elif firstParam.type == "variable":
                 if warn_non_literal_keys:
                     console.warn(
                         "qx.core.Environment call with non-literal key (%s:%s)"
                         % (self.id, variantNode.get("line", False))
                     )
             elif firstParam.type == "map":  # e.g. .filter() method
                 mapMap = treeutil.mapNodeToMap(firstParam)
                 classvariants.update(mapMap.keys())
             else:
                 console.warn(
                     "qx.core.Environment call with alien first argument (%s:%s)"
                     % (self.id, variantNode.get("line", False))
                 )
     return classvariants
Example #7
0
    def _getMembersMap(self):
        classMap = self._getClassMap()
        if not "members" in classMap:
            return {}

        members = treeutil.mapNodeToMap(classMap["members"].children[0])
        return members
Example #8
0
    def _getClassMap(self):
        define = treeutil.findQxDefine(self.tree)
        if not define:
            return {}

        classMapNode = treeutil.selectNode(define, "params/2")
        if classMapNode is None:
            return {}

        classMap = treeutil.mapNodeToMap(classMapNode)
        return classMap
Example #9
0
    def _getClassMap(self):
        define = treeutil.findQxDefine(self.tree)
        if not define:
            return {}

        classMapNode = treeutil.selectNode(define, "params/2")
        if classMapNode is None:
            return {}

        classMap = treeutil.mapNodeToMap(classMapNode)
        return classMap
Example #10
0
    def checkFields(self):
        define = treeutil.findQxDefine(self.tree)
        if not define:
            return

        classMapNode = treeutil.selectNode(define, "params/2")
        if classMapNode is None:
            return

        classMap = treeutil.mapNodeToMap(classMapNode)
        if not classMap.has_key("members"):
            return

        members = treeutil.mapNodeToMap(classMap["members"].children[0])
        restricted = [key for key in members if key.startswith("_")]

        assignNodes = [node for node in treeutil.nodeIterator(classMap["members"], "assignment")]
        if classMap.has_key("construct"):
            for node in treeutil.nodeIterator(classMap["construct"], "assignment"):
                assignNodes.append(node)

        for node in assignNodes:
            this = treeutil.selectNode(node, "left/variable/identifier[1]/@name")
            if this != "this":
                continue

            field = treeutil.selectNode(node, "left/variable/identifier[2]/@name")
            if field is None:
                continue

            if field[0] != "_":
                continue
            elif field[1] == "_":
                prot = "private"
            else:
                prot = "protected"

            if prot == "protected":
                self.log(node, "Protected data field '%s'. Protected fields are deprecated. Better use private fields in combination with getter and setter methods." % field)
            elif not field in restricted:
                self.log(node, "Implicit declaration of %s field '%s'. You should list this field in the members section." % (prot, field))
Example #11
0
 def _variantsFromTree(self, node):
     console = self.context['console']
     classvariants = set()
     for variantNode in variantoptimizer.findVariantNodes(node):
         firstParam = treeutil.selectNode(variantNode, "../../params/1")
         if firstParam:
             if treeutil.isStringLiteral(firstParam):
                 classvariants.add(firstParam.get("value"))
             elif firstParam.type == "map": # e.g. .filter() method
                 mapMap = treeutil.mapNodeToMap(firstParam)
                 classvariants.update(mapMap.keys())
             else:
                 console.warn("qx.core.Environment call with alien first argument (%s:%s)" % (self.id, variantNode.get("line", False)))
     return classvariants
Example #12
0
def transfer(id, properties, members):
    # print "Transfer properties of %s" % id
    
    for propName, value in treeutil.mapNodeToMap(properties).items():
        keyvalue = value.parent
        value = value.getFirstChild()

        if value.type != "map":
            continue

        propDefinition = treeutil.mapNodeToMap(value)
    
        if "group" in propDefinition:
            continue

        if propDefinition.get("refine", False) != "true":
            generateProperty(propName, propDefinition, members, "set")
            generateProperty(propName, propDefinition, members, "get")
            generateProperty(propName, propDefinition, members, "init")
            generateProperty(propName, propDefinition, members, "reset")
            
            if propDefinition.get("check", False) == "Boolean":
                generateProperty(propName, propDefinition, members, "toggle")
                generateProperty(propName, propDefinition, members, "is")
Example #13
0
 def extractChecksMap(self):
     tree = self.tree()
     checksMap = None
     for node in treeutil.nodeIterator(tree, "keyvalue"):
         if node.get("key", "") == "_checksMap":
             checksMap = node
             break
     assert checksMap
     assert checksMap.hasParentContext("keyvalue/value/map")  # 'statics/_checksMap'
     checksMap = treeutil.selectNode(checksMap, "value/map")
     checksMap = treeutil.mapNodeToMap(checksMap)
     # stringify map values
     for key in checksMap:
         checksMap[key] = checksMap[key].children[0].get("value")
     return checksMap
Example #14
0
def transfer(id, properties, members):
    # print "Transfer properties of %s" % id

    for propName, value in treeutil.mapNodeToMap(properties).items():
        keyvalue = value.parent
        value = value.getFirstChild()

        if value.type != "map":
            continue

        propDefinition = treeutil.mapNodeToMap(value)

        if "group" in propDefinition:
            continue

        if propDefinition.get("refine", False) != "true":
            generateProperty(propName, propDefinition, members, "set")
            generateProperty(propName, propDefinition, members, "get")
            generateProperty(propName, propDefinition, members, "init")
            generateProperty(propName, propDefinition, members, "reset")

            if propDefinition.get("check", False) == "Boolean":
                generateProperty(propName, propDefinition, members, "toggle")
                generateProperty(propName, propDefinition, members, "is")
Example #15
0
 def extractChecksMap(self):
     tree = self.tree()
     checksMap = None
     for node in treeutil.nodeIterator(tree, "keyvalue"):
         if node.get("key", "") == "_checksMap":
             checksMap = node
             break
     assert checksMap
     assert checksMap.hasParentContext("keyvalue/value/map") # 'statics/_checksMap'
     checksMap = treeutil.selectNode(checksMap, "value/map")
     checksMap = treeutil.mapNodeToMap(checksMap)
     # stringify map values
     for key in checksMap:
         try:
             checksMap[key] = checksMap[key].children[0].get("value")
         except NodeAccessException:
             raise ValueError(("Error extracting checks map from %s: " +
                               "expected string value for key '%s' (found %s)") % 
                               (self.id, key, checksMap[key].children[0].type))
     return checksMap
Example #16
0
 def extractChecksMap(self):
     tree = self.tree()
     checksMap = None
     for node in treeutil.nodeIterator(tree, "keyvalue"):
         if node.get("key", "") == "_checksMap":
             checksMap = node
             break
     assert checksMap
     assert checksMap.hasParentContext("keyvalue/value/map") # 'statics/_checksMap'
     checksMap = treeutil.selectNode(checksMap, "value/map")
     checksMap = treeutil.mapNodeToMap(checksMap)
     # stringify map values
     for key in checksMap:
         try:
             checksMap[key] = checksMap[key].children[0].get("value")
         except NodeAccessException:
             raise ValueError(("Error extracting checks map from %s: " +
                               "expected string value for key '%s' (found %s)") % 
                               (self.id, key, checksMap[key].children[0].type))
     return checksMap
Example #17
0
 def _variantsFromTree(self, node):
     console = self.context['console']
     #config  = self.context['jobconf'] - TODO: this can yield job 'apiconf::build-resources' when running 'apiconf::build-data'!?
     config  = Context.jobconf
     warn_non_literal_keys = "non-literal-keys" not in config.get("config-warnings/environment",[])
     classvariants = set()
     for variantNode in variantoptimizer.findVariantNodes(node):
         firstParam = treeutil.selectNode(variantNode, "../../params/1")
         if firstParam:
             if treeutil.isStringLiteral(firstParam):
                 classvariants.add(firstParam.get("value"))
             elif firstParam.isVar():
                 if warn_non_literal_keys:
                     console.warn("qx.core.Environment call with non-literal key (%s:%s)" % (self.id, variantNode.get("line", False)))
             elif firstParam.type == "map": # e.g. .filter() method
                 mapMap = treeutil.mapNodeToMap(firstParam)
                 classvariants.update(mapMap.keys())
             else:
                 console.warn("qx.core.Environment call with alien first argument (%s:%s)" % (self.id, variantNode.get("line", False)))
     return classvariants