From 4821e818ea7c2b7c4a0dc0332d3c2387e1bb0b3b Mon Sep 17 00:00:00 2001 From: Piotr Stenke Date: Tue, 23 Aug 2022 12:50:29 +0200 Subject: [PATCH] Fix all issues and add CopyFrom sample --- Durian.sln | 15 + internal/GenerateAnalyzerReleases/Program.cs | 3 +- .../Durian.Samples.CopyFrom.csproj | 16 + samples/Durian.Samples.CopyFrom/Program.cs | 32 ++ .../Durian.Samples.DefaultParam.csproj | 5 +- .../Properties/launchSettings.json | 8 - .../Program.cs | 10 +- .../Data/FromSource/AccessorData.cs | 2 +- .../Data/FromSource/ConstructorData.cs | 2 +- .../Data/FromSource/ConversionOperatorData.cs | 2 +- .../Data/FromSource/DestructorData.cs | 2 +- .../Data/FromSource/LambdaData.cs | 2 +- .../Data/FromSource/LocalFunctionData.cs | 2 +- .../Data/FromSource/MethodData.cs | 4 +- .../Data/FromSource/NamespaceData.cs | 6 +- .../Data/FromSource/NamespaceOrTypeData.cs | 2 +- .../Data/FromSource/OperatorData.cs | 2 +- .../Data/FromSource/TypeData.cs | 12 +- .../DurianGeneratorBase.cs | 34 +- .../DurianGeneratorWithBuilder.cs | 312 ++++++++++++++--- .../_attr/LoggingConfigurationAttribute.cs | 11 +- ...iner.cs => GenericInnerMemberContainer.cs} | 6 +- ...ontainer.cs => IncludedMemberContainer.cs} | 14 +- ...=> IncludedMemberContainerWithoutInner.cs} | 16 +- ...peContainer.cs => InnerMemberContainer.cs} | 16 +- ...ypesContainer.cs => InnerTypeContainer.cs} | 14 +- ...Container.cs => LocalFunctionContainer.cs} | 14 +- ...ontainer.cs => MethodOverloadContainer.cs} | 10 +- ...ntainer.cs => NamespaceOrTypeContainer.cs} | 16 +- ...sContainer.cs => SubNamespaceContainer.cs} | 10 +- ...cs => WritableNamespaceOrTypeContainer.cs} | 18 +- ...sContainer.cs => WritableTypeContainer.cs} | 18 +- .../SymbolContainerFactory.cs | 48 +-- src/Durian.ConstExpr/Durian.ConstExpr.csproj | 3 +- src/Durian.CopyFrom/CopyFromGenerator.cs | 76 ++++- src/Durian.CopyFrom/Durian.CopyFrom.csproj | 3 +- .../Methods/CopyFromGenerator.method.cs | 33 +- .../Properties/launchSettings.json | 8 + .../Types/CopyFromGenerator.type.cs | 8 +- .../Durian.Core.Analyzer.csproj | 3 +- src/Durian.Core/DiagnosticData.cs | 5 +- .../DefaultParamAnalyzer.cs | 24 +- .../DefaultParamUtilities.cs | 4 +- .../Delegates/DefaultParamDelegateFilter.cs | 2 +- .../Durian.DefaultParam.csproj | 3 +- .../Methods/DefaultParamMethodFilter.cs | 2 +- .../Types/DefaultParamTypeFilter.cs | 2 +- .../Durian.FriendClass.csproj | 3 +- .../Properties/launchSettings.json | 8 + .../Durian.InterfaceTargets.csproj | 3 +- .../Properties/launchSettings.json | 8 + .../CopyFromMethodGeneratatorTests.cs | 322 ++++++++++++++---- .../CopyFromTypeGeneratorTests.cs | 6 +- 53 files changed, 871 insertions(+), 339 deletions(-) create mode 100644 samples/Durian.Samples.CopyFrom/Durian.Samples.CopyFrom.csproj create mode 100644 samples/Durian.Samples.CopyFrom/Program.cs delete mode 100644 samples/Durian.Samples.FriendClass/Properties/launchSettings.json rename src/Durian.AnalysisServices/SymbolContainers/Specialized/{InnerMembersContainer.cs => GenericInnerMemberContainer.cs} (92%) rename src/Durian.AnalysisServices/SymbolContainers/Specialized/{IncludedMembersSymbolContainer.cs => IncludedMemberContainer.cs} (95%) rename src/Durian.AnalysisServices/SymbolContainers/Specialized/{IncludedMembersSymbolContainerWithoutInner.cs => IncludedMemberContainerWithoutInner.cs} (83%) rename src/Durian.AnalysisServices/SymbolContainers/Specialized/{MembersOfTypeContainer.cs => InnerMemberContainer.cs} (88%) rename src/Durian.AnalysisServices/SymbolContainers/Specialized/{InnerTypesContainer.cs => InnerTypeContainer.cs} (88%) rename src/Durian.AnalysisServices/SymbolContainers/Specialized/{LocalFunctionsContainer.cs => LocalFunctionContainer.cs} (90%) rename src/Durian.AnalysisServices/SymbolContainers/Specialized/{OverloadsContainer.cs => MethodOverloadContainer.cs} (87%) rename src/Durian.AnalysisServices/SymbolContainers/Specialized/{NamespacesOrTypesContainer.cs => NamespaceOrTypeContainer.cs} (86%) rename src/Durian.AnalysisServices/SymbolContainers/Specialized/{SubNamespacesContainer.cs => SubNamespaceContainer.cs} (87%) rename src/Durian.AnalysisServices/SymbolContainers/Specialized/{WritableNamespacesOrTypesContainer.cs => WritableNamespaceOrTypeContainer.cs} (76%) rename src/Durian.AnalysisServices/SymbolContainers/Specialized/{WritableTypesContainer.cs => WritableTypeContainer.cs} (67%) create mode 100644 src/Durian.CopyFrom/Properties/launchSettings.json create mode 100644 src/Durian.FriendClass/Properties/launchSettings.json create mode 100644 src/Durian.InterfaceTargets/Properties/launchSettings.json diff --git a/Durian.sln b/Durian.sln index 40698ba8..79036981 100644 --- a/Durian.sln +++ b/Durian.sln @@ -192,6 +192,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CopyFrom", "CopyFrom", "{07 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Durian.ConstExpr", "src\Durian.ConstExpr\Durian.ConstExpr.csproj", "{4563AEC2-3292-4CDD-B920-E615670CB101}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Durian.Samples.CopyFrom", "samples\Durian.Samples.CopyFrom\Durian.Samples.CopyFrom.csproj", "{9C383ACD-8C9E-4C24-B2EA-4326C7553866}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -442,6 +444,18 @@ Global {4563AEC2-3292-4CDD-B920-E615670CB101}.Release|x64.Build.0 = Release|Any CPU {4563AEC2-3292-4CDD-B920-E615670CB101}.Release|x86.ActiveCfg = Release|Any CPU {4563AEC2-3292-4CDD-B920-E615670CB101}.Release|x86.Build.0 = Release|Any CPU + {9C383ACD-8C9E-4C24-B2EA-4326C7553866}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9C383ACD-8C9E-4C24-B2EA-4326C7553866}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9C383ACD-8C9E-4C24-B2EA-4326C7553866}.Debug|x64.ActiveCfg = Debug|Any CPU + {9C383ACD-8C9E-4C24-B2EA-4326C7553866}.Debug|x64.Build.0 = Debug|Any CPU + {9C383ACD-8C9E-4C24-B2EA-4326C7553866}.Debug|x86.ActiveCfg = Debug|Any CPU + {9C383ACD-8C9E-4C24-B2EA-4326C7553866}.Debug|x86.Build.0 = Debug|Any CPU + {9C383ACD-8C9E-4C24-B2EA-4326C7553866}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9C383ACD-8C9E-4C24-B2EA-4326C7553866}.Release|Any CPU.Build.0 = Release|Any CPU + {9C383ACD-8C9E-4C24-B2EA-4326C7553866}.Release|x64.ActiveCfg = Release|Any CPU + {9C383ACD-8C9E-4C24-B2EA-4326C7553866}.Release|x64.Build.0 = Release|Any CPU + {9C383ACD-8C9E-4C24-B2EA-4326C7553866}.Release|x86.ActiveCfg = Release|Any CPU + {9C383ACD-8C9E-4C24-B2EA-4326C7553866}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -474,6 +488,7 @@ Global {99672AD8-65D0-4F8F-95D1-ADF6839F5584} = {F6EC89D8-4343-42A1-B6D6-B0022D3004A0} {072AEE81-1199-4446-B2D5-54384D23DAE0} = {BA3DE2E2-7B32-4612-8219-24FBCF850813} {4563AEC2-3292-4CDD-B920-E615670CB101} = {74D7ECF9-D1F6-46FA-B8D8-D34F86F713EA} + {9C383ACD-8C9E-4C24-B2EA-4326C7553866} = {D98DD137-AADE-4474-86EF-9F0874607687} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {09524C45-0D6D-4456-B89D-9673853B9FA0} diff --git a/internal/GenerateAnalyzerReleases/Program.cs b/internal/GenerateAnalyzerReleases/Program.cs index 2c7327b0..4be2527b 100644 --- a/internal/GenerateAnalyzerReleases/Program.cs +++ b/internal/GenerateAnalyzerReleases/Program.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; using System.Text.RegularExpressions; @@ -142,7 +143,7 @@ private static void HandleDiagnosticFiles(string[] files, string currentDirector private static void WriteMatchData(MatchCollection matches, string moduleName, StringBuilder builder) { - foreach (Match match in matches) + foreach (Match match in matches.Cast()) { DiagnosticData? data = RetrieveDiagnosticData(match.ToString()); diff --git a/samples/Durian.Samples.CopyFrom/Durian.Samples.CopyFrom.csproj b/samples/Durian.Samples.CopyFrom/Durian.Samples.CopyFrom.csproj new file mode 100644 index 00000000..ce292c97 --- /dev/null +++ b/samples/Durian.Samples.CopyFrom/Durian.Samples.CopyFrom.csproj @@ -0,0 +1,16 @@ + + + + Exe + net6.0 + 9 + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/samples/Durian.Samples.CopyFrom/Program.cs b/samples/Durian.Samples.CopyFrom/Program.cs new file mode 100644 index 00000000..19f7c3ea --- /dev/null +++ b/samples/Durian.Samples.CopyFrom/Program.cs @@ -0,0 +1,32 @@ +// Copyright (c) Piotr Stenke. All rights reserved. +// Licensed under the MIT license. + +using System; + +namespace Durian.Samples.CopyFrom +{ + internal class Program + { + private static void Main() + { + // This method will print "Hello world!". + Test.Source(); + + // This method will print "Hello beautiful world!", even though it wasn't explicily written anywhere in the code! + Test.Target(); + + Console.ReadKey(); + } + } + + public static partial class Test + { + [CopyFromMethod(nameof(Source)), Pattern("world", "beautiful world")] + public static partial void Target(); + + public static void Source() + { + Console.WriteLine("Hello world!"); + } + } +} \ No newline at end of file diff --git a/samples/Durian.Samples.DefaultParam/Durian.Samples.DefaultParam.csproj b/samples/Durian.Samples.DefaultParam/Durian.Samples.DefaultParam.csproj index 59853a28..fbed0ae6 100644 --- a/samples/Durian.Samples.DefaultParam/Durian.Samples.DefaultParam.csproj +++ b/samples/Durian.Samples.DefaultParam/Durian.Samples.DefaultParam.csproj @@ -8,10 +8,7 @@ - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/samples/Durian.Samples.FriendClass/Properties/launchSettings.json b/samples/Durian.Samples.FriendClass/Properties/launchSettings.json deleted file mode 100644 index 08aa238a..00000000 --- a/samples/Durian.Samples.FriendClass/Properties/launchSettings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "profiles": { - "WSL": { - "commandName": "WSL2", - "distributionName": "" - } - } -} \ No newline at end of file diff --git a/samples/Durian.Samples.InterfaceTargets/Program.cs b/samples/Durian.Samples.InterfaceTargets/Program.cs index ad32ac79..c37dcbd8 100644 --- a/samples/Durian.Samples.InterfaceTargets/Program.cs +++ b/samples/Durian.Samples.InterfaceTargets/Program.cs @@ -8,6 +8,11 @@ public class Class : IInterface { } + // Error! + //public struct Struct : IInterface + //{ + //} + // This interface can only be implemented by classes. [InterfaceTargets(Durian.InterfaceTargets.Class)] public interface IInterface @@ -20,9 +25,4 @@ private static void Main() { } } - - // Error! - //public struct Struct : IInterface - //{ - //} } diff --git a/src/Durian.AnalysisServices/Data/FromSource/AccessorData.cs b/src/Durian.AnalysisServices/Data/FromSource/AccessorData.cs index bda69e71..b7965661 100644 --- a/src/Durian.AnalysisServices/Data/FromSource/AccessorData.cs +++ b/src/Durian.AnalysisServices/Data/FromSource/AccessorData.cs @@ -227,7 +227,7 @@ internal AccessorData(IMethodSymbol symbol, ICompilationData compilation, Member /// public ISymbolContainer GetLocalFunctions(IncludedMembers members) { - _localFunctions ??= new LocalFunctionsContainer(this, ParentCompilation); + _localFunctions ??= new LocalFunctionContainer(this, ParentCompilation); if (_localFunctions is IMappedSymbolContainer mapped) { diff --git a/src/Durian.AnalysisServices/Data/FromSource/ConstructorData.cs b/src/Durian.AnalysisServices/Data/FromSource/ConstructorData.cs index 61e2b7a8..5aa09ffc 100644 --- a/src/Durian.AnalysisServices/Data/FromSource/ConstructorData.cs +++ b/src/Durian.AnalysisServices/Data/FromSource/ConstructorData.cs @@ -247,7 +247,7 @@ internal ConstructorData(IMethodSymbol symbol, ICompilationData compilation, Mem /// public ISymbolContainer GetLocalFunctions(IncludedMembers members) { - _localFunctions ??= new LocalFunctionsContainer(this, ParentCompilation); + _localFunctions ??= new LocalFunctionContainer(this, ParentCompilation); if (_localFunctions is IMappedSymbolContainer mapped) { diff --git a/src/Durian.AnalysisServices/Data/FromSource/ConversionOperatorData.cs b/src/Durian.AnalysisServices/Data/FromSource/ConversionOperatorData.cs index 0baef0ec..038aaa79 100644 --- a/src/Durian.AnalysisServices/Data/FromSource/ConversionOperatorData.cs +++ b/src/Durian.AnalysisServices/Data/FromSource/ConversionOperatorData.cs @@ -262,7 +262,7 @@ internal ConversionOperatorData(IMethodSymbol symbol, ICompilationData compilati /// public ISymbolContainer GetLocalFunctions(IncludedMembers members) { - _localFunctions ??= new LocalFunctionsContainer(this, ParentCompilation); + _localFunctions ??= new LocalFunctionContainer(this, ParentCompilation); if (_localFunctions is IMappedSymbolContainer mapped) { diff --git a/src/Durian.AnalysisServices/Data/FromSource/DestructorData.cs b/src/Durian.AnalysisServices/Data/FromSource/DestructorData.cs index 4c89ec33..f33b8583 100644 --- a/src/Durian.AnalysisServices/Data/FromSource/DestructorData.cs +++ b/src/Durian.AnalysisServices/Data/FromSource/DestructorData.cs @@ -171,7 +171,7 @@ internal DestructorData(IMethodSymbol symbol, ICompilationData compilation, Memb /// public ISymbolContainer GetLocalFunctions(IncludedMembers members) { - _localFunctions ??= new LocalFunctionsContainer(this, ParentCompilation); + _localFunctions ??= new LocalFunctionContainer(this, ParentCompilation); if (_localFunctions is IMappedSymbolContainer mapped) { diff --git a/src/Durian.AnalysisServices/Data/FromSource/LambdaData.cs b/src/Durian.AnalysisServices/Data/FromSource/LambdaData.cs index a55bf9be..331bd023 100644 --- a/src/Durian.AnalysisServices/Data/FromSource/LambdaData.cs +++ b/src/Durian.AnalysisServices/Data/FromSource/LambdaData.cs @@ -206,7 +206,7 @@ internal LambdaData(IMethodSymbol symbol, ICompilationData compilation, MemberDa /// public ISymbolContainer GetLocalFunctions(IncludedMembers members) { - _localFunctions ??= new LocalFunctionsContainer(this, ParentCompilation); + _localFunctions ??= new LocalFunctionContainer(this, ParentCompilation); if (_localFunctions is IMappedSymbolContainer mapped) { diff --git a/src/Durian.AnalysisServices/Data/FromSource/LocalFunctionData.cs b/src/Durian.AnalysisServices/Data/FromSource/LocalFunctionData.cs index 3978c527..0e9a1bdc 100644 --- a/src/Durian.AnalysisServices/Data/FromSource/LocalFunctionData.cs +++ b/src/Durian.AnalysisServices/Data/FromSource/LocalFunctionData.cs @@ -232,7 +232,7 @@ internal LocalFunctionData(IMethodSymbol symbol, ICompilationData compilation, M /// public ISymbolContainer GetLocalFunctions(IncludedMembers members) { - _localFunctions ??= new LocalFunctionsContainer(this, ParentCompilation); + _localFunctions ??= new LocalFunctionContainer(this, ParentCompilation); if (_localFunctions is IMappedSymbolContainer mapped) { diff --git a/src/Durian.AnalysisServices/Data/FromSource/MethodData.cs b/src/Durian.AnalysisServices/Data/FromSource/MethodData.cs index 6696dd67..3270966f 100644 --- a/src/Durian.AnalysisServices/Data/FromSource/MethodData.cs +++ b/src/Durian.AnalysisServices/Data/FromSource/MethodData.cs @@ -346,7 +346,7 @@ internal MethodData(IMethodSymbol symbol, ICompilationData compilation, MemberDa /// public ISymbolContainer GetLocalFunctions(IncludedMembers members) { - _localFunctions ??= new LocalFunctionsContainer(this, ParentCompilation); + _localFunctions ??= new LocalFunctionContainer(this, ParentCompilation); if (_localFunctions is IMappedSymbolContainer mapped) { @@ -359,7 +359,7 @@ public ISymbolContainer GetLocalFunctions(Inc /// public ISymbolContainer GetOverloads(IncludedMembers members) { - _overloads ??= new OverloadsContainer(this, ParentCompilation); + _overloads ??= new MethodOverloadContainer(this, ParentCompilation); if (_localFunctions is IMappedSymbolContainer mapped) { diff --git a/src/Durian.AnalysisServices/Data/FromSource/NamespaceData.cs b/src/Durian.AnalysisServices/Data/FromSource/NamespaceData.cs index 38830b25..ea5901ea 100644 --- a/src/Durian.AnalysisServices/Data/FromSource/NamespaceData.cs +++ b/src/Durian.AnalysisServices/Data/FromSource/NamespaceData.cs @@ -160,7 +160,7 @@ public ISymbolContainer GetNamespaces(Included switch (_members) { - case NamespacesOrTypesContainer typed: + case NamespaceOrTypeContainer typed: IMappedSymbolContainer namespaces = typed.GetNamespaces(); return namespaces.ResolveLevel(members); @@ -191,7 +191,7 @@ public ISymbolContainer GetTypes(IncludedMembers me switch (_members) { - case NamespacesOrTypesContainer typed: + case NamespaceOrTypeContainer typed: IMappedSymbolContainer types = typed.GetTypes(); return types.ResolveLevel(members); @@ -287,7 +287,7 @@ INamespaceOrTypeData INamespaceOrTypeData.Clone() [MemberNotNull(nameof(_members))] private void InitMembers() { - _members ??= new NamespacesOrTypesContainer(this, ParentCompilation); + _members ??= new NamespaceOrTypeContainer(this, ParentCompilation); } } } diff --git a/src/Durian.AnalysisServices/Data/FromSource/NamespaceOrTypeData.cs b/src/Durian.AnalysisServices/Data/FromSource/NamespaceOrTypeData.cs index f8037223..1c657d01 100644 --- a/src/Durian.AnalysisServices/Data/FromSource/NamespaceOrTypeData.cs +++ b/src/Durian.AnalysisServices/Data/FromSource/NamespaceOrTypeData.cs @@ -161,7 +161,7 @@ internal NamespaceOrTypeData(INamespaceOrTypeSymbol symbol, ICompilationData com /// public ISymbolContainer GetTypes(IncludedMembers members) { - _types ??= new NamespacesOrTypesContainer(this, ParentCompilation).GetTypes(); + _types ??= new NamespaceOrTypeContainer(this, ParentCompilation).GetTypes(); #pragma warning disable IDE0066 // Convert switch statement to expression switch (_types) diff --git a/src/Durian.AnalysisServices/Data/FromSource/OperatorData.cs b/src/Durian.AnalysisServices/Data/FromSource/OperatorData.cs index 0f791524..e5a0ca14 100644 --- a/src/Durian.AnalysisServices/Data/FromSource/OperatorData.cs +++ b/src/Durian.AnalysisServices/Data/FromSource/OperatorData.cs @@ -196,7 +196,7 @@ internal OperatorData(IMethodSymbol symbol, ICompilationData compilation, Member /// public ISymbolContainer GetLocalFunctions(IncludedMembers members) { - _localFunctions ??= new LocalFunctionsContainer(this, ParentCompilation); + _localFunctions ??= new LocalFunctionContainer(this, ParentCompilation); if (_localFunctions is IMappedSymbolContainer mapped) { diff --git a/src/Durian.AnalysisServices/Data/FromSource/TypeData.cs b/src/Durian.AnalysisServices/Data/FromSource/TypeData.cs index 2c91f28a..0c234eb3 100644 --- a/src/Durian.AnalysisServices/Data/FromSource/TypeData.cs +++ b/src/Durian.AnalysisServices/Data/FromSource/TypeData.cs @@ -259,7 +259,7 @@ public ISymbolContainer GetEvents(IncludedMembers memb switch (_members) { - case MembersOfTypeContainer typed: + case InnerMemberContainer typed: IMappedSymbolContainer events = typed.GetEvents(); return events.ResolveLevel(members); @@ -284,7 +284,7 @@ public ISymbolContainer GetFields(IncludedMembers memb switch (_members) { - case MembersOfTypeContainer typed: + case InnerMemberContainer typed: IMappedSymbolContainer fields = typed.GetFields(); return fields.ResolveLevel(members); @@ -322,7 +322,7 @@ public ISymbolContainer GetMethods(IncludedMembers m switch (_members) { - case MembersOfTypeContainer typed: + case InnerMemberContainer typed: IMappedSymbolContainer methods = typed.GetMethods(); return methods.ResolveLevel(members); @@ -353,7 +353,7 @@ public ISymbolContainer GetProperties(IncludedMe switch (_members) { - case MembersOfTypeContainer typed: + case InnerMemberContainer typed: IMappedSymbolContainer properties = typed.GetProperties(); return properties.ResolveLevel(members); @@ -378,7 +378,7 @@ public ISymbolContainer GetTypes(IncludedMembers me switch (_members) { - case MembersOfTypeContainer typed: + case InnerMemberContainer typed: IMappedSymbolContainer types = typed.GetTypes(); return types.ResolveLevel(members); @@ -488,7 +488,7 @@ INamespaceOrTypeData INamespaceOrTypeData.Clone() [MethodImpl(MethodImplOptions.AggressiveInlining)] private void InitMembers() { - _members ??= new MembersOfTypeContainer(this, ParentCompilation); + _members ??= new InnerMemberContainer(this, ParentCompilation); } } } diff --git a/src/Durian.AnalysisServices/DurianGeneratorBase.cs b/src/Durian.AnalysisServices/DurianGeneratorBase.cs index 7566cd99..4127882a 100644 --- a/src/Durian.AnalysisServices/DurianGeneratorBase.cs +++ b/src/Durian.AnalysisServices/DurianGeneratorBase.cs @@ -23,6 +23,8 @@ namespace Durian.Analysis /// public abstract partial class DurianGeneratorBase : IDurianGenerator { + private readonly LoggingConfiguration? _initialConfig; + /// public abstract string GeneratorName { get; } @@ -44,7 +46,10 @@ public abstract partial class DurianGeneratorBase : IDurianGenerator public virtual int NumStaticTrees => GetInitialSources().Count(); /// + [MemberNotNullWhen(true, nameof(_initialConfig))] +#pragma warning disable CS8775 // Member must have a non-null value when exiting in some condition. public virtual bool SupportsDynamicLoggingConfiguration => true; +#pragma warning restore CS8775 // Member must have a non-null value when exiting in some condition. /// /// Initializes a new instance of the class. @@ -52,6 +57,12 @@ public abstract partial class DurianGeneratorBase : IDurianGenerator protected DurianGeneratorBase() { LogHandler = InitLogHandler(null); + + if(SupportsDynamicLoggingConfiguration) + { + _initialConfig = LoggingConfiguration.ForGenerator(this); + } + InstanceId = Guid.NewGuid(); } @@ -247,41 +258,60 @@ private protected bool PrepareForExecution(in GeneratorExecutionContext context, return InitializeCompilation(in context, modules, out compilation); } - private static LoggingConfiguration CreateDynamicLoggingConfiguration(AttributeData attribute) + private LoggingConfiguration CreateDynamicLoggingConfiguration(AttributeData attribute) { LoggingConfigurationAttribute attr = new(); + bool isChanged = false; if (attribute.TryGetNamedArgumentValue(nameof(EnableLoggingAttribute.EnableExceptions), out bool enableExceptions)) { attr.EnableExceptions = enableExceptions; + isChanged = true; } if (attribute.TryGetNamedArgumentEnumValue(nameof(EnableLoggingAttribute.DefaultNodeOutput), out NodeOutput defaultNodeOutput)) { attr.DefaultNodeOutput = defaultNodeOutput; + isChanged = true; } if (attribute.TryGetNamedArgumentValue(nameof(EnableLoggingAttribute.SupportsDiagnostics), out bool supportsDiagnostics)) { attr.SupportsDiagnostics = supportsDiagnostics; + isChanged = true; } if (attribute.TryGetNamedArgumentEnumValue(nameof(EnableLoggingAttribute.SupportedLogs), out GeneratorLogs supportedLogs)) { attr.SupportedLogs = supportedLogs; + isChanged = true; } if (attribute.TryGetNamedArgumentValue(nameof(EnableLoggingAttribute.LogDirectory), out string? logDirectory)) { attr.LogDirectory = logDirectory; + isChanged = true; } if (attribute.TryGetNamedArgumentValue(nameof(EnableLoggingAttribute.RelativeToDefault), out bool relativeToDefault)) { attr.RelativeToDefault = relativeToDefault; + isChanged = true; + } + + attr.RelativeToGlobal = false; + + if(isChanged) + { + if(logDirectory is null && !attr.RelativeToDefault) + { + return LoggingConfiguration.Default; + } + + return LoggingConfiguration.FromAttribute(attr as ILoggingConfigurationAttribute); } - return LoggingConfiguration.FromAttribute(attr as ILoggingConfigurationAttribute); + return _initialConfig!; } private static void EnableModules(ref CSharpCompilation compilation, in GeneratorExecutionContext context, DurianModule[] modules) diff --git a/src/Durian.AnalysisServices/DurianGeneratorWithBuilder.cs b/src/Durian.AnalysisServices/DurianGeneratorWithBuilder.cs index 57b359f4..eb720e82 100644 --- a/src/Durian.AnalysisServices/DurianGeneratorWithBuilder.cs +++ b/src/Durian.AnalysisServices/DurianGeneratorWithBuilder.cs @@ -24,8 +24,9 @@ public abstract class DurianGeneratorWithBuilder : DurianGenerator /// Initializes a new instance of the class. /// - protected DurianGeneratorWithBuilder() : this(null) + protected DurianGeneratorWithBuilder() { + _autoGeneratedAttribute = AutoGenerated.GetGeneratedCodeAttribute(GeneratorName, GeneratorVersion); } /// @@ -271,10 +272,17 @@ protected void WriteDeclarationLead(CodeBuilder builder, IMemberData member, str /// that was generated during the current generation pass. /// this was generated from. /// Current . + /// Determines whether to apply the and attributes to the generated node. /// Determines when to apply the <inheritdoc/> tag. - protected void WriteGeneratedMember(SyntaxNode generated, IMemberData original, TContext context, GenerateDocumentation applyInheritdoc = GenerateDocumentation.WhenPossible) + protected void WriteGeneratedMember( + SyntaxNode generated, + IMemberData original, + TContext context, + bool includeGenerationAttributes = true, + GenerateDocumentation applyInheritdoc = GenerateDocumentation.WhenPossible + ) { - WriteGeneratedMember(NodeToString(generated), original, context, applyInheritdoc); + WriteGeneratedMember(NodeToString(generated), original, context, includeGenerationAttributes, applyInheritdoc); } /// @@ -283,18 +291,44 @@ protected void WriteGeneratedMember(SyntaxNode generated, IMemberData original, /// that was generated during the current generation pass. /// this was generated from. /// Current . + /// Determines whether to apply the and attributes to the generated node. /// Determines when to apply the <inheritdoc/> tag. - protected void WriteGeneratedMember(string generated, IMemberData original, TContext context, GenerateDocumentation applyInheritdoc = GenerateDocumentation.WhenPossible) + protected void WriteGeneratedMember( + string generated, + IMemberData original, + TContext context, + bool includeGenerationAttributes = true, + GenerateDocumentation applyInheritdoc = GenerateDocumentation.WhenPossible) { - string generatedFrom = AutoGenerated.GetDurianGeneratedAttribute(SymbolToString(original.Symbol)); - if (TryGetInheritdoc(original, applyInheritdoc, out string? inheritdoc)) { - WriteGeneratedMember_Internal(generated, generatedFrom, inheritdoc, context); + if(includeGenerationAttributes) + { + string generatedFrom = AutoGenerated.GetDurianGeneratedAttribute(SymbolToString(original.Symbol)); + WriteGeneratedMember_Internal(generated, generatedFrom, inheritdoc, context); + } + else + { + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(inheritdoc); + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(generated); + context.CodeBuilder.NewLine(); + } } else { - WriteGeneratedMember_Internal(generated, generatedFrom, context); + if(includeGenerationAttributes) + { + string generatedFrom = AutoGenerated.GetDurianGeneratedAttribute(SymbolToString(original.Symbol)); + WriteGeneratedMember_Internal(generated, generatedFrom, context); + } + else + { + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(generated); + context.CodeBuilder.NewLine(); + } } } @@ -304,10 +338,16 @@ protected void WriteGeneratedMember(string generated, IMemberData original, TCon /// that was generated during the current generation pass. /// this was generated from. /// Current . + /// Determines whether to apply the and attributes to the generated node. /// Determines when to apply the <inheritdoc/> tag. - protected void WriteGeneratedMember(SyntaxNode generated, ISymbol original, TContext context, GenerateDocumentation applyInheritdoc = GenerateDocumentation.WhenPossible) + protected void WriteGeneratedMember( + SyntaxNode generated, + ISymbol original, + TContext context, + bool includeGenerationAttributes = true, + GenerateDocumentation applyInheritdoc = GenerateDocumentation.WhenPossible) { - WriteGeneratedMember(NodeToString(generated), original, context, applyInheritdoc); + WriteGeneratedMember(NodeToString(generated), original, context, includeGenerationAttributes, applyInheritdoc); } /// @@ -316,18 +356,45 @@ protected void WriteGeneratedMember(SyntaxNode generated, ISymbol original, TCon /// that was generated during the current generation pass. /// this was generated from. /// Current . + /// Determines whether to apply the and attributes to the generated node. /// Determines when to apply the <inheritdoc/> tag. - protected void WriteGeneratedMember(string generated, ISymbol original, TContext context, GenerateDocumentation applyInheritdoc = GenerateDocumentation.WhenPossible) + protected void WriteGeneratedMember( + string generated, + ISymbol original, + TContext context, + bool includeGenerationAttributes = true, + GenerateDocumentation applyInheritdoc = GenerateDocumentation.WhenPossible + ) { - string generatedFrom = AutoGenerated.GetDurianGeneratedAttribute(SymbolToString(original)); - if (TryGetInheritdoc(original, applyInheritdoc, out string? inheritdoc)) { - WriteGeneratedMember_Internal(generated, generatedFrom, inheritdoc, context); + if(includeGenerationAttributes) + { + string generatedFrom = AutoGenerated.GetDurianGeneratedAttribute(SymbolToString(original)); + WriteGeneratedMember_Internal(generated, generatedFrom, inheritdoc, context); + } + else + { + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(inheritdoc); + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(generated); + context.CodeBuilder.NewLine(); + } } else { - WriteGeneratedMember_Internal(generated, generatedFrom, context); + if(includeGenerationAttributes) + { + string generatedFrom = AutoGenerated.GetDurianGeneratedAttribute(SymbolToString(original)); + WriteGeneratedMember_Internal(generated, generatedFrom, context); + } + else + { + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(generated); + context.CodeBuilder.NewLine(); + } } } @@ -346,9 +413,19 @@ protected void WriteGeneratedMember(SyntaxNode generated, TContext context) /// /// that was generated during the current generation pass. /// Current . - protected void WriteGeneratedMember(string generated, TContext context) + /// Determines whether to apply the and attributes to the generated node. + protected void WriteGeneratedMember(string generated, TContext context, bool includeGenerationAttributes = true) { - WriteGeneratedMember_Internal(generated, AutoGenerated.GetDurianGeneratedAttribute(), context); + if(includeGenerationAttributes) + { + WriteGeneratedMember_Internal(generated, AutoGenerated.GetDurianGeneratedAttribute(), context); + } + else + { + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(generated); + context.CodeBuilder.NewLine(); + } } /// @@ -357,9 +434,10 @@ protected void WriteGeneratedMember(string generated, TContext context) /// that was generated during the current generation pass. /// Name of member this was generated from. /// Current . - protected void WriteGeneratedMember(SyntaxNode generated, string? generatedFrom, TContext context) + /// Determines whether to apply the and attributes to the generated node. + protected void WriteGeneratedMember(SyntaxNode generated, string? generatedFrom, TContext context, bool includeGenerationAttributes = true) { - WriteGeneratedMember(NodeToString(generated), generatedFrom, context); + WriteGeneratedMember(NodeToString(generated), generatedFrom, context, includeGenerationAttributes); } /// @@ -368,9 +446,19 @@ protected void WriteGeneratedMember(SyntaxNode generated, string? generatedFrom, /// that was generated during the current generation pass. /// Name of member this was generated from. /// Current . - protected void WriteGeneratedMember(string generated, string? generatedFrom, TContext context) + /// Determines whether to apply the and attributes to the generated node. + protected void WriteGeneratedMember(string generated, string? generatedFrom, TContext context, bool includeGenerationAttributes = true) { - WriteGeneratedMember_Internal(generated, AutoGenerated.GetDurianGeneratedAttribute(generatedFrom), context); + if (includeGenerationAttributes) + { + WriteGeneratedMember_Internal(generated, AutoGenerated.GetDurianGeneratedAttribute(generatedFrom), context); + } + else + { + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(generated); + context.CodeBuilder.NewLine(); + } } /// @@ -380,9 +468,10 @@ protected void WriteGeneratedMember(string generated, string? generatedFrom, TCo /// Name of member this was generated from. /// Text to put in the 'inheritdoc' tag. /// Current . - protected void WriteGeneratedMember(SyntaxNode generated, string? generatedFrom, string? inheritdoc, TContext context) + /// Determines whether to apply the and attributes to the generated node. + protected void WriteGeneratedMember(SyntaxNode generated, string? generatedFrom, string? inheritdoc, TContext context, bool includeGenerationAttributes = true) { - WriteGeneratedMember(NodeToString(generated), generatedFrom, inheritdoc, context); + WriteGeneratedMember(NodeToString(generated), generatedFrom, inheritdoc, context, includeGenerationAttributes); } /// @@ -392,9 +481,21 @@ protected void WriteGeneratedMember(SyntaxNode generated, string? generatedFrom, /// Name of member this was generated from. /// Text to put in the 'inheritdoc' tag. /// Current . - protected void WriteGeneratedMember(string generated, string? generatedFrom, string? inheritdoc, TContext context) + /// Determines whether to apply the and attributes to the generated node. + protected void WriteGeneratedMember(string generated, string? generatedFrom, string? inheritdoc, TContext context, bool includeGenerationAttributes = true) { - WriteGeneratedMember_Internal(generated, AutoGenerated.GetDurianGeneratedAttribute(generatedFrom), AutoGenerated.GetInheritdoc(inheritdoc), context); + if(includeGenerationAttributes) + { + WriteGeneratedMember_Internal(generated, AutoGenerated.GetDurianGeneratedAttribute(generatedFrom), AutoGenerated.GetInheritdoc(inheritdoc), context); + } + else + { + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(AutoGenerated.GetInheritdoc(inheritdoc)); + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(generated); + context.CodeBuilder.NewLine(); + } } /// @@ -402,9 +503,10 @@ protected void WriteGeneratedMember(string generated, string? generatedFrom, str /// /// s that were generated during the current generation pass. /// Current . - protected void WriteGeneratedMembers(SyntaxNode[] generated, TContext context) + /// Determines whether to apply the and attributes to the generated node. + protected void WriteGeneratedMembers(SyntaxNode[] generated, TContext context, bool includeGenerationAttributes = true) { - WriteGeneratedMembers(ConvertString(generated), context); + WriteGeneratedMembers(ConvertString(generated), context, includeGenerationAttributes); } /// @@ -412,15 +514,16 @@ protected void WriteGeneratedMembers(SyntaxNode[] generated, TContext context) /// /// s that were generated during the current generation pass. /// Current . - protected void WriteGeneratedMembers(string[] generated, TContext context) + /// Determines whether to apply the and attributes to the generated node. + protected void WriteGeneratedMembers(string[] generated, TContext context, bool includeGenerationAttributes = true) { - WriteGeneratedMember(generated[0], context); + WriteGeneratedMember(generated[0], context, includeGenerationAttributes); int length = generated.Length; for (int i = 1; i < length; i++) { context.CodeBuilder.NewLine(); - WriteGeneratedMember(generated[i], context); + WriteGeneratedMember(generated[i], context, includeGenerationAttributes); } } @@ -430,10 +533,17 @@ protected void WriteGeneratedMembers(string[] generated, TContext context) /// s that were generated during the current generation pass. /// this s were generated from. /// Current . + /// Determines whether to apply the and attributes to the generated node. /// Determines when to apply the <inheritdoc/> tag. - protected void WriteGeneratedMembers(SyntaxNode[] generated, IMemberData original, TContext context, GenerateDocumentation applyInheritdoc = GenerateDocumentation.WhenPossible) + protected void WriteGeneratedMembers( + SyntaxNode[] generated, + IMemberData original, + TContext context, + bool includeGenerationAttributes = true, + GenerateDocumentation applyInheritdoc = GenerateDocumentation.WhenPossible + ) { - WriteGeneratedMembers(ConvertString(generated), original, context, applyInheritdoc); + WriteGeneratedMembers(ConvertString(generated), original, context, includeGenerationAttributes, applyInheritdoc); } /// @@ -442,35 +552,79 @@ protected void WriteGeneratedMembers(SyntaxNode[] generated, IMemberData origina /// s that were generated during the current generation pass. /// this s were generated from. /// Current . + /// Determines whether to apply the and attributes to the generated node. /// Determines when to apply the <inheritdoc/> tag. - protected void WriteGeneratedMembers(string[] generated, IMemberData original, TContext context, GenerateDocumentation applyInheritdoc = GenerateDocumentation.WhenPossible) + protected void WriteGeneratedMembers( + string[] generated, + IMemberData original, + TContext context, + bool includeGenerationAttributes = true, + GenerateDocumentation applyInheritdoc = GenerateDocumentation.WhenPossible + ) { if (generated.Length == 0) { return; } - string generatedFrom = AutoGenerated.GetDurianGeneratedAttribute(SymbolToString(original.Symbol)); - int length = generated.Length; - if (TryGetInheritdoc(original, applyInheritdoc, out string? inheritdoc)) { - WriteGeneratedMember_Internal(generated[0], generatedFrom, inheritdoc, context); + if(includeGenerationAttributes) + { + string generatedFrom = AutoGenerated.GetDurianGeneratedAttribute(SymbolToString(original.Symbol)); + WriteGeneratedMember_Internal(generated[0], generatedFrom, inheritdoc, context); - for (int i = 1; i < length; i++) + for (int i = 1; i < generated.Length; i++) + { + context.CodeBuilder.NewLine(); + WriteGeneratedMember_Internal(generated[i], generatedFrom, inheritdoc, context); + } + } + else { + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(inheritdoc); + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(generated[0]); context.CodeBuilder.NewLine(); - WriteGeneratedMember_Internal(generated[i], generatedFrom, inheritdoc, context); + + for (int i = 1; i < generated.Length; i++) + { + context.CodeBuilder.NewLine(); + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(inheritdoc); + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(generated[i]); + context.CodeBuilder.NewLine(); + } } } else { - WriteGeneratedMember_Internal(generated[0], generatedFrom, context); + if(includeGenerationAttributes) + { + string generatedFrom = AutoGenerated.GetDurianGeneratedAttribute(SymbolToString(original.Symbol)); + WriteGeneratedMember_Internal(generated[0], generatedFrom, context); - for (int i = 1; i < length; i++) + for (int i = 1; i < generated.Length; i++) + { + context.CodeBuilder.NewLine(); + WriteGeneratedMember_Internal(generated[i], generatedFrom, context); + } + } + else { + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(generated[0]); context.CodeBuilder.NewLine(); - WriteGeneratedMember_Internal(generated[i], generatedFrom, context); + + for (int i = 1; i < generated.Length; i++) + { + context.CodeBuilder.NewLine(); + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(generated[i]); + context.CodeBuilder.NewLine(); + } } } } @@ -481,10 +635,17 @@ protected void WriteGeneratedMembers(string[] generated, IMemberData original, T /// s that were generated during the current generation pass. /// this s were generated from. /// Current . + /// Determines whether to apply the and attributes to the generated node. /// Determines when to apply the <inheritdoc/> tag. - protected void WriteGeneratedMembers(SyntaxNode[] generated, ISymbol original, TContext context, GenerateDocumentation applyInheritdoc = GenerateDocumentation.WhenPossible) + protected void WriteGeneratedMembers( + SyntaxNode[] generated, + ISymbol original, + TContext context, + bool includeGenerationAttributes = true, + GenerateDocumentation applyInheritdoc = GenerateDocumentation.WhenPossible + ) { - WriteGeneratedMembers(ConvertString(generated), original, context, applyInheritdoc); + WriteGeneratedMembers(ConvertString(generated), original, context, includeGenerationAttributes, applyInheritdoc); } /// @@ -493,35 +654,78 @@ protected void WriteGeneratedMembers(SyntaxNode[] generated, ISymbol original, T /// s that were generated during the current generation pass. /// this s were generated from. /// Current . + /// Determines whether to apply the and attributes to the generated node. /// Determines when to apply the <inheritdoc/> tag. - protected void WriteGeneratedMembers(string[] generated, ISymbol original, TContext context, GenerateDocumentation applyInheritdoc = GenerateDocumentation.WhenPossible) + protected void WriteGeneratedMembers( + string[] generated, + ISymbol original, + TContext context, + bool includeGenerationAttributes = true, + GenerateDocumentation applyInheritdoc = GenerateDocumentation.WhenPossible) { if (generated.Length == 0) { return; } - string generatedFrom = AutoGenerated.GetDurianGeneratedAttribute(SymbolToString(original)); - int length = generated.Length; - if (TryGetInheritdoc(original, applyInheritdoc, out string? inheritdoc)) { - WriteGeneratedMember_Internal(generated[0], generatedFrom, inheritdoc, context); + if(includeGenerationAttributes) + { + string generatedFrom = AutoGenerated.GetDurianGeneratedAttribute(SymbolToString(original)); + WriteGeneratedMember_Internal(generated[0], generatedFrom, inheritdoc, context); - for (int i = 1; i < length; i++) + for (int i = 1; i < generated.Length; i++) + { + context.CodeBuilder.NewLine(); + WriteGeneratedMember_Internal(generated[i], generatedFrom, inheritdoc, context); + } + } + else { + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(inheritdoc); + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(generated[0]); context.CodeBuilder.NewLine(); - WriteGeneratedMember_Internal(generated[i], generatedFrom, inheritdoc, context); + + for (int i = 1; i < generated.Length; i++) + { + context.CodeBuilder.NewLine(); + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(inheritdoc); + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(generated[i]); + context.CodeBuilder.NewLine(); + } } } else { - WriteGeneratedMember_Internal(generated[0], generatedFrom, context); + if(includeGenerationAttributes) + { + string generatedFrom = AutoGenerated.GetDurianGeneratedAttribute(SymbolToString(original)); + WriteGeneratedMember_Internal(generated[0], generatedFrom, context); - for (int i = 1; i < length; i++) + for (int i = 1; i < generated.Length; i++) + { + context.CodeBuilder.NewLine(); + WriteGeneratedMember_Internal(generated[i], generatedFrom, context); + } + } + else { + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(generated[0]); context.CodeBuilder.NewLine(); - WriteGeneratedMember_Internal(generated[i], generatedFrom, context); + + for (int i = 1; i < generated.Length; i++) + { + context.CodeBuilder.NewLine(); + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(generated[i]); + context.CodeBuilder.NewLine(); + } } } } diff --git a/src/Durian.AnalysisServices/Logging/_attr/LoggingConfigurationAttribute.cs b/src/Durian.AnalysisServices/Logging/_attr/LoggingConfigurationAttribute.cs index acb2a5af..69f1f091 100644 --- a/src/Durian.AnalysisServices/Logging/_attr/LoggingConfigurationAttribute.cs +++ b/src/Durian.AnalysisServices/Logging/_attr/LoggingConfigurationAttribute.cs @@ -32,14 +32,8 @@ public sealed class LoggingConfigurationAttribute : Attribute, ILoggingConfigura /// /// Determines whether the is relative to the . Defaults to . /// - /// If is set to , value of is irrelevant. public bool RelativeToDefault { get; set; } - /// - /// Determines whether the is relative to the global . Defaults to . - /// - public bool RelativeToGlobal { get; set; } = true; - /// public GeneratorLogs SupportedLogs { get; set; } @@ -48,6 +42,11 @@ public sealed class LoggingConfigurationAttribute : Attribute, ILoggingConfigura /// public bool SupportsDiagnostics { get; set; } + /// + /// Determines whether the is relative to the global . Defaults to . + /// + public bool RelativeToGlobal { get; set; } = true; + /// /// Initializes a new instance of the class. /// diff --git a/src/Durian.AnalysisServices/SymbolContainers/Specialized/InnerMembersContainer.cs b/src/Durian.AnalysisServices/SymbolContainers/Specialized/GenericInnerMemberContainer.cs similarity index 92% rename from src/Durian.AnalysisServices/SymbolContainers/Specialized/InnerMembersContainer.cs rename to src/Durian.AnalysisServices/SymbolContainers/Specialized/GenericInnerMemberContainer.cs index 04cdaac4..d3c3437a 100644 --- a/src/Durian.AnalysisServices/SymbolContainers/Specialized/InnerMembersContainer.cs +++ b/src/Durian.AnalysisServices/SymbolContainers/Specialized/GenericInnerMemberContainer.cs @@ -11,7 +11,7 @@ namespace Durian.Analysis.SymbolContainers.Specialized /// /// that handles inner members of a symbol. /// - internal sealed class InnerMembersContainer : IncludedMembersSymbolContainerWithoutInner + internal sealed class GenericInnerMemberContainer : IncludedMemberContainerWithoutInner where TSymbol : class, ISymbol where TData : class, IMemberData where TParentSymbol : class, ISymbol @@ -19,7 +19,7 @@ internal sealed class InnerMembersContainer ParentContainer { get; } - public InnerMembersContainer( + public GenericInnerMemberContainer( LeveledSymbolContainer parentContainer, ISymbolOrMember root ) : base(root, parentContainer.ParentCompilation, parentContainer.SymbolNameResolver, parentContainer.IncludeRoot) @@ -27,7 +27,7 @@ ISymbolOrMember root ParentContainer = parentContainer; } - public InnerMembersContainer( + public GenericInnerMemberContainer( LeveledSymbolContainer parentContainer, ISymbolOrMember root ) : base(root, parentContainer.ParentCompilation, parentContainer.SymbolNameResolver) diff --git a/src/Durian.AnalysisServices/SymbolContainers/Specialized/IncludedMembersSymbolContainer.cs b/src/Durian.AnalysisServices/SymbolContainers/Specialized/IncludedMemberContainer.cs similarity index 95% rename from src/Durian.AnalysisServices/SymbolContainers/Specialized/IncludedMembersSymbolContainer.cs rename to src/Durian.AnalysisServices/SymbolContainers/Specialized/IncludedMemberContainer.cs index 0519bb3b..b40785dd 100644 --- a/src/Durian.AnalysisServices/SymbolContainers/Specialized/IncludedMembersSymbolContainer.cs +++ b/src/Durian.AnalysisServices/SymbolContainers/Specialized/IncludedMemberContainer.cs @@ -13,7 +13,7 @@ namespace Durian.Analysis.SymbolContainers.Specialized /// /// Type of returned s. /// Type of returned s.s - public abstract class IncludedMembersSymbolContainer : LeveledSymbolContainer, IMappedSymbolContainer + public abstract class IncludedMemberContainer : LeveledSymbolContainer, IMappedSymbolContainer where TSymbol : class, ISymbol where TData : class, IMemberData { @@ -38,14 +38,14 @@ public abstract class IncludedMembersSymbolContainer : LeveledSy protected virtual IncludedMembers Limit => IncludedMembers.All; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// that is a root of all the underlaying containers. /// used to create s. /// used to resolve names of symbols when is called. /// Determines whether the should be included in the underlaying containers. /// is . - protected IncludedMembersSymbolContainer( + protected IncludedMemberContainer( ISymbolOrMember root, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default, @@ -56,13 +56,13 @@ protected IncludedMembersSymbolContainer( } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// that is a root of all the underlaying containers. /// used to create s. /// used to resolve names of symbols when is called. /// is . - protected IncludedMembersSymbolContainer( + protected IncludedMemberContainer( ISymbolOrMember root, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default @@ -105,9 +105,9 @@ public void ClearLevel(IncludedMembers level) } /// - public new IncludedMembersSymbolContainer Reverse() + public new IncludedMemberContainer Reverse() { - return (base.Reverse() as IncludedMembersSymbolContainer)!; + return (base.Reverse() as IncludedMemberContainer)!; } /// diff --git a/src/Durian.AnalysisServices/SymbolContainers/Specialized/IncludedMembersSymbolContainerWithoutInner.cs b/src/Durian.AnalysisServices/SymbolContainers/Specialized/IncludedMemberContainerWithoutInner.cs similarity index 83% rename from src/Durian.AnalysisServices/SymbolContainers/Specialized/IncludedMembersSymbolContainerWithoutInner.cs rename to src/Durian.AnalysisServices/SymbolContainers/Specialized/IncludedMemberContainerWithoutInner.cs index ae068b73..cd35752b 100644 --- a/src/Durian.AnalysisServices/SymbolContainers/Specialized/IncludedMembersSymbolContainerWithoutInner.cs +++ b/src/Durian.AnalysisServices/SymbolContainers/Specialized/IncludedMemberContainerWithoutInner.cs @@ -10,23 +10,23 @@ namespace Durian.Analysis.SymbolContainers.Specialized { /// - /// that is configured to ignore or map . + /// that is configured to ignore or map . /// /// Type of returned s. /// Type of returned s.s - public abstract class IncludedMembersSymbolContainerWithoutInner : IncludedMembersSymbolContainer + public abstract class IncludedMemberContainerWithoutInner : IncludedMemberContainer where TSymbol : class, ISymbol where TData : class, IMemberData { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// that is a root of all the underlaying containers. /// used to create s. /// used to resolve names of symbols when is called. /// Determines whether the should be included in the underlaying containers. /// is . - protected IncludedMembersSymbolContainerWithoutInner( + protected IncludedMemberContainerWithoutInner( ISymbolOrMember root, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default, @@ -36,13 +36,13 @@ protected IncludedMembersSymbolContainerWithoutInner( } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// that is a root of all the underlaying containers. /// used to create s. /// used to resolve names of symbols when is called. /// is . - protected IncludedMembersSymbolContainerWithoutInner( + protected IncludedMemberContainerWithoutInner( ISymbolOrMember root, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default @@ -51,9 +51,9 @@ protected IncludedMembersSymbolContainerWithoutInner( } /// - public new IncludedMembersSymbolContainerWithoutInner Reverse() + public new IncludedMemberContainerWithoutInner Reverse() { - return (base.Reverse() as IncludedMembersSymbolContainerWithoutInner)!; + return (base.Reverse() as IncludedMemberContainerWithoutInner)!; } /// diff --git a/src/Durian.AnalysisServices/SymbolContainers/Specialized/MembersOfTypeContainer.cs b/src/Durian.AnalysisServices/SymbolContainers/Specialized/InnerMemberContainer.cs similarity index 88% rename from src/Durian.AnalysisServices/SymbolContainers/Specialized/MembersOfTypeContainer.cs rename to src/Durian.AnalysisServices/SymbolContainers/Specialized/InnerMemberContainer.cs index 66f0ea90..6380a921 100644 --- a/src/Durian.AnalysisServices/SymbolContainers/Specialized/MembersOfTypeContainer.cs +++ b/src/Durian.AnalysisServices/SymbolContainers/Specialized/InnerMemberContainer.cs @@ -13,13 +13,13 @@ namespace Durian.Analysis.SymbolContainers.Specialized /// /// that handles members of a type. /// - public sealed class MembersOfTypeContainer : IncludedMembersSymbolContainerWithoutInner + public sealed class InnerMemberContainer : IncludedMemberContainerWithoutInner { - private InnerMembersContainer? _innerTypes; - private InnerMembersContainer? _properties; - private InnerMembersContainer? _fields; - private InnerMembersContainer? _methods; - private InnerMembersContainer? _events; + private GenericInnerMemberContainer? _innerTypes; + private GenericInnerMemberContainer? _properties; + private GenericInnerMemberContainer? _fields; + private GenericInnerMemberContainer? _methods; + private GenericInnerMemberContainer? _events; /// public new ISymbolOrMember Root => (base.Root as ISymbolOrMember)!; @@ -29,14 +29,14 @@ public sealed class MembersOfTypeContainer : IncludedMembersSymbolContainerWitho public new ISymbolOrMember TargetRoot => Root; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// that is a root of all the underlaying containers. /// used to create s. /// used to resolve names of symbols when is called. /// Determines whether the should be included in the underlaying containers. /// is . - public MembersOfTypeContainer( + public InnerMemberContainer( ISymbolOrMember root, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default, diff --git a/src/Durian.AnalysisServices/SymbolContainers/Specialized/InnerTypesContainer.cs b/src/Durian.AnalysisServices/SymbolContainers/Specialized/InnerTypeContainer.cs similarity index 88% rename from src/Durian.AnalysisServices/SymbolContainers/Specialized/InnerTypesContainer.cs rename to src/Durian.AnalysisServices/SymbolContainers/Specialized/InnerTypeContainer.cs index dbdb0cea..906734ae 100644 --- a/src/Durian.AnalysisServices/SymbolContainers/Specialized/InnerTypesContainer.cs +++ b/src/Durian.AnalysisServices/SymbolContainers/Specialized/InnerTypeContainer.cs @@ -13,20 +13,20 @@ namespace Durian.Analysis.SymbolContainers.Specialized /// /// that handles inner types. /// - public sealed class InnerTypesContainer : IncludedMembersSymbolContainerWithoutInner + public sealed class InnerTypeContainer : IncludedMemberContainerWithoutInner { /// public new ISymbolOrMember TargetRoot => (base.TargetRoot as ISymbolOrMember)!; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// that is a root of all the underlaying containers. /// used to create s. /// used to resolve names of symbols when is called. /// Determines whether the should be included in the underlaying containers. /// is . - public InnerTypesContainer( + public InnerTypeContainer( ISymbolOrMember root, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default, @@ -36,13 +36,13 @@ public InnerTypesContainer( } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// that is a root of all the underlaying containers. /// used to create s. /// used to resolve names of symbols when is called. /// is . - public InnerTypesContainer( + public InnerTypeContainer( ISymbolOrMember root, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default @@ -69,9 +69,9 @@ protected override IEnumerable> Res } /// - public new InnerTypesContainer Reverse() + public new InnerTypeContainer Reverse() { - return (base.Reverse() as InnerTypesContainer)!; + return (base.Reverse() as InnerTypeContainer)!; } private IEnumerable> GetTypes(ISymbolOrMember member) diff --git a/src/Durian.AnalysisServices/SymbolContainers/Specialized/LocalFunctionsContainer.cs b/src/Durian.AnalysisServices/SymbolContainers/Specialized/LocalFunctionContainer.cs similarity index 90% rename from src/Durian.AnalysisServices/SymbolContainers/Specialized/LocalFunctionsContainer.cs rename to src/Durian.AnalysisServices/SymbolContainers/Specialized/LocalFunctionContainer.cs index 71d22705..868025e5 100644 --- a/src/Durian.AnalysisServices/SymbolContainers/Specialized/LocalFunctionsContainer.cs +++ b/src/Durian.AnalysisServices/SymbolContainers/Specialized/LocalFunctionContainer.cs @@ -13,17 +13,17 @@ namespace Durian.Analysis.SymbolContainers.Specialized /// /// that handles local functions. /// - public sealed class LocalFunctionsContainer : IncludedMembersSymbolContainerWithoutInner + public sealed class LocalFunctionContainer : IncludedMemberContainerWithoutInner { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// that is a root of all the underlaying containers. /// used to create s. /// used to resolve names of symbols when is called. /// Determines whether the should be included in the underlaying containers. /// is . - public LocalFunctionsContainer( + public LocalFunctionContainer( ISymbolOrMember root, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default, @@ -33,13 +33,13 @@ public LocalFunctionsContainer( } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// that is a root of all the underlaying containers. /// used to create s. /// used to resolve names of symbols when is called. /// is . - public LocalFunctionsContainer( + public LocalFunctionContainer( ISymbolOrMember root, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default @@ -66,9 +66,9 @@ protected override IEnumerable - public new LocalFunctionsContainer Reverse() + public new LocalFunctionContainer Reverse() { - return (base.Reverse() as LocalFunctionsContainer)!; + return (base.Reverse() as LocalFunctionContainer)!; } private IEnumerable> GetLocalFunctions(ISymbolOrMember member) diff --git a/src/Durian.AnalysisServices/SymbolContainers/Specialized/OverloadsContainer.cs b/src/Durian.AnalysisServices/SymbolContainers/Specialized/MethodOverloadContainer.cs similarity index 87% rename from src/Durian.AnalysisServices/SymbolContainers/Specialized/OverloadsContainer.cs rename to src/Durian.AnalysisServices/SymbolContainers/Specialized/MethodOverloadContainer.cs index 000d1276..1504c857 100644 --- a/src/Durian.AnalysisServices/SymbolContainers/Specialized/OverloadsContainer.cs +++ b/src/Durian.AnalysisServices/SymbolContainers/Specialized/MethodOverloadContainer.cs @@ -13,17 +13,17 @@ namespace Durian.Analysis.SymbolContainers.Specialized /// /// that handles method overloads. /// - public sealed class OverloadsContainer : IncludedMembersSymbolContainerWithoutInner + public sealed class MethodOverloadContainer : IncludedMemberContainerWithoutInner { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// that is a root of all the underlaying containers. /// used to create s. /// used to resolve names of symbols when is called. /// Determines whether the should be included in the underlaying containers. /// is . - public OverloadsContainer( + public MethodOverloadContainer( ISymbolOrMember root, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default, @@ -51,9 +51,9 @@ protected override IEnumerable> Reso } /// - public new OverloadsContainer Reverse() + public new MethodOverloadContainer Reverse() { - return (base.Reverse() as OverloadsContainer)!; + return (base.Reverse() as MethodOverloadContainer)!; } private IEnumerable> GetOverloads(ISymbolOrMember member) diff --git a/src/Durian.AnalysisServices/SymbolContainers/Specialized/NamespacesOrTypesContainer.cs b/src/Durian.AnalysisServices/SymbolContainers/Specialized/NamespaceOrTypeContainer.cs similarity index 86% rename from src/Durian.AnalysisServices/SymbolContainers/Specialized/NamespacesOrTypesContainer.cs rename to src/Durian.AnalysisServices/SymbolContainers/Specialized/NamespaceOrTypeContainer.cs index 20fcbc48..f0419447 100644 --- a/src/Durian.AnalysisServices/SymbolContainers/Specialized/NamespacesOrTypesContainer.cs +++ b/src/Durian.AnalysisServices/SymbolContainers/Specialized/NamespaceOrTypeContainer.cs @@ -14,20 +14,20 @@ namespace Durian.Analysis.SymbolContainers.Specialized /// /// that handles sub-namespaces and types. /// - public sealed class NamespacesOrTypesContainer : IncludedMembersSymbolContainer + public sealed class NamespaceOrTypeContainer : IncludedMemberContainer { private IMappedSymbolContainer? _subNamespaces; - private InnerMembersContainer? _innerTypes; + private GenericInnerMemberContainer? _innerTypes; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// that is a root of all the underlaying containers. /// used to create s. /// used to resolve names of symbols when is called. /// Determines whether the should be included in the underlaying containers. /// is . - public NamespacesOrTypesContainer( + public NamespaceOrTypeContainer( ISymbolOrMember root, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default, @@ -53,7 +53,7 @@ public IMappedSymbolContainer /// public IMappedSymbolContainer GetTypes() { - return _innerTypes ??= new InnerMembersContainer(this, TargetRoot); + return _innerTypes ??= new GenericInnerMemberContainer(this, TargetRoot); } /// @@ -81,9 +81,9 @@ protected override IEnumerable - public new NamespacesOrTypesContainer Reverse() + public new NamespaceOrTypeContainer Reverse() { - return (base.Reverse() as NamespacesOrTypesContainer)!; + return (base.Reverse() as NamespaceOrTypeContainer)!; } private IEnumerable> GetNamespacesOrTypes(ISymbolOrMember member) @@ -103,7 +103,7 @@ private IMappedSymbolContainer @namespace) { - return new InnerMembersContainer(this, @namespace); + return new GenericInnerMemberContainer(this, @namespace); } return (SymbolContainerFactory.EmptyLeveled() as IMappedSymbolContainer)!; diff --git a/src/Durian.AnalysisServices/SymbolContainers/Specialized/SubNamespacesContainer.cs b/src/Durian.AnalysisServices/SymbolContainers/Specialized/SubNamespaceContainer.cs similarity index 87% rename from src/Durian.AnalysisServices/SymbolContainers/Specialized/SubNamespacesContainer.cs rename to src/Durian.AnalysisServices/SymbolContainers/Specialized/SubNamespaceContainer.cs index 4e0c9405..daedd77d 100644 --- a/src/Durian.AnalysisServices/SymbolContainers/Specialized/SubNamespacesContainer.cs +++ b/src/Durian.AnalysisServices/SymbolContainers/Specialized/SubNamespaceContainer.cs @@ -13,17 +13,17 @@ namespace Durian.Analysis.SymbolContainers.Specialized /// /// that handles sub-namespaces. /// - public sealed class SubNamespacesContainer : IncludedMembersSymbolContainerWithoutInner + public sealed class SubNamespaceContainer : IncludedMemberContainerWithoutInner { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// that is a root of all the underlaying containers. /// used to create s. /// used to resolve names of symbols when is called. /// Determines whether the should be included in the underlaying containers. /// is . - public SubNamespacesContainer( + public SubNamespaceContainer( ISymbolOrMember root, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default, @@ -51,9 +51,9 @@ protected override IEnumerable } /// - public new SubNamespacesContainer Reverse() + public new SubNamespaceContainer Reverse() { - return (base.Reverse() as SubNamespacesContainer)!; + return (base.Reverse() as SubNamespaceContainer)!; } private IEnumerable> GetNamespaces(ISymbolOrMember member) diff --git a/src/Durian.AnalysisServices/SymbolContainers/Specialized/WritableNamespacesOrTypesContainer.cs b/src/Durian.AnalysisServices/SymbolContainers/Specialized/WritableNamespaceOrTypeContainer.cs similarity index 76% rename from src/Durian.AnalysisServices/SymbolContainers/Specialized/WritableNamespacesOrTypesContainer.cs rename to src/Durian.AnalysisServices/SymbolContainers/Specialized/WritableNamespaceOrTypeContainer.cs index 53c41ec8..4e5d5047 100644 --- a/src/Durian.AnalysisServices/SymbolContainers/Specialized/WritableNamespacesOrTypesContainer.cs +++ b/src/Durian.AnalysisServices/SymbolContainers/Specialized/WritableNamespaceOrTypeContainer.cs @@ -13,46 +13,46 @@ namespace Durian.Analysis.SymbolContainers.Specialized /// that provides default configuration for handling s. /// /// Type of target . - public sealed class WritableNamespacesOrTypesContainer : WritableSymbolContainer where TData : class, INamespaceOrTypeData + public sealed class WritableNamespaceOrTypeContainer : WritableSymbolContainer where TData : class, INamespaceOrTypeData { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public WritableNamespacesOrTypesContainer() + public WritableNamespaceOrTypeContainer() { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Parent of the current container. /// Required for converting s to s. /// used to resolve names of symbols when is called. - public WritableNamespacesOrTypesContainer(ICompilationData? parentCompilation, ISymbolNameResolver? nameResolver = default) : base(parentCompilation, nameResolver) + public WritableNamespaceOrTypeContainer(ICompilationData? parentCompilation, ISymbolNameResolver? nameResolver = default) : base(parentCompilation, nameResolver) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Collection of s to add to the container. /// Parent of the current container. /// Required for converting s to s. /// used to resolve names of symbols when is called. /// is . - public WritableNamespacesOrTypesContainer(IEnumerable collection, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default) : base(collection, parentCompilation, nameResolver) + public WritableNamespaceOrTypeContainer(IEnumerable collection, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default) : base(collection, parentCompilation, nameResolver) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Collection of to add to the container. /// Parent of the current container. /// Required for converting s to s. /// used to resolve names of symbols when is called. /// is . - public WritableNamespacesOrTypesContainer(IEnumerable> collection, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default) : base(collection, parentCompilation, nameResolver) + public WritableNamespaceOrTypeContainer(IEnumerable> collection, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default) : base(collection, parentCompilation, nameResolver) { } diff --git a/src/Durian.AnalysisServices/SymbolContainers/Specialized/WritableTypesContainer.cs b/src/Durian.AnalysisServices/SymbolContainers/Specialized/WritableTypeContainer.cs similarity index 67% rename from src/Durian.AnalysisServices/SymbolContainers/Specialized/WritableTypesContainer.cs rename to src/Durian.AnalysisServices/SymbolContainers/Specialized/WritableTypeContainer.cs index 4a3b49f8..f0c3bd81 100644 --- a/src/Durian.AnalysisServices/SymbolContainers/Specialized/WritableTypesContainer.cs +++ b/src/Durian.AnalysisServices/SymbolContainers/Specialized/WritableTypeContainer.cs @@ -12,46 +12,46 @@ namespace Durian.Analysis.SymbolContainers.Specialized /// that provides default configuration for handling s. /// /// Type of target . - public sealed class WritableTypesContainer : WritableSymbolContainer where TData : class, ITypeData + public sealed class WritableTypeContainer : WritableSymbolContainer where TData : class, ITypeData { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public WritableTypesContainer() + public WritableTypeContainer() { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Parent of the current container. /// Required for converting s to s. /// used to resolve names of symbols when is called. - public WritableTypesContainer(ICompilationData? parentCompilation, ISymbolNameResolver? nameResolver = default) : base(parentCompilation, nameResolver) + public WritableTypeContainer(ICompilationData? parentCompilation, ISymbolNameResolver? nameResolver = default) : base(parentCompilation, nameResolver) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Collection of s to add to the container. /// Parent of the current container. /// Required for converting s to s. /// used to resolve names of symbols when is called. /// is . - public WritableTypesContainer(IEnumerable collection, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default) : base(collection, parentCompilation, nameResolver) + public WritableTypeContainer(IEnumerable collection, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default) : base(collection, parentCompilation, nameResolver) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Collection of to add to the container. /// Parent of the current container. /// Required for converting s to s. /// used to resolve names of symbols when is called. /// is . - public WritableTypesContainer(IEnumerable> collection, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default) : base(collection, parentCompilation, nameResolver) + public WritableTypeContainer(IEnumerable> collection, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default) : base(collection, parentCompilation, nameResolver) { } diff --git a/src/Durian.AnalysisServices/SymbolContainers/SymbolContainerFactory.cs b/src/Durian.AnalysisServices/SymbolContainers/SymbolContainerFactory.cs index e7d3c085..7d4dfcf5 100644 --- a/src/Durian.AnalysisServices/SymbolContainers/SymbolContainerFactory.cs +++ b/src/Durian.AnalysisServices/SymbolContainers/SymbolContainerFactory.cs @@ -1662,7 +1662,7 @@ public static SymbolContainerBuilder. /// /// Collection of s to add to the container. - public static SymbolContainerBuilder> ToWritableContainer(this IEnumerable collection) + public static SymbolContainerBuilder> ToWritableContainer(this IEnumerable collection) { return new(collection); } @@ -1671,7 +1671,7 @@ public static SymbolContainerBuilder> ToWritab /// Creates a new . /// /// Collection of s to add to the container. - public static SymbolContainerBuilder> ToWritableContainer(this IEnumerable> collection) + public static SymbolContainerBuilder> ToWritableContainer(this IEnumerable> collection) { return new(collection); } @@ -1681,7 +1681,7 @@ public static SymbolContainerBuilder> ToWritab /// /// Collection of s to add to the container. /// Type of target . - public static SymbolContainerBuilder> ToWritableContainer(this IEnumerable collection) where TData : class, ITypeData + public static SymbolContainerBuilder> ToWritableContainer(this IEnumerable collection) where TData : class, ITypeData { return new(collection); } @@ -1691,7 +1691,7 @@ public static SymbolContainerBuilder> ToWritableCo /// /// Collection of s to add to the container. /// Type of target . - public static SymbolContainerBuilder> ToWritableContainer(this IEnumerable> collection) where TData : class, ITypeData + public static SymbolContainerBuilder> ToWritableContainer(this IEnumerable> collection) where TData : class, ITypeData { return new(collection); } @@ -1700,7 +1700,7 @@ public static SymbolContainerBuilder> ToWritableCo /// Creates a new . /// /// Collection of s to add to the container. - public static SymbolContainerBuilder> ToWritableContainer(this IEnumerable collection) + public static SymbolContainerBuilder> ToWritableContainer(this IEnumerable collection) { return new(collection); } @@ -1709,7 +1709,7 @@ public static SymbolContainerBuilder. /// /// Collection of s to add to the container. - public static SymbolContainerBuilder> ToWritableContainer(this IEnumerable> collection) + public static SymbolContainerBuilder> ToWritableContainer(this IEnumerable> collection) { return new(collection); } @@ -1719,7 +1719,7 @@ public static SymbolContainerBuilder /// Collection of s to add to the container. /// Type of target . - public static SymbolContainerBuilder> ToWritableContainer(this IEnumerable collection) where TData : class, INamespaceOrTypeData + public static SymbolContainerBuilder> ToWritableContainer(this IEnumerable collection) where TData : class, INamespaceOrTypeData { return new(collection); } @@ -1729,7 +1729,7 @@ public static SymbolContainerBuilder> /// /// Collection of s to add to the container. /// Type of target . - public static SymbolContainerBuilder> ToWritableContainer(this IEnumerable> collection) where TData : class, INamespaceOrTypeData + public static SymbolContainerBuilder> ToWritableContainer(this IEnumerable> collection) where TData : class, INamespaceOrTypeData { return new(collection); } @@ -1821,7 +1821,7 @@ public static WritableSymbolContainer ToWritableContain } /// - /// Creates a new . + /// Creates a new . /// /// Collection of s to add to the container. /// @@ -1829,13 +1829,13 @@ public static WritableSymbolContainer ToWritableContain /// Required for converting s to s. /// /// used to resolve names of symbols when is called. - public static WritableTypesContainer ToWritableContainer(this IEnumerable collection, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default) + public static WritableTypeContainer ToWritableContainer(this IEnumerable collection, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default) { return new(collection, parentCompilation, nameResolver); } /// - /// Creates a new . + /// Creates a new . /// /// Collection of s to add to the container. /// @@ -1843,13 +1843,13 @@ public static WritableTypesContainer ToWritableContainer(this IEnumer /// Required for converting s to s. /// /// used to resolve names of symbols when is called. - public static WritableTypesContainer ToWritableContainer(this IEnumerable> collection, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default) + public static WritableTypeContainer ToWritableContainer(this IEnumerable> collection, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default) { return new(collection, parentCompilation, nameResolver); } /// - /// Creates a new . + /// Creates a new . /// /// Type of target . /// Collection of s to add to the container. @@ -1858,13 +1858,13 @@ public static WritableTypesContainer ToWritableContainer(this IEnumer /// Required for converting s to s. /// /// used to resolve names of symbols when is called. - public static WritableTypesContainer ToWritableContainer(this IEnumerable collection, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default) where TData : class, ITypeData + public static WritableTypeContainer ToWritableContainer(this IEnumerable collection, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default) where TData : class, ITypeData { return new(collection, parentCompilation, nameResolver); } /// - /// Creates a new . + /// Creates a new . /// /// Type of target . /// Collection of s to add to the container. @@ -1873,13 +1873,13 @@ public static WritableTypesContainer ToWritableContainer(this IEnu /// Required for converting s to s. /// /// used to resolve names of symbols when is called. - public static WritableTypesContainer ToWritableContainer(this IEnumerable> collection, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default) where TData : class, ITypeData + public static WritableTypeContainer ToWritableContainer(this IEnumerable> collection, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default) where TData : class, ITypeData { return new(collection, parentCompilation, nameResolver); } /// - /// Creates a new . + /// Creates a new . /// /// Collection of s to add to the container. /// @@ -1887,13 +1887,13 @@ public static WritableTypesContainer ToWritableContainer(this IEnu /// Required for converting s to s. /// /// used to resolve names of symbols when is called. - public static WritableNamespacesOrTypesContainer ToWritableContainer(this IEnumerable collection, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default) + public static WritableNamespaceOrTypeContainer ToWritableContainer(this IEnumerable collection, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default) { return new(collection, parentCompilation, nameResolver); } /// - /// Creates a new . + /// Creates a new . /// /// Collection of s to add to the container. /// @@ -1901,13 +1901,13 @@ public static WritableNamespacesOrTypesContainer ToWritabl /// Required for converting s to s. /// /// used to resolve names of symbols when is called. - public static WritableNamespacesOrTypesContainer ToWritableContainer(this IEnumerable> collection, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default) + public static WritableNamespaceOrTypeContainer ToWritableContainer(this IEnumerable> collection, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default) { return new(collection, parentCompilation, nameResolver); } /// - /// Creates a new . + /// Creates a new . /// /// Type of target . /// Collection of s to add to the container. @@ -1916,13 +1916,13 @@ public static WritableNamespacesOrTypesContainer ToWritabl /// Required for converting s to s. /// /// used to resolve names of symbols when is called. - public static WritableNamespacesOrTypesContainer ToWritableContainer(this IEnumerable collection, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default) where TData : class, INamespaceOrTypeData + public static WritableNamespaceOrTypeContainer ToWritableContainer(this IEnumerable collection, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default) where TData : class, INamespaceOrTypeData { return new(collection, parentCompilation, nameResolver); } /// - /// Creates a new . + /// Creates a new . /// /// Type of target . /// Collection of s to add to the container. @@ -1931,7 +1931,7 @@ public static WritableNamespacesOrTypesContainer ToWritableContainerRequired for converting s to s. /// /// used to resolve names of symbols when is called. - public static WritableNamespacesOrTypesContainer ToWritableContainer(this IEnumerable> collection, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default) where TData : class, INamespaceOrTypeData + public static WritableNamespaceOrTypeContainer ToWritableContainer(this IEnumerable> collection, ICompilationData? parentCompilation = default, ISymbolNameResolver? nameResolver = default) where TData : class, INamespaceOrTypeData { return new(collection, parentCompilation, nameResolver); } diff --git a/src/Durian.ConstExpr/Durian.ConstExpr.csproj b/src/Durian.ConstExpr/Durian.ConstExpr.csproj index d9f52272..ab4df982 100644 --- a/src/Durian.ConstExpr/Durian.ConstExpr.csproj +++ b/src/Durian.ConstExpr/Durian.ConstExpr.csproj @@ -5,7 +5,8 @@ netstandard2.0 Experimental stage is a playground of sorts - modules included here are very early in development and there in no guarantee that they will be ever actually released. - Do not reference this package if the main Durian package is already referenced. + +Do not reference this package if the main Durian package is already referenced. Durian;Analyzer;Source;Generator;Generation;Roslyn;Code;Fix;Extension;Feature;CSharp;C#;Analysis;Syntax;Tree;Node;Const;Constant;Expression;Expr;ConstExpr 1.0.0 diff --git a/src/Durian.CopyFrom/CopyFromGenerator.cs b/src/Durian.CopyFrom/CopyFromGenerator.cs index becb9b3e..bd1ce20e 100644 --- a/src/Durian.CopyFrom/CopyFromGenerator.cs +++ b/src/Durian.CopyFrom/CopyFromGenerator.cs @@ -613,25 +613,15 @@ private void WriteGeneratedMember( ISymbol original, CopyFromPassContext context, GenerateDocumentation applyInheritdoc, - DocumentationCommentTriviaSyntax? documentation + DocumentationCommentTriviaSyntax? documentation, + bool includeGenerationAttributes ) { string current = NodeToString(node); - string generatedFrom = AutoGenerated.GetDurianGeneratedAttribute(SymbolToString(original)); if (documentation is null) { - current = ApplyPattern(member, context, current); - - if (applyInheritdoc == GenerateDocumentation.Always) - { - WriteGeneratedMember_Internal(current, generatedFrom, AutoGenerated.GetInheritdoc(original.GetFullyQualifiedName(QualifiedName.Xml)), context); - } - else - { - WriteGeneratedMember_Internal(current, generatedFrom, context); - } - + WriteGeneratedMemberWithoutDocumentation(member, original, context, applyInheritdoc, includeGenerationAttributes, current); return; } @@ -648,7 +638,57 @@ private void WriteGeneratedMember( context.CodeBuilder.Indent(); context.CodeBuilder.Write(doc); - WriteGeneratedMember_Internal(current, generatedFrom, context); + + if(includeGenerationAttributes) + { + string generatedFrom = AutoGenerated.GetDurianGeneratedAttribute(SymbolToString(original)); + WriteGeneratedMember_Internal(current, generatedFrom, context); + } + else + { + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(current); + context.CodeBuilder.NewLine(); + } + } + + private void WriteGeneratedMemberWithoutDocumentation( + ICopyFromMember member, + ISymbol original, + CopyFromPassContext context, + GenerateDocumentation applyInheritdoc, + bool includeGenerationAttributes, + string current + ) + { + current = ApplyPattern(member, context, current); + + if (includeGenerationAttributes) + { + string generatedFrom = AutoGenerated.GetDurianGeneratedAttribute(SymbolToString(original)); + + if (applyInheritdoc == GenerateDocumentation.Always) + { + WriteGeneratedMember_Internal(current, generatedFrom, AutoGenerated.GetInheritdoc(original.GetFullyQualifiedName(QualifiedName.Xml)), context); + } + else + { + WriteGeneratedMember_Internal(current, generatedFrom, context); + } + } + else + { + if (applyInheritdoc == GenerateDocumentation.Always) + { + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(AutoGenerated.GetInheritdoc(original.GetFullyQualifiedName(QualifiedName.Xml))); + } + + context.CodeBuilder.NewLine(); + context.CodeBuilder.Indent(); + context.CodeBuilder.WriteLine(current); + context.CodeBuilder.NewLine(); + } } private void WriteGeneratedMember( @@ -656,12 +696,13 @@ private void WriteGeneratedMember( SyntaxNode node, ISymbol original, CopyFromPassContext context, - GenerateDocumentation applyInheritdoc + GenerateDocumentation applyInheritdoc, + bool includeGenerationAttributes ) { if (member.Patterns is null || member.Patterns.Length == 0) { - WriteGeneratedMember(node, original, context, applyInheritdoc); + WriteGeneratedMember(node, original, context, includeGenerationAttributes, applyInheritdoc); return; } @@ -678,7 +719,8 @@ GenerateDocumentation applyInheritdoc original, context, applyInheritdoc, - documentation + documentation, + includeGenerationAttributes ); } } diff --git a/src/Durian.CopyFrom/Durian.CopyFrom.csproj b/src/Durian.CopyFrom/Durian.CopyFrom.csproj index eaefdf6e..4f1b20a5 100644 --- a/src/Durian.CopyFrom/Durian.CopyFrom.csproj +++ b/src/Durian.CopyFrom/Durian.CopyFrom.csproj @@ -5,7 +5,8 @@ netstandard2.0 CopyFrom allows to copy implementations of members to other members, without the need for inheritance. A regex pattern can be provided to customize the copied implementation. - Do not reference this package if the main Durian package is already referenced. + +Do not reference this package if the main Durian package is already referenced. Durian;Analyzer;Source;Generator;Generation;Roslyn;Code;Fix;Extension;Feature;CSharp;C#;Analysis;Syntax;Tree;Node;Copy;From;Move;Implementation 1.0.0 diff --git a/src/Durian.CopyFrom/Methods/CopyFromGenerator.method.cs b/src/Durian.CopyFrom/Methods/CopyFromGenerator.method.cs index 765775ad..445aa400 100644 --- a/src/Durian.CopyFrom/Methods/CopyFromGenerator.method.cs +++ b/src/Durian.CopyFrom/Methods/CopyFromGenerator.method.cs @@ -62,24 +62,18 @@ private static void HandleGenericMethod(IMethodSymbol target, ref SyntaxNode cur ReplaceTypeParameters(ref currentNode, replacer, replacements); } - private static void WriteBlockBody(CopyFromMethodData method, CopyFromPassContext context, BlockSyntax decl) + private void WriteBlockBody(CopyFromMethodData method, CopyFromPassContext context, BlockSyntax decl) { BlockSyntax block = (BlockSyntax)WriteMethodHead(method, context, decl); - context.CodeBuilder.BeginBlock(); - - foreach (StatementSyntax statement in block.Statements) - { - context.CodeBuilder.Indent(); - context.CodeBuilder.WriteLine(statement.ToString()); - } + WriteGeneratedMember(method, block, method.Symbol, context, CodeGeneration.GenerateDocumentation.Never, false); } - private static void WriteExpressionBody(CopyFromMethodData method, CopyFromPassContext context, ArrowExpressionClauseSyntax decl) + private void WriteExpressionBody(CopyFromMethodData method, CopyFromPassContext context, ArrowExpressionClauseSyntax decl) { ArrowExpressionClauseSyntax expression = (ArrowExpressionClauseSyntax)WriteMethodHead(method, context, decl); - context.CodeBuilder.Write(" =>"); - context.CodeBuilder.Write(expression.Expression.ToFullString()); - context.CodeBuilder.WriteLine(';'); + WriteGeneratedMember(method, expression, method.Symbol, context, CodeGeneration.GenerateDocumentation.Never, false); + context.CodeBuilder.Write(';'); + context.CodeBuilder.NewLine(); } private static SyntaxNode WriteMethodHead(CopyFromMethodData method, CopyFromPassContext context, SyntaxNode currentNode) @@ -165,16 +159,12 @@ private bool GenerateMethod(CopyFromMethodData method, string hintName, CopyFrom switch (node) { case BlockSyntax block: - WriteDeclarationLead(context.CodeBuilder, method, method.Target.Usings); - HandleAdditionalNodes(method, method.Target, declaration, context); - WriteGenerationAttributes(method.Target.Symbol.ConstructedFrom, context); + BeginDeclaration(method, context, declaration); WriteBlockBody(method, context, block); break; case ArrowExpressionClauseSyntax arrow: - WriteDeclarationLead(context.CodeBuilder, method, method.Target.Usings); - HandleAdditionalNodes(method, method.Target, declaration, context); - WriteGenerationAttributes(method.Target.Symbol.ConstructedFrom, context); + BeginDeclaration(method, context, declaration); WriteExpressionBody(method, context, arrow); break; @@ -187,6 +177,13 @@ private bool GenerateMethod(CopyFromMethodData method, string hintName, CopyFrom AddSourceWithOriginal(method.Declaration, hintName, context); return true; + + void BeginDeclaration(CopyFromMethodData method, CopyFromPassContext context, SyntaxNode declaration) + { + WriteDeclarationLead(context.CodeBuilder, method, method.Target.Usings); + HandleAdditionalNodes(method, method.Target, declaration, context); + WriteGenerationAttributes(method.Target.Symbol.ConstructedFrom, context); + } } } } diff --git a/src/Durian.CopyFrom/Properties/launchSettings.json b/src/Durian.CopyFrom/Properties/launchSettings.json new file mode 100644 index 00000000..8d175c7b --- /dev/null +++ b/src/Durian.CopyFrom/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "Durian.CopyFrom": { + "commandName": "DebugRoslynComponent", + "targetProject": "..\\..\\samples\\Durian.Samples.CopyFrom\\Durian.Samples.CopyFrom.csproj" + } + } +} \ No newline at end of file diff --git a/src/Durian.CopyFrom/Types/CopyFromGenerator.type.cs b/src/Durian.CopyFrom/Types/CopyFromGenerator.type.cs index 01e7b6ea..49e56585 100644 --- a/src/Durian.CopyFrom/Types/CopyFromGenerator.type.cs +++ b/src/Durian.CopyFrom/Types/CopyFromGenerator.type.cs @@ -380,14 +380,14 @@ private GenerateAction GetGenerationMethod(CopyFromTypeData type, TargetTypeData { HandleSpecialMemberTypes(ref member, type, target.Symbol); ReplaceTypeParameters(ref member, replacer, replacements); - WriteGeneratedMember(type, member, symbol, context, applyInheritdoc); + WriteGeneratedMember(type, member, symbol, context, applyInheritdoc, true); }; } return (member, symbol, context, applyInheritdoc) => { ReplaceTypeParameters(ref member, replacer, replacements); - WriteGeneratedMember(type, member, symbol, context, applyInheritdoc); + WriteGeneratedMember(type, member, symbol, context, applyInheritdoc, true); }; } @@ -396,11 +396,11 @@ private GenerateAction GetGenerationMethod(CopyFromTypeData type, TargetTypeData return (member, symbol, context, applyInheritdoc) => { HandleSpecialMemberTypes(ref member, type, target.Symbol); - WriteGeneratedMember(type, member, symbol, context, applyInheritdoc); + WriteGeneratedMember(type, member, symbol, context, applyInheritdoc, true); }; } - return (member, symbol, context, applyInheritdoc) => WriteGeneratedMember(type, member, symbol, context, applyInheritdoc); + return (member, symbol, context, applyInheritdoc) => WriteGeneratedMember(type, member, symbol, context, applyInheritdoc, true); } private static List<(string identifier, string replacement)> GetTypeParameterReplacements(INamedTypeSymbol type) diff --git a/src/Durian.Core.Analyzer/Durian.Core.Analyzer.csproj b/src/Durian.Core.Analyzer/Durian.Core.Analyzer.csproj index 14f58f98..cdf02b98 100644 --- a/src/Durian.Core.Analyzer/Durian.Core.Analyzer.csproj +++ b/src/Durian.Core.Analyzer/Durian.Core.Analyzer.csproj @@ -5,7 +5,8 @@ netstandard2.0 Durian.Core.Analyzer is a small, entirely analyzer-based package that provides diagnostics for situations when the Durian.Core package is used improperly. - Do not reference this package if the main Durian package is already referenced. + +Do not reference this package if the main Durian package is already referenced. Durian;Analyzer;Source;Generator;Generation;Roslyn;Code;Fix;Extension;Feature;CSharp;C#;Analysis;Syntax;Tree;Node;Core 3.0.0 diff --git a/src/Durian.Core/DiagnosticData.cs b/src/Durian.Core/DiagnosticData.cs index 3ac48edc..a41b0f06 100644 --- a/src/Durian.Core/DiagnosticData.cs +++ b/src/Durian.Core/DiagnosticData.cs @@ -179,10 +179,7 @@ internal void SetModule(ModuleIdentity module) { ModuleReference reference = new(module); - if (_originalModule is null) - { - _originalModule = reference; - } + _originalModule ??= reference; _module = reference; } diff --git a/src/Durian.DefaultParam/DefaultParamAnalyzer.cs b/src/Durian.DefaultParam/DefaultParamAnalyzer.cs index 458e4b72..30ccc62a 100644 --- a/src/Durian.DefaultParam/DefaultParamAnalyzer.cs +++ b/src/Durian.DefaultParam/DefaultParamAnalyzer.cs @@ -263,7 +263,7 @@ IDiagnosticReceiver diagnosticReceiver IWritableSymbolContainer container = symbol.GetContainingTypes().ToWritableContainer(compilation); bool isValid = true; - foreach (ITypeData parent in container.GetData()) + foreach (ITypeData parent in container.GetData().CastArray()) { if (!parent.IsPartial) { @@ -351,35 +351,34 @@ public static bool AnalyzeContainingTypes(ISymbol symbol, DefaultParamCompilatio public static bool AnalyzeContainingTypes( ISymbol symbol, DefaultParamCompilationData compilation, - [NotNullWhen(true)] out ITypeData[]? containingTypes + out ImmutableArray containingTypes ) { INamedTypeSymbol[] types = symbol.GetContainingTypes().ToArray(); + ImmutableArray arr = types.ToContainer(compilation).GetData(); - if (types.Length == 0) + if (arr.Length == 0) { - containingTypes = null; - return false; + containingTypes = arr; + return true; } - ImmutableArray arr = types.ToWritableContainer(compilation).GetData(); - foreach (ITypeData parent in arr) { if (!parent.IsPartial) { - containingTypes = null; + containingTypes = default; return false; } if (!HasDefaultParamAttribute(parent.Symbol!, compilation)) { - containingTypes = null; + containingTypes = default; return false; } } - containingTypes = arr.ToArray(); + containingTypes = arr; return true; } @@ -789,10 +788,7 @@ private protected static IEnumerable GetBaseDiagnostics() [MethodImpl(MethodImplOptions.AggressiveInlining)] private protected static void InitializeAttributes([NotNull] ref IEnumerable? attributes, ISymbol symbol) { - if (attributes is null) - { - attributes = symbol.GetAttributes(); - } + attributes ??= symbol.GetAttributes(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/Durian.DefaultParam/DefaultParamUtilities.cs b/src/Durian.DefaultParam/DefaultParamUtilities.cs index ddcd9f50..ea139ebd 100644 --- a/src/Durian.DefaultParam/DefaultParamUtilities.cs +++ b/src/Durian.DefaultParam/DefaultParamUtilities.cs @@ -434,9 +434,9 @@ public static bool TryUpdateTypeParameters(TypeParameterListSyntax? current, int /// Converts an array of s to an array of s. /// /// Array of s to convert. - public static ImmutableArray TypeDatasToTypeSymbols(ITypeData[]? types) + public static ImmutableArray TypeDatasToTypeSymbols(ImmutableArray types) { - if (types is null) + if (types.IsDefault) { return ImmutableArray.Empty; } diff --git a/src/Durian.DefaultParam/Delegates/DefaultParamDelegateFilter.cs b/src/Durian.DefaultParam/Delegates/DefaultParamDelegateFilter.cs index 784c14dd..60112acf 100644 --- a/src/Durian.DefaultParam/Delegates/DefaultParamDelegateFilter.cs +++ b/src/Durian.DefaultParam/Delegates/DefaultParamDelegateFilter.cs @@ -30,7 +30,7 @@ public DefaultParamDelegateFilter() public override bool ValidateAndCreate(in DefaultParamDelegateContext context, out IMemberData? data) { if (AnalyzeAgainstProhibitedAttributes(context.Symbol, context.TargetCompilation, out AttributeData[]? attributes) && - AnalyzeContainingTypes(context.Symbol, context.TargetCompilation, out ITypeData[]? containingTypes) && + AnalyzeContainingTypes(context.Symbol, context.TargetCompilation, out ImmutableArray containingTypes) && AnalyzeTypeParameters(context.Symbol, in context.GetTypeParameters())) { ImmutableArray symbols = DefaultParamUtilities.TypeDatasToTypeSymbols(containingTypes); diff --git a/src/Durian.DefaultParam/Durian.DefaultParam.csproj b/src/Durian.DefaultParam/Durian.DefaultParam.csproj index 447f7b9b..3d827214 100644 --- a/src/Durian.DefaultParam/Durian.DefaultParam.csproj +++ b/src/Durian.DefaultParam/Durian.DefaultParam.csproj @@ -5,7 +5,8 @@ netstandard2.0 DefaultParam, based on a similar feature in C++, allows to specify a default type for a generic parameter. - Do not reference this package if the main Durian package is already referenced. + +Do not reference this package if the main Durian package is already referenced. Durian;Analyzer;Source;Generator;Generation;Roslyn;Code;Fix;Extension;Feature;CSharp;C#;Analysis;Syntax;Tree;Node;Default;Param;Parameter;Type;Generic;Argument 3.0.0 diff --git a/src/Durian.DefaultParam/Methods/DefaultParamMethodFilter.cs b/src/Durian.DefaultParam/Methods/DefaultParamMethodFilter.cs index 9e988bd1..2f79c720 100644 --- a/src/Durian.DefaultParam/Methods/DefaultParamMethodFilter.cs +++ b/src/Durian.DefaultParam/Methods/DefaultParamMethodFilter.cs @@ -86,7 +86,7 @@ public override bool ValidateAndCreate(in DefaultParamMethodContext context, [No AnalyzeAgainstInvalidMethodType(context.Symbol) && AnalyzeAgainstPartialOrExtern(context.Symbol, context.Node) && AnalyzeAgainstProhibitedAttributes(context.Symbol, context.TargetCompilation, out AttributeData[]? attributes) && - AnalyzeContainingTypes(context.Symbol, context.TargetCompilation, out ITypeData[]? containingTypes) + AnalyzeContainingTypes(context.Symbol, context.TargetCompilation, out ImmutableArray containingTypes) ) { TypeParameterContainer combinedParameters = context.GetTypeParameters(); diff --git a/src/Durian.DefaultParam/Types/DefaultParamTypeFilter.cs b/src/Durian.DefaultParam/Types/DefaultParamTypeFilter.cs index 1533353c..cde30832 100644 --- a/src/Durian.DefaultParam/Types/DefaultParamTypeFilter.cs +++ b/src/Durian.DefaultParam/Types/DefaultParamTypeFilter.cs @@ -31,7 +31,7 @@ public override bool ValidateAndCreate(in DefaultParamTypeContext context, [NotN { if (AnalyzeAgainstPartial(context.Symbol, context.CancellationToken) && AnalyzeAgainstProhibitedAttributes(context.Symbol, context.TargetCompilation, out AttributeData[]? attributes) && - AnalyzeContainingTypes(context.Symbol, context.TargetCompilation, out ITypeData[]? containingTypes) && + AnalyzeContainingTypes(context.Symbol, context.TargetCompilation, out ImmutableArray containingTypes) && AnalyzeTypeParameters(context.Symbol, in context.GetTypeParameters()) ) { diff --git a/src/Durian.FriendClass/Durian.FriendClass.csproj b/src/Durian.FriendClass/Durian.FriendClass.csproj index adaf987a..44348a68 100644 --- a/src/Durian.FriendClass/Durian.FriendClass.csproj +++ b/src/Durian.FriendClass/Durian.FriendClass.csproj @@ -5,7 +5,8 @@ netstandard2.0 FriendClass allows to limit access to 'internal' members by specifying a fixed list of friend types. - Do not reference this package if the main Durian package is already referenced. + +Do not reference this package if the main Durian package is already referenced. Durian;Analyzer;Source;Generator;Generation;Roslyn;Code;Fix;Extension;Feature;CSharp;C#;Analysis;Syntax;Tree;Node;Friend;Type;Class 2.0.0 diff --git a/src/Durian.FriendClass/Properties/launchSettings.json b/src/Durian.FriendClass/Properties/launchSettings.json new file mode 100644 index 00000000..7ae85b2e --- /dev/null +++ b/src/Durian.FriendClass/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "Durian.FriendClass": { + "commandName": "DebugRoslynComponent", + "targetProject": "..\\..\\samples\\Durian.Samples.FriendClass\\Durian.Samples.FriendClass.csproj" + } + } +} \ No newline at end of file diff --git a/src/Durian.InterfaceTargets/Durian.InterfaceTargets.csproj b/src/Durian.InterfaceTargets/Durian.InterfaceTargets.csproj index 1dd40aab..bdaee559 100644 --- a/src/Durian.InterfaceTargets/Durian.InterfaceTargets.csproj +++ b/src/Durian.InterfaceTargets/Durian.InterfaceTargets.csproj @@ -5,7 +5,8 @@ netstandard2.0 Durian.InterfaceTargets, similar to how the System.AttributeUsageAttribute works, allows to specify member kinds an interface can be implemented by. - Do not reference this package if the main Durian package is already referenced. + +Do not reference this package if the main Durian package is already referenced. Durian;Analyzer;Source;Generator;Generation;Roslyn;Code;Fix;Extension;Feature;CSharp;C#;Analysis;Syntax;Tree;Node;Interface;Target;Targets;Usage 2.0.0 diff --git a/src/Durian.InterfaceTargets/Properties/launchSettings.json b/src/Durian.InterfaceTargets/Properties/launchSettings.json new file mode 100644 index 00000000..8456c84a --- /dev/null +++ b/src/Durian.InterfaceTargets/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "Durian.InterfaceTargets": { + "commandName": "DebugRoslynComponent", + "targetProject": "..\\..\\samples\\Durian.Samples.InterfaceTargets\\Durian.Samples.InterfaceTargets.csproj" + } + } +} \ No newline at end of file diff --git a/tests/Durian.CopyFrom.Tests/CopyFromMethodGeneratatorTests.cs b/tests/Durian.CopyFrom.Tests/CopyFromMethodGeneratatorTests.cs index 52b3c82f..33a1e253 100644 --- a/tests/Durian.CopyFrom.Tests/CopyFromMethodGeneratatorTests.cs +++ b/tests/Durian.CopyFrom.Tests/CopyFromMethodGeneratatorTests.cs @@ -1558,7 +1558,7 @@ private partial void Method() } [Fact] - public void Success_When_CopiesFromMethodWithAttribtes_And_AllowsCopyFromAttributes_And_HasPattern() + public void Success_When_CopiesFromMethodWithAttributes_And_AllowsCopyFromAttributes() { string input = $@"using {DurianStrings.MainNamespace}; @@ -1567,7 +1567,6 @@ public void Success_When_CopiesFromMethodWithAttribtes_And_AllowsCopyFromAttribu partial class Test {{ [{CopyFromMethodAttributeProvider.TypeName}(""Target"", {CopyFromMethodAttributeProvider.AdditionalNodes} = {CopyFromAdditionalNodesProvider.TypeName}.{CopyFromAdditionalNodesProvider.Attributes})] - [{PatternAttributeProvider.TypeName}(""DEBUG"", ""RELEASE"")] partial void Method(); [System.Diagnostics.Conditional(""DEBUG"")] @@ -1580,7 +1579,7 @@ void Target() string expected = $@"internal partial class Test {{ - [System.Diagnostics.Conditional(""RELEASE"")] + [System.Diagnostics.Conditional(""DEBUG"")] {GetCodeGenerationAttributes("Test.Target()")} private partial void Method() {{ @@ -1592,7 +1591,7 @@ private partial void Method() } [Fact] - public void Success_When_CopiesFromMethodWithAttributes_And_AllowsCopyFromAttributes() + public void Success_When_CopiesFromMethodWithAttributes_And_AllowsCopyFromAttributes_And_HasPattern() { string input = $@"using {DurianStrings.MainNamespace}; @@ -1601,6 +1600,7 @@ public void Success_When_CopiesFromMethodWithAttributes_And_AllowsCopyFromAttrib partial class Test {{ [{CopyFromMethodAttributeProvider.TypeName}(""Target"", {CopyFromMethodAttributeProvider.AdditionalNodes} = {CopyFromAdditionalNodesProvider.TypeName}.{CopyFromAdditionalNodesProvider.Attributes})] + [{PatternAttributeProvider.TypeName}(""DEBUG"", ""RELEASE"")] partial void Method(); [System.Diagnostics.Conditional(""DEBUG"")] @@ -1613,7 +1613,7 @@ void Target() string expected = $@"internal partial class Test {{ - [System.Diagnostics.Conditional(""DEBUG"")] + [System.Diagnostics.Conditional(""RELEASE"")] {GetCodeGenerationAttributes("Test.Target()")} private partial void Method() {{ @@ -1760,6 +1760,38 @@ private partial void Method() Assert.True(RunGenerator(input).Compare(expected)); } + [Fact] + public void Success_When_HasArglist() + { + string input = +$@"using {DurianStrings.MainNamespace}; + +partial class Test +{{ + [{CopyFromMethodAttributeProvider.TypeName}(""Target(__arglist)"")] + private partial void Method(__arglist); + + static void Target(__arglist) + {{ + string a = string.Empty; + }} +}} +"; + string expected = +$@"using {DurianStrings.MainNamespace}; + +internal partial class Test +{{ + {GetCodeGenerationAttributes("Test.Target(__arglist)")} + private partial void Method(__arglist) + {{ + string a = string.Empty; + }} +}} +"; + Assert.True(RunGenerator(input).Compare(expected)); + } + [Fact] public void Success_When_HasCollidingMethodAndTypeName() { @@ -1897,6 +1929,190 @@ private partial void Method2() Assert.True(RunGeneratorWithMultipleOutputs(input).Compare(expected1, expected2)); } + [Fact] + public void Success_When_HasMultiplePattern() + { + string input = +$@"using {DurianStrings.MainNamespace}; + +partial class Test +{{ + [{CopyFromMethodAttributeProvider.TypeName}(""Target"")] + [{PatternAttributeProvider.TypeName}(""name"", ""variable"")] + [{PatternAttributeProvider.TypeName}(""variable"", ""abc"")] + public partial void Method(); + + public void Target() + {{ + string name = string.Empty; + }} +}} +"; + string expected = +$@"using {DurianStrings.MainNamespace}; + +internal partial class Test +{{ + {GetCodeGenerationAttributes("Test.Target()")} + public partial void Method() + {{ + string abc = string.Empty; + }} +}} +"; + Assert.True(RunGenerator(input).Compare(expected)); + } + + [Fact] + public void Success_When_HasMultiplePattern_And_IsArrowExpression() + { + string input = +$@"using {DurianStrings.MainNamespace}; + +partial class Test +{{ + [{CopyFromMethodAttributeProvider.TypeName}(""Target"")] + [{PatternAttributeProvider.TypeName}(""int"", ""long"")] + [{PatternAttributeProvider.TypeName}(""long"", ""short"")] + public partial short Method(); + + public int Target() => int.MaxValue; +}} +"; + string expected = +$@"using {DurianStrings.MainNamespace}; + +internal partial class Test +{{ + {GetCodeGenerationAttributes("Test.Target()")} + public partial short Method() => short.MaxValue; +}} +"; + Assert.True(RunGenerator(input).Compare(expected)); + } + + [Fact] + public void Success_When_HasMultiplePatternWithOrder() + { + string input = +$@"using {DurianStrings.MainNamespace}; + +partial class Test +{{ + [{CopyFromMethodAttributeProvider.TypeName}(""Target"")] + [{PatternAttributeProvider.TypeName}(""abc"", ""variable"", {PatternAttributeProvider.Order} = 1)] + [{PatternAttributeProvider.TypeName}(""name"", ""abc"", {PatternAttributeProvider.Order} = 0)] + public partial void Method(); + + public void Target() + {{ + string name = string.Empty; + }} +}} +"; + string expected = +$@"using {DurianStrings.MainNamespace}; + +internal partial class Test +{{ + {GetCodeGenerationAttributes("Test.Target()")} + public partial void Method() + {{ + string variable = string.Empty; + }} +}} +"; + Assert.True(RunGenerator(input).Compare(expected)); + } + + [Fact] + public void Success_When_HasMultiplePatternWithOrder_And_IsArrowExpression() + { + string input = +$@"using {DurianStrings.MainNamespace}; + +partial class Test +{{ + [{CopyFromMethodAttributeProvider.TypeName}(""Target"")] + [{PatternAttributeProvider.TypeName}(""long"", ""short"", {PatternAttributeProvider.Order} = 1)] + [{PatternAttributeProvider.TypeName}(""int"", ""long"", {PatternAttributeProvider.Order} = 0)] + public partial short Method(); + + public int Target() => int.MaxValue; +}} +"; + string expected = +$@"using {DurianStrings.MainNamespace}; + +internal partial class Test +{{ + {GetCodeGenerationAttributes("Test.Target()")} + public partial short Method() => short.MaxValue; +}} +"; + Assert.True(RunGenerator(input).Compare(expected)); + } + + [Fact] + public void Success_When_HasPattern() + { + string input = +$@"using {DurianStrings.MainNamespace}; + +partial class Test +{{ + [{CopyFromMethodAttributeProvider.TypeName}(""Target"")] + [{PatternAttributeProvider.TypeName}(""name"", ""variable"")] + public partial void Method(); + + public void Target() + {{ + string name = string.Empty; + }} +}} +"; + string expected = +$@"using {DurianStrings.MainNamespace}; + +internal partial class Test +{{ + {GetCodeGenerationAttributes("Test.Target()")} + public partial void Method() + {{ + string variable = string.Empty; + }} +}} +"; + Assert.True(RunGenerator(input).Compare(expected)); + } + + [Fact] + public void Success_When_HasPattern_And_IsArrowExpression() + { + string input = +$@"using {DurianStrings.MainNamespace}; + +partial class Test +{{ + [{CopyFromMethodAttributeProvider.TypeName}(""Target"")] + [{PatternAttributeProvider.TypeName}(""int"", ""long"")] + public partial long Method(); + + public int Target() => int.MaxValue; +}} +"; + string expected = +$@"using {DurianStrings.MainNamespace}; + +internal partial class Test +{{ + {GetCodeGenerationAttributes("Test.Target()")} + public partial long Method() => long.MaxValue; +}} +"; + Assert.True(RunGenerator(input).Compare(expected)); + } + [Fact] public void Success_When_HasRefOutInParameters() { @@ -2225,6 +2441,38 @@ private partial void Method() Assert.True(RunGenerator(input).Compare(expected, true)); } + [Fact] + public void Success_When_IsExtensionMethod() + { + string input = +$@"using {DurianStrings.MainNamespace}; + +static partial class Test +{{ + [{CopyFromMethodAttributeProvider.TypeName}(""Target"")] + static partial void Method(this int a); + + static void Target() + {{ + string a = string.Empty; + }} +}} +"; + string expected = +$@"using {DurianStrings.MainNamespace}; + +internal static partial class Test +{{ + {GetCodeGenerationAttributes("Test.Target()")} + private static partial void Method(this int a) + {{ + string a = string.Empty; + }} +}} +"; + Assert.True(RunGenerator(input).Compare(expected)); + } + [Fact] public void Success_When_IsGeneric() { @@ -3329,70 +3577,6 @@ private partial void Method() Assert.True(RunGenerator(input).Compare(expected)); } - [Fact] - public void Success_When_HasArglist() - { - string input = -$@"using {DurianStrings.MainNamespace}; - -partial class Test -{{ - [{CopyFromMethodAttributeProvider.TypeName}(""Target(__arglist)"")] - private partial void Method(__arglist); - - static void Target(__arglist) - {{ - string a = string.Empty; - }} -}} -"; - string expected = -$@"using {DurianStrings.MainNamespace}; - -internal partial class Test -{{ - {GetCodeGenerationAttributes("Test.Target(__arglist)")} - private partial void Method(__arglist) - {{ - string a = string.Empty; - }} -}} -"; - Assert.True(RunGenerator(input).Compare(expected)); - } - - [Fact] - public void Success_When_IsExtensionMethod() - { - string input = -$@"using {DurianStrings.MainNamespace}; - -static partial class Test -{{ - [{CopyFromMethodAttributeProvider.TypeName}(""Target"")] - static partial void Method(this int a); - - static void Target() - {{ - string a = string.Empty; - }} -}} -"; - string expected = -$@"using {DurianStrings.MainNamespace}; - -internal static partial class Test -{{ - {GetCodeGenerationAttributes("Test.Target()")} - private static partial void Method(this int a) - {{ - string a = string.Empty; - }} -}} -"; - Assert.True(RunGenerator(input).Compare(expected)); - } - [Fact] public void Warning_When_AddsEquivalentUsing() { diff --git a/tests/Durian.CopyFrom.Tests/CopyFromTypeGeneratorTests.cs b/tests/Durian.CopyFrom.Tests/CopyFromTypeGeneratorTests.cs index 8b06d166..6d138d5a 100644 --- a/tests/Durian.CopyFrom.Tests/CopyFromTypeGeneratorTests.cs +++ b/tests/Durian.CopyFrom.Tests/CopyFromTypeGeneratorTests.cs @@ -1642,7 +1642,7 @@ public void Success_When_HasMultiplePatternsWithOrder() $@"using {DurianStrings.MainNamespace}; [{CopyFromTypeAttributeProvider.TypeName}(""Target"")] -[{PatternAttributeProvider.TypeName}(""A"", ""B"", {PatternAttributeProvider.Order} = 1), {PatternAttributeProvider.TypeName}(""B"", ""C"", {PatternAttributeProvider.Order} = 0)] +[{PatternAttributeProvider.TypeName}(""B"", ""C"", {PatternAttributeProvider.Order} = 1), {PatternAttributeProvider.TypeName}(""A"", ""B"", {PatternAttributeProvider.Order} = 0)] partial class Test {{ }} @@ -1661,9 +1661,9 @@ void A() internal partial class Test {{ {GetCodeGenerationAttributes("Target.A()")} - void B() + void C() {{ - B(); + C(); }} }} ";