-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GH-1] - first draft of SubstituteAnalyzer adjusted to dev branch cha…
…nges
- Loading branch information
Showing
13 changed files
with
176 additions
and
31 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
src/NSubstitute.Analyzers.CSharp/DiagnosticAnalyzers/SubstituteAnalysis.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using NSubstitute.Analyzers.CSharp.Extensions; | ||
using NSubstitute.Analyzers.Shared.DiagnosticAnalyzers; | ||
|
||
namespace NSubstitute.Analyzers.CSharp.DiagnosticAnalyzers | ||
{ | ||
public class SubstituteAnalysis : AbstractSubstituteAnalysis<InvocationExpressionSyntax> | ||
{ | ||
protected override IList<SyntaxNode> GetInvocationArguments(InvocationExpressionSyntax invocationExpression) | ||
{ | ||
return invocationExpression.ArgumentList.Arguments.Select<ArgumentSyntax, SyntaxNode>(syntax => syntax).ToList(); | ||
} | ||
|
||
// TODO get rid of casts | ||
protected override IList<SyntaxNode> GetParameterExpressionsFromArrayArgument(SyntaxNode syntaxNode) | ||
{ | ||
return ((ArgumentSyntax)syntaxNode).Expression.GetParameterExpressionsFromArrayArgument() | ||
.Select<ExpressionSyntax, SyntaxNode>(syntax => syntax).ToList(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/NSubstitute.Analyzers.CSharp/DiagnosticAnalyzers/SubstituteConstructorMatcher.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using NSubstitute.Analyzers.Shared.DiagnosticAnalyzers; | ||
|
||
namespace NSubstitute.Analyzers.CSharp.DiagnosticAnalyzers | ||
{ | ||
public class SubstituteConstructorMatcher : AbstractSubstituteConstructorMatcher | ||
{ | ||
protected override bool ClasifyConversion(Compilation compilation, ITypeSymbol source, ITypeSymbol destination) | ||
{ | ||
var conversion = compilation.ClassifyConversion(source, destination); | ||
|
||
return conversion.Exists && conversion.IsImplicit; | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/NSubstitute.Analyzers.CSharp/Extensions/ExpressionSyntaxExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
|
||
namespace NSubstitute.Analyzers.CSharp.Extensions | ||
{ | ||
public static class ExpressionSyntaxExtensions | ||
{ | ||
private static readonly IList<ExpressionSyntax> EmptyExpressionList = new ExpressionSyntax[0]; | ||
|
||
public static IList<ExpressionSyntax> GetParameterExpressionsFromArrayArgument(this ExpressionSyntax expression) | ||
{ | ||
InitializerExpressionSyntax initializer = null; | ||
switch (expression.Kind()) | ||
{ | ||
case SyntaxKind.ArrayCreationExpression: | ||
initializer = ((ArrayCreationExpressionSyntax)expression).Initializer; | ||
break; | ||
case SyntaxKind.ImplicitArrayCreationExpression: | ||
initializer = ((ImplicitArrayCreationExpressionSyntax)expression).Initializer; | ||
break; | ||
default: | ||
return null; | ||
} | ||
|
||
if (initializer == null) | ||
{ | ||
return EmptyExpressionList; | ||
} | ||
|
||
return initializer.Expressions.ToList(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/NSubstitute.Analyzers.VisualBasic/DiagnosticAnalyzers/SubstituteAnalysis.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.VisualBasic.Syntax; | ||
using NSubstitute.Analyzers.Shared.DiagnosticAnalyzers; | ||
using NSubstitute.Analyzers.VisualBasic.Extensions; | ||
|
||
namespace NSubstitute.Analyzers.VisualBasic.DiagnosticAnalyzers | ||
{ | ||
public class SubstituteAnalysis : AbstractSubstituteAnalysis<InvocationExpressionSyntax> | ||
{ | ||
protected override IList<SyntaxNode> GetInvocationArguments(InvocationExpressionSyntax invocationExpression) | ||
{ | ||
return invocationExpression.ArgumentList.Arguments.Select<ArgumentSyntax, SyntaxNode>(syntax => syntax).ToList(); | ||
} | ||
|
||
// TODO get rid of casts | ||
protected override IList<SyntaxNode> GetParameterExpressionsFromArrayArgument(SyntaxNode syntaxNode) | ||
{ | ||
return ((ArgumentSyntax)syntaxNode).GetExpression().GetParameterExpressionsFromArrayArgument() | ||
.Select<ExpressionSyntax, SyntaxNode>(syntax => syntax).ToList(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/NSubstitute.Analyzers.VisualBasic/DiagnosticAnalyzers/SubstituteConstructorMatcher.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.VisualBasic; | ||
using NSubstitute.Analyzers.Shared.DiagnosticAnalyzers; | ||
|
||
namespace NSubstitute.Analyzers.VisualBasic.DiagnosticAnalyzers | ||
{ | ||
public class SubstituteConstructorMatcher : AbstractSubstituteConstructorMatcher | ||
{ | ||
protected override bool ClasifyConversion(Compilation compilation, ITypeSymbol source, ITypeSymbol destination) | ||
{ | ||
var conversion = compilation.ClassifyConversion(source, destination); | ||
|
||
return conversion.Exists && conversion.IsNarrowing; | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/NSubstitute.Analyzers.VisualBasic/Extensions/ExpressionSyntaxExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Microsoft.CodeAnalysis.VisualBasic; | ||
using Microsoft.CodeAnalysis.VisualBasic.Syntax; | ||
|
||
namespace NSubstitute.Analyzers.VisualBasic.Extensions | ||
{ | ||
public static class ExpressionSyntaxExtensions | ||
{ | ||
public static IList<ExpressionSyntax> GetParameterExpressionsFromArrayArgument(this ExpressionSyntax expression) | ||
{ | ||
switch (expression.Kind()) | ||
{ | ||
case SyntaxKind.ArrayCreationExpression: | ||
var initializer = ((ArrayCreationExpressionSyntax)expression).Initializer; | ||
return initializer.Initializers.ToList(); | ||
case SyntaxKind.CollectionInitializer: | ||
return ((CollectionInitializerSyntax)expression).Initializers.ToList(); | ||
default: | ||
return null; | ||
} | ||
} | ||
} | ||
} |