protected override Task<EvaluationResult> EvaluateImpl(SyntaxNode node, SemanticModel semanticModel, Solution solution) { if (IsEmptyFinalizer(node, semanticModel)) { var result = new EvaluationResult { Snippet = node.ToFullString() }; return Task.FromResult(result); } return Task.FromResult<EvaluationResult>(null); }
private static ModelNode CreateProjectNode( IProjectMetric projectMetric, IProjectMetric[] projectMetrics, EvaluationResult[] evaluationResults) { var children = projectMetric.Dependencies.Select( y => { var couplings = projectMetric.NamespaceMetrics.SelectMany(x => x.ClassCouplings) .Where(x => x.Assembly == y.GetFileNameWithoutExtension()) .Select(x => new ModelNode(x.Namespace, NodeKind.Namespace, CodeQuality.Good, 0, 100, 0)) .Cast<IModelNode>() .ToList(); return new ModelNode( y.GetFileNameWithoutExtension(), NodeKind.Assembly, CodeQuality.Good, 0, 100, 0, couplings); }) .Concat( projectMetric.NamespaceMetrics.Select( namespaceMetric => CreateNamespaceNode( namespaceMetric, projectMetrics, evaluationResults.Where(r => r.Namespace == namespaceMetric.Name)))) .Merge() .ToList(); return new ModelNode( projectMetric.Name, NodeKind.Assembly, evaluationResults.Where(x => x.ProjectName == projectMetric.Name).GetQuality(), projectMetric.LinesOfCode, projectMetric.MaintainabilityIndex, projectMetric.CyclomaticComplexity, children); }
protected override Task<EvaluationResult> EvaluateImpl(SyntaxNode node, SemanticModel semanticModel, Solution solution) { //// TODO: For this to be correct, we need flow analysis to determine if a given method //// is actually invoked inside the current constructor. A method may be assigned to a //// delegate which can be called inside or outside the constructor. A method may also //// be called from within a lambda which is called inside or outside the constructor. //// Currently, FxCop does not produce a warning if a virtual method is called indirectly //// through a delegate or through a lambda. var constructor = (ConstructorDeclarationSyntax)node; var constructorSymbol = semanticModel.GetDeclaredSymbol(constructor); var containingType = constructorSymbol.ContainingType; if ( constructor.Body.DescendantNodes() .Where(x => x.Kind() == SyntaxKind.InvocationExpression) .Any(x => CallVirtualMethod((InvocationExpressionSyntax)x, semanticModel, containingType))) { var result = new EvaluationResult { Snippet = node.ToFullString(), LinesOfCodeAffected = GetLinesOfCode(node) }; return Task.FromResult(result); } return Task.FromResult<EvaluationResult>(null); }
protected override EvaluationResult EvaluateImpl(SyntaxNode node) { var catchClause = (CatchClauseSyntax)node; var catchesException = catchClause .DescendantNodesAndSelf() .OfType<CatchDeclarationSyntax>() .SelectMany(x => x.DescendantNodes()) .OfType<IdentifierNameSyntax>() .Any(x => x.Identifier.ValueText == "Exception"); var throwsSomething = catchClause .DescendantNodes() .OfType<ThrowStatementSyntax>() .Any(x => x.Expression != null); if (catchesException && throwsSomething) { var result = new EvaluationResult { Snippet = catchClause.ToFullString() }; return result; } return null; }