mirror of
https://github.com/AnnulusGames/Alchemy.git
synced 2025-01-22 08:18:51 -05:00
Add: NestedNotAllow DiagnosticDescriptor
This commit is contained in:
parent
53d042ceac
commit
0a74551727
@ -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()
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user