From 0bcfdb28cbdb18338b361b58c5c4cfd6150efd4c Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 3 Oct 2023 23:24:05 +0100 Subject: [PATCH] [Aaru.Helpers] Reformat and cleanup. --- Aaru.Generators/Aaru.Generators.csproj | 2 +- Aaru.Generators/PluginRegisterGenerator.cs | 40 ++++++++++++++++++++-- Aaru.Helpers | 2 +- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/Aaru.Generators/Aaru.Generators.csproj b/Aaru.Generators/Aaru.Generators.csproj index 62f5ff4a4..a4bd8a98b 100644 --- a/Aaru.Generators/Aaru.Generators.csproj +++ b/Aaru.Generators/Aaru.Generators.csproj @@ -10,7 +10,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/Aaru.Generators/PluginRegisterGenerator.cs b/Aaru.Generators/PluginRegisterGenerator.cs index 2f196d52f..92c00e91c 100644 --- a/Aaru.Generators/PluginRegisterGenerator.cs +++ b/Aaru.Generators/PluginRegisterGenerator.cs @@ -9,6 +9,8 @@ namespace Aaru.Generators; [Generator] public class PluginRegisterGenerator : ISourceGenerator { +#region ISourceGenerator Members + /// public void Initialize(GeneratorInitializationContext context) => @@ -32,7 +34,7 @@ public class PluginRegisterGenerator : ISourceGenerator if(pluginRegister == null) return; - string @namespace = + var @namespace = (pluginRegister.Ancestors().FirstOrDefault(x => x is FileScopedNamespaceDeclarationSyntax) as FileScopedNamespaceDeclarationSyntax)?.Name.ToString(); @@ -270,6 +272,10 @@ public class PluginRegisterGenerator : ISourceGenerator context.AddSource("Register.g.cs", sb.ToString()); } +#endregion + +#region Nested type: PluginFinder + sealed class PluginFinder : ISyntaxReceiver { public List Archives { get; } = new(); @@ -285,6 +291,8 @@ public class PluginRegisterGenerator : ISourceGenerator public List ByteAddressableImagePlugins { get; } = new(); public ClassDeclarationSyntax Register { get; private set; } + #region ISyntaxReceiver Members + public void OnVisitSyntaxNode(SyntaxNode syntaxNode) { if(syntaxNode is not ClassDeclarationSyntax plugin) @@ -296,63 +304,89 @@ public class PluginRegisterGenerator : ISourceGenerator if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier. ValueText == "IArchive") == true) + { if(!Archives.Contains(plugin.Identifier.Text)) Archives.Add(plugin.Identifier.Text); + } if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier. ValueText == "IChecksum") == true) + { if(!Checksums.Contains(plugin.Identifier.Text)) Checksums.Add(plugin.Identifier.Text); + } if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier. ValueText == "IFilesystem") == true) + { if(!FileSystems.Contains(plugin.Identifier.Text)) FileSystems.Add(plugin.Identifier.Text); + } if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier. ValueText == "IFilter") == true) + { if(!Filters.Contains(plugin.Identifier.Text)) Filters.Add(plugin.Identifier.Text); + } if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier. ValueText == "IFloppyImage") == true) + { if(!FloppyImagePlugins.Contains(plugin.Identifier.Text)) FloppyImagePlugins.Add(plugin.Identifier.Text); + } if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier. ValueText is "IMediaImage" or "IOpticalMediaImage" or "IFloppyImage" - or "ITapeImage") == true) + or "ITapeImage") == true) + { if(!MediaImagePlugins.Contains(plugin.Identifier.Text)) MediaImagePlugins.Add(plugin.Identifier.Text); + } if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier. ValueText == "IPartition") == true) + { if(!PartitionPlugins.Contains(plugin.Identifier.Text)) PartitionPlugins.Add(plugin.Identifier.Text); + } if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier. ValueText == "IReadOnlyFilesystem") == true) + { if(!ReadOnlyFileSystems.Contains(plugin.Identifier.Text)) ReadOnlyFileSystems.Add(plugin.Identifier.Text); + } if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier. ValueText == "IWritableFloppyImage") == true) + { if(!WritableFloppyImagePlugins.Contains(plugin.Identifier.Text)) WritableFloppyImagePlugins.Add(plugin.Identifier.Text); + } if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier. ValueText is "IWritableImage" or "IWritableOpticalImage" - or "IWritableTapeImage" or "IByteAddressableImage") == true) + or "IWritableTapeImage" or "IByteAddressableImage") == true) + { if(!WritableImagePlugins.Contains(plugin.Identifier.Text)) WritableImagePlugins.Add(plugin.Identifier.Text); + } if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier. ValueText == "IByteAddressableImage") == true) + { if(!ByteAddressableImagePlugins.Contains(plugin.Identifier.Text)) ByteAddressableImagePlugins.Add(plugin.Identifier.Text); + } MediaImagePlugins.AddRange(WritableImagePlugins); FileSystems.AddRange(ReadOnlyFileSystems); } + + #endregion } + +#endregion } \ No newline at end of file diff --git a/Aaru.Helpers b/Aaru.Helpers index ca2f08311..57ad637c2 160000 --- a/Aaru.Helpers +++ b/Aaru.Helpers @@ -1 +1 @@ -Subproject commit ca2f08311f0abcf9ddd2b302f6177073a9e17865 +Subproject commit 57ad637c20b8b520c78fa099d7fbdad6ab2ce263