Add: NestedNotAllow DiagnosticDescriptor

This commit is contained in:
AnnulusGames 2024-02-16 23:18:43 +09:00
parent 53d042ceac
commit 0a74551727
3 changed files with 22 additions and 2 deletions

View File

@ -32,7 +32,13 @@ namespace Alchemy.SourceGenerator
if (!IsPartial(typeSyntax))
{
context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.MustBePartial, typeSyntax.Identifier.GetLocation(), typeSymbol.Name));
return;
continue;
}
if (IsNested(typeSyntax))
{
context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.NestedNotAllow, typeSyntax.Identifier.GetLocation(), typeSymbol.Name));
continue;
}
var fieldSymbols = new List<IFieldSymbol>();
@ -171,6 +177,11 @@ catch (global::System.Exception ex)
return typeDeclaration.Modifiers.Any(m => m.IsKind(SyntaxKind.PartialKeyword));
}
static bool IsNested(TypeDeclarationSyntax typeDeclaration)
{
return typeDeclaration.Parent is TypeDeclarationSyntax;
}
sealed class SyntaxReceiver : ISyntaxReceiver
{
internal static ISyntaxReceiver Create()

View File

@ -9,10 +9,19 @@ namespace Alchemy.SourceGenerator
public static readonly DiagnosticDescriptor MustBePartial = new(
id: "ALCHEMY001",
title: "AlchemySerialize class must be partial.",
messageFormat: "AlchemySerialize class '{0}' must be partial",
messageFormat: "AlchemySerialize class '{0}' must be partial.",
category: Category,
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true
);
public static readonly DiagnosticDescriptor NestedNotAllow = new(
id: "ALCHEMY002",
title: "AlchemySerialize class must not be nested type.",
messageFormat: "The AlchemySerialize class '{0}' must be not nested type.",
category: Category,
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true);
}
}