Fix generators project

This commit is contained in:
2024-08-28 15:33:32 +02:00
parent 552b72b1b9
commit 681bec01f2
2 changed files with 68 additions and 71 deletions
@@ -1,79 +1,78 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
namespace System.Extensions
namespace System.Extensions;
internal static class Diagnostics
{
internal static class Diagnostics
{
public const string DependencyPropertyGenerator_NoAttributeFound = "DGD 0001";
public const string DependencyPropertyGenerator_ClassMustBeTopLevel = "DGD 1001";
public const string DependencyPropertyGenerator_ClassMustBePartial = "DGD 1002";
public const string DependencyPropertyGenerator_ClassMustBeInNamespace = "DGD 1003";
public const string DependencyPropertyGenerator_ClassMustImplementINotifyPropertyChanged = "DGD 1004";
public const string DependencyPropertyGenerator_NoAttributeFound = "DGD 0001";
public const string DependencyPropertyGenerator_ClassMustBeTopLevel = "DGD 1001";
public const string DependencyPropertyGenerator_ClassMustBePartial = "DGD 1002";
public const string DependencyPropertyGenerator_ClassMustBeInNamespace = "DGD 1003";
public const string DependencyPropertyGenerator_ClassMustImplementINotifyPropertyChanged = "DGD 1004";
public static Diagnostic MissingAttributeDiagnostic(string attributeName, string attributeNamespace) => Diagnostic.Create(
new DiagnosticDescriptor(
DependencyPropertyGenerator_NoAttributeFound,
$"{attributeNamespace}.{attributeName} not found",
"Could not find attribute with name {0} in namespace {1}.",
"WpfExtended.SourceGeneration",
DiagnosticSeverity.Error,
true,
$"This error occurs when the attribute generated by the {nameof(DependencyPropertyGenerator)} is not found",
null),
Location.None,
attributeName, attributeNamespace);
public static Diagnostic MissingAttributeDiagnostic(string attributeName, string attributeNamespace) => Diagnostic.Create(
new DiagnosticDescriptor(
DependencyPropertyGenerator_NoAttributeFound,
$"{attributeNamespace}.{attributeName} not found",
"Could not find attribute with name {0} in namespace {1}.",
"SystemExtensions.NetStandard.Generators",
DiagnosticSeverity.Error,
true,
$"This error occurs when the attribute generated by the {nameof(NotifyPropertyChangedGenerator)} is not found",
null),
Location.None,
attributeName, attributeNamespace);
public static Diagnostic ClassNotTopLevelDiagnostic(string className, string containingSymbol, SyntaxTree syntaxTree, TextSpan textSpan) => Diagnostic.Create(
new DiagnosticDescriptor(
DependencyPropertyGenerator_ClassMustBeTopLevel,
$"{className} must be top level",
"Class {0} must be top level. It is currently declared under {1}.",
"WpfExtended.SourceGeneration",
DiagnosticSeverity.Error,
true,
null,
null),
Location.Create(syntaxTree, textSpan),
className, containingSymbol);
public static Diagnostic ClassNotTopLevelDiagnostic(string className, string containingSymbol, SyntaxTree syntaxTree, TextSpan textSpan) => Diagnostic.Create(
new DiagnosticDescriptor(
DependencyPropertyGenerator_ClassMustBeTopLevel,
$"{className} must be top level",
"Class {0} must be top level. It is currently declared under {1}.",
"SystemExtensions.NetStandard.Generators",
DiagnosticSeverity.Error,
true,
null,
null),
Location.Create(syntaxTree, textSpan),
className, containingSymbol);
public static Diagnostic ClassNotPartial(string className) => Diagnostic.Create(
new DiagnosticDescriptor(
DependencyPropertyGenerator_ClassMustBePartial,
$"{className} is not partial",
"Class {0} must be marked as partial in order for the generator to work",
"WpfExtended.SourceGeneration",
DiagnosticSeverity.Error,
true,
null,
null),
Location.None,
className);
public static Diagnostic ClassNotPartial(string className) => Diagnostic.Create(
new DiagnosticDescriptor(
DependencyPropertyGenerator_ClassMustBePartial,
$"{className} is not partial",
"Class {0} must be marked as partial in order for the generator to work",
"SystemExtensions.NetStandard.Generators",
DiagnosticSeverity.Error,
true,
null,
null),
Location.None,
className);
public static Diagnostic ClassNotInNamespace(string className) => Diagnostic.Create(
new DiagnosticDescriptor(
DependencyPropertyGenerator_ClassMustBeInNamespace,
$"{className} is not defined in a namespace",
"Class {0} must be defined inside a namespace for the generator to work",
"WpfExtended.SourceGeneration",
DiagnosticSeverity.Error,
true,
null,
null),
Location.None,
className);
public static Diagnostic ClassNotInNamespace(string className) => Diagnostic.Create(
new DiagnosticDescriptor(
DependencyPropertyGenerator_ClassMustBeInNamespace,
$"{className} is not defined in a namespace",
"Class {0} must be defined inside a namespace for the generator to work",
"SystemExtensions.NetStandard.Generators",
DiagnosticSeverity.Error,
true,
null,
null),
Location.None,
className);
public static Diagnostic ClassDoesNotImplementINotifyPropertyChanged(string className) => Diagnostic.Create(
new DiagnosticDescriptor(
DependencyPropertyGenerator_ClassMustImplementINotifyPropertyChanged,
$"{className} must implement INotifyPropertyChanged",
"Class {0} must implement INotifyPropertyChanged for the generator to work",
"WpfExtended.SourceGeneration",
DiagnosticSeverity.Error,
true,
null,
null),
Location.None,
className);
}
public static Diagnostic ClassDoesNotImplementINotifyPropertyChanged(string className) => Diagnostic.Create(
new DiagnosticDescriptor(
DependencyPropertyGenerator_ClassMustImplementINotifyPropertyChanged,
$"{className} must implement INotifyPropertyChanged",
"Class {0} must implement INotifyPropertyChanged for the generator to work",
"SystemExtensions.NetStandard.Generators",
DiagnosticSeverity.Error,
true,
null,
null),
Location.None,
className);
}
@@ -3,10 +3,8 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Authors>Alexandru Macocian</Authors>
<Description>Source generators extensions for netstandard2.0.</Description>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Version>0.1.0</Version>
<LangVersion>latest</LangVersion>
<EnableNETAnalyzers>true</EnableNETAnalyzers>