Exemple #1
0
 def __init__(self, classDict, scope, typedefDict):
     self.classDict = classDict
     self.scope = scope
     self.typedefDict = typedefDict
     self.classCollector = ClassCollector(self.classDict, self.typedefDict)
     self.log = Logger().get_instance(self)
Exemple #2
0
	def __init__(self, classDict, scope, typedefDict):
		self.classDict = classDict
		self.scope = scope
		self.typedefDict = typedefDict
		self.classCollector = ClassCollector(self.classDict, self.typedefDict)
		self.log = Logger().get_instance(self)
Exemple #3
0
class ClassSelector:
    ##
    # @param classDict: a complete class dictionary
    # @param inclueDict: a (non-transitive) include dictionary
    # @param namespaceDict: a dictionary of namespace declarations:
    # @param namespaceUsageChecker: a NamespaceCountainmentChecker for verifying
    # which namespace usages are surrounding a line in a source file.,
    # con
    ##
    def __init__(self, classDict, scope, typedefDict):
        self.classDict = classDict
        self.scope = scope
        self.typedefDict = typedefDict
        self.classCollector = ClassCollector(self.classDict, self.typedefDict)
        self.log = Logger().get_instance(self)

    def translateAsTypeDef(self, qualifiedClassName):
        translatedName = qualifiedClassName

        if self.typedefDict.containsAlias(qualifiedClassName):
            translatedName = self.typedefDict.getBaseType(qualifiedClassName)

        return translatedName

    ##
    # Gathers a list of references to classes that potentially correspond
    # to the given characteristics.
    #
    # @param qualifiedClassName: the qualified name of the classes to select (possible qualified)
    # @param referencingSourceFile: the name of the file from which the reference to className was made
    # @param referencingLineNr: the line number at which the reference is made from the referencingSourceFile
    #
    # @returns a list of  [sourceFile, lineNr] elements
    ##
    def selectClasses(self, qualifiedClassName, referencingSourceFile,
                      referencingLineNr):
        relevantClassReferences = []

        translatedName = self.translateAsTypeDef(qualifiedClassName)

        parentNamespaceName = getParentNamespaceName(qualifiedClassName)
        nonQualifiedClassName = getNonQualifiedName(qualifiedClassName)

        #namespacesUsed = self.scope.getUsedNamespaces(parentNamespaceName, referencingSourceFile, referencingLineNr)
        namespacesUsed = self.scope.getUsedNamespaces(referencingSourceFile,
                                                      referencingLineNr)

        if parentNamespaceName != "":
            index = 0
            while index < len(namespacesUsed):
                usedNamespace = namespacesUsed[index]
                if usedNamespace == "":
                    usedNamespace = parentNamespaceName
                else:
                    usedNamespace += "::" + parentNamespaceName
                namespacesUsed[index] = usedNamespace
                index += 1

        classReferences = self.classCollector.collectClassReferences(
            nonQualifiedClassName, namespacesUsed)

        # Which classes are reachable through (transitive) #includes?
        #print qualifiedClassName
        transIncludeDict = self.scope.getTransitiveIncludeDict()
        transitiveIncludedFiles = transIncludeDict.getTransitiveIncludedFiles(
            referencingSourceFile)
        for classReference in classReferences:
            sourceFile = classReference.getSourceFile()
            #print sourceFile, " in ", transitiveIncludedFiles
            #selectSourceFileMatches(sourceFile,transitiveIncludedFiles)
            if sourceFile in transitiveIncludedFiles:
                if not (classReference in relevantClassReferences):
                    relevantClassReferences.append(classReference)
            else:
                conf = transIncludeDict.trySymlinkPath(
                    sourceFile, transitiveIncludedFiles)
                if conf > 1 and not (classReference
                                     in relevantClassReferences):
                    relevantClassReferences.append(classReference)

        sl = SourceLocation(referencingSourceFile, referencingLineNr,
                            referencingLineNr)

        # TODO: we do an 'or' here, but we should check that (i) it is reachable
        # via include, and (ii) the namespacing is also ok

        # Which classes are reachable through namespacing.
        usedClassesLocations = self.scope.getTransitiveUsedClassesLocationsUsingLoc(
            sl)
        for usedClassLoc in usedClassesLocations:
            # convert to ClassReferenceEntity
            clsName = usedClassLoc.getNonQualifiedName()
            nspName = utils.spliceLastPackageName(usedClassLoc.getName(),
                                                  utils.qualSeparator)
            sLoc = usedClassLoc.getSourceLocations()[0]

            cre = ClassReferenceEntity(clsName, nspName, sLoc.sourceFile,
                                       sLoc.start, "")
            if clsName == qualifiedClassName and not cre in relevantClassReferences:
                relevantClassReferences.append(cre)

        return relevantClassReferences
Exemple #4
0
class ClassSelector:
	##
	# @param classDict: a complete class dictionary
	# @param inclueDict: a (non-transitive) include dictionary
	# @param namespaceDict: a dictionary of namespace declarations:
	# @param namespaceUsageChecker: a NamespaceCountainmentChecker for verifying
	# which namespace usages are surrounding a line in a source file.,
	# con
	##
	def __init__(self, classDict, scope, typedefDict):
		self.classDict = classDict
		self.scope = scope
		self.typedefDict = typedefDict
		self.classCollector = ClassCollector(self.classDict, self.typedefDict)
		self.log = Logger().get_instance(self)

	def translateAsTypeDef(self, qualifiedClassName):
		translatedName = qualifiedClassName

		if self.typedefDict.containsAlias(qualifiedClassName):
			translatedName = self.typedefDict.getBaseType(qualifiedClassName)

		return translatedName

	##
	# Gathers a list of references to classes that potentially correspond
	# to the given characteristics.
	#
	# @param qualifiedClassName: the qualified name of the classes to select (possible qualified)
	# @param referencingSourceFile: the name of the file from which the reference to className was made
	# @param referencingLineNr: the line number at which the reference is made from the referencingSourceFile
	#
	# @returns a list of  [sourceFile, lineNr] elements
	##
	def selectClasses(self, qualifiedClassName, referencingSourceFile, referencingLineNr):
		relevantClassReferences = []

		translatedName = self.translateAsTypeDef(qualifiedClassName)

		parentNamespaceName = getParentNamespaceName(qualifiedClassName)
		nonQualifiedClassName = getNonQualifiedName(qualifiedClassName)

		#namespacesUsed = self.scope.getUsedNamespaces(parentNamespaceName, referencingSourceFile, referencingLineNr)
		namespacesUsed = self.scope.getUsedNamespaces(referencingSourceFile, referencingLineNr)

		if parentNamespaceName != "":
			index = 0
			while index < len(namespacesUsed):
				usedNamespace = namespacesUsed[index]
				if usedNamespace == "":
					usedNamespace = parentNamespaceName
				else:
					usedNamespace += "::" + parentNamespaceName
				namespacesUsed[index] = usedNamespace
				index += 1

		classReferences = self.classCollector.collectClassReferences(nonQualifiedClassName, namespacesUsed)

		# Which classes are reachable through (transitive) #includes?
		#print qualifiedClassName
		transIncludeDict = self.scope.getTransitiveIncludeDict()
		transitiveIncludedFiles=transIncludeDict.getTransitiveIncludedFiles(referencingSourceFile)
		for classReference in classReferences:
			sourceFile = classReference.getSourceFile()
			#print sourceFile, " in ", transitiveIncludedFiles
			#selectSourceFileMatches(sourceFile,transitiveIncludedFiles)
			if sourceFile in transitiveIncludedFiles:
				if not(classReference in relevantClassReferences):
					relevantClassReferences.append(classReference)
			else:
				conf = transIncludeDict.trySymlinkPath(sourceFile, transitiveIncludedFiles)
				if conf > 1 and not(classReference in relevantClassReferences):
					relevantClassReferences.append(classReference)

		sl = SourceLocation(referencingSourceFile, referencingLineNr, referencingLineNr)

		# TODO: we do an 'or' here, but we should check that (i) it is reachable
		# via include, and (ii) the namespacing is also ok

		# Which classes are reachable through namespacing.
		usedClassesLocations = self.scope.getTransitiveUsedClassesLocationsUsingLoc(sl)
		for usedClassLoc in usedClassesLocations:
			# convert to ClassReferenceEntity
			clsName = usedClassLoc.getNonQualifiedName()
			nspName = utils.spliceLastPackageName(usedClassLoc.getName(),utils.qualSeparator)
			sLoc = usedClassLoc.getSourceLocations()[0]

			cre = ClassReferenceEntity(clsName, nspName, sLoc.sourceFile, sLoc.start, "")
			if clsName == qualifiedClassName and not cre in relevantClassReferences:
				relevantClassReferences.append(cre)

		return relevantClassReferences