Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for the CollectionExpression syntax kind early in UseSearchValuesAnalyzer #7279

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information.

using System.Collections.Generic;
using Analyzer.Utilities.Lightup;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
Expand Down Expand Up @@ -112,7 +113,7 @@ internal static bool IsConstantByteOrCharArrayCreationExpression(SemanticModel s
return true;
}
}
else
else if (expression.IsKind(SyntaxKindEx.CollectionExpression))
{
return
semanticModel.GetOperation(expression) is { } operation &&
Expand Down Expand Up @@ -165,12 +166,9 @@ expression is LiteralExpressionSyntax characterLiteral &&

private static bool IsUtf8StringLiteralExpression(ExpressionSyntax expression, out int length)
{
const SyntaxKind Utf8StringLiteralExpression = (SyntaxKind)8756;
const SyntaxKind Utf8StringLiteralToken = (SyntaxKind)8520;

if (expression.IsKind(Utf8StringLiteralExpression) &&
if (expression.IsKind(SyntaxKindEx.Utf8StringLiteralExpression) &&
expression is LiteralExpressionSyntax literal &&
literal.Token.IsKind(Utf8StringLiteralToken) &&
literal.Token.IsKind(SyntaxKindEx.Utf8StringLiteralToken) &&
literal.Token.Value is string value)
{
length = value.Length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Extensions\SyntaxNodeExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Lightup\SyntaxKindEx.cs" />
</ItemGroup>
</Project>
14 changes: 14 additions & 0 deletions src/Utilities/Compiler.CSharp/Lightup/SyntaxKindEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information.

using Microsoft.CodeAnalysis.CSharp;

namespace Analyzer.Utilities.Lightup
{
internal static class SyntaxKindEx
{
// https://github.com/dotnet/roslyn/blob/main/src/Compilers/CSharp/Portable/Syntax/SyntaxKind.cs
public const SyntaxKind Utf8StringLiteralToken = (SyntaxKind)8520;
public const SyntaxKind Utf8StringLiteralExpression = (SyntaxKind)8756;
public const SyntaxKind CollectionExpression = (SyntaxKind)9076;
}
}