public void Analyze(ClassDeclarationSyntax classDeclarationSyntax, ClassModel classModel) { List <MethodDeclarationSyntax> methodDeclarationSyntaxes = classDeclarationSyntax .DescendantNodes() .OfType <MethodDeclarationSyntax>() .ToList(); foreach (MethodDeclarationSyntax methodDeclarationSyntax in methodDeclarationSyntaxes) { MethodModel methodModel = new MethodModel(); methodModel.Name = methodDeclarationSyntax.Identifier.Text; IMethodSymbol methodSymbol = SemanticModel.GetDeclaredSymbol(methodDeclarationSyntax) as IMethodSymbol; if (methodSymbol != null && !methodSymbol.IsAbstract) { ControlFlowGraph controlFlowGraph = ControlFlowGraph .Create(methodDeclarationSyntax, SemanticModel, CancellationToken.None); int numberOfBlocks = controlFlowGraph.Blocks.Length; int numberOfEdges = 0; foreach (BasicBlock basicBlock in controlFlowGraph.Blocks) { if (basicBlock.ConditionalSuccessor != null) { numberOfEdges++; } if (basicBlock.FallThroughSuccessor != null) { numberOfEdges++; } } methodModel.CyclomaticComplexity = numberOfEdges - numberOfBlocks + 2; } methodModel.Fqn = methodSymbol.ToString(); methodModel.Static = methodSymbol.IsStatic; methodModel.Abstract = methodSymbol.IsAbstract; methodModel.Sealed = methodSymbol.IsSealed; methodModel.Async = methodSymbol.IsAsync; methodModel.Override = methodSymbol.IsOverride; methodModel.Virtual = methodSymbol.IsVirtual; methodModel.Extern = methodSymbol.IsExtern; methodModel.Accessibility = methodSymbol.DeclaredAccessibility.ToString(); methodModel.ReturnType = methodSymbol.ReturnType.ToString(); methodModel.FirstLineNumber = methodDeclarationSyntax.GetLocation().GetLineSpan().StartLinePosition.Line + 1; methodModel.LastLineNumber = methodDeclarationSyntax.GetLocation().GetLineSpan().EndLinePosition.Line + 1; _invocationAnalyzer.Analyze(methodDeclarationSyntax, methodModel); _parameterAnalyzer.Analyze(methodDeclarationSyntax, methodModel); classModel.Methods.Add(methodModel); } }
private List <ConstructorModel> FindContructors(SyntaxNode syntaxNode) { List <ConstructorDeclarationSyntax> constructorDeclarationSyntaxes = syntaxNode .DescendantNodes() .OfType <ConstructorDeclarationSyntax>() .ToList(); List <ConstructorModel> result = new List <ConstructorModel>(); foreach (ConstructorDeclarationSyntax constructorDeclarationSyntax in constructorDeclarationSyntaxes) { ConstructorModel constructorModel = new ConstructorModel(); constructorModel.Name = constructorDeclarationSyntax.Identifier.Text; IMethodSymbol methodSymbol = SemanticModel.GetDeclaredSymbol(constructorDeclarationSyntax) as IMethodSymbol; constructorModel.Fqn = methodSymbol.ToString(); constructorModel.Static = methodSymbol.IsStatic; constructorModel.Abstract = methodSymbol.IsAbstract; constructorModel.Sealed = methodSymbol.IsSealed; constructorModel.Async = methodSymbol.IsAsync; constructorModel.Override = methodSymbol.IsOverride; constructorModel.Virtual = methodSymbol.IsVirtual; constructorModel.Accessibility = methodSymbol.DeclaredAccessibility.ToString(); constructorModel.FirstLineNumber = constructorDeclarationSyntax.GetLocation().GetLineSpan().StartLinePosition.Line + 1; constructorModel.LastLineNumber = constructorDeclarationSyntax.GetLocation().GetLineSpan().EndLinePosition.Line + 1; _invocationAnalyzer.Analyze(constructorDeclarationSyntax, constructorModel); _parameterAnalyzer.Analyze(constructorDeclarationSyntax, constructorModel); result.Add(constructorModel); } return(result); }