Пример #1
0
def parseAttributes(attributeDBD, classSelector, attributeDictFiller, namespaceContainmentChecker):

    for line in open(attributeDBD, 'r'):
        attribute = AttributeEntity(line)
        attrRef = attribute.getReference()

        sourceLoc = SourceLocation(attrRef.getSourceFile(),\
                                        attrRef.getLineNr(),\
                                        attrRef.getLineNr())
        namespaceName = namespaceContainmentChecker.getSurroundingNamespaceName(sourceLoc)

        attribute.setNamespaceName(namespaceName)
        attrRef = attribute.getReference()

        parentRef = attribute.getParentReference()
        potentialTargets = classSelector.selectClasses(parentRef.getReferencedName(), attrRef.getSourceFile(), attrRef.getLineNr())
        nrOfTargets = len(potentialTargets)

        if ( nrOfTargets > 1 ):
            log.warn("Attribute-owner-problem: ",nrOfTargets," classes with name \"" + parentRef.getReferencedName() + ".")
            continue # ignore containment link since we can't pinpoint the target.
        elif ( nrOfTargets == 0 ):
            log.warn("Attribute-owner-problem: no class with name \"" + parentRef.getReferencedName() + "\" known from file ",attrRef.getSourceFile(),"@",attrRef.getLineNr(),".")
            # seems to happen for inner-classes, e.g. owner named SpreadsheetApp::Group
            continue # ignore containment link since we can't find the declaration of the owner.
        else:
            # get the data on the sole left-over attribute-owner
            classReference = potentialTargets[0]
            parentRef.setSourceFile(classReference.getSourceFile())
            parentRef.setLineNr(classReference.getLineNr())
            attribute.ownerTemplateParameters=classReference.getTemplateParameters()

        # resolve the attribute type
        typeRef = attribute.getTypeReference()

        if not(typeRef.isPrimitive()):
            potentialTargets = classSelector.selectClasses(typeRef.getCleanName(),\
                                                     attrRef.getSourceFile(), attrRef.getLineNr())
            nrOfTargets = len(potentialTargets)

            if ( nrOfTargets > 1 ):
                pass
                #log.warn("Attribute-type-problem: ",nrOfTargets," classes with name \""\
                #         + typeRef.getCleanName() + ".")
                typeRef.setResolvedName(typeRef.getCleanName())
            elif ( nrOfTargets == 0 ):
                pass
                #log.warn("Attribute-type-problem: no class with name \"" \
                #        + typeRef.getCleanName() + "\" known from file ",\
                #        attrRef.getSourceFile(),"@",attrRef.getLineNr(),".")
                typeRef.setResolvedName(typeRef.getCleanName())
            else:
                # get the data on the sole left-over method-type
                classReference = potentialTargets[0]

                typeRef.setResolvedName(classReference.getUniqueName())
                typeRef.setSourceFile(classReference.getSourceFile())
                typeRef.setLineNr(classReference.getLineNr())

                # TODO: fill in the attribute type template parameters
        else:
            typeRef.setResolvedName(typeRef.getCleanName())
        
        attrRef = attribute.getReference()

        # TODO: also put the attribute type in the attribute dictionary, so that it can be passed
        # on to the access-dictionary when accesses are resolved. That way, the resolution of
        # further accesses invocations

        aCommandList = RuleChecker.checkAttributeEntity(attribute)
        RuleChecker.generateAttributeInfo(aCommandList, attribute)
        attributeDictFiller.add(attribute)