Skip to content

Commit

Permalink
coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mary-georgiou-sonarsource committed Jun 7, 2024
1 parent dc1dc0c commit f696d63
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System.Xml.Linq;
using SonarAnalyzer.Json.Parsing;
using SonarAnalyzer.SymbolicExecution.Roslyn.OperationProcessors;

namespace SonarAnalyzer.Rules;

public abstract class ArrayPassedAsParamsBase<TSyntaxKind, TArgumentNode> : SonarDiagnosticAnalyzer<TSyntaxKind>
Expand All @@ -38,20 +42,16 @@ protected sealed override void Initialize(SonarAnalysisContext context) =>
context.RegisterNodeAction(Language.GeneratedCodeRecognizer, c =>
{
if (LastArgumentIfArrayCreation(c.Node) is { } lastArgument
&& c.SemanticModel.GetSymbolInfo(c.Node).Symbol is IMethodSymbol methodSymbol
&& ParameterSymbol(methodSymbol, c.Node, lastArgument) is { IsParams: true } param
&& !IsObjectOrArrayType(c.Node, methodSymbol, param, c.SemanticModel)
&& !IsJaggedArrayParam(param))
&& c.SemanticModel.GetSymbolInfo(c.Node).Symbol is IMethodSymbol methodSymbol
&& Language.MethodParameterLookup(c.Node, methodSymbol).TryGetSymbol(lastArgument, out var param)
&& param is { IsParams: true }
&& !IsObjectOrArrayType(c.Node, methodSymbol, param, c.SemanticModel)
&& !IsJaggedArrayParam(param))
{
c.ReportIssue(Rule, lastArgument.GetLocation());
}
}, ExpressionKinds);

private IParameterSymbol ParameterSymbol(IMethodSymbol symbol, SyntaxNode invocation, TArgumentNode argument) =>
Language.MethodParameterLookup(invocation, symbol).TryGetSymbol(argument, out var param)
? param
: null;

private static bool IsJaggedArrayParam(IParameterSymbol param) =>
param.Type is IArrayTypeSymbol { ElementType: IArrayTypeSymbol };

Expand Down

0 comments on commit f696d63

Please sign in to comment.