Ejemplo n.º 1
0
        private void AggregateSourceSymbols(InputFile inputFile)
        {
            var sourceFile = SourceFile.CreateFromInputFile(inputFile);

            sourceFile.ChangedSinceLastCommit = _changedFiles.Contains(inputFile.RelativePath);
            var tree     = GetSyntaxTree(inputFile);
            var root     = (CompilationUnitSyntax)tree.GetRoot();
            var semantic = _compilation.GetSemanticModel(tree);


            var namespaceName = FindNamespace(root);

            if (namespaceName == null)
            {
                return;                        //invalid source file! (ie. AssemblyInfo)
            }
            if (!_namespacesByName.ContainsKey(namespaceName))
            {
                _namespacesByName.Add(namespaceName, new SourceNamespace {
                    FullName = namespaceName
                });
            }

            var namespaceObj = _namespacesByName[namespaceName];

            namespaceObj.Files.Add(sourceFile);

            var classes = FindClasses(root).Select(className => new SourceClass {
                Name = className, File = sourceFile
            }).ToList();
            var methods = FindMethods(root).Select(method => {
                var semanticName = GetMethodDeclarationSymbolName(semantic, method);
                var name         = $"{method.ReturnType} {method.Identifier}{method.ParameterList}";
                int compl        = CalculateMethodCyclomaticComplexity(method);

                return(new SourceMethod {
                    Name = name, ParentFile = sourceFile, SemanticName = semanticName,
                    CyclomaticComplexity = compl
                });
            }).ToList();

            sourceFile.Namespace = namespaceObj;
            sourceFile.Classes   = classes;
            sourceFile.Methods   = methods;

            _filesByIdentifier.Add(sourceFile.UniqueIdentifier, sourceFile);
            foreach (var sourceMethod in methods)
            {
                _methodsBySemanticName.Add(sourceMethod.SemanticName, sourceMethod);
            }

            foreach (var sourceClass in classes)
            {
                if (_classesByName.ContainsKey(sourceClass.Name))
                {
                    continue;
                }
                _classesByName.Add(sourceClass.Name, sourceClass);
            }
        }