Skip to content

Commit

Permalink
[GH-153] - simplifying SubstituteAnalyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
tpodolak committed Dec 20, 2020
1 parent 186b2eb commit e598b8c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace NSubstitute.Analyzers.CSharp.DiagnosticAnalyzers
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
internal sealed class SubstituteAnalyzer : AbstractSubstituteAnalyzer<SyntaxKind, InvocationExpressionSyntax, ExpressionSyntax, ArgumentSyntax>
internal sealed class SubstituteAnalyzer : AbstractSubstituteAnalyzer<SyntaxKind, InvocationExpressionSyntax>
{
public SubstituteAnalyzer()
: base(NSubstitute.Analyzers.CSharp.DiagnosticDescriptorsProvider.Instance, SubstituteProxyAnalysis.Instance, SubstituteConstructorAnalysis.Instance, SubstituteConstructorMatcher.Instance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@

namespace NSubstitute.Analyzers.Shared.DiagnosticAnalyzers
{
internal abstract class AbstractSubstituteAnalyzer<TSyntaxKind, TInvocationExpressionSyntax, TExpressionSyntax, TArgumentSyntax> : AbstractDiagnosticAnalyzer
internal abstract class AbstractSubstituteAnalyzer<TSyntaxKind, TInvocationExpressionSyntax> : AbstractDiagnosticAnalyzer
where TSyntaxKind : struct
where TInvocationExpressionSyntax : SyntaxNode
where TExpressionSyntax : SyntaxNode
where TArgumentSyntax : SyntaxNode
{
private readonly ISubstituteProxyAnalysis<TInvocationExpressionSyntax> _substituteProxyAnalysis;
private readonly ISubstituteConstructorAnalysis<TInvocationExpressionSyntax> _substituteConstructorAnalysis;
Expand Down Expand Up @@ -211,11 +209,10 @@ private bool AnalyzeConstructorParametersCount(SubstituteContext<TInvocationExpr

if (constructorContext.PossibleConstructors != null && constructorContext.PossibleConstructors.Any() == false)
{
var symbol = substituteContext.SyntaxNodeAnalysisContext.SemanticModel.GetSymbolInfo(substituteContext.InvocationExpression);
var diagnostic = Diagnostic.Create(
DiagnosticDescriptorsProvider.SubstituteForConstructorParametersMismatch,
substituteContext.InvocationExpression.GetLocation(),
symbol.Symbol.ToMinimalMethodString(substituteContext.SyntaxNodeAnalysisContext.SemanticModel),
substituteContext.MethodSymbol.ToMinimalMethodString(substituteContext.SyntaxNodeAnalysisContext.SemanticModel),
constructorContext.ConstructorType);

substituteContext.SyntaxNodeAnalysisContext.ReportDiagnostic(diagnostic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace NSubstitute.Analyzers.VisualBasic.DiagnosticAnalyzers
{
[DiagnosticAnalyzer(LanguageNames.VisualBasic)]
internal sealed class SubstituteAnalyzer : AbstractSubstituteAnalyzer<SyntaxKind, InvocationExpressionSyntax, ExpressionSyntax, ArgumentSyntax>
internal sealed class SubstituteAnalyzer : AbstractSubstituteAnalyzer<SyntaxKind, InvocationExpressionSyntax>
{
protected override SyntaxKind InvocationExpressionKind { get; } = SyntaxKind.InvocationExpression;

Expand Down

0 comments on commit e598b8c

Please sign in to comment.