From dd5dd905a844d9363c2f1174a9dce4f8584be403 Mon Sep 17 00:00:00 2001 From: David Vreony Date: Wed, 5 Jun 2024 19:47:01 +0100 Subject: [PATCH 1/3] skip obsolete classes --- .../AbstractBaseSourceGenerator.cs | 6 ++- .../Core/AbstractGeneratorProcessor.cs | 45 ++++++++++++------- .../Features/Core/ReportDiagnosticIds.cs | 5 +++ 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/Vetuviem.SourceGenerator/AbstractBaseSourceGenerator.cs b/src/Vetuviem.SourceGenerator/AbstractBaseSourceGenerator.cs index 63e46a10..5dac3f50 100644 --- a/src/Vetuviem.SourceGenerator/AbstractBaseSourceGenerator.cs +++ b/src/Vetuviem.SourceGenerator/AbstractBaseSourceGenerator.cs @@ -141,6 +141,9 @@ public void Execute(GeneratorExecutionContext context) // allows for 3rd parties to use the generator and produce a custom namespace that inherits off the root, or custom namespace. globalOptions.TryGetBuildPropertyValue("Vetuviem_Base_Namespace", out var baseType); + globalOptions.TryGetBuildPropertyValue("Vetuviem_Include_Obsolete_Items", out var includeObsoleteItemsAsString); + bool.TryParse(includeObsoleteItemsAsString, out var includeObsoleteItems); + var namespaceDeclaration = SyntaxFactory.NamespaceDeclaration(SyntaxFactory.IdentifierName(namespaceName)); var compilation = context.Compilation; @@ -221,7 +224,8 @@ public void Execute(GeneratorExecutionContext context) desiredCommandInterface, platformName, namespaceName, - makeClassesPublic); + makeClassesPublic, + includeObsoleteItems); return result; } diff --git a/src/Vetuviem.SourceGenerator/Features/Core/AbstractGeneratorProcessor.cs b/src/Vetuviem.SourceGenerator/Features/Core/AbstractGeneratorProcessor.cs index 0f9b1673..659c48c6 100644 --- a/src/Vetuviem.SourceGenerator/Features/Core/AbstractGeneratorProcessor.cs +++ b/src/Vetuviem.SourceGenerator/Features/Core/AbstractGeneratorProcessor.cs @@ -29,9 +29,9 @@ public abstract class AbstractGeneratorProcessor /// Name of the UI Platform. /// The root namespace to place the binding classes inside. /// A flag indicating whether to expose the generated binding classes as public rather than internal. Set this to true if you're created a reusable library file. + /// Whether to include obsolete items in the generated code. /// Namespace declaration containing generated code. - public NamespaceDeclarationSyntax GenerateNamespaceDeclaration( - NamespaceDeclarationSyntax namespaceDeclaration, + public NamespaceDeclarationSyntax GenerateNamespaceDeclaration(NamespaceDeclarationSyntax namespaceDeclaration, MetadataReference[] assembliesOfInterest, Compilation compilation, Action reportDiagnosticAction, @@ -40,7 +40,8 @@ public NamespaceDeclarationSyntax GenerateNamespaceDeclaration( string? desiredCommandInterface, string platformName, string rootNamespace, - bool makeClassesPublic) + bool makeClassesPublic, + bool includeObsoleteItems) { if (namespaceDeclaration == null) { @@ -87,7 +88,8 @@ public NamespaceDeclarationSyntax GenerateNamespaceDeclaration( desiredCommandInterface, platformName, rootNamespace, - makeClassesPublic); + makeClassesPublic, + includeObsoleteItems); } return namespaceDeclaration; @@ -112,8 +114,7 @@ public NamespaceDeclarationSyntax GenerateNamespaceDeclaration( } } - private static void CheckTypeForUiType( - INamedTypeSymbol namedTypeSymbol, + private static void CheckTypeForUiType(INamedTypeSymbol namedTypeSymbol, Action reportDiagnosticAction, string baseUiElement, bool desiredBaseTypeIsInterface, @@ -123,7 +124,8 @@ private static void CheckTypeForUiType( Func[] classGenerators, List memberDeclarationSyntaxes, string rootNamespace, - bool makeClassesPublic) + bool makeClassesPublic, + bool includeObsoleteItems) { var fullName = namedTypeSymbol.GetFullName(); @@ -159,6 +161,14 @@ private static void CheckTypeForUiType( previouslyGeneratedClasses.Add(fullName); reportDiagnosticAction(ReportDiagnosticFactory.HasDesiredBaseType(baseUiElement, namedTypeSymbol)); + // check for obsolete attribute + var attributes = namedTypeSymbol.GetAttributes(); + if (!includeObsoleteItems && attributes.Any(a => a.AttributeClass?.Name.Equals("ObsoleteAttribute", StringComparison.Ordinal) == true)) + { + reportDiagnosticAction(ReportDiagnosticFactory.IsObsoleteType(namedTypeSymbol)); + return; + } + foreach (var classGeneratorFactory in classGenerators) { var generator = classGeneratorFactory(); @@ -212,8 +222,7 @@ private static bool HasDesiredBaseType( return false; } - private NamespaceDeclarationSyntax CheckAssemblyForUiTypes( - NamespaceDeclarationSyntax namespaceDeclaration, + private NamespaceDeclarationSyntax CheckAssemblyForUiTypes(NamespaceDeclarationSyntax namespaceDeclaration, MetadataReference metadataReference, Compilation compilation, Action reportDiagnosticAction, @@ -223,7 +232,8 @@ private NamespaceDeclarationSyntax CheckAssemblyForUiTypes( string? desiredCommandInterface, string platformName, string rootNamespace, - bool makeClassesPublic) + bool makeClassesPublic, + bool includeObsoleteItems) { reportDiagnosticAction(ReportDiagnosticFactory.StartingScanOfAssembly(metadataReference)); @@ -257,7 +267,8 @@ private NamespaceDeclarationSyntax CheckAssemblyForUiTypes( platformName, classGenerators, rootNamespace, - makeClassesPublic); + makeClassesPublic, + includeObsoleteItems); if (nestedDeclarationSyntax != null) { @@ -280,8 +291,7 @@ private NamespaceDeclarationSyntax CheckAssemblyForUiTypes( return namespaceDeclaration; } - private NamespaceDeclarationSyntax? CheckNamespaceForUiTypes( - INamespaceSymbol namespaceSymbol, + private NamespaceDeclarationSyntax? CheckNamespaceForUiTypes(INamespaceSymbol namespaceSymbol, Action reportDiagnosticAction, string baseUiElement, bool desiredBaseTypeIsInterface, @@ -290,7 +300,8 @@ private NamespaceDeclarationSyntax CheckAssemblyForUiTypes( string platformName, Func[] classGenerators, string rootNamespace, - bool makeClassesPublic) + bool makeClassesPublic, + bool includeObsoleteItems) { reportDiagnosticAction(ReportDiagnosticFactory.StartingScanOfNamespace(namespaceSymbol)); @@ -311,7 +322,8 @@ private NamespaceDeclarationSyntax CheckAssemblyForUiTypes( classGenerators, nestedMembers, rootNamespace, - makeClassesPublic); + makeClassesPublic, + includeObsoleteItems); } var nestedSymbols = namespaceSymbol.GetNamespaceMembers(); @@ -328,7 +340,8 @@ private NamespaceDeclarationSyntax CheckAssemblyForUiTypes( platformName, classGenerators, rootNamespace, - makeClassesPublic); + makeClassesPublic, + includeObsoleteItems); if (nestedNamespace != null) { diff --git a/src/Vetuviem.SourceGenerator/Features/Core/ReportDiagnosticIds.cs b/src/Vetuviem.SourceGenerator/Features/Core/ReportDiagnosticIds.cs index 92fa6c61..7a951fe3 100644 --- a/src/Vetuviem.SourceGenerator/Features/Core/ReportDiagnosticIds.cs +++ b/src/Vetuviem.SourceGenerator/Features/Core/ReportDiagnosticIds.cs @@ -83,5 +83,10 @@ public static class ReportDiagnosticIds /// Diagnostic ID for when the desired base type symbol has not been found on a type. /// public const string DesiredBaseTypeSymbolSearchNotNamedTypeSymbol = "VET015"; + + /// + /// Diagnostic ID for when a type is obsolete and won't be generated. + /// + public const string IsObsoleteType = "VET016"; } } From 51c6491e89e9e5af5d3e7bbce957c0f6546cea7e Mon Sep 17 00:00:00 2001 From: David Vreony Date: Wed, 5 Jun 2024 20:35:40 +0100 Subject: [PATCH 2/3] skip property generation --- .../AbstractBaseSourceGenerator.cs | 48 ++++++++++++----- ...stractControlBindingModelClassGenerator.cs | 17 +++++-- .../ControlBindingModelPropertyGenerator.cs | 13 ++++- ...lBoundControlBindingModelClassGenerator.cs | 3 +- ...enericControlBindingModelClassGenerator.cs | 51 ++++++++++++++----- .../Core/AbstractGeneratorProcessor.cs | 5 +- .../Features/Core/IClassGenerator.cs | 4 +- .../Features/Core/ReportDiagnosticFactory.cs | 7 +++ 8 files changed, 116 insertions(+), 32 deletions(-) diff --git a/src/Vetuviem.SourceGenerator/AbstractBaseSourceGenerator.cs b/src/Vetuviem.SourceGenerator/AbstractBaseSourceGenerator.cs index 5dac3f50..f3e5bc12 100644 --- a/src/Vetuviem.SourceGenerator/AbstractBaseSourceGenerator.cs +++ b/src/Vetuviem.SourceGenerator/AbstractBaseSourceGenerator.cs @@ -120,29 +120,44 @@ public void Execute(GeneratorExecutionContext context) var configOptions = context.AnalyzerConfigOptions; var globalOptions = configOptions.GlobalOptions; - globalOptions.TryGetBuildPropertyValue("Vetuviem_Root_Namespace", out var rootNamespace); + globalOptions.TryGetBuildPropertyValue( + "Vetuviem_Root_Namespace", + out var rootNamespace); var namespaceName = GetNamespace(rootNamespace); - globalOptions.TryGetBuildPropertyValue("Vetuviem_Make_Classes_Public", out var makeClassesPublicAsString); + globalOptions.TryGetBuildPropertyValue( + "Vetuviem_Make_Classes_Public", + out var makeClassesPublicAsString); bool.TryParse(makeClassesPublicAsString, out var makeClassesPublic); - globalOptions.TryGetBuildPropertyValue("Vetuviem_Assemblies", out var assemblies); + globalOptions.TryGetBuildPropertyValue( + "Vetuviem_Assemblies", + out var assemblies); var assembliesArray = assemblies?.Split( [','], StringSplitOptions.RemoveEmptyEntries) .Where(s => !string.IsNullOrWhiteSpace(s)) .ToArray(); - globalOptions.TryGetBuildPropertyValue("Vetuviem_Assembly_Mode", out var assemblyModeAsString); + globalOptions.TryGetBuildPropertyValue( + "Vetuviem_Assembly_Mode", + out var assemblyModeAsString); var assemblyMode = GetAssemblyMode(assemblyModeAsString); // base type name only used if passing a custom set of assemblies to search for. // allows for 3rd parties to use the generator and produce a custom namespace that inherits off the root, or custom namespace. - globalOptions.TryGetBuildPropertyValue("Vetuviem_Base_Namespace", out var baseType); - - globalOptions.TryGetBuildPropertyValue("Vetuviem_Include_Obsolete_Items", out var includeObsoleteItemsAsString); - bool.TryParse(includeObsoleteItemsAsString, out var includeObsoleteItems); + globalOptions.TryGetBuildPropertyValue( + "Vetuviem_Base_Namespace", + out var baseType); + + globalOptions.TryGetBuildPropertyValue( + "Vetuviem_Include_Obsolete_Items", + out var includeObsoleteItemsAsString); + bool.TryParse( + includeObsoleteItemsAsString, + out var includeObsoleteItems); + // includeObsoleteItems = true; var namespaceDeclaration = SyntaxFactory.NamespaceDeclaration(SyntaxFactory.IdentifierName(namespaceName)); @@ -163,7 +178,10 @@ public void Execute(GeneratorExecutionContext context) //} #endif - var assembliesOfInterest = GetAssembliesOfInterest(platformResolver, assembliesArray, assemblyMode); + var assembliesOfInterest = GetAssembliesOfInterest( + platformResolver, + assembliesArray, + assemblyMode); if (assembliesOfInterest.Length == 0) { return null; @@ -180,12 +198,16 @@ public void Execute(GeneratorExecutionContext context) if (referencesOfInterest.Length != assembliesOfInterest.Length) { // not got the expected count back, drop out. - context.ReportDiagnostic(ReportDiagnosticFactory.ReferencesOfInterestCountMismatch(assembliesOfInterest.Length, referencesOfInterest.Length)); + context.ReportDiagnostic(ReportDiagnosticFactory.ReferencesOfInterestCountMismatch( + assembliesOfInterest.Length, + referencesOfInterest.Length)); return namespaceDeclaration; } var desiredBaseType = platformResolver.GetBaseUiElement(); - var desiredNameWithoutGlobal = desiredBaseType.Replace("global::", string.Empty); + var desiredNameWithoutGlobal = desiredBaseType.Replace( + "global::", + string.Empty); var desiredBaseTypeSymbolMatch = compilation.GetTypeByMetadataName(desiredNameWithoutGlobal); if (desiredBaseTypeSymbolMatch == null) @@ -237,7 +259,9 @@ private static AssemblyMode GetAssemblyMode(string? assemblyModeAsString) return AssemblyMode.Replace; } - if ( !Enum.TryParse(assemblyModeAsString, out var assemblyMode)) + if ( !Enum.TryParse( + assemblyModeAsString, + out var assemblyMode)) { return assemblyMode; } diff --git a/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/AbstractControlBindingModelClassGenerator.cs b/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/AbstractControlBindingModelClassGenerator.cs index 697eb383..b0ba30b4 100644 --- a/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/AbstractControlBindingModelClassGenerator.cs +++ b/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/AbstractControlBindingModelClassGenerator.cs @@ -24,7 +24,8 @@ public ClassDeclarationSyntax GenerateClass( string? desiredCommandInterface, string platformName, string rootNamespace, - bool makeClassesPublic) + bool makeClassesPublic, + bool includeObsoleteItems) { var typeParameterList = GetTypeParameterListSyntax(namedTypeSymbol); @@ -51,7 +52,15 @@ public ClassDeclarationSyntax GenerateClass( var members = new SyntaxList(GetConstructorMethod(namedTypeSymbol, isDerivedType, makeClassesPublic, typeParameterList)); - members = ApplyMembers(members, namedTypeSymbol, desiredCommandInterface, isDerivedType, controlClassFullName, platformName, makeClassesPublic); + members = ApplyMembers( + members, + namedTypeSymbol, + desiredCommandInterface, + isDerivedType, + controlClassFullName, + platformName, + makeClassesPublic, + includeObsoleteItems); return classDeclaration .WithModifiers(modifiers) @@ -172,6 +181,7 @@ protected static IEnumerable GetTypeArgumentsFromTypeParameters(INam /// Full Name of the Control Class. /// Friendly Name for the platform. /// A flag indicating whether to expose the generated binding classes as public rather than internal. Set this to true if you're created a reusable library file. + /// Whether to include obsolete items in the generated code. /// Modified Syntax List of Member declarations. protected abstract SyntaxList ApplyMembers( SyntaxList members, @@ -180,7 +190,8 @@ protected abstract SyntaxList ApplyMembers( bool isDerivedType, string controlClassFullName, string platformName, - bool makeClassesPublic); + bool makeClassesPublic, + bool includeObsoleteItems); /// /// Gets the class name identifier from a named type symbol. diff --git a/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBindingModelPropertyGenerator.cs b/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBindingModelPropertyGenerator.cs index f7668250..15bd8247 100644 --- a/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBindingModelPropertyGenerator.cs +++ b/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBindingModelPropertyGenerator.cs @@ -24,11 +24,13 @@ public static class ControlBindingModelPropertyGenerator /// The type to check the properties on. /// The fully qualified typename for the Command interface used by the UI platform, if it uses one. /// A flag indicating whether to expose the generated binding classes as public rather than internal. Set this to true if you're created a reusable library file. + /// Whether to include obsolete items in the generated code. /// List of property declarations. public static SyntaxList GetProperties( INamedTypeSymbol namedTypeSymbol, string? desiredCommandInterface, - bool makeClassesPublic) + bool makeClassesPublic, + bool includeObsoleteItems) { if (namedTypeSymbol == null) { @@ -55,6 +57,15 @@ public static SyntaxList GetProperties( continue; } + // check for obsolete attribute + var attributes = propertySymbol.GetAttributes(); + if (!includeObsoleteItems && attributes.Any(a => a.AttributeClass?.GetFullName().Equals( + "global::System.ObsoleteAttribute", + StringComparison.Ordinal) == true)) + { + continue; + } + // windows forms has an issue where some properties are provided as "new" instances instead of overridden // we're getting build warnings for these. if (ReplacesBaseProperty(propertySymbol, namedTypeSymbol)) diff --git a/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBoundControlBindingModelClassGenerator.cs b/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBoundControlBindingModelClassGenerator.cs index df4db844..a3ef543c 100644 --- a/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBoundControlBindingModelClassGenerator.cs +++ b/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/ControlBoundControlBindingModelClassGenerator.cs @@ -31,7 +31,8 @@ protected override SyntaxList ApplyMembers( bool isDerivedType, string controlClassFullName, string platformName, - bool makeClassesPublic) + bool makeClassesPublic, + bool includeObsoleteItems) { return members; } diff --git a/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/GenericControlBindingModelClassGenerator.cs b/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/GenericControlBindingModelClassGenerator.cs index 8b92595b..89d21671 100644 --- a/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/GenericControlBindingModelClassGenerator.cs +++ b/src/Vetuviem.SourceGenerator/Features/ControlBindingModels/GenericControlBindingModelClassGenerator.cs @@ -33,22 +33,26 @@ protected override SyntaxList ApplyMembers( bool isDerivedType, string controlClassFullName, string platformName, - bool makeClassesPublic) + bool makeClassesPublic, + bool includeObsoleteItems) { members = members.AddRange(ControlBindingModelPropertyGenerator.GetProperties( namedTypeSymbol, desiredCommandInterface, - makeClassesPublic)); + makeClassesPublic, + includeObsoleteItems)); members = members.Add(GetApplyBindingsWithDisposableActionMethod( namedTypeSymbol, isDerivedType, - desiredCommandInterface)); + desiredCommandInterface, + includeObsoleteItems)); members = members.Add(GetApplyBindingsWithCompositeDisposableMethod( namedTypeSymbol, isDerivedType, - desiredCommandInterface)); + desiredCommandInterface, + includeObsoleteItems)); return members; } @@ -269,7 +273,8 @@ private static SeparatedSyntaxList GetTypeArgumentSeparatedSyntaxLis private static MemberDeclarationSyntax GetApplyBindingsWithDisposableActionMethod( INamedTypeSymbol namedTypeSymbol, bool isDerivedType, - string? desiredCommandInterface) + string? desiredCommandInterface, + bool includeObsoleteItems) { const string methodName = "ApplyBindings"; var returnType = SyntaxFactory.ParseTypeName("void"); @@ -277,7 +282,8 @@ private static MemberDeclarationSyntax GetApplyBindingsWithDisposableActionMetho var methodBody = GetApplyBindingMethodBody( namedTypeSymbol, isDerivedType, - desiredCommandInterface); + desiredCommandInterface, + includeObsoleteItems); var parameters = RoslynGenerationHelpers.GetParams(new[] { @@ -300,7 +306,8 @@ private static MemberDeclarationSyntax GetApplyBindingsWithDisposableActionMetho private static MemberDeclarationSyntax GetApplyBindingsWithCompositeDisposableMethod( INamedTypeSymbol namedTypeSymbol, bool isDerivedType, - string? desiredCommandInterface) + string? desiredCommandInterface, + bool includeObsoleteItems) { const string methodName = "ApplyBindings"; var returnType = SyntaxFactory.ParseTypeName("void"); @@ -308,7 +315,8 @@ private static MemberDeclarationSyntax GetApplyBindingsWithCompositeDisposableMe var methodBody = GetApplyBindingCompositeDisposableMethodBody( namedTypeSymbol, isDerivedType, - desiredCommandInterface); + desiredCommandInterface, + includeObsoleteItems); var parameters = RoslynGenerationHelpers.GetParams(new[] { @@ -331,7 +339,8 @@ private static MemberDeclarationSyntax GetApplyBindingsWithCompositeDisposableMe private static StatementSyntax[] GetApplyBindingMethodBody( INamedTypeSymbol namedTypeSymbol, bool isDerivedType, - string? desiredCommandInterface) + string? desiredCommandInterface, + bool includeObsoleteItems) { var body = new List(); @@ -370,6 +379,15 @@ private static StatementSyntax[] GetApplyBindingMethodBody( continue; } + // check for obsolete attribute + var attributes = propertySymbol.GetAttributes(); + if (!includeObsoleteItems && attributes.Any(a => a.AttributeClass?.GetFullName().Equals( + "global::System.ObsoleteAttribute", + StringComparison.Ordinal) == true)) + { + continue; + } + var propType = propertySymbol.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); var invokeArgs = new[] @@ -402,10 +420,10 @@ private static StatementSyntax[] GetApplyBindingMethodBody( return body.ToArray(); } - private static StatementSyntax[] GetApplyBindingCompositeDisposableMethodBody( - INamedTypeSymbol namedTypeSymbol, + private static StatementSyntax[] GetApplyBindingCompositeDisposableMethodBody(INamedTypeSymbol namedTypeSymbol, bool isDerivedType, - string? desiredCommandInterface) + string? desiredCommandInterface, + bool includeObsoleteItems) { var body = new List(); @@ -444,6 +462,15 @@ private static StatementSyntax[] GetApplyBindingCompositeDisposableMethodBody( continue; } + // check for obsolete attribute + var attributes = propertySymbol.GetAttributes(); + if (!includeObsoleteItems && attributes.Any(a => a.AttributeClass?.GetFullName().Equals( + "global::System.ObsoleteAttribute", + StringComparison.Ordinal) == true)) + { + continue; + } + var propType = propertySymbol.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); var invokeArgs = new[] diff --git a/src/Vetuviem.SourceGenerator/Features/Core/AbstractGeneratorProcessor.cs b/src/Vetuviem.SourceGenerator/Features/Core/AbstractGeneratorProcessor.cs index 659c48c6..b26e89dc 100644 --- a/src/Vetuviem.SourceGenerator/Features/Core/AbstractGeneratorProcessor.cs +++ b/src/Vetuviem.SourceGenerator/Features/Core/AbstractGeneratorProcessor.cs @@ -163,7 +163,7 @@ private static void CheckTypeForUiType(INamedTypeSymbol namedTypeSymbol, // check for obsolete attribute var attributes = namedTypeSymbol.GetAttributes(); - if (!includeObsoleteItems && attributes.Any(a => a.AttributeClass?.Name.Equals("ObsoleteAttribute", StringComparison.Ordinal) == true)) + if (!includeObsoleteItems && attributes.Any(a => a.AttributeClass?.GetFullName().Equals("global::System.ObsoleteAttribute", StringComparison.Ordinal) == true)) { reportDiagnosticAction(ReportDiagnosticFactory.IsObsoleteType(namedTypeSymbol)); return; @@ -178,7 +178,8 @@ private static void CheckTypeForUiType(INamedTypeSymbol namedTypeSymbol, desiredCommandInterface, platformName, rootNamespace, - makeClassesPublic); + makeClassesPublic, + includeObsoleteItems); memberDeclarationSyntaxes.Add(generatedClass); } diff --git a/src/Vetuviem.SourceGenerator/Features/Core/IClassGenerator.cs b/src/Vetuviem.SourceGenerator/Features/Core/IClassGenerator.cs index 2f63ee9c..c8137e4b 100644 --- a/src/Vetuviem.SourceGenerator/Features/Core/IClassGenerator.cs +++ b/src/Vetuviem.SourceGenerator/Features/Core/IClassGenerator.cs @@ -21,6 +21,7 @@ public interface IClassGenerator /// The name of the Platform code is being generated for. /// The root namespace to place the binding classes inside. /// A flag indicating whether to expose the generated binding classes as public rather than internal. Set this to true if you're created a reusable library file. + /// Whether to include obsolete items in the generated code. /// Class Declaration Syntax Node. ClassDeclarationSyntax GenerateClass( INamedTypeSymbol namedTypeSymbol, @@ -28,6 +29,7 @@ ClassDeclarationSyntax GenerateClass( string? desiredCommandInterface, string platformName, string rootNamespace, - bool makeClassesPublic); + bool makeClassesPublic, + bool includeObsoleteItems); } } diff --git a/src/Vetuviem.SourceGenerator/Features/Core/ReportDiagnosticFactory.cs b/src/Vetuviem.SourceGenerator/Features/Core/ReportDiagnosticFactory.cs index 7a55726d..0acaa59d 100644 --- a/src/Vetuviem.SourceGenerator/Features/Core/ReportDiagnosticFactory.cs +++ b/src/Vetuviem.SourceGenerator/Features/Core/ReportDiagnosticFactory.cs @@ -133,6 +133,13 @@ public static Diagnostic NoGlobalNamespaceInAssemblyOrModule(MetadataReference m $"No global namespace in Assembly or Module Symbol: {metadataReference.Display}"); } + public static Diagnostic IsObsoleteType(INamedTypeSymbol namedTypeSymbol) + { + return InfoDiagnostic( + ReportDiagnosticIds.IsObsoleteType, + $"{namedTypeSymbol.GetFullName()} is obsolete"); + } + private static Diagnostic InfoDiagnostic( string id, string message) From 3526547de60463c6265d5af107afde737035de9a Mon Sep 17 00:00:00 2001 From: David Vreony Date: Wed, 5 Jun 2024 23:44:13 +0100 Subject: [PATCH 3/3] add msbuild property --- src/Vetuviem.SourceGenerator/Vetuviem-SourceGenerator.props | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Vetuviem.SourceGenerator/Vetuviem-SourceGenerator.props b/src/Vetuviem.SourceGenerator/Vetuviem-SourceGenerator.props index 1b91f923..46ba69fa 100644 --- a/src/Vetuviem.SourceGenerator/Vetuviem-SourceGenerator.props +++ b/src/Vetuviem.SourceGenerator/Vetuviem-SourceGenerator.props @@ -5,5 +5,6 @@ +