private static void AnalyzeCall(SyntaxNodeAnalysisContext context) { var call = context.Node as InvocationExpressionSyntax; if (call == null) { return; } var methodSymbol = SymbolHelpers.GetCalledMethodSymbol(call, context); if (methodSymbol == null) { return; } var methodFullName = string.Concat(methodSymbol.ContainingType.GetFullName(), ".", methodSymbol.GetDecoratedName()); var descriptor = DiagnosticsMap.GetValueOrDefault(methodFullName); if (descriptor == null) { return; } if (call.Parent is ExpressionStatementSyntax) { var diagnostic = Diagnostic.Create(descriptor, call.GetLocation(), call.ToString()); context.ReportDiagnostic(diagnostic); } }
private void AnalyzeNode(SyntaxNodeAnalysisContext context) { var memberAccess = context.Node as MemberAccessExpressionSyntax; if (memberAccess == null) { return; } var propertySymbol = SymbolHelpers.GetAccessedPropertySymbol(memberAccess, context); if (propertySymbol == null) { return; } var propertyFullName = string.Concat(propertySymbol.ContainingType.GetFullName(), ".", propertySymbol.Name); if (!this.IsSupportedArgumentConstraintProperty(propertyFullName)) { return; } var completeConstraint = GetCompleteConstraint(context.Node); this.AnalyzeArgumentConstraintCore(context, completeConstraint); }
private static void AnalyzeCall(SyntaxNodeAnalysisContext context) { if (!(context.Node is InvocationExpressionSyntax call) || call.ArgumentList.Arguments.Count != 1 || GetTypeName(context, call.ArgumentList.Arguments[0]) != "FakeItEasy.Repeated") { return; } // Abort if the called method isn't MustHaveHappened or if the referenced version of // FakeItEasy doesn't support the new assertion API, as evidenced by the absence of the // MustHaveHappenedANumberOfTimesMatching method. var calledMethod = SymbolHelpers.GetCalledMethodSymbol(call, context); if (calledMethod.GetFullName() != "FakeItEasy.Configuration.IAssertConfiguration.MustHaveHappened" || !calledMethod.ContainingType.MemberNames.Contains("MustHaveHappenedANumberOfTimesMatching")) { return; } // call is an InvocationExpression whose expression will be a MemberAccessExpression // corresponding to the MustHaveHappened call. The text "MustHaveHappened" can be found // as that node's Name. var memberAccessNode = (MemberAccessExpressionSyntax)call.Expression; var mustHaveHappenedNode = memberAccessNode.Name; var descriptor = DiagnosticDefinitions.RepeatedAssertion; var location = Location.Create(call.SyntaxTree, TextSpan.FromBounds(mustHaveHappenedNode.SpanStart, call.ArgumentList.Span.End)); context.ReportDiagnostic(Diagnostic.Create(descriptor, location)); }
private static bool TryGetNameAndParameters( SyntaxNodeAnalysisContext context, SyntaxNode node, [NotNullWhen(true)] out string?methodOrIndexerName, [NotNullWhen(true)] out IReadOnlyList <IParameterSymbol>?parameters) { methodOrIndexerName = null; parameters = null; switch (node) { case InvocationExpressionSyntax invocation: { var method = SymbolHelpers.GetCalledMethodSymbol(invocation, context); if (method is null) { #if VISUAL_BASIC var indexer = SymbolHelpers.GetAccessedIndexerSymbol(invocation, context); if (indexer is null) { return(false); } methodOrIndexerName = indexer.Name; parameters = indexer.Parameters; return(true); #else return(false); #endif } parameters = method.Parameters; methodOrIndexerName = method.GetDecoratedName(); return(true); } #if CSHARP case ElementAccessExpressionSyntax elementAccess: { var indexer = SymbolHelpers.GetAccessedIndexerSymbol(elementAccess, context); if (indexer is null) { return(false); } methodOrIndexerName = indexer.Name; parameters = indexer.Parameters; return(true); } #endif default: return(false); } }
private static bool IsSetupInvocation(SyntaxNodeAnalysisContext context, InvocationExpressionSyntax parent) { var methodSymbol = SymbolHelpers.GetCalledMethodSymbol(parent, context); if (methodSymbol == null) { return(false); } var methodFullName = string.Concat(methodSymbol.ContainingType.GetFullName(), ".", methodSymbol.GetDecoratedName()); return(DiagnosticsMap.Contains(methodFullName)); }
private static bool SupportsArgumentConstraints(InvocationExpressionSyntax invocation, SyntaxNodeAnalysisContext context) { var methodSymbol = SymbolHelpers.GetCalledMethodSymbol(invocation, context, true); if (methodSymbol == null) { return(false); } if (MethodsSupportingArgumentConstraints.Contains(methodSymbol.GetFullName())) { return(methodSymbol.Parameters.Length == 1 && (methodSymbol.Parameters[0].Type as INamedTypeSymbol)?.GetFullName() == "System.Linq.Expressions.Expression`1"); } return(false); }
private static void AnalyzeCall(SyntaxNodeAnalysisContext context) { var call = context.Node as InvocationExpressionSyntax; if (call == null) { return; } var methodSymbol = SymbolHelpers.GetCalledMethodSymbol(call, context); if (methodSymbol == null || !CallSpecMethods.Contains(methodSymbol.GetFullName())) { return; } if (call.Parent is ExpressionStatementSyntax) { var descriptor = DiagnosticDefinitions.UnusedCallSpecification; var diagnostic = Diagnostic.Create(descriptor, call.GetLocation(), call.ToString()); context.ReportDiagnostic(diagnostic); } }
private static bool IsSetupInvocation(SyntaxNodeAnalysisContext context, InvocationExpressionSyntax parent) { var methodSymbol = SymbolHelpers.GetCalledMethodSymbol(parent, context); return(methodSymbol is object && CallSpecMethods.Contains(methodSymbol.GetFullName())); }