summaryrefslogtreecommitdiffstats
path: root/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MustBeVariantAnalyzer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MustBeVariantAnalyzer.cs')
-rw-r--r--modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MustBeVariantAnalyzer.cs40
1 files changed, 30 insertions, 10 deletions
diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MustBeVariantAnalyzer.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MustBeVariantAnalyzer.cs
index b4f78fd218..95eaca4d3d 100644
--- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MustBeVariantAnalyzer.cs
+++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MustBeVariantAnalyzer.cs
@@ -8,7 +8,7 @@ using Microsoft.CodeAnalysis.Diagnostics;
namespace Godot.SourceGenerators
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
- public class MustBeVariantAnalyzer : DiagnosticAnalyzer
+ public sealed class MustBeVariantAnalyzer : DiagnosticAnalyzer
{
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
=> ImmutableArray.Create(
@@ -62,7 +62,11 @@ namespace Godot.SourceGenerators
{
if (!typeParamSymbol.GetAttributes().Any(a => a.AttributeClass?.IsGodotMustBeVariantAttribute() ?? false))
{
- Common.ReportGenericTypeParameterMustBeVariantAnnotated(context, typeSyntax, typeSymbol);
+ context.ReportDiagnostic(Diagnostic.Create(
+ Common.GenericTypeParameterMustBeVariantAnnotatedRule,
+ typeSyntax.GetLocation(),
+ typeSymbol.ToDisplayString()
+ ));
}
continue;
}
@@ -71,8 +75,11 @@ namespace Godot.SourceGenerators
if (marshalType is null)
{
- Common.ReportGenericTypeArgumentMustBeVariant(context, typeSyntax, typeSymbol);
- continue;
+ context.ReportDiagnostic(Diagnostic.Create(
+ Common.GenericTypeArgumentMustBeVariantRule,
+ typeSyntax.GetLocation(),
+ typeSymbol.ToDisplayString()
+ ));
}
}
}
@@ -106,8 +113,15 @@ namespace Godot.SourceGenerators
/// <param name="parentSymbol">The symbol retrieved for the parent node syntax.</param>
/// <param name="typeArgumentSyntax">The type node syntax of the argument type to check.</param>
/// <param name="typeArgumentSymbol">The symbol retrieved for the type node syntax.</param>
+ /// <param name="typeArgumentIndex"></param>
/// <returns><see langword="true"/> if the type must be variant and must be analyzed.</returns>
- private bool ShouldCheckTypeArgument(SyntaxNodeAnalysisContext context, SyntaxNode parentSyntax, ISymbol parentSymbol, TypeSyntax typeArgumentSyntax, ITypeSymbol typeArgumentSymbol, int typeArgumentIndex)
+ private bool ShouldCheckTypeArgument(
+ SyntaxNodeAnalysisContext context,
+ SyntaxNode parentSyntax,
+ ISymbol parentSymbol,
+ TypeSyntax typeArgumentSyntax,
+ ITypeSymbol typeArgumentSymbol,
+ int typeArgumentIndex)
{
ITypeParameterSymbol? typeParamSymbol = parentSymbol switch
{
@@ -120,18 +134,24 @@ namespace Godot.SourceGenerators
INamedTypeSymbol { TypeParameters.Length: > 0 } typeSymbol
=> typeSymbol.TypeParameters[typeArgumentIndex],
+
_
=> null
};
- if (typeParamSymbol == null)
+ if (typeParamSymbol != null)
{
- Common.ReportTypeArgumentParentSymbolUnhandled(context, typeArgumentSyntax, parentSymbol);
- return false;
+ return typeParamSymbol.GetAttributes()
+ .Any(a => a.AttributeClass?.IsGodotMustBeVariantAttribute() ?? false);
}
- return typeParamSymbol.GetAttributes()
- .Any(a => a.AttributeClass?.IsGodotMustBeVariantAttribute() ?? false);
+ context.ReportDiagnostic(Diagnostic.Create(
+ Common.TypeArgumentParentSymbolUnhandledRule,
+ typeArgumentSyntax.GetLocation(),
+ parentSymbol.ToDisplayString()
+ ));
+
+ return false;
}
}
}