diff --git a/Aaru.Generators/PluginRegisterGenerator.cs b/Aaru.Generators/PluginRegisterGenerator.cs index c9ff74c4c..2f196d52f 100644 --- a/Aaru.Generators/PluginRegisterGenerator.cs +++ b/Aaru.Generators/PluginRegisterGenerator.cs @@ -42,27 +42,17 @@ public class PluginRegisterGenerator : ISourceGenerator string className = pluginRegister.Identifier.Text; - List archives = ((PluginFinder)context.SyntaxReceiver)?.Archives; - List checksums = ((PluginFinder)context.SyntaxReceiver)?.Checksums; - List fileSystems = ((PluginFinder)context.SyntaxReceiver)?.FileSystems; - List filters = ((PluginFinder)context.SyntaxReceiver)?.Filters; - - List floppyImagePlugins = ((PluginFinder)context.SyntaxReceiver)?.FloppyImagePlugins; - - List partitionPlugins = ((PluginFinder)context.SyntaxReceiver)?.PartitionPlugins; - - List mediaImagePlugins = ((PluginFinder)context.SyntaxReceiver)?.MediaImagePlugins; - - List readOnlyFileSystems = ((PluginFinder)context.SyntaxReceiver)?.ReadOnlyFileSystems; - - List writableFloppyImagePlugins = - ((PluginFinder)context.SyntaxReceiver)?.WritableFloppyImagePlugins; - - List writableImagePlugins = - ((PluginFinder)context.SyntaxReceiver)?.WritableImagePlugins; - - List byteAddressableImagePlugins = - ((PluginFinder)context.SyntaxReceiver)?.ByteAddressableImagePlugins; + List archives = ((PluginFinder)context.SyntaxReceiver)?.Archives; + List checksums = ((PluginFinder)context.SyntaxReceiver)?.Checksums; + List fileSystems = ((PluginFinder)context.SyntaxReceiver)?.FileSystems; + List filters = ((PluginFinder)context.SyntaxReceiver)?.Filters; + List floppyImagePlugins = ((PluginFinder)context.SyntaxReceiver)?.FloppyImagePlugins; + List partitionPlugins = ((PluginFinder)context.SyntaxReceiver)?.PartitionPlugins; + List mediaImagePlugins = ((PluginFinder)context.SyntaxReceiver)?.MediaImagePlugins; + List readOnlyFileSystems = ((PluginFinder)context.SyntaxReceiver)?.ReadOnlyFileSystems; + List writableFloppyImagePlugins = ((PluginFinder)context.SyntaxReceiver)?.WritableFloppyImagePlugins; + List writableImagePlugins = ((PluginFinder)context.SyntaxReceiver)?.WritableImagePlugins; + List byteAddressableImagePlugins = ((PluginFinder)context.SyntaxReceiver)?.ByteAddressableImagePlugins; StringBuilder sb = new(); @@ -117,8 +107,8 @@ public class PluginRegisterGenerator : ISourceGenerator sb.AppendLine(" public List GetAllArchivePlugins() => new()"); sb.AppendLine(" {"); - foreach(ClassDeclarationSyntax plugin in archives) - sb.AppendLine($" typeof({plugin.Identifier.Text}),"); + foreach(string plugin in archives) + sb.AppendLine($" typeof({plugin}),"); sb.AppendLine(" };"); } @@ -132,8 +122,8 @@ public class PluginRegisterGenerator : ISourceGenerator sb.AppendLine(" public List GetAllChecksumPlugins() => new()"); sb.AppendLine(" {"); - foreach(ClassDeclarationSyntax plugin in checksums) - sb.AppendLine($" typeof({plugin.Identifier.Text}),"); + foreach(string plugin in checksums) + sb.AppendLine($" typeof({plugin}),"); sb.AppendLine(" };"); } @@ -147,8 +137,8 @@ public class PluginRegisterGenerator : ISourceGenerator sb.AppendLine(" public List GetAllFilesystemPlugins() => new()"); sb.AppendLine(" {"); - foreach(ClassDeclarationSyntax plugin in fileSystems) - sb.AppendLine($" typeof({plugin.Identifier.Text}),"); + foreach(string plugin in fileSystems) + sb.AppendLine($" typeof({plugin}),"); sb.AppendLine(" };"); } @@ -162,8 +152,8 @@ public class PluginRegisterGenerator : ISourceGenerator sb.AppendLine(" public List GetAllFilterPlugins() => new()"); sb.AppendLine(" {"); - foreach(ClassDeclarationSyntax plugin in filters) - sb.AppendLine($" typeof({plugin.Identifier.Text}),"); + foreach(string plugin in filters) + sb.AppendLine($" typeof({plugin}),"); sb.AppendLine(" };"); } @@ -177,8 +167,8 @@ public class PluginRegisterGenerator : ISourceGenerator sb.AppendLine(" public List GetAllFloppyImagePlugins() => new()"); sb.AppendLine(" {"); - foreach(ClassDeclarationSyntax plugin in floppyImagePlugins) - sb.AppendLine($" typeof({plugin.Identifier.Text}),"); + foreach(string plugin in floppyImagePlugins) + sb.AppendLine($" typeof({plugin}),"); sb.AppendLine(" };"); } @@ -192,8 +182,8 @@ public class PluginRegisterGenerator : ISourceGenerator sb.AppendLine(" public List GetAllMediaImagePlugins() => new()"); sb.AppendLine(" {"); - foreach(ClassDeclarationSyntax plugin in mediaImagePlugins) - sb.AppendLine($" typeof({plugin.Identifier.Text}),"); + foreach(string plugin in mediaImagePlugins) + sb.AppendLine($" typeof({plugin}),"); sb.AppendLine(" };"); } @@ -207,8 +197,8 @@ public class PluginRegisterGenerator : ISourceGenerator sb.AppendLine(" public List GetAllPartitionPlugins() => new()"); sb.AppendLine(" {"); - foreach(ClassDeclarationSyntax plugin in partitionPlugins) - sb.AppendLine($" typeof({plugin.Identifier.Text}),"); + foreach(string plugin in partitionPlugins) + sb.AppendLine($" typeof({plugin}),"); sb.AppendLine(" };"); } @@ -222,8 +212,8 @@ public class PluginRegisterGenerator : ISourceGenerator sb.AppendLine(" public List GetAllReadOnlyFilesystemPlugins() => new()"); sb.AppendLine(" {"); - foreach(ClassDeclarationSyntax plugin in readOnlyFileSystems) - sb.AppendLine($" typeof({plugin.Identifier.Text}),"); + foreach(string plugin in readOnlyFileSystems) + sb.AppendLine($" typeof({plugin}),"); sb.AppendLine(" };"); } @@ -237,8 +227,8 @@ public class PluginRegisterGenerator : ISourceGenerator sb.AppendLine(" public List GetAllWritableFloppyImagePlugins() => new()"); sb.AppendLine(" {"); - foreach(ClassDeclarationSyntax plugin in writableFloppyImagePlugins) - sb.AppendLine($" typeof({plugin.Identifier.Text}),"); + foreach(string plugin in writableFloppyImagePlugins) + sb.AppendLine($" typeof({plugin}),"); sb.AppendLine(" };"); } @@ -252,8 +242,8 @@ public class PluginRegisterGenerator : ISourceGenerator sb.AppendLine(" public List GetAllWritableImagePlugins() => new()"); sb.AppendLine(" {"); - foreach(ClassDeclarationSyntax plugin in writableImagePlugins) - sb.AppendLine($" typeof({plugin.Identifier.Text}),"); + foreach(string plugin in writableImagePlugins) + sb.AppendLine($" typeof({plugin}),"); sb.AppendLine(" };"); } @@ -267,8 +257,8 @@ public class PluginRegisterGenerator : ISourceGenerator sb.AppendLine(" public List GetAllByteAddressablePlugins() => new()"); sb.AppendLine(" {"); - foreach(ClassDeclarationSyntax plugin in byteAddressableImagePlugins) - sb.AppendLine($" typeof({plugin.Identifier.Text}),"); + foreach(string plugin in byteAddressableImagePlugins) + sb.AppendLine($" typeof({plugin}),"); sb.AppendLine(" };"); } @@ -282,18 +272,18 @@ public class PluginRegisterGenerator : ISourceGenerator sealed class PluginFinder : ISyntaxReceiver { - public List Archives { get; } = new(); - public List Checksums { get; } = new(); - public List FileSystems { get; } = new(); - public List Filters { get; } = new(); - public List FloppyImagePlugins { get; } = new(); - public List MediaImagePlugins { get; } = new(); - public List PartitionPlugins { get; } = new(); - public List ReadOnlyFileSystems { get; } = new(); - public List WritableFloppyImagePlugins { get; } = new(); - public List WritableImagePlugins { get; } = new(); - public List ByteAddressableImagePlugins { get; } = new(); - public ClassDeclarationSyntax Register { get; private set; } + public List Archives { get; } = new(); + public List Checksums { get; } = new(); + public List FileSystems { get; } = new(); + public List Filters { get; } = new(); + public List FloppyImagePlugins { get; } = new(); + public List MediaImagePlugins { get; } = new(); + public List PartitionPlugins { get; } = new(); + public List ReadOnlyFileSystems { get; } = new(); + public List WritableFloppyImagePlugins { get; } = new(); + public List WritableImagePlugins { get; } = new(); + public List ByteAddressableImagePlugins { get; } = new(); + public ClassDeclarationSyntax Register { get; private set; } public void OnVisitSyntaxNode(SyntaxNode syntaxNode) { @@ -306,49 +296,60 @@ public class PluginRegisterGenerator : ISourceGenerator if(plugin.BaseList?.Types.Any(t => ((t as SimpleBaseTypeSyntax)?.Type as IdentifierNameSyntax)?.Identifier. ValueText == "IArchive") == true) - Archives.Add(plugin); + 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) - Checksums.Add(plugin); + 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) - FileSystems.Add(plugin); + 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) - Filters.Add(plugin); + 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) - FloppyImagePlugins.Add(plugin); + 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) - MediaImagePlugins.Add(plugin); + 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) - PartitionPlugins.Add(plugin); + 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) - ReadOnlyFileSystems.Add(plugin); + 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) - WritableFloppyImagePlugins.Add(plugin); + 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) - WritableImagePlugins.Add(plugin); + 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) - ByteAddressableImagePlugins.Add(plugin); + if(!ByteAddressableImagePlugins.Contains(plugin.Identifier.Text)) + ByteAddressableImagePlugins.Add(plugin.Identifier.Text); MediaImagePlugins.AddRange(WritableImagePlugins); FileSystems.AddRange(ReadOnlyFileSystems);