diff --git a/.gitignore b/.gitignore index 20879b3..0eba03e 100644 --- a/.gitignore +++ b/.gitignore @@ -26,9 +26,6 @@ # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets !packages/*/build/ -# Debug artifacts -launchSettings.json - # Prevent accidental re-checkin of NuGet.exe NuGet.exe diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Aspid.MVVM.Generators.csproj b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Aspid.MVVM.Generators.csproj index 19aae24..a8001cc 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Aspid.MVVM.Generators.csproj +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Aspid.MVVM.Generators.csproj @@ -12,12 +12,15 @@ + + all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Binders/BinderGenerator.Find.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Binders/BinderGenerator.Find.cs index 255c714..34eeefa 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Binders/BinderGenerator.Find.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Binders/BinderGenerator.Find.cs @@ -2,27 +2,27 @@ using System.Threading; using System.Diagnostics; using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; +using Aspid.Generators.Helper; using System.Collections.Generic; using Microsoft.CodeAnalysis.CSharp; using System.Runtime.CompilerServices; -using Aspid.MVVM.Generators.Binders.Data; -using Aspid.MVVM.Generators.Descriptions; using Microsoft.CodeAnalysis.CSharp.Syntax; +using Aspid.MVVM.Generators.Generators.Binders.Data; +using Classes = Aspid.MVVM.Generators.Generators.Descriptions.Classes; -namespace Aspid.MVVM.Generators.Binders; +namespace Aspid.MVVM.Generators.Generators.Binders; public partial class BinderGenerator { - private static FoundForGenerator FindBinders(GeneratorSyntaxContext context, + private static BinderData? FindBinders(GeneratorSyntaxContext context, CancellationToken cancellationToken) { Debug.Assert(context.Node is TypeDeclarationSyntax); var candidate = Unsafe.As(context.Node); var symbol = context.SemanticModel.GetDeclaredSymbol(candidate, cancellationToken); - if (symbol is null) return default; - if (!symbol.HasInterfaceInSelfOrBases(Classes.IBinder, out var binderInterface)) return default; + if (symbol is null) return null; + if (!symbol.TryGetAnyInterfaceInSelfAndBases(out var binderInterface, Classes.IBinder)) return null; var hasBinderLogInBaseType = false; const string setValueName = "SetValue"; @@ -40,11 +40,11 @@ private static FoundForGenerator FindBinders(GeneratorSyntaxContext method.ExplicitInterfaceImplementations.Length != 0; }); - if (methodsExplicitImplemented) return default; + if (methodsExplicitImplemented) return null; if (!hasBinderLogInBaseType && !SymbolEqualityComparer.Default.Equals(type, symbol) - && method.HasAnyAttribute(Classes.BinderLogAttribute)) + && method.HasAnyAttributeInSelf(Classes.BinderLogAttribute)) { hasBinderLogInBaseType = true; } @@ -57,15 +57,15 @@ private static FoundForGenerator FindBinders(GeneratorSyntaxContext { if (method.Parameters.Length != 1) continue; if (method.NameFromExplicitImplementation() != setValueName) continue; - if (!symbol.HasInterfaceInSelfOrBases($"{Classes.IBinder.FullName}<{method.Parameters[0].Type.ToDisplayString()}>")) continue; + if (!symbol.HasAnyInterfaceInSelfAndBases($"{Classes.IBinder.FullName}<{method.Parameters[0].Type.ToDisplayString()}>")) continue; - if (method.HasAnyAttribute(Classes.BinderLogAttribute) && + if (method.HasAnyAttributeInSelf(Classes.BinderLogAttribute) && !method.ExplicitInterfaceImplementations.Any()) binderLogMethods.Add(method); } - - if (binderLogMethods.Count == 0) return default; - - return new FoundForGenerator(new BinderData(symbol, candidate, hasBinderLogInBaseType, binderLogMethods)); + + return binderLogMethods.Count is 0 + ? null + : new BinderData(symbol, candidate, hasBinderLogInBaseType, binderLogMethods); } } \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Binders/BinderGenerator.Generate.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Binders/BinderGenerator.Generate.cs index c99b203..17d6520 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Binders/BinderGenerator.Generate.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Binders/BinderGenerator.Generate.cs @@ -1,10 +1,10 @@ using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; -using Aspid.MVVM.Generators.Binders.Body; -using Aspid.MVVM.Generators.Binders.Data; -using Aspid.MVVM.Generators.Descriptions; +using Aspid.Generators.Helper; +using Aspid.MVVM.Generators.Generators.Binders.Body; +using Aspid.MVVM.Generators.Generators.Binders.Data; +using Aspid.MVVM.Generators.Generators.Descriptions; -namespace Aspid.MVVM.Generators.Binders; +namespace Aspid.MVVM.Generators.Generators.Binders; public partial class BinderGenerator { @@ -14,7 +14,7 @@ private static void GenerateCode(SourceProductionContext context, BinderData bin { var declaration = binderData.Declaration; var @namespace = declaration.GetNamespaceName(); - var declarationText = declaration.GetDeclarationText(); + var declarationText = new DeclarationText(declaration); GenerateBinderLog(@namespace, new BinderDataSpan(binderData), context, declarationText); } @@ -31,15 +31,15 @@ private static void GenerateBinderLog( #if DEBUG code.AppendLine($"#if !{Defines.ASPID_MVVM_BINDER_LOG_DISABLED}") - .AppendClassBegin(@namespace, declarationText) + .BeginClass(@namespace, declarationText) .AppendBinderLogBody(data) - .AppendClassEnd(@namespace) + .EndClass(@namespace) .AppendLine("#endif"); #else - code.AppendLine($"#if {Defines.UNITY_EDITOR} && !{Defines.ASPID_MVVM_BINDER_LOG_DISABLED}") - .AppendClassBegin(@namespace, declarationText) + code.AppendLine($"#if {Aspid.Generators.Helper.Unity.Defines.UNITY_EDITOR} && !{Defines.ASPID_MVVM_BINDER_LOG_DISABLED}") + .BeginClass(@namespace, declarationText) .AppendBinderLogBody(data) - .AppendClassEnd(@namespace) + .EndClass(@namespace) .Append("#endif"); #endif diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Binders/BinderGenerator.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Binders/BinderGenerator.cs index 196ad03..f0b64e8 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Binders/BinderGenerator.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Binders/BinderGenerator.cs @@ -3,16 +3,17 @@ using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; -namespace Aspid.MVVM.Generators.Binders; +namespace Aspid.MVVM.Generators.Generators.Binders; [Generator] public partial class BinderGenerator : IIncrementalGenerator { public void Initialize(IncrementalGeneratorInitializationContext context) { + // ReSharper disable once NullableWarningSuppressionIsUsed var provider = context.SyntaxProvider.CreateSyntaxProvider(SyntacticPredicate, FindBinders) - .Where(foundForSourceGenerator => foundForSourceGenerator.IsNeed) - .Select((foundForSourceGenerator, _) => foundForSourceGenerator.Container); + .Where(data => data.HasValue) + .Select((data, _) => data!.Value); context.RegisterSourceOutput( source: provider, diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Binders/Body/BinderLogBody.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Binders/Body/BinderLogBody.cs index 51fec3b..def4d21 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Binders/Body/BinderLogBody.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Binders/Body/BinderLogBody.cs @@ -1,20 +1,21 @@ using System; using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; -using Aspid.MVVM.Generators.Binders.Data; -using Aspid.MVVM.Generators.Descriptions; +using Aspid.Generators.Helper; +using Aspid.MVVM.Generators.Generators.Binders.Data; +using Aspid.MVVM.Generators.Generators.Descriptions; +using static Aspid.Generators.Helper.Classes; +using static Aspid.Generators.Helper.Unity.UnityClasses; +using Classes = Aspid.MVVM.Generators.Generators.Descriptions.Classes; -namespace Aspid.MVVM.Generators.Binders.Body; +namespace Aspid.MVVM.Generators.Generators.Binders.Body; // ReSharper disable InconsistentNaming public static class BinderLogBody { private const string GeneratedAttribute = General.GeneratedCodeLogBinderAttribute; - private static readonly string List = Classes.List.Global; - private static readonly string IBinder = Classes.IBinder.Global; - private static readonly string Exception = Classes.Exception.Global; - private static readonly string SerializeFieldAttribute = Classes.SerializeField.Global; + private static readonly string IBinder = Classes.IBinder; + private static readonly string Exception = Aspid.Generators.Helper.Classes.Exception; public static CodeWriter AppendBinderLogBody(this CodeWriter code, in BinderDataSpan data) { @@ -39,7 +40,7 @@ private static CodeWriter AppendProfilerMarkers(this CodeWriter code, in BinderD var modifier = data.Symbol.IsSealed ? "private" : "protected"; var className = data.Declaration.Identifier.Text; - code.AppendLine($"{modifier} static readonly {Classes.ProfilerMarker.Global} SetValueMarker = new(\"{className}.SetValue\");"); + code.AppendLine($"{modifier} static readonly {ProfilerMarker} SetValueMarker = new(\"{className}.SetValue\");"); return code.AppendLine(); } @@ -50,11 +51,11 @@ private static CodeWriter AppendProperties(this CodeWriter code, in BinderDataSp code.AppendMultiline( $""" {GeneratedAttribute} - [{SerializeFieldAttribute}] private bool _isDebug; + [{SerializeField}] private bool _isDebug; // TODO Add Custom Property {GeneratedAttribute} - [{SerializeFieldAttribute}] private {Classes.List.Global} _log; + [{SerializeField}] private {List_1} _log; {GeneratedAttribute} {modifier} bool IsDebug => _isDebug; @@ -66,7 +67,7 @@ private static CodeWriter AppendProperties(this CodeWriter code, in BinderDataSp private static CodeWriter AppendSetValueMethods(this CodeWriter code, in ReadOnlySpan methods) { - code.AppendLoop(methods, method => + foreach (var method in methods) { var parameterName = method.Parameters[0].Name; var parameterType = method.Parameters[0].Type.ToDisplayStringGlobal(); @@ -103,7 +104,7 @@ private static CodeWriter AppendSetValueMethods(this CodeWriter code, in ReadOnl } """) .AppendLine(); - }); + } return code; } @@ -117,7 +118,7 @@ private static CodeWriter AppendAddLogMethod(this CodeWriter code, in BinderData {{GeneratedAttribute}} {{modifier}} void AddLog(string log) { - _log ??= new {{List}}(); + _log ??= new {{List_1}}(); _log.Add(log); } """); diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Binders/Data/BinderData.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Binders/Data/BinderData.cs index a870d34..f2aebe0 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Binders/Data/BinderData.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Binders/Data/BinderData.cs @@ -3,7 +3,7 @@ using System.Collections.Immutable; using Microsoft.CodeAnalysis.CSharp.Syntax; -namespace Aspid.MVVM.Generators.Binders.Data; +namespace Aspid.MVVM.Generators.Generators.Binders.Data; public readonly struct BinderData( INamedTypeSymbol symbol, diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Binders/Data/BinderDataSpan.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Binders/Data/BinderDataSpan.cs index e3a607b..f2a5ddd 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Binders/Data/BinderDataSpan.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Binders/Data/BinderDataSpan.cs @@ -2,7 +2,7 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; -namespace Aspid.MVVM.Generators.Binders.Data; +namespace Aspid.MVVM.Generators.Generators.Binders.Data; public readonly ref struct BinderDataSpan(BinderData data) { diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/CreateFrom/Body/CreateFromBody.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/CreateFrom/Body/CreateFromBody.cs deleted file mode 100644 index 4bead8e..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/CreateFrom/Body/CreateFromBody.cs +++ /dev/null @@ -1,313 +0,0 @@ -using System; -using System.Text; -using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; -using Aspid.MVVM.Generators.Descriptions; -using Aspid.MVVM.Generators.CreateFrom.Data; - -namespace Aspid.MVVM.Generators.CreateFrom.Body; - -// ReSharper disable InconsistentNaming -public static class CreateFromBody -{ - private const string GeneratedAttribute = General.GeneratedCodeCreateFromAttribute; - - private static readonly string List = Classes.List.Global; - private static readonly string Func = Classes.Func.Global; - private static readonly string Span = Classes.Span.Global; - private static readonly string IList = Classes.IList.Global; - private static readonly string IEnumerable = Classes.IEnumerable.Global; - private static readonly string ReadOnlySpan = Classes.ReadOnlySpan.Global; - private static readonly SymbolEqualityComparer Comparer = SymbolEqualityComparer.Default; - - public static CodeWriter AppendCreateFromBody(this CodeWriter code, in CreateFromDataSpan data) - { - if (data.Constructor.Parameters.Length == 0) return code; - var parameters = GetParameters(data.Constructor, data.FromType); - - code.AppendLine($"[{Classes.MethodImplAttribute.Global}({Classes.MethodImplOptions.Global}.AggressiveInlining)]") - .AppendMethodDeclaration(data, parameters, ParameterType.None, ParameterType.None) - .AppendMultiline( - $$""" - { - return new({{parameters.Constructor(parameters.From)}}); - } - """) - .AppendLine(); - - code.AppendArrayMethodBody(data, ParameterType.Array, parameters) - .AppendArrayMethodBody(data, ParameterType.Span, parameters) - .AppendArrayMethodBody(data, ParameterType.ReadOnlySpan, parameters) - .AppendArrayMethodBody(data, ParameterType.List, parameters); - - code.AppendListMethodBody(data, ParameterType.Array, parameters) - .AppendListMethodBody(data, ParameterType.List, parameters) - .AppendListMethodBody(data, ParameterType.Span, parameters) - .AppendListMethodBody(data, ParameterType.ReadOnlySpan, parameters) - .AppendListMethodBody(data ,ParameterType.Enumerable, parameters); - - code.AppendIListMethodBody(data, ParameterType.Array, parameters) - .AppendIListMethodBody(data, ParameterType.List, parameters) - .AppendIListMethodBody(data, ParameterType.Span, parameters) - .AppendIListMethodBody(data, ParameterType.ReadOnlySpan, parameters) - .AppendIListMethodBody(data, ParameterType.Enumerable, parameters); - - code.AppendEnumerableMethodBody(data, ParameterType.Array, ParameterType.Enumerable, parameters) - .AppendEnumerableMethodBody(data, ParameterType.List, ParameterType.Enumerable, parameters) - .AppendEnumerableMethodBody(data, ParameterType.Enumerable, ParameterType.Enumerable, parameters); - - return code; - } - - private static CodeWriter AppendArrayMethodBody( - this CodeWriter code, - in CreateFromDataSpan data, - ParameterType fromParameterType, - in Parameters parameters) - { - var fromName = parameters.From; - - var capacity = GetLengthType(fromParameterType) switch - { - LengthType.None => "0", - LengthType.Count => $"{fromName}.Count", - LengthType.Length => $"{fromName}.Length", - _ => throw new ArgumentOutOfRangeException() - }; - - return code - .AppendMethodDeclaration(data, parameters, fromParameterType, ParameterType.Array) - .AppendMultiline( - $$""" - { - var __to = new {{data.ToTypeName}}[{{capacity}}]; - - for (var __i = 0; __i < __to.Length; __i++) - __to[__i] = {{fromName}}[__i].{{data.MethodName}}({{parameters.EnumParameters}}); - - return __to; - } - """) - .AppendLine(); - } - - private static CodeWriter AppendListMethodBody( - this CodeWriter code, - in CreateFromDataSpan data, - ParameterType fromParameterType, - in Parameters parameters) - { - var capacity = GetLengthType(fromParameterType) switch - { - LengthType.None => string.Empty, - LengthType.Count => $"{parameters.From}.Count", - LengthType.Length => $"{parameters.From}.Length", - _ => throw new ArgumentOutOfRangeException() - }; - - return code - .AppendMethodDeclaration(data, parameters, fromParameterType, ParameterType.List) - .AppendMultiline( - $$""" - { - var __to = new {{List}}<{{data.ToTypeName}}>({{capacity}}); - - foreach(var __from in {{parameters.From}}) - __to.Add(__from.{{data.MethodName}}({{parameters.EnumParameters}})); - - return __to; - } - """) - .AppendLine(); - } - - private static CodeWriter AppendIListMethodBody( - this CodeWriter code, - in CreateFromDataSpan data, - ParameterType fromParameterType, - in Parameters parameters) - { - return code - .AppendMethodDeclaration(data, parameters, fromParameterType, ParameterType.IList) - .AppendMultiline( - $$""" - { - var __to = __createList(); - - foreach(var __from in {{parameters.From}}) - __to.Add(__from.{{data.MethodName}}({{parameters.EnumParameters}})); - - return __to; - } - """) - .AppendLine(); - } - - private static CodeWriter AppendEnumerableMethodBody( - this CodeWriter code, - in CreateFromDataSpan data, - ParameterType fromParameterType, - ParameterType toParameterType, - in Parameters parameters) - { - return code - .AppendMethodDeclaration(data, parameters, fromParameterType, toParameterType) - .AppendMultiline( - $$""" - { - foreach (var __from in {{parameters.From}}) - yield return __from.{{data.MethodName}}({{parameters.EnumParameters}}); - } - """) - .AppendLine(); - } - - private static CodeWriter AppendMethodDeclaration( - this CodeWriter code, - in CreateFromDataSpan data, - in Parameters parameters, - ParameterType fromParameterType, - ParameterType toParameterType) - { - var methodName = data.MethodName; - var returnType = data.ToTypeName; - var additionalParameter = string.Empty; - - switch (toParameterType) - { - case ParameterType.None: break; - case ParameterType.List: - methodName += "AsList"; - returnType = $"{List}<{returnType}>"; - break; - - case ParameterType.Span: - case ParameterType.Array: - case ParameterType.ReadOnlySpan: - methodName += "AsArray"; - returnType += "[]"; - break; - - case ParameterType.Enumerable: - methodName += "AsEnumerable"; - returnType = $"{IEnumerable}<{returnType}>"; - break; - - case ParameterType.IList: - methodName += "AsList"; - returnType = $"{IList}<{returnType}>"; - additionalParameter = $", {Func}<{IList}<{data.ToTypeName}>> __createList"; - break; - - default: throw new ArgumentOutOfRangeException(nameof(toParameterType), toParameterType, null); - } - - if (!data.CanBeInherited) - { - return code.AppendMultiline( - $""" - {GeneratedAttribute} - public static {returnType} {methodName}({parameters.Method(fromParameterType, data.FromTypeName)}{additionalParameter}) - """); - } - - return code.AppendMultiline( - $""" - {GeneratedAttribute} - public static {returnType} {methodName}({parameters.Method(fromParameterType, "T")}{additionalParameter}) - where T : {data.FromTypeName} - """); - } - - private static LengthType GetLengthType(ParameterType type) => type switch - { - ParameterType.None => LengthType.None, - ParameterType.Array => LengthType.Length, - ParameterType.List => LengthType.Count, - ParameterType.IList => LengthType.Count, - ParameterType.Span => LengthType.Length, - ParameterType.ReadOnlySpan => LengthType.Length, - ParameterType.Enumerable => LengthType.None, - _ => throw new ArgumentOutOfRangeException(nameof(type), type, null) - }; - - private static Parameters GetParameters(IMethodSymbol constructor, ITypeSymbol fromType) - { - string? fromName = null; - StringBuilder parameters = new(); - StringBuilder methodParameters = new(); - StringBuilder constructorParameters = new(); - - foreach (var parameter in constructor.Parameters) - { - if (constructorParameters.Length is not 0) - constructorParameters.Append(", "); - - if (fromName is null && Comparer.Equals(parameter.Type, fromType)) - { - fromName = parameter.Name; - constructorParameters.Append("{0}"); - } - else - { - if (parameters.Length is not 0) - parameters.Append(", "); - - parameters.Append($"{parameter.Name}"); - methodParameters.Append($", {parameter.Type.ToDisplayStringGlobal()} {parameter.Name}"); - constructorParameters.Append($"{parameter.Name}"); - } - } - - return new Parameters(fromName!, methodParameters, parameters, constructorParameters); - } - - private readonly ref struct Parameters( - string from, - StringBuilder method, - StringBuilder parameters, - StringBuilder constructor) - { - public readonly string From = from; - public readonly string EnumParameters = parameters.ToString(); - - private readonly string _methods = from + method; - private readonly string _constructor = constructor.ToString(); - - - public string Method(ParameterType type, string fromType) - { - return type switch - { - ParameterType.None => $"this {fromType} {_methods}", - ParameterType.Array => $"this {fromType}[] {_methods}", - ParameterType.Span => $"this {Span}<{fromType}> {_methods}", - ParameterType.List => $"this {List}<{fromType}> {_methods}", - ParameterType.IList => $"this {IList}<{fromType}> {_methods}", - ParameterType.ReadOnlySpan => $"this {ReadOnlySpan}<{fromType}> {_methods}", - ParameterType.Enumerable => $"this {IEnumerable}<{fromType}> {_methods}", - _ => throw new ArgumentOutOfRangeException(nameof(type), type, null) - }; - } - - public string Constructor(string fromName) => string.Format(_constructor, fromName); - } - - private enum LengthType - { - None, - Count, - Length, - } - - private enum ParameterType - { - None, - List, - IList, - Array, - Span, - ReadOnlySpan, - Enumerable, - } -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/CreateFrom/CreateFromGenerator.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/CreateFrom/CreateFromGenerator.cs deleted file mode 100644 index 3b77551..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/CreateFrom/CreateFromGenerator.cs +++ /dev/null @@ -1,91 +0,0 @@ -using System.Linq; -using System.Threading; -using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; -using Microsoft.CodeAnalysis.CSharp; -using System.Runtime.CompilerServices; -using Aspid.MVVM.Generators.Descriptions; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using Aspid.MVVM.Generators.CreateFrom.Body; -using Aspid.MVVM.Generators.CreateFrom.Data; - -namespace Aspid.MVVM.Generators.CreateFrom; - -[Generator(LanguageNames.CSharp)] -public class CreateFromGenerator : IIncrementalGenerator -{ - public void Initialize(IncrementalGeneratorInitializationContext context) - { - var provider = context.SyntaxProvider.ForAttributeWithMetadataName(Classes.CreateFromAttribute.FullName, SyntacticPredicate, FindCreateFrom). - Where(foundForSourceGenerator => foundForSourceGenerator.IsNeed). - Select((foundForSourceGenerator, _) => foundForSourceGenerator.Container); - - context.RegisterSourceOutput( - source: provider, - action: GenerateCode); - } - - private static bool SyntacticPredicate(SyntaxNode node, CancellationToken cancellationToken) - { - var candidate = node switch - { - ConstructorDeclarationSyntax syntax => syntax, - _ => null - }; - - return candidate is not null && !candidate.Modifiers.Any(SyntaxKind.StaticKeyword); - } - - private static FoundForGenerator FindCreateFrom( - GeneratorAttributeSyntaxContext context, - CancellationToken cancellationToken) - { - if (context.TargetSymbol is not IMethodSymbol constructor) return default; - - var attribute = context.Attributes.First(attribute => - attribute.AttributeClass?.ToDisplayString() == Classes.CreateFromAttribute.FullName); - - if (attribute.ConstructorArguments.First().Value is not ITypeSymbol fromType) return default; - - if (constructor.Parameters.Length == 0) return default; - var candidate = Unsafe.As(context.TargetNode); - return new FoundForGenerator(new CreateFromData(candidate, constructor, fromType)); - } - - private static void GenerateCode(SourceProductionContext context, CreateFromData data) - { - var @namespace = data.Declaration.GetNamespaceName(); - var dataSpan = new CreateFromDataSpan(data); - - if (data.Declaration.Parent is not TypeDeclarationSyntax typeDeclaration) return; - - var i = 0; - var index = -1; - - foreach (var constructor in typeDeclaration.Members.OfType()) - { - if (constructor == data.Declaration) - { - index = i; - break; - } - - i++; - } - - if (index == -1) return; - - var declaration = new DeclarationText( - "public static", - "class", - $"{dataSpan.FromType.ToDisplayString().Replace(".", "_")}To{dataSpan.ToType.ToDisplayString().Replace(".", "_")}_{index}", - null); - - var code = new CodeWriter(); - code.AppendClassBegin(@namespace, declaration) - .AppendCreateFromBody(dataSpan) - .AppendClassEnd(@namespace); - - context.AddSource(declaration.GetFileName(@namespace, "IViewModel"), code.GetSourceText()); - } -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/CreateFrom/Data/CreateFromData.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/CreateFrom/Data/CreateFromData.cs deleted file mode 100644 index b02b9ab..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/CreateFrom/Data/CreateFromData.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp.Syntax; - -namespace Aspid.MVVM.Generators.CreateFrom.Data; - -public readonly struct CreateFromData( - ConstructorDeclarationSyntax declaration, - IMethodSymbol constructor, - ITypeSymbol fromType) -{ - public readonly ITypeSymbol FromType = fromType; - public readonly IMethodSymbol Constructor = constructor; - public readonly ConstructorDeclarationSyntax Declaration = declaration; -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/CreateFrom/Data/CreateFromDataSpan.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/CreateFrom/Data/CreateFromDataSpan.cs deleted file mode 100644 index 82c5741..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/CreateFrom/Data/CreateFromDataSpan.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; - -namespace Aspid.MVVM.Generators.CreateFrom.Data; - -public readonly ref struct CreateFromDataSpan(CreateFromData data) -{ - public readonly CreateFromData Data = data; - public readonly IMethodSymbol Constructor = data.Constructor; - - public readonly ITypeSymbol ToType = data.Constructor.ContainingType; - public readonly string ToName = data.Declaration.Identifier.Text; - public readonly string ToTypeName = data.Constructor.ContainingType.ToDisplayStringGlobal(); - - public readonly ITypeSymbol FromType = data.FromType; - public readonly string FromTypeName = data.FromType.ToDisplayStringGlobal(); - - public readonly string MethodName = $"To{data.Declaration.Identifier.Text}"; - public readonly bool CanBeInherited = data.FromType.TypeKind != TypeKind.Struct && !data.FromType.IsSealed; -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Classes.Aspid.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Classes.Aspid.cs index 4535b0e..05c6017 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Classes.Aspid.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Classes.Aspid.cs @@ -1,19 +1,19 @@ -using Aspid.Generator.Helpers; +using Aspid.Generators.Helper; -namespace Aspid.MVVM.Generators.Descriptions; +namespace Aspid.MVVM.Generators.Generators.Descriptions; // ReSharper disable InconsistentNaming -public static partial class Classes +public static class Classes { #region Views public static readonly TypeText IView = new(nameof(IView), Namespaces.Aspid_MVVM); public static readonly AttributeText ViewAttribute = - new("View", Namespaces.Aspid_MVVM); + new("ViewAttribute", Namespaces.Aspid_MVVM); public static readonly AttributeText AsBinderAttribute = - new("AsBinder", Namespaces.Aspid_MVVM); + new("AsBinderAttribute", Namespaces.Aspid_MVVM); public static readonly TypeText ViewBinder = new (nameof(ViewBinder), Namespaces.Aspid_MVVM); @@ -33,10 +33,10 @@ public static partial class Classes new(nameof(MonoBinder), Namespaces.Aspid_MVVM_UNITY); public static readonly AttributeText BinderLogAttribute = - new("BinderLog", Namespaces.Aspid_MVVM); + new("BinderLogAttribute", Namespaces.Aspid_MVVM); public static readonly AttributeText RequireBinderAttribute = - new("RequireBinder", Namespaces.Aspid_MVVM); + new("RequireBinderAttribute", Namespaces.Aspid_MVVM); #endregion #region View Models @@ -44,7 +44,7 @@ public static partial class Classes new(nameof(IViewModel), Namespaces.Aspid_MVVM); public static readonly AttributeText ViewModelAttribute = - new("ViewModel", Namespaces.Aspid_MVVM); + new("ViewModelAttribute", Namespaces.Aspid_MVVM); public static readonly TypeText FindBindableMemberResult = new(nameof(FindBindableMemberResult), Namespaces.Aspid_MVVM); @@ -55,31 +55,31 @@ public static partial class Classes #region Bind Attributes public static readonly AttributeText BindAttribute = - new("Bind", Namespaces.Aspid_MVVM); + new("BindAttribute", Namespaces.Aspid_MVVM); public static readonly AttributeText IdAttribute = - new("BindId", Namespaces.Aspid_MVVM); + new("BindIdAttribute", Namespaces.Aspid_MVVM); public static readonly AttributeText AccessAttribute = - new("Access", Namespaces.Aspid_MVVM); + new("AccessAttribute", Namespaces.Aspid_MVVM); public static readonly AttributeText BindAlsoAttribute = - new("BindAlso", Namespaces.Aspid_MVVM); + new("BindAlsoAttribute", Namespaces.Aspid_MVVM); public static readonly AttributeText IgnoreAttribute = - new("IgnoreBind", Namespaces.Aspid_MVVM); + new("IgnoreBindAttribute", Namespaces.Aspid_MVVM); public static readonly AttributeText OneWayBindAttribute = - new("OneWayBind", Namespaces.Aspid_MVVM); + new("OneWayBindAttribute", Namespaces.Aspid_MVVM); public static readonly AttributeText TwoWayBindAttribute = - new("TwoWayBind", Namespaces.Aspid_MVVM); + new("TwoWayBindAttribute", Namespaces.Aspid_MVVM); public static readonly AttributeText OneTimeBindAttribute = - new("OneTimeBind", Namespaces.Aspid_MVVM); + new("OneTimeBindAttribute", Namespaces.Aspid_MVVM); public static readonly AttributeText OneWayToSourceBindAttribute = - new("OneWayToSourceBind", Namespaces.Aspid_MVVM); + new("OneWayToSourceBindAttribute", Namespaces.Aspid_MVVM); #endregion #region Bindable Member Events @@ -98,40 +98,40 @@ public static partial class Classes public static readonly TypeText IBinderRemover = new(nameof(IBinderRemover), Namespaces.Aspid_MVVM); - public static readonly TypeText? OneWayBindableMember = + public static readonly TypeText OneWayBindableMember = new(nameof(OneWayBindableMember), Namespaces.Aspid_MVVM); - public static readonly TypeText? OneWayStructBindableMember = + public static readonly TypeText OneWayStructBindableMember = new(nameof(OneWayStructBindableMember), Namespaces.Aspid_MVVM); - public static readonly TypeText? OneWayEnumBindableMember = + public static readonly TypeText OneWayEnumBindableMember = new(nameof(OneWayEnumBindableMember), Namespaces.Aspid_MVVM); - public static readonly TypeText? TwoWayBindableMember = + public static readonly TypeText TwoWayBindableMember = new(nameof(TwoWayBindableMember), Namespaces.Aspid_MVVM); - public static readonly TypeText? TwoWayStructBindableMember = + public static readonly TypeText TwoWayStructBindableMember = new(nameof(TwoWayStructBindableMember), Namespaces.Aspid_MVVM); - public static readonly TypeText? TwoWayEnumBindableMember = + public static readonly TypeText TwoWayEnumBindableMember = new(nameof(TwoWayEnumBindableMember), Namespaces.Aspid_MVVM); - public static readonly TypeText? OneTimeBindableMember = + public static readonly TypeText OneTimeBindableMember = new(nameof(OneTimeBindableMember), Namespaces.Aspid_MVVM); - public static readonly TypeText? OneTimeStructBindableMember = + public static readonly TypeText OneTimeStructBindableMember = new(nameof(OneTimeStructBindableMember), Namespaces.Aspid_MVVM); - public static readonly TypeText? OneTimeEnumBindableMember = + public static readonly TypeText OneTimeEnumBindableMember = new(nameof(OneTimeEnumBindableMember), Namespaces.Aspid_MVVM); - public static readonly TypeText? OneWayToSourceBindableMember = + public static readonly TypeText OneWayToSourceBindableMember = new(nameof(OneWayToSourceBindableMember), Namespaces.Aspid_MVVM); - public static readonly TypeText? OneWayToSourceStructBindableMember = + public static readonly TypeText OneWayToSourceStructBindableMember = new(nameof(OneWayToSourceStructBindableMember), Namespaces.Aspid_MVVM); - public static readonly TypeText? OneWayToSourceEnumBindableMember = + public static readonly TypeText OneWayToSourceEnumBindableMember = new(nameof(OneWayToSourceEnumBindableMember), Namespaces.Aspid_MVVM); #endregion @@ -143,7 +143,7 @@ public static partial class Classes new(nameof(IRelayCommand), Namespaces.Aspid_MVVM); public static readonly AttributeText RelayCommandAttribute = - new("RelayCommand", Namespaces.Aspid_MVVM); + new("RelayCommandAttribute", Namespaces.Aspid_MVVM); #endregion public static readonly TypeText Unsafe = @@ -153,8 +153,8 @@ public static partial class Classes new(nameof(Ids), Namespaces.Aspid_MVVM_Generated); public static readonly AttributeText CreateFromAttribute = - new("CreateFrom", Namespaces.Aspid_MVVM); + new("CreateFromAttribute", Namespaces.Aspid_MVVM); public static readonly AttributeText AddComponentContextMenuAttribute = - new ("AddComponentContextMenu", Namespaces.Aspid_MVVM_UNITY); + new ("AddComponentContextMenuAttribute", Namespaces.Aspid_MVVM_UNITY); } \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Classes.System.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Classes.System.cs deleted file mode 100644 index 3a8d0f2..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Classes.System.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Aspid.Generator.Helpers; - -namespace Aspid.MVVM.Generators.Descriptions; - -public static partial class Classes -{ - public static readonly TypeText Span = new("Span", Namespaces.System); - public static readonly TypeText ReadOnlySpan = new("ReadOnlySpan", Namespaces.System); - public static readonly TypeText Func = new("Func", Namespaces.System); - public static readonly TypeText Action = new("Action", Namespaces.System); - public static readonly TypeText Delegate = new("Delegate", Namespaces.System); - - public static readonly TypeText Exception = new("Exception", Namespaces.System); - public static readonly TypeText ArgumentNullException = new("ArgumentNullException", Namespaces.System); - public static readonly TypeText InvalidOperationException = new("InvalidOperationException", Namespaces.System); - - public static readonly TypeText List = new("List", Namespaces.System_Collections_Generic); - public static readonly TypeText IList = new("IList", Namespaces.System_Collections_Generic); - public static readonly TypeText Dictionary = new("Dictionary", Namespaces.System_Collections_Generic); - public static readonly TypeText IEnumerable = new("IEnumerable", Namespaces.System_Collections_Generic); - public static readonly TypeText EqualityComparer = new("EqualityComparer", Namespaces.System_Collections_Generic); - - public static readonly TypeText EditorBrowsableState = new(nameof(EditorBrowsableState), Namespaces.System_ComponentModel); - public static readonly AttributeText EditorBrowsableAttribute = new("EditorBrowsable", Namespaces.System_ComponentModel); - - public static readonly TypeText MethodImplOptions = new("MethodImplOptions", Namespaces.System_Runtime_CompilerServices); - public static readonly AttributeText MethodImplAttribute = new("MethodImpl", Namespaces.System_Runtime_CompilerServices); -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Classes.UnityEngine.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Classes.UnityEngine.cs deleted file mode 100644 index aa04347..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Classes.UnityEngine.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Aspid.Generator.Helpers; - -namespace Aspid.MVVM.Generators.Descriptions; - -public static partial class Classes -{ - public static readonly TypeText ProfilerMarker = new("ProfilerMarker", Namespaces.Unity_Profiling); - - public static readonly TypeText Object = new("Object", Namespaces.UnityEngine); - public static readonly TypeText Component = new("Component", Namespaces.UnityEngine); - public static readonly TypeText MonoBehaviour = new("MonoBehaviour", Namespaces.UnityEngine); - public static readonly TypeText SerializeField = new("SerializeField", Namespaces.UnityEngine); - - public static readonly TypeText MenuItem = new("MenuItem", Namespaces.UnityEditor); - public static readonly TypeText MenuCommand = new("MenuCommand", Namespaces.UnityEditor); - - public static readonly TypeText Button = new("Button", Namespaces.UnityEngine_UI); - public static readonly TypeText Toggle = new("Toggle", Namespaces.UnityEngine_UI); - public static readonly TypeText Slider = new("Slider", Namespaces.UnityEngine_UI); - public static readonly TypeText ScrollRect = new("ScrollRect", Namespaces.UnityEngine_UI); -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Defines.Aspid.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Defines.Aspid.cs index a15c35a..69ee7e4 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Defines.Aspid.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Defines.Aspid.cs @@ -1,7 +1,7 @@ -namespace Aspid.MVVM.Generators.Descriptions; +namespace Aspid.MVVM.Generators.Generators.Descriptions; // ReSharper disable InconsistentNaming -public static partial class Defines +public static class Defines { public const string ASPID_MVVM_BINDER_LOG_DISABLED = nameof(ASPID_MVVM_BINDER_LOG_DISABLED); diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Defines.UnityEngine.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Defines.UnityEngine.cs deleted file mode 100644 index c5601dc..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Defines.UnityEngine.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Aspid.MVVM.Generators.Descriptions; - -// ReSharper disable InconsistentNaming -public static partial class Defines -{ - public const string UNITY_EDITOR = nameof(UNITY_EDITOR); - - public const string UNITY_IOS = nameof(UNITY_IOS); - public const string UNITY_ANDROID = nameof(UNITY_ANDROID); -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/General.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/General.cs index 7d1aaf3..6fc3ced 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/General.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/General.cs @@ -1,6 +1,6 @@ -namespace Aspid.MVVM.Generators.Descriptions; +namespace Aspid.MVVM.Generators.Generators.Descriptions; -public class General +public static class General { public const string GeneratedCodeIdAttribute = "[global::System.CodeDom.Compiler.GeneratedCode(\"Aspid.MVVM.Generators.IdGenerator\", \"1.0.0\")]"; diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Namespaces.Aspid.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Namespaces.Aspid.cs index 345c9f3..fdc8958 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Namespaces.Aspid.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Namespaces.Aspid.cs @@ -1,9 +1,9 @@ -using Aspid.Generator.Helpers; +using Aspid.Generators.Helper; -namespace Aspid.MVVM.Generators.Descriptions; +namespace Aspid.MVVM.Generators.Generators.Descriptions; // ReSharper disable InconsistentNaming -public static partial class Namespaces +public static class Namespaces { public static readonly NamespaceText Aspid = new(nameof(Aspid)); diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Namespaces.System.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Namespaces.System.cs deleted file mode 100644 index 44f3571..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Namespaces.System.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Aspid.Generator.Helpers; - -namespace Aspid.MVVM.Generators.Descriptions; - -// ReSharper disable InconsistentNaming -public static partial class Namespaces -{ - public static readonly NamespaceText System = new(nameof(System)); - public static readonly NamespaceText System_Runtime = new("Runtime", System); - public static readonly NamespaceText System_Collections = new("Collections", System); - public static readonly NamespaceText System_ComponentModel = new("ComponentModel", System); - public static readonly NamespaceText System_Collections_Generic = new("Generic", System_Collections); - public static readonly NamespaceText System_Runtime_CompilerServices = new("CompilerServices", System_Runtime); -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Namespaces.UnityEngine.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Namespaces.UnityEngine.cs deleted file mode 100644 index cfd9f33..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Descriptions/Namespaces.UnityEngine.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Aspid.Generator.Helpers; - -namespace Aspid.MVVM.Generators.Descriptions; - -// ReSharper disable InconsistentNaming -public static partial class Namespaces -{ - public static readonly NamespaceText Unity = new("Unity"); - public static readonly NamespaceText Unity_Profiling = new("Profiling", Unity); - - public static readonly NamespaceText UnityEngine = new("UnityEngine"); - public static readonly NamespaceText UnityEngine_UI = new("UI", UnityEngine); - - public static readonly NamespaceText UnityEditor = new("UnityEditor"); -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Ids/Data/IdData.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Ids/Data/IdData.cs index 764e4b7..fd45829 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Ids/Data/IdData.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Ids/Data/IdData.cs @@ -1,9 +1,9 @@ using System; using Microsoft.CodeAnalysis; -using Aspid.MVVM.Generators.Descriptions; -using Aspid.MVVM.Generators.Ids.Extensions; +using Aspid.MVVM.Generators.Generators.Descriptions; +using Aspid.MVVM.Generators.Generators.Ids.Extensions; -namespace Aspid.MVVM.Generators.Ids.Data; +namespace Aspid.MVVM.Generators.Generators.Ids.Data; public readonly struct IdData : IEquatable { diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Ids/Extensions/IdGeneratorExtensions.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Ids/Extensions/IdGeneratorExtensions.cs index 06eb234..624595e 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Ids/Extensions/IdGeneratorExtensions.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Ids/Extensions/IdGeneratorExtensions.cs @@ -1,14 +1,15 @@ using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; -using Aspid.MVVM.Generators.Descriptions; +using Aspid.Generators.Helper; +using Classes = Aspid.MVVM.Generators.Generators.Descriptions.Classes; +using SymbolExtensions = Aspid.MVVM.Generators.Helpers.SymbolExtensions; -namespace Aspid.MVVM.Generators.Ids.Extensions; +namespace Aspid.MVVM.Generators.Generators.Ids.Extensions; public static class IdGeneratorExtensions { public static string GetId(this ISymbol member, string prefixName = "") { - if (!member.HasAnyAttribute(out var attribute, Classes.IdAttribute)) + if (!member.TryGetAnyAttributeInSelf(out var attribute, Classes.IdAttribute)) return member.GetName(prefixName); var value = attribute!.ConstructorArguments[0].Value as string; diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Ids/IdGenerator.Find.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Ids/IdGenerator.Find.cs index 7fd4fb5..ad917ea 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Ids/IdGenerator.Find.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Ids/IdGenerator.Find.cs @@ -1,26 +1,26 @@ using System.Threading; using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; +using Aspid.Generators.Helper; using System.Collections.Generic; using Microsoft.CodeAnalysis.CSharp; -using Aspid.MVVM.Generators.Descriptions; using Microsoft.CodeAnalysis.CSharp.Syntax; -using Aspid.MVVM.Generators.Views.Factories; -using Aspid.MVVM.Generators.ViewModels.Factories; +using Aspid.MVVM.Generators.Generators.Views.Factories; +using Aspid.MVVM.Generators.Generators.ViewModels.Factories; +using Classes = Aspid.MVVM.Generators.Generators.Descriptions.Classes; -namespace Aspid.MVVM.Generators.Ids; +namespace Aspid.MVVM.Generators.Generators.Ids; public partial class IdGenerator { - private static FoundForGenerator> GetIdsForSourceGeneration( + private static HashSet? GetIdsForSourceGeneration( GeneratorSyntaxContext context, CancellationToken cancellationToken) { var syntax = (TypeDeclarationSyntax)context.Node; - if (context.SemanticModel.GetDeclaredSymbol(syntax) is not { } symbol) return default; + if (context.SemanticModel.GetDeclaredSymbol(syntax) is not { } symbol) return null; var ids = new HashSet(); - if (symbol.HasAnyAttribute(out var attribute, Classes.ViewAttribute, Classes.ViewModelAttribute)) + if (symbol.TryGetAnyAttributeInSelf(out var attribute, Classes.ViewAttribute, Classes.ViewModelAttribute)) { var attributeName = attribute!.AttributeClass!.ToDisplayString(); @@ -40,8 +40,6 @@ private static FoundForGenerator> GetIdsForSourceGeneration( } } - return ids.Count is 0 - ? default - : new FoundForGenerator>(ids); + return ids.Count is 0 ? null : ids; } } \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Ids/IdGenerator.Generate.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Ids/IdGenerator.Generate.cs index 7daf40f..1222dcf 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Ids/IdGenerator.Generate.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Ids/IdGenerator.Generate.cs @@ -1,10 +1,10 @@ using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; +using Aspid.Generators.Helper; using System.Collections.Generic; using System.Collections.Immutable; -using static Aspid.MVVM.Generators.Descriptions.General; +using static Aspid.MVVM.Generators.Generators.Descriptions.General; -namespace Aspid.MVVM.Generators.Ids; +namespace Aspid.MVVM.Generators.Generators.Ids; public partial class IdGenerator { diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Ids/IdGenerator.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Ids/IdGenerator.cs index 4a768c4..74c2798 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Ids/IdGenerator.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Ids/IdGenerator.cs @@ -3,16 +3,17 @@ using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; -namespace Aspid.MVVM.Generators.Ids; +namespace Aspid.MVVM.Generators.Generators.Ids; [Generator(LanguageNames.CSharp)] public partial class IdGenerator : IIncrementalGenerator { public void Initialize(IncrementalGeneratorInitializationContext context) { + // ReSharper disable once NullableWarningSuppressionIsUsed var provider = context.SyntaxProvider.CreateSyntaxProvider(SyntacticPredicate, GetIdsForSourceGeneration) - .Where(foundFor => foundFor.IsNeed) - .Select((foundFor, _) => foundFor.Container); + .Where(foundFor => foundFor is not null) + .Select((foundFor, _) => foundFor!); context.RegisterSourceOutput(provider.Collect(), GenerateCode); } diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Body/BindableMembersBody.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Body/BindableMembersBody.cs index 3e7af2e..ea8a752 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Body/BindableMembersBody.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Body/BindableMembersBody.cs @@ -1,24 +1,24 @@ using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; -using Aspid.MVVM.Generators.ViewModels.Data; -using static Aspid.MVVM.Generators.Descriptions.Classes; -using static Aspid.MVVM.Generators.Descriptions.General; -using BindMode = Aspid.MVVM.Generators.ViewModels.Data.BindMode; +using Aspid.Generators.Helper; +using Aspid.MVVM.Generators.Generators.ViewModels.Data; +using static Aspid.MVVM.Generators.Generators.Descriptions.General; +using static Aspid.MVVM.Generators.Generators.Descriptions.Classes; +using BindMode = Aspid.MVVM.Generators.Generators.ViewModels.Data.BindMode; -namespace Aspid.MVVM.Generators.ViewModels.Body; +namespace Aspid.MVVM.Generators.Generators.ViewModels.Body; public static class BindableMembersBody { public static void Generate( string @namespace, in ViewModelData data, - in DeclarationText declaration, + DeclarationText declaration, in SourceProductionContext context) { var code = new CodeWriter(); - code.AppendClassBegin(@namespace, declaration) + code.BeginClass(@namespace, declaration) .AppendProperties(data) - .AppendClassEnd(@namespace); + .EndClass(@namespace); context.AddSource(declaration.GetFileName(@namespace, "BindableMembers"), code.GetSourceText()); } diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Body/FindBindableMembersBody.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Body/FindBindableMembersBody.cs index 0e73bbd..7473cf9 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Body/FindBindableMembersBody.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Body/FindBindableMembersBody.cs @@ -1,29 +1,31 @@ using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; +using Aspid.Generators.Helper; using System.Collections.Generic; using System.Collections.Immutable; -using Aspid.MVVM.Generators.ViewModels.Data; -using Aspid.MVVM.Generators.ViewModels.Data.Members; -using static Aspid.MVVM.Generators.Descriptions.Classes; -using static Aspid.MVVM.Generators.Descriptions.Defines; -using static Aspid.MVVM.Generators.Descriptions.General; +using Aspid.MVVM.Generators.Generators.ViewModels.Data; +using Aspid.MVVM.Generators.Generators.ViewModels.Data.Members; +using static Aspid.Generators.Helper.Classes; +using static Aspid.Generators.Helper.Unity.UnityClasses; +using static Aspid.MVVM.Generators.Generators.Descriptions.Classes; +using static Aspid.MVVM.Generators.Generators.Descriptions.Defines; +using static Aspid.MVVM.Generators.Generators.Descriptions.General; -namespace Aspid.MVVM.Generators.ViewModels.Body; +namespace Aspid.MVVM.Generators.Generators.ViewModels.Body; public static class FindBindableMembersBody { public static void Generate( string @namespace, in ViewModelData data, - in DeclarationText declaration, + DeclarationText declaration, in SourceProductionContext context) { string[] baseTypes = [IViewModel]; var code = new CodeWriter(); - code.AppendClassBegin(@namespace, declaration, baseTypes) + code.BeginClass(@namespace, declaration, baseTypes) .AppendBody(data) - .AppendClassEnd(@namespace); + .EndClass(@namespace); context.AddSource(declaration.GetFileName(@namespace, "FindBindableMembers"), code.GetSourceText()); } diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Body/PropertiesBody.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Body/PropertiesBody.cs index 4187432..2a5006c 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Body/PropertiesBody.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Body/PropertiesBody.cs @@ -1,24 +1,24 @@ using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; -using Aspid.MVVM.Generators.ViewModels.Data; -using Aspid.MVVM.Generators.ViewModels.Data.Members; -using static Aspid.MVVM.Generators.Descriptions.General; +using Aspid.Generators.Helper; +using Aspid.MVVM.Generators.Generators.ViewModels.Data; +using Aspid.MVVM.Generators.Generators.ViewModels.Data.Members; +using static Aspid.MVVM.Generators.Generators.Descriptions.General; -namespace Aspid.MVVM.Generators.ViewModels.Body; +namespace Aspid.MVVM.Generators.Generators.ViewModels.Body; public static class PropertiesBody { public static void Generate( string @namespace, in ViewModelData data, - in DeclarationText declaration, + DeclarationText declaration, in SourceProductionContext context) { var code = new CodeWriter(); - code.AppendClassBegin(@namespace, declaration) + code.BeginClass(@namespace, declaration) .AppendBody(data) - .AppendClassEnd(@namespace); + .EndClass(@namespace); context.AddSource(declaration.GetFileName(@namespace, "Properties"), code.GetSourceText()); } diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Body/RelayCommandBody.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Body/RelayCommandBody.cs index a5b134d..7de88ec 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Body/RelayCommandBody.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Body/RelayCommandBody.cs @@ -1,26 +1,26 @@ using System.Linq; using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; -using Aspid.MVVM.Generators.ViewModels.Data; -using Aspid.MVVM.Generators.ViewModels.Data.Members; +using Aspid.Generators.Helper; +using Aspid.MVVM.Generators.Generators.ViewModels.Data; +using Aspid.MVVM.Generators.Generators.ViewModels.Data.Members; -namespace Aspid.MVVM.Generators.ViewModels.Body; +namespace Aspid.MVVM.Generators.Generators.ViewModels.Body; public static class RelayCommandBody { public static void Generate( string @namespace, in ViewModelData data, - in DeclarationText declaration, + DeclarationText declaration, in SourceProductionContext context) { if (!data.Members.OfType().Any()) return; var code = new CodeWriter(); - code.AppendClassBegin(@namespace, declaration) + code.BeginClass(@namespace, declaration) .AppendBody(data) - .AppendClassEnd(@namespace); + .EndClass(@namespace); context.AddSource(declaration.GetFileName(@namespace, "Commands"), code.GetSourceText()); } diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/BindMode.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/BindMode.cs index 344db09..af1f4e0 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/BindMode.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/BindMode.cs @@ -1,4 +1,4 @@ -namespace Aspid.MVVM.Generators.ViewModels.Data; +namespace Aspid.MVVM.Generators.Generators.ViewModels.Data; public enum BindMode { diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Inheritor.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Inheritor.cs index 9ea8296..122bb98 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Inheritor.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Inheritor.cs @@ -1,4 +1,4 @@ -namespace Aspid.MVVM.Generators.ViewModels.Data; +namespace Aspid.MVVM.Generators.Generators.ViewModels.Data; public enum Inheritor { diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Members/BindableBindAlso.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Members/BindableBindAlso.cs index 966ce75..cbba561 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Members/BindableBindAlso.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Members/BindableBindAlso.cs @@ -1,8 +1,8 @@ using System; using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; +using Aspid.Generators.Helper; -namespace Aspid.MVVM.Generators.ViewModels.Data.Members; +namespace Aspid.MVVM.Generators.Generators.ViewModels.Data.Members; public sealed class BindableBindAlso : BindableMember, IEquatable { diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Members/BindableCommand.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Members/BindableCommand.cs index 89e99fc..02aaf64 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Members/BindableCommand.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Members/BindableCommand.cs @@ -1,11 +1,13 @@ using System.Linq; using System.Text; using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; -using static Aspid.MVVM.Generators.Descriptions.Classes; -using static Aspid.MVVM.Generators.Descriptions.General; +using Aspid.Generators.Helper; +using Aspid.MVVM.Generators.Helpers; +using static Aspid.Generators.Helper.Classes; +using static Aspid.MVVM.Generators.Generators.Descriptions.Classes; +using static Aspid.MVVM.Generators.Generators.Descriptions.General; -namespace Aspid.MVVM.Generators.ViewModels.Data.Members; +namespace Aspid.MVVM.Generators.Generators.ViewModels.Data.Members; public sealed class BindableCommand : BindableMember { diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Members/BindableField.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Members/BindableField.cs index d751fc6..e0e5ff5 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Members/BindableField.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Members/BindableField.cs @@ -1,11 +1,13 @@ using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; +using Aspid.Generators.Helper; using System.Collections.Immutable; using Microsoft.CodeAnalysis.CSharp; -using static Aspid.MVVM.Generators.Descriptions.Classes; -using static Aspid.MVVM.Generators.Descriptions.General; +using Aspid.MVVM.Generators.Helpers; +using static Aspid.Generators.Helper.Classes; +using static Aspid.MVVM.Generators.Generators.Descriptions.Classes; +using static Aspid.MVVM.Generators.Generators.Descriptions.General; -namespace Aspid.MVVM.Generators.ViewModels.Data.Members; +namespace Aspid.MVVM.Generators.Generators.ViewModels.Data.Members; public class BindableField : BindableMember { @@ -77,7 +79,7 @@ public string ToSetMethodString() {{GeneratedCodeViewModelAttribute}} private void {{setMethod}}({{Type}} value) { - if ({{EqualityComparer}}<{{Type}}>.Default.Equals({{SourceName}}, value)) return; + if ({{EqualityComparer_1}}<{{Type}}>.Default.Equals({{SourceName}}, value)) return; {{onMethodChanging}}({{SourceName}}, value); {{keyWordThis}}{{SourceName}} = value; @@ -104,7 +106,7 @@ public string ToSetMethodString() private static Accessors GetAccessors(IFieldSymbol field) { var accessors = new Accessors(SyntaxKind.PrivateKeyword, SyntaxKind.PrivateKeyword); - if (!field.HasAnyAttribute(out var accessAttribute, AccessAttribute)) return accessors; + if (!field.TryGetAnyAttributeInSelf(out var accessAttribute, AccessAttribute)) return accessors; if (accessAttribute!.ConstructorArguments.Length == 1) { diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Members/BindableMember.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Members/BindableMember.cs index d680117..df45ba8 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Members/BindableMember.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Members/BindableMember.cs @@ -1,10 +1,11 @@ using Microsoft.CodeAnalysis; -using Aspid.MVVM.Generators.Ids.Data; -using static Aspid.Generator.Helpers.SymbolExtensions; -using static Aspid.MVVM.Generators.Descriptions.General; -using static Aspid.MVVM.Generators.Descriptions.Classes; +using Aspid.MVVM.Generators.Generators.Ids.Data; +using static Aspid.Generators.Helper.Classes; +using static Aspid.MVVM.Generators.Helpers.SymbolExtensions; +using static Aspid.MVVM.Generators.Generators.Descriptions.General; +using static Aspid.MVVM.Generators.Generators.Descriptions.Classes; -namespace Aspid.MVVM.Generators.ViewModels.Data.Members; +namespace Aspid.MVVM.Generators.Generators.ViewModels.Data.Members; public abstract class BindableMember : BindableMember where T : ISymbol diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Members/Collections/IdLengthMemberGroup.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Members/Collections/IdLengthMemberGroup.cs index d686f96..ea8dfe6 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Members/Collections/IdLengthMemberGroup.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Members/Collections/IdLengthMemberGroup.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Collections.Immutable; -namespace Aspid.MVVM.Generators.ViewModels.Data.Members.Collections; +namespace Aspid.MVVM.Generators.Generators.ViewModels.Data.Members.Collections; public readonly struct IdLengthMemberGroup(int length, ImmutableArray members) { diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Members/CustomViewModelInterface.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Members/CustomViewModelInterface.cs index 5edb3ef..8c2ac44 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Members/CustomViewModelInterface.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/Members/CustomViewModelInterface.cs @@ -1,6 +1,6 @@ using Microsoft.CodeAnalysis; -namespace Aspid.MVVM.Generators.ViewModels.Data.Members; +namespace Aspid.MVVM.Generators.Generators.ViewModels.Data.Members; public readonly struct CustomViewModelInterface(string id, IPropertySymbol property, ITypeSymbol @interface) { diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/ViewModelData.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/ViewModelData.cs index d09ff45..7c9ba39 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/ViewModelData.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Data/ViewModelData.cs @@ -2,10 +2,10 @@ using System.Collections.Generic; using System.Collections.Immutable; using Microsoft.CodeAnalysis.CSharp.Syntax; -using Aspid.MVVM.Generators.ViewModels.Data.Members; -using Aspid.MVVM.Generators.ViewModels.Data.Members.Collections; +using Aspid.MVVM.Generators.Generators.ViewModels.Data.Members; +using Aspid.MVVM.Generators.Generators.ViewModels.Data.Members.Collections; -namespace Aspid.MVVM.Generators.ViewModels.Data; +namespace Aspid.MVVM.Generators.Generators.ViewModels.Data; public readonly struct ViewModelData( Inheritor inheritor, diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Extensions/SymbolExtensions.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Extensions/SymbolExtensions.cs index 8ed9654..15d3f17 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Extensions/SymbolExtensions.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Extensions/SymbolExtensions.cs @@ -1,15 +1,15 @@ using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; -using Aspid.MVVM.Generators.Descriptions; -using Aspid.MVVM.Generators.ViewModels.Data; +using Aspid.Generators.Helper; +using Aspid.MVVM.Generators.Generators.ViewModels.Data; +using Classes = Aspid.MVVM.Generators.Generators.Descriptions.Classes; -namespace Aspid.MVVM.Generators.ViewModels.Extensions; +namespace Aspid.MVVM.Generators.Generators.ViewModels.Extensions; public static class SymbolExtensions { public static BindMode GetBindMode(this ISymbol member) { - if (member.HasAnyAttribute(out var attribute, Classes.BindAttribute, Classes.OneWayBindAttribute, + if (member.TryGetAnyAttributeInSelf(out var attribute, Classes.BindAttribute, Classes.OneWayBindAttribute, Classes.TwoWayBindAttribute, Classes.OneTimeBindAttribute, Classes.OneWayToSourceBindAttribute)) { var attributeName = attribute!.AttributeClass!.ToDisplayString(); diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Factories/BindableBindAlsoFactory.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Factories/BindableBindAlsoFactory.cs index 19ae3c9..92cae1e 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Factories/BindableBindAlsoFactory.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Factories/BindableBindAlsoFactory.cs @@ -1,11 +1,11 @@ using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; +using Aspid.Generators.Helper; using System.Collections.Generic; using System.Collections.Immutable; -using Aspid.MVVM.Generators.ViewModels.Data.Members; -using static Aspid.MVVM.Generators.Descriptions.Classes; +using Aspid.MVVM.Generators.Generators.ViewModels.Data.Members; +using static Aspid.MVVM.Generators.Generators.Descriptions.Classes; -namespace Aspid.MVVM.Generators.ViewModels.Factories; +namespace Aspid.MVVM.Generators.Generators.ViewModels.Factories; public static class BindableBindAlsoFactory { @@ -16,8 +16,8 @@ public static IReadOnlyCollection Create(ImmutableArray Create( foreach (var method in methods) { - if (!method.HasAnyAttribute(out var attribute, Classes.RelayCommandAttribute)) continue; + if (!method.TryGetAnyAttributeInSelf(out var attribute, Classes.RelayCommandAttribute)) continue; var canExecuteArgument = attribute!.NamedArguments .Where(pair => pair.Key == "CanExecute") diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Factories/BindableFieldFactory.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Factories/BindableFieldFactory.cs index df4b51a..9dd2289 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Factories/BindableFieldFactory.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Factories/BindableFieldFactory.cs @@ -1,14 +1,14 @@ using System.Linq; using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; +using Aspid.Generators.Helper; using System.Collections.Generic; using System.Collections.Immutable; -using Aspid.MVVM.Generators.ViewModels.Extensions; -using Aspid.MVVM.Generators.ViewModels.Data.Members; -using static Aspid.MVVM.Generators.Descriptions.Classes; -using BindMode = Aspid.MVVM.Generators.ViewModels.Data.BindMode; +using Aspid.MVVM.Generators.Generators.ViewModels.Extensions; +using Aspid.MVVM.Generators.Generators.ViewModels.Data.Members; +using static Aspid.MVVM.Generators.Generators.Descriptions.Classes; +using BindMode = Aspid.MVVM.Generators.Generators.ViewModels.Data.BindMode; -namespace Aspid.MVVM.Generators.ViewModels.Factories; +namespace Aspid.MVVM.Generators.Generators.ViewModels.Factories; public static class BindableFieldFactory { @@ -48,7 +48,7 @@ private static ImmutableArray GetBindableBindAlso(IFieldSymbol foreach (var attribute in field.GetAttributes()) { if (attribute.AttributeClass != null && - attribute.AttributeClass.ToDisplayStringGlobal() == BindAlsoAttribute.Global) + attribute.AttributeClass.ToDisplayStringGlobal() == BindAlsoAttribute) { var value = attribute.ConstructorArguments[0].Value; if (value is null) continue; diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Factories/BindableMembersFactory.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Factories/BindableMembersFactory.cs index 4c94839..b3cc928 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Factories/BindableMembersFactory.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Factories/BindableMembersFactory.cs @@ -1,11 +1,11 @@ using System.Linq; using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; using System.Collections.Generic; using System.Collections.Immutable; -using Aspid.MVVM.Generators.ViewModels.Data.Members; +using Aspid.MVVM.Generators.Helpers; +using Aspid.MVVM.Generators.Generators.ViewModels.Data.Members; -namespace Aspid.MVVM.Generators.ViewModels.Factories; +namespace Aspid.MVVM.Generators.Generators.ViewModels.Factories; public static class BindableMembersFactory { diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Factories/CustomViewModelInterfacesFactory.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Factories/CustomViewModelInterfacesFactory.cs index 8218543..b21e919 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Factories/CustomViewModelInterfacesFactory.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/Factories/CustomViewModelInterfacesFactory.cs @@ -1,12 +1,12 @@ using System.Linq; using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; +using Aspid.Generators.Helper; using System.Collections.Generic; -using Aspid.MVVM.Generators.Ids.Extensions; -using Aspid.MVVM.Generators.ViewModels.Data.Members; -using static Aspid.MVVM.Generators.Descriptions.Classes; +using Aspid.MVVM.Generators.Generators.Ids.Extensions; +using Aspid.MVVM.Generators.Generators.ViewModels.Data.Members; +using static Aspid.MVVM.Generators.Generators.Descriptions.Classes; -namespace Aspid.MVVM.Generators.ViewModels.Factories; +namespace Aspid.MVVM.Generators.Generators.ViewModels.Factories; public static class CustomViewModelInterfacesFactory { @@ -22,7 +22,7 @@ public static Dictionary Create(ITypeSymbol sy void AddMembers(ITypeSymbol @interface) { - if (!@interface.HasInterfaceInSelfOrBases(IViewModel)) return; + if (!@interface.HasAnyInterfaceInSelfAndBases(IViewModel)) return; foreach (var property in @interface.GetMembers() .OfType() @@ -34,7 +34,7 @@ void AddMembers(ITypeSymbol @interface) || type.Contains(IReadOnlyValueBindableMember); })) { - if (property.HasAnyAttribute(IgnoreAttribute)) continue; + if (property.HasAnyAttributeInSelf(IgnoreAttribute)) continue; var id = property.GetId(); dictionary[id] = new CustomViewModelInterface(id, property, @interface); diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/ViewModelGenerator.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/ViewModelGenerator.cs index 62e26d3..f2a7823 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/ViewModelGenerator.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/ViewModels/ViewModelGenerator.cs @@ -1,26 +1,28 @@ +using System; using System.Threading; using System.Diagnostics; using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; +using Aspid.Generators.Helper; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; -using Aspid.MVVM.Generators.ViewModels.Body; -using Aspid.MVVM.Generators.ViewModels.Data; -using Aspid.MVVM.Generators.ViewModels.Factories; -using Aspid.MVVM.Generators.ViewModels.Data.Members.Collections; +using Aspid.MVVM.Generators.Generators.ViewModels.Body; +using Aspid.MVVM.Generators.Generators.ViewModels.Data; +using Aspid.MVVM.Generators.Generators.ViewModels.Factories; +using Aspid.MVVM.Generators.Generators.ViewModels.Data.Members.Collections; using Unsafe = System.Runtime.CompilerServices.Unsafe; -using static Aspid.MVVM.Generators.Descriptions.Classes; +using static Aspid.MVVM.Generators.Generators.Descriptions.Classes; -namespace Aspid.MVVM.Generators.ViewModels; +namespace Aspid.MVVM.Generators.Generators.ViewModels; [Generator(LanguageNames.CSharp)] public sealed class ViewModelGenerator : IIncrementalGenerator { public void Initialize(IncrementalGeneratorInitializationContext context) { + Console.WriteLine(ViewModelAttribute.FullName); var provider = context.SyntaxProvider.ForAttributeWithMetadataName(ViewModelAttribute.FullName, SyntacticPredicate, FindViewModels) - .Where(static foundForSourceGenerator => foundForSourceGenerator.IsNeed) - .Select(static (foundForSourceGenerator, _) => foundForSourceGenerator.Container); + .Where(static foundForSourceGenerator => foundForSourceGenerator.HasValue) + .Select(static (foundForSourceGenerator, _) => foundForSourceGenerator!.Value); context.RegisterSourceOutput( source: provider, @@ -35,15 +37,15 @@ private static bool SyntacticPredicate(SyntaxNode node, CancellationToken cancel && !candidate.Modifiers.Any(SyntaxKind.StaticKeyword); } - private static FoundForGenerator FindViewModels(GeneratorAttributeSyntaxContext context, + private static ViewModelData? FindViewModels(GeneratorAttributeSyntaxContext context, CancellationToken cancellationToken) { - if (context.TargetSymbol is not INamedTypeSymbol symbol) return default; + if (context.TargetSymbol is not INamedTypeSymbol symbol) return null; Debug.Assert(context.TargetNode is ClassDeclarationSyntax); var candidate = Unsafe.As(context.TargetNode); - var inheritor = symbol.HasAttributeInBases(ViewModelAttribute) + var inheritor = symbol.HasAnyAttributeInBases(ViewModelAttribute) ? Inheritor.Inheritor : Inheritor.None; @@ -51,15 +53,14 @@ private static FoundForGenerator FindViewModels(GeneratorAttribut var memberByGroups = IdLengthMemberGroup.Create(bindableMembers); var customViewModelInterfaces = CustomViewModelInterfacesFactory.Create(symbol); - var data = new ViewModelData(inheritor, symbol, candidate, bindableMembers, memberByGroups, customViewModelInterfaces); - return new FoundForGenerator(data); + return new ViewModelData(inheritor, symbol, candidate, bindableMembers, memberByGroups, customViewModelInterfaces); } private static void GenerateCode(SourceProductionContext context, ViewModelData data) { var declaration = data.Declaration; var @namespace = declaration.GetNamespaceName(); - var declarationText = declaration.GetDeclarationText(); + var declarationText = new DeclarationText(declaration); PropertiesBody.Generate(@namespace, data, declarationText, context); RelayCommandBody.Generate(@namespace, data, declarationText, context); diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Body/BinderCachedBody.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Body/BinderCachedBody.cs index 1533b13..c67d1cf 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Body/BinderCachedBody.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Body/BinderCachedBody.cs @@ -1,28 +1,28 @@ using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; -using Aspid.MVVM.Generators.Descriptions; -using Aspid.MVVM.Generators.Views.Data; -using Aspid.MVVM.Generators.Views.Data.Members; +using Aspid.Generators.Helper; +using Aspid.MVVM.Generators.Generators.Views.Data; +using Aspid.MVVM.Generators.Generators.Descriptions; +using Aspid.MVVM.Generators.Generators.Views.Data.Members; +using static Aspid.Generators.Helper.Classes; -namespace Aspid.MVVM.Generators.Views.Body; +namespace Aspid.MVVM.Generators.Generators.Views.Body; public static class BinderCachedBody { private const string GeneratedAttribute = General.GeneratedCodeViewAttribute; - private static readonly string EditorBrowsableAttribute = $"[{Classes.EditorBrowsableAttribute.Global}({Classes.EditorBrowsableState.Global}.Never)]"; public static void Generate( string @namespace, in ViewDataSpan data, - in DeclarationText declaration, + DeclarationText declaration, in SourceProductionContext context) { if (data.MembersByType.PropertyBinders.Length + data.MembersByType.AsBinders.Length == 0) return; var code = new CodeWriter(); - code.AppendClassBegin(@namespace, declaration) + code.BeginClass(@namespace, declaration) .AppendCachedBinders(data) - .AppendClassEnd(@namespace); + .EndClass(@namespace); context.AddSource(declaration.GetFileName(@namespace, "CachedBinders"), code.GetSourceText()); } @@ -43,7 +43,7 @@ private static CodeWriter AppendCachedBinders(this CodeWriter code, in ViewDataS private static CodeWriter AppendCachedBinderMember(this CodeWriter code, in CachedBinderMember cashedBinderMember) { - code.AppendLine(EditorBrowsableAttribute) + code.AppendLine($"[{EditorBrowsableAttribute}({EditorBrowsableState}.Never)]") .AppendLine(GeneratedAttribute) .AppendLine($"private {cashedBinderMember.Type?.ToDisplayStringGlobal()} {cashedBinderMember.CachedName};") .AppendLine(); @@ -53,7 +53,7 @@ private static CodeWriter AppendCachedBinderMember(this CodeWriter code, in Cach private static CodeWriter AppendAsBinderMember(this CodeWriter code, AsBinderMember asBinderMember) { - code.AppendLine(EditorBrowsableAttribute) + code.AppendLine($"[{EditorBrowsableAttribute}({EditorBrowsableState}.Never)]") .AppendLine(GeneratedAttribute) .AppendLine(asBinderMember.Type is IArrayTypeSymbol ? $"private {asBinderMember.AsBinderType}[] {asBinderMember.CachedName};" diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Body/Extensions/BindSafelyExtensions.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Body/Extensions/BindSafelyExtensions.cs index 2ea5ade..c91c2a1 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Body/Extensions/BindSafelyExtensions.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Body/Extensions/BindSafelyExtensions.cs @@ -1,9 +1,9 @@ using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; -using Aspid.MVVM.Generators.ViewModels.Data.Members; -using Aspid.MVVM.Generators.Views.Data.Members; +using Aspid.Generators.Helper; +using Aspid.MVVM.Generators.Generators.Views.Data.Members; +using Aspid.MVVM.Generators.Generators.ViewModels.Data.Members; -namespace Aspid.MVVM.Generators.Views.Body.Extensions; +namespace Aspid.MVVM.Generators.Generators.Views.Body.Extensions; public static class BindSafelyExtensions { diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Body/GenericInitializeView.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Body/GenericInitializeView.cs index b86e7dc..1c22db9 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Body/GenericInitializeView.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Body/GenericInitializeView.cs @@ -1,33 +1,34 @@ using System.Linq; using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; +using Aspid.Generators.Helper; using System.Collections.Generic; -using Aspid.MVVM.Generators.Views.Data; -using Aspid.MVVM.Generators.Descriptions; -using Aspid.MVVM.Generators.ViewModels.Factories; -using Aspid.MVVM.Generators.Views.Body.Extensions; -using Aspid.MVVM.Generators.ViewModels.Data.Members; -using static Aspid.MVVM.Generators.Descriptions.Classes; -using static Aspid.MVVM.Generators.Descriptions.Defines; -using static Aspid.MVVM.Generators.Descriptions.General; +using Aspid.MVVM.Generators.Generators.Views.Data; +using Aspid.MVVM.Generators.Generators.Descriptions; +using Aspid.MVVM.Generators.Generators.ViewModels.Factories; +using Aspid.MVVM.Generators.Generators.Views.Body.Extensions; +using Aspid.MVVM.Generators.Generators.ViewModels.Data.Members; +using static Aspid.Generators.Helper.Classes; +using static Aspid.Generators.Helper.Unity.UnityClasses; +using static Aspid.MVVM.Generators.Generators.Descriptions.Defines; +using static Aspid.MVVM.Generators.Generators.Descriptions.General; -namespace Aspid.MVVM.Generators.Views.Body; +namespace Aspid.MVVM.Generators.Generators.Views.Body; public static class GenericInitializeView { public static void Generate( string @namespace, in ViewDataSpan data, - in DeclarationText declaration, + DeclarationText declaration, in SourceProductionContext context) { foreach (var genericView in data.GenericViews) { var code = new CodeWriter(); - code.AppendClassBegin([Namespaces.Aspid_MVVM], @namespace, declaration, null) + code.BeginClass([Namespaces.Aspid_MVVM], @namespace, declaration, null) .AppendGenericViews(data, genericView) - .AppendClassEnd(@namespace); + .EndClass(@namespace); context.AddSource(declaration.GetFileName(@namespace, genericView.Type.ToDisplayString()), code.GetSourceText()); } diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Body/InitializeBody.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Body/InitializeBody.cs index 00440c9..f06ac5c 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Body/InitializeBody.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Body/InitializeBody.cs @@ -1,35 +1,33 @@ -using System; using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; -using Aspid.MVVM.Generators.Views.Data; -using Aspid.MVVM.Generators.Descriptions; -using Aspid.MVVM.Generators.Views.Data.Members; -using Aspid.MVVM.Generators.Views.Body.Extensions; +using Aspid.Generators.Helper; +using Aspid.MVVM.Generators.Generators.Views.Data; +using Aspid.MVVM.Generators.Generators.Descriptions; +using Aspid.MVVM.Generators.Generators.Views.Data.Members; +using Aspid.MVVM.Generators.Generators.Views.Body.Extensions; +using static Aspid.Generators.Helper.Classes; +using static Aspid.Generators.Helper.Unity.UnityClasses; +using static Aspid.MVVM.Generators.Generators.Descriptions.Classes; -namespace Aspid.MVVM.Generators.Views.Body; +namespace Aspid.MVVM.Generators.Generators.Views.Body; // ReSharper disable InconsistentNaming // ReSharper disable once InconsistentNaming public static class InitializeBody { private const string GeneratedAttribute = General.GeneratedCodeViewAttribute; - - private static readonly string IViewModel = Classes.IViewModel.Global; - private static readonly string ProfilerMarker = Classes.ProfilerMarker.Global; - private static readonly string EditorBrowsableAttribute = $"[{Classes.EditorBrowsableAttribute.Global}({Classes.EditorBrowsableState.Global}.Never)]"; public static void Generate( string @namespace, in ViewDataSpan data, - in DeclarationText declaration, + DeclarationText declaration, in SourceProductionContext context) { var code = new CodeWriter(); var baseTypes = GetBaseTypes(data); - code.AppendClassBegin([Namespaces.Aspid_MVVM], @namespace, declaration, baseTypes) + code.BeginClass([Namespaces.Aspid_MVVM], @namespace, declaration, baseTypes) .AppendIView(data) - .AppendClassEnd(@namespace); + .EndClass(@namespace); context.AddSource(declaration.GetFileName(@namespace, "Initialize"), code.GetSourceText()); } @@ -40,7 +38,7 @@ private static CodeWriter AppendIView(this CodeWriter code, in ViewDataSpan data { Inheritor.None => code.AppendNone(data), Inheritor.InheritorViewAttribute => code.AppendHasInterfaceOrInheritor(data), - _ => throw new ArgumentOutOfRangeException() + _ => code }; if (!data.IsInstantiateBinders) return code; @@ -62,7 +60,7 @@ private static CodeWriter AppendNone(this CodeWriter code, in ViewDataSpan data) $""" [global::System.NonSerialized] {GeneratedAttribute} - {EditorBrowsableAttribute} + [{EditorBrowsableAttribute}({EditorBrowsableState}.Never)] private bool __isInitializing; """) @@ -70,7 +68,7 @@ private static CodeWriter AppendNone(this CodeWriter code, in ViewDataSpan data) $""" [global::System.NonSerialized] {GeneratedAttribute} - {EditorBrowsableAttribute} + [{EditorBrowsableAttribute}({EditorBrowsableState}.Never)] private bool __isBindersCached; """) @@ -82,8 +80,8 @@ private static CodeWriter AppendNone(this CodeWriter code, in ViewDataSpan data) {{GeneratedAttribute}} public void Initialize({{IViewModel}} viewModel) { - if (viewModel is null) throw new {{Classes.ArgumentNullException.Global}}(nameof(viewModel)); - if (ViewModel is not null) throw new {{Classes.InvalidOperationException.Global}}("View is already initialized."); + if (viewModel is null) throw new {{ArgumentNullException}}(nameof(viewModel)); + if (ViewModel is not null) throw new {{InvalidOperationException}}("View is already initialized."); ViewModel = viewModel; InitializeInternal(viewModel); @@ -126,7 +124,7 @@ private static CodeWriter AppendHasInterfaceOrInheritor(this CodeWriter code, in $""" [global::System.NonSerialized] {GeneratedAttribute} - {EditorBrowsableAttribute} + [{EditorBrowsableAttribute}({EditorBrowsableState}.Never)] private bool __isInitializing; """) @@ -134,7 +132,7 @@ private static CodeWriter AppendHasInterfaceOrInheritor(this CodeWriter code, in $""" [global::System.NonSerialized] {GeneratedAttribute} - {EditorBrowsableAttribute} + [{EditorBrowsableAttribute}({EditorBrowsableState}.Never)] private bool __isBindersCached; """); @@ -156,11 +154,11 @@ private static CodeWriter AppendProfilerMarkers(this CodeWriter code, string cla return code.AppendMultiline( $""" #if !{Defines.ASPID_MVVM_UNITY_PROFILER_DISABLED} - {EditorBrowsableAttribute} + [{EditorBrowsableAttribute}({EditorBrowsableState}.Never)] {GeneratedAttribute} private static readonly {ProfilerMarker} __initializeMarker = new("{className}.Initialize"); - {EditorBrowsableAttribute} + [{EditorBrowsableAttribute}({EditorBrowsableState}.Never)] {GeneratedAttribute} private static readonly {ProfilerMarker} __deinitializeMarker = new("{className}.Deinitialize"); #endif @@ -341,12 +339,12 @@ private static CodeWriter AppendCreateBinders(this CodeWriter code, in ViewDataS code.AppendLineIf(isAppend) .AppendMultiline( - $$""" - var {{localName}} = {{name}}; - {{binderName}} = new {{binderType}}[{{localName}}.Length]; + $""" + var {localName} = {name}; + {binderName} = new {binderType}[{localName}.Length]; - for (var i = 0; i < {{localName}}.Length; i++) - {{binderName}}[i] = new {{member.AsBinderType}}({{localName}}[i]{{arguments}}); + for (var i = 0; i < {localName}.Length; i++) + {binderName}[i] = new {member.AsBinderType}({localName}[i]{arguments}); """) .AppendLineIf(i + 1 < membersCount); @@ -390,5 +388,5 @@ private static CodeWriter AppendDeinitializeInternalEvents(this CodeWriter code) } private static string[]? GetBaseTypes(in ViewDataSpan data) => - data.Inheritor is Inheritor.None ? [Classes.IView.ToString()] : null; + data.Inheritor is Inheritor.None ? [IView.ToString()] : null; } \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/GenericViewData.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/GenericViewData.cs index 66625af..386bc02 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/GenericViewData.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/GenericViewData.cs @@ -1,7 +1,7 @@ using System; using Microsoft.CodeAnalysis; -namespace Aspid.MVVM.Generators.Views.Data; +namespace Aspid.MVVM.Generators.Generators.Views.Data; public readonly struct GenericViewData(bool isSelf, ITypeSymbol type) : IEquatable { diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/Inheritor.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/Inheritor.cs index f34b095..94219c6 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/Inheritor.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/Inheritor.cs @@ -1,4 +1,4 @@ -namespace Aspid.MVVM.Generators.Views.Data; +namespace Aspid.MVVM.Generators.Generators.Views.Data; public enum Inheritor { diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/Members/AsBinderMember.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/Members/AsBinderMember.cs index 4960011..9a3d2c4 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/Members/AsBinderMember.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/Members/AsBinderMember.cs @@ -1,7 +1,7 @@ using Microsoft.CodeAnalysis; using System.Collections.Generic; -namespace Aspid.MVVM.Generators.Views.Data.Members; +namespace Aspid.MVVM.Generators.Generators.Views.Data.Members; public class AsBinderMember(ISymbol member, string asBinderType, IReadOnlyList? arguments) : CachedBinderMember(member) { diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/Members/BinderMember.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/Members/BinderMember.cs index ff9ff22..a1d676c 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/Members/BinderMember.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/Members/BinderMember.cs @@ -1,8 +1,8 @@ using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; -using Aspid.MVVM.Generators.Ids.Data; +using Aspid.Generators.Helper; +using Aspid.MVVM.Generators.Generators.Ids.Data; -namespace Aspid.MVVM.Generators.Views.Data.Members; +namespace Aspid.MVVM.Generators.Generators.Views.Data.Members; public class BinderMember { diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/Members/CachedBinderMember.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/Members/CachedBinderMember.cs index 1bfa836..9c65a86 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/Members/CachedBinderMember.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/Members/CachedBinderMember.cs @@ -1,7 +1,7 @@ using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; +using Aspid.MVVM.Generators.Helpers; -namespace Aspid.MVVM.Generators.Views.Data.Members; +namespace Aspid.MVVM.Generators.Generators.Views.Data.Members; public class CachedBinderMember(ISymbol member) : BinderMember(member) { diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/Members/Collections/BinderMembersCollectionSpanByType.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/Members/Collections/BinderMembersCollectionSpanByType.cs index e6cfbbe..26b65fb 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/Members/Collections/BinderMembersCollectionSpanByType.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/Members/Collections/BinderMembersCollectionSpanByType.cs @@ -1,9 +1,9 @@ using System; using System.Linq; -using Aspid.Generator.Helpers; using System.Collections.Immutable; +using Aspid.MVVM.Generators.Helpers; -namespace Aspid.MVVM.Generators.Views.Data.Members.Collections; +namespace Aspid.MVVM.Generators.Generators.Views.Data.Members.Collections; public readonly ref struct BinderMembersCollectionSpanByType { diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/ViewData.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/ViewData.cs index cccc8d3..fff5b81 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/ViewData.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/ViewData.cs @@ -1,9 +1,9 @@ using Microsoft.CodeAnalysis; using System.Collections.Immutable; using Microsoft.CodeAnalysis.CSharp.Syntax; -using Aspid.MVVM.Generators.Views.Data.Members; +using Aspid.MVVM.Generators.Generators.Views.Data.Members; -namespace Aspid.MVVM.Generators.Views.Data; +namespace Aspid.MVVM.Generators.Generators.Views.Data; public readonly struct ViewData( INamedTypeSymbol symbol, diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/ViewDataSpan.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/ViewDataSpan.cs index 0eb1720..b7192ca 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/ViewDataSpan.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Data/ViewDataSpan.cs @@ -1,10 +1,10 @@ using System; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; -using Aspid.MVVM.Generators.Views.Data.Members; -using Aspid.MVVM.Generators.Views.Data.Members.Collections; +using Aspid.MVVM.Generators.Generators.Views.Data.Members; +using Aspid.MVVM.Generators.Generators.Views.Data.Members.Collections; -namespace Aspid.MVVM.Generators.Views.Data; +namespace Aspid.MVVM.Generators.Generators.Views.Data; public readonly ref struct ViewDataSpan(ViewData viewData) { diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Factories/BinderMembersFactory.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Factories/BinderMembersFactory.cs index 7e4bdca..299f76e 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Factories/BinderMembersFactory.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/Factories/BinderMembersFactory.cs @@ -1,14 +1,14 @@ using System.Linq; using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; +using Aspid.Generators.Helper; using System.Collections.Generic; using System.Collections.Immutable; using Microsoft.CodeAnalysis.CSharp; -using Aspid.MVVM.Generators.Descriptions; using Microsoft.CodeAnalysis.CSharp.Syntax; -using Aspid.MVVM.Generators.Views.Data.Members; +using Aspid.MVVM.Generators.Generators.Views.Data.Members; +using Classes = Aspid.MVVM.Generators.Generators.Descriptions.Classes; -namespace Aspid.MVVM.Generators.Views.Factories; +namespace Aspid.MVVM.Generators.Generators.Views.Factories; public static class BinderMembersFactory { @@ -18,17 +18,17 @@ public static ImmutableArray Create(INamedTypeSymbol symbolClass, foreach (var member in symbolClass.GetMembers()) { - if (member.HasAnyAttribute(Classes.IgnoreAttribute)) continue; + if (member.HasAnyAttributeInSelf()) continue; var type = GetType(member); if (type is null) continue; - if (member.HasAnyAttribute(out var asBinderAttribute, Classes.AsBinderAttribute)) + if (member.TryGetAnyAttributeInSelf(out var asBinderAttribute, Classes.AsBinderAttribute)) { if (asBinderAttribute!.ConstructorArguments[0].Value is not INamedTypeSymbol argumentType) continue; if (argumentType.IsAbstract) continue; - if (!argumentType.HasInterfaceInSelfOrBases(Classes.IBinder)) continue; + if (!argumentType.HasAnyInterfaceInSelfAndBases(Classes.IBinder)) continue; var arguments = new List(); @@ -93,11 +93,11 @@ invocationExpression.Expression is IdentifierNameSyntax identifier && binderMembers.Add(new AsBinderMember(member, argumentType.ToDisplayStringGlobal(), arguments)); } - else if (type.HasAnyAttribute(Classes.ViewAttribute) || type.HasInterfaceInSelfOrBases(Classes.IView)) + else if (type.HasAnyAttributeInSelf(Classes.ViewAttribute) || type.HasAnyInterfaceInSelfAndBases(Classes.IView)) { - binderMembers.Add(new AsBinderMember(member, Classes.ViewBinder.Global, null)); + binderMembers.Add(new AsBinderMember(member, Classes.ViewBinder, null)); } - else if (type.HasInterfaceInSelfOrBases(Classes.IBinder)) + else if (type.HasAnyInterfaceInSelfAndBases(Classes.IBinder)) { switch (member) { @@ -110,7 +110,7 @@ invocationExpression.Expression is IdentifierNameSyntax identifier && var symbols = GetPropertyReturnSymbols(property, semanticModel); if (symbols is null) continue; - if (symbols.Any(symbol => symbol is IFieldSymbol or IPropertySymbol && !symbol.HasAnyAttribute(Classes.IgnoreAttribute))) continue; + if (symbols.Any(symbol => symbol is IFieldSymbol or IPropertySymbol && !symbol.HasAnyAttributeInSelf(Classes.IgnoreAttribute))) continue; binderMembers.Add(new CachedBinderMember(property)); break; diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/ViewGenerator.Find.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/ViewGenerator.Find.cs index 10c18a9..5a2d494 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/ViewGenerator.Find.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/ViewGenerator.Find.cs @@ -1,26 +1,26 @@ using System.Threading; using System.Diagnostics; using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; +using Aspid.Generators.Helper; using System.Collections.Generic; using System.Collections.Immutable; using System.Runtime.CompilerServices; -using Aspid.MVVM.Generators.Views.Data; -using Aspid.MVVM.Generators.Descriptions; using Microsoft.CodeAnalysis.CSharp.Syntax; -using Aspid.MVVM.Generators.Views.Factories; +using Aspid.MVVM.Generators.Generators.Views.Data; +using Aspid.MVVM.Generators.Generators.Views.Factories; +using Classes = Aspid.MVVM.Generators.Generators.Descriptions.Classes; -namespace Aspid.MVVM.Generators.Views; +namespace Aspid.MVVM.Generators.Generators.Views; public partial class ViewGenerator { - private static FoundForGenerator FindView( + private static ViewData? FindView( GeneratorAttributeSyntaxContext context, CancellationToken cancellationToken) { - if (context.TargetSymbol is not INamedTypeSymbol symbol) return default; + if (context.TargetSymbol is not INamedTypeSymbol symbol) return null; - var inheritor = symbol.HasAttributeInBases(Classes.ViewAttribute) + var inheritor = symbol.HasAnyAttributeInBases(Classes.ViewAttribute) ? Inheritor.InheritorViewAttribute : Inheritor.None; @@ -29,8 +29,7 @@ private static FoundForGenerator FindView( Debug.Assert(context.TargetNode is TypeDeclarationSyntax); var candidate = Unsafe.As(context.TargetNode); - var viewData = new ViewData(symbol, inheritor, candidate, members, GetGenericViews(symbol)); - return new FoundForGenerator(viewData); + return new ViewData(symbol, inheritor, candidate, members, GetGenericViews(symbol)); } private static ImmutableArray GetGenericViews(INamedTypeSymbol symbol) diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/ViewGenerator.Generate.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/ViewGenerator.Generate.cs index 4c78aec..cd4a91d 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/ViewGenerator.Generate.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/ViewGenerator.Generate.cs @@ -1,9 +1,9 @@ using Microsoft.CodeAnalysis; -using Aspid.Generator.Helpers; -using Aspid.MVVM.Generators.Views.Body; -using Aspid.MVVM.Generators.Views.Data; +using Aspid.Generators.Helper; +using Aspid.MVVM.Generators.Generators.Views.Body; +using Aspid.MVVM.Generators.Generators.Views.Data; -namespace Aspid.MVVM.Generators.Views; +namespace Aspid.MVVM.Generators.Generators.Views; public partial class ViewGenerator { @@ -13,7 +13,7 @@ private static void GenerateCode(SourceProductionContext context, ViewData data) var declaration = dataSpan.Declaration; var @namespace = declaration.GetNamespaceName(); - var declarationText = declaration.GetDeclarationText(); + var declarationText = new DeclarationText(declaration); InitializeBody.Generate(@namespace, dataSpan, declarationText, context); BinderCachedBody.Generate(@namespace, dataSpan, declarationText, context); diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/ViewGenerator.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/ViewGenerator.cs index 54b8a13..72fe30e 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/ViewGenerator.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Generators/Views/ViewGenerator.cs @@ -1,10 +1,10 @@ using System.Threading; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; -using Aspid.MVVM.Generators.Descriptions; using Microsoft.CodeAnalysis.CSharp.Syntax; +using Aspid.MVVM.Generators.Generators.Descriptions; -namespace Aspid.MVVM.Generators.Views; +namespace Aspid.MVVM.Generators.Generators.Views; [Generator(LanguageNames.CSharp)] public partial class ViewGenerator : IIncrementalGenerator @@ -12,8 +12,8 @@ public partial class ViewGenerator : IIncrementalGenerator public void Initialize(IncrementalGeneratorInitializationContext context) { var provider = context.SyntaxProvider.ForAttributeWithMetadataName(Classes.ViewAttribute.FullName, SyntacticPredicate, FindView) - .Where(foundForSourceGenerator => foundForSourceGenerator.IsNeed) - .Select((foundForSourceGenerator, _) => foundForSourceGenerator.Container); + .Where(foundForSourceGenerator => foundForSourceGenerator.HasValue) + .Select((foundForSourceGenerator, _) => foundForSourceGenerator!.Value); context.RegisterSourceOutput( source: provider, diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/AttributeText.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/AttributeText.cs deleted file mode 100644 index 183c698..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/AttributeText.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Aspid.Generator.Helpers; - -public class AttributeText(string name, NamespaceText? @namespace = null) : - TypeText(name + "Attribute", @namespace) -{ - public string AttributeName => name; - - public string AttributeFullName => (Namespace != null ? $"{Namespace}." : "") + AttributeName; - - public string AttributeGlobal => $"global::{AttributeFullName}"; - - public override string ToString() => - AttributeGlobal; - - public static implicit operator string(AttributeText type) => - type.ToString(); -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Data/CastedSpan.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/CastedSpan.cs similarity index 95% rename from Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Data/CastedSpan.cs rename to Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/CastedSpan.cs index 520dd1b..450eeb7 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Data/CastedSpan.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/CastedSpan.cs @@ -1,7 +1,7 @@ using System; using System.Runtime.CompilerServices; -namespace Aspid.Generator.Helpers; +namespace Aspid.MVVM.Generators.Helpers; public ref struct CastedSpan(ReadOnlySpan span) { diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/CodeWriter.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/CodeWriter.cs deleted file mode 100644 index 72c76c8..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/CodeWriter.cs +++ /dev/null @@ -1,120 +0,0 @@ -using System; -using System.IO; -using System.Text; -using System.CodeDom.Compiler; -using Microsoft.CodeAnalysis.Text; - -namespace Aspid.Generator.Helpers; - -public sealed class CodeWriter -{ - private readonly MemoryStream _sourceStream; - private readonly IndentedTextWriter _textWriter; - - public int Indent - { - get => _textWriter.Indent; - set => _textWriter.Indent = value; - } - - public CodeWriter() - { - _sourceStream = new MemoryStream(); - var sourceStreamWriter = new StreamWriter(_sourceStream, Encoding.UTF8); - _textWriter = new IndentedTextWriter(sourceStreamWriter); - } - - public CodeWriter Append(string value = "") - { - _textWriter.Write(value); - return this; - } - - public CodeWriter AppendLine(string value = "") - { - _textWriter.WriteLine(value); - return this; - } - - public CodeWriter AppendMultiline(string value) - { - var indent = Indent; - Indent = 0; - - var tab = new string('\t', indent); - value = $"{tab}{value}"; - value = value.Replace("\n", $"\n{tab}"); - AppendLine(value); - - Indent = indent; - return this; - } - - public IDisposable BeginIndentScope() => - new IndentScope(this); - - public IDisposable BeginBlockScope() => - new BlockScope(this); - - public CodeWriter BeginBlock() - { - AppendLine("{"); - IncreaseIndent(); - - return this; - } - - public CodeWriter EndBlock() - { - DecreaseIndent(); - AppendLine("}"); - - return this; - } - - public CodeWriter IncreaseIndent() - { - _textWriter.Indent++; - return this; - } - - public CodeWriter DecreaseIndent() - { - _textWriter.Indent--; - return this; - } - - public SourceText GetSourceText() - { - _textWriter.Flush(); - return SourceText.From(_sourceStream, Encoding.UTF8, canBeEmbedded: true); - } - - private readonly struct IndentScope : IDisposable - { - private readonly CodeWriter _source; - - public IndentScope(CodeWriter source) - { - _source = source; - source.IncreaseIndent(); - } - - public void Dispose() => - _source.DecreaseIndent(); - } - - private readonly struct BlockScope : IDisposable - { - private readonly CodeWriter _source; - - public BlockScope(CodeWriter source) - { - _source = source; - source.BeginBlock(); - } - - public void Dispose() => - _source.EndBlock(); - } -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/DeclarationText.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/DeclarationText.cs deleted file mode 100644 index 751ad04..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/DeclarationText.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Linq; - -namespace Aspid.Generator.Helpers; - -public readonly struct DeclarationText(string? modifiers, string typeType, string name, string? genericArguments) -{ - public string? Modifiers { get; } = modifiers; - - public string TypeType { get; } = typeType; - - public string Name { get; } = name; - - public string? GenericArguments { get; } = genericArguments; - - public string GetFileName(string? namespaceName, string? postfix) - { - postfix ??= ""; - if (postfix.Length > 0 && postfix[0] != '.') postfix = $".{postfix}"; - - namespaceName = string.IsNullOrEmpty(namespaceName) ? "" : $"{namespaceName}."; - - return namespaceName + (string.IsNullOrEmpty(GenericArguments) - ? $"{Name}{postfix}.g.cs" - : $"{Name}`{GenericArguments!.Count(arg => arg == ',') + 1}{postfix}.g.cs"); - } - - public override string ToString() - { - var modifiers = !string.IsNullOrEmpty(Modifiers) ? $"{Modifiers} " : ""; - var arguments = !string.IsNullOrEmpty(GenericArguments) ? $"<{GenericArguments}>" : ""; - - return $"{modifiers}{TypeType} {Name}{arguments}"; - } - - public static implicit operator string(DeclarationText declaration) => - declaration.ToString(); -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Declarations/CSharpSyntaxNodeExtensions.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Declarations/CSharpSyntaxNodeExtensions.cs deleted file mode 100644 index 762e70b..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Declarations/CSharpSyntaxNodeExtensions.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; - -namespace Aspid.Generator.Helpers; - -public static class CSharpSyntaxNodeExtensions -{ - public static string GetNamespaceName(this CSharpSyntaxNode node) - { - for (var parent = node.Parent; parent != null; parent = parent.Parent) - { - if (parent is BaseNamespaceDeclarationSyntax namespaceDeclaration) - return namespaceDeclaration.Name.ToString(); - } - - return ""; - } -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Declarations/MemberDeclarationSyntaxExtensions.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Declarations/MemberDeclarationSyntaxExtensions.cs deleted file mode 100644 index 0869f7e..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Declarations/MemberDeclarationSyntaxExtensions.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Linq; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp.Syntax; - -namespace Aspid.Generator.Helpers; - -public static class MemberDeclarationSyntaxExtensions -{ - public static bool HasAttribute(this MemberDeclarationSyntax declaration, SemanticModel semanticModel, string name) - { - foreach (var attribute in declaration.AttributeLists.SelectMany(attributeList => attributeList.Attributes)) - { - if (semanticModel.GetSymbolInfo(attribute).Symbol is not IMethodSymbol attributeSymbol) continue; - if (attributeSymbol.ContainingType?.ToDisplayString() == name) return true; - } - - return false; - } -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Declarations/PropertyDeclarationSyntaxExtensions.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Declarations/PropertyDeclarationSyntaxExtensions.cs deleted file mode 100644 index fabb772..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Declarations/PropertyDeclarationSyntaxExtensions.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Linq; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; - -namespace Aspid.Generator.Helpers; - -public static class PropertyDeclarationSyntaxExtensions -{ - public static bool HasGetAccessor(this PropertyDeclarationSyntax property) => - property.HasAccessor(SyntaxKind.GetAccessorDeclaration); - - public static bool HasSetAccessor(this PropertyDeclarationSyntax property) => - property.HasAccessor(SyntaxKind.SetAccessorDeclaration); - - public static bool HasInitAccessor(this PropertyDeclarationSyntax property) => - property.HasAccessor(SyntaxKind.InitAccessorDeclaration); - - private static bool HasAccessor(this PropertyDeclarationSyntax propertyDeclaration, SyntaxKind accessorKind) - { - var accessorList = propertyDeclaration.AccessorList; - return accessorList != null && accessorList.Accessors.Any(accessor => accessor.Kind() == accessorKind); - } -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Declarations/TypeDeclarationSyntaxExtensions.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Declarations/TypeDeclarationSyntaxExtensions.cs deleted file mode 100644 index 884392c..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Declarations/TypeDeclarationSyntaxExtensions.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System.Text; -using Microsoft.CodeAnalysis.CSharp.Syntax; - -namespace Aspid.Generator.Helpers; - -public static class TypeDeclarationSyntaxExtensions -{ - public static DeclarationText GetDeclarationText(this TypeDeclarationSyntax declaration) - { - var modifiers = declaration.GetModifiersAsText(); - var typeType = declaration is ClassDeclarationSyntax ? "class" : "struct"; - var typeName = declaration.Identifier.Text; - var genericArguments = declaration.GetGenericArgumentsAsText(); - - return new DeclarationText(modifiers, typeType, typeName, genericArguments); - } - - private static string GetModifiersAsText(this TypeDeclarationSyntax declaration) - { - var modifiers = new StringBuilder(); - foreach (var modifier in declaration.Modifiers) - modifiers.Append(modifier.ToString() + " "); - - modifiers.Length--; - return modifiers.ToString(); - } - - private static string GetGenericArgumentsAsText(this TypeDeclarationSyntax declaration) - { - var types = declaration.TypeParameterList; - if (types == null || types.Parameters.Count == 0) return ""; - - var genericTypes = new StringBuilder(); - foreach (var type in types.Parameters) - { - if (genericTypes.Length > 0) - genericTypes.Append(", "); - - genericTypes.Append(type.Identifier.Text); - } - - return genericTypes.ToString(); - } -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Symbols/MethodSymbolExtensions.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Symbols/MethodSymbolExtensions.cs deleted file mode 100644 index 3ed60a4..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Symbols/MethodSymbolExtensions.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Linq; -using Microsoft.CodeAnalysis; - -namespace Aspid.Generator.Helpers; - -public static class MethodSymbolExtensions -{ - public static bool EqualsSignature(this IMethodSymbol method1, IMethodSymbol method2) - { - if (method1.Parameters.Length != method2.Parameters.Length) return false; - - var method1Name = method1.NameFromExplicitImplementation(); - var method2Name = method2.NameFromExplicitImplementation(); - if (method1Name != method2Name) return false; - - if (!SymbolEqualityComparer.Default.Equals(method1.ReturnType, method2.ReturnType)) return false; - - var areParametersEqual = method1.Parameters - .Where((parameter, i) => SymbolEqualityComparer.Default.Equals(parameter.Type, method2.Parameters[i].Type)) - .Any(); - - return areParametersEqual; - } - - public static string NameFromExplicitImplementation(this IMethodSymbol method) => - method.Name.Substring(method.Name.LastIndexOf('.') + 1); -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Symbols/SymbolExtensions.Attribute.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Symbols/SymbolExtensions.Attribute.cs deleted file mode 100644 index 4eed3fd..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Symbols/SymbolExtensions.Attribute.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System.Linq; -using Microsoft.CodeAnalysis; -using System.Collections.Generic; - -namespace Aspid.Generator.Helpers; - -public static partial class SymbolExtensions -{ - public static bool HasAnyAttribute(this ISymbol symbol, params IReadOnlyCollection attributeText) => - symbol.HasAnyAttribute(attributeText.Select(attribute => attribute.FullName).ToArray()); - - public static bool HasAnyAttribute(this ISymbol symbol, params IReadOnlyCollection attributeFullName) - { - foreach (var attribute in symbol.GetAttributes()) - { - if (attribute.AttributeClass != null && attributeFullName.Any(name => name == attribute.AttributeClass.ToDisplayString())) - return true; - } - - return false; - } - - public static bool HasAnyAttribute(this ISymbol symbol, out AttributeData? foundAttribute, params IReadOnlyCollection attributeText) => - symbol.HasAnyAttribute(out foundAttribute, attributeText.Select(attribute => attribute.FullName).ToArray()); - - public static bool HasAnyAttribute(this ISymbol symbol, out AttributeData? foundAttribute, params IReadOnlyCollection attributeFullName) - { - foundAttribute = null; - - foreach (var attribute in symbol.GetAttributes()) - { - if (attribute.AttributeClass != null && attributeFullName.Any(name => name == attribute.AttributeClass.ToDisplayString())) - { - foundAttribute = attribute; - return true; - } - } - - return false; - } -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Symbols/TypeSymbolExtensions.Attribute.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Symbols/TypeSymbolExtensions.Attribute.cs deleted file mode 100644 index eb6d80f..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Symbols/TypeSymbolExtensions.Attribute.cs +++ /dev/null @@ -1,64 +0,0 @@ -using Microsoft.CodeAnalysis; - -namespace Aspid.Generator.Helpers; - -public static partial class TypeSymbolExtensions -{ - public static bool HasAttributeInBases(this ITypeSymbol typeSymbol, AttributeText attributeText) => - HasAttributeInBases(typeSymbol, attributeText.FullName); - - public static bool HasAttributeInBases(this ITypeSymbol symbol, string fullName) - { - for (var type = symbol.BaseType; type is not null; type = type.BaseType) - { - if (type.HasAnyAttribute(fullName)) - return true; - } - - return false; - } - - public static bool HasAttributeInBases(this ITypeSymbol typeSymbol, AttributeText attributeText, out AttributeData? attribute) => - HasAttributeInBases(typeSymbol, attributeText.FullName, out attribute); - - public static bool HasAttributeInBases(this ITypeSymbol symbol, string fullName, out AttributeData? attribute) - { - for (var type = symbol.BaseType; type is not null; type = type.BaseType) - { - if (type.HasAnyAttribute(out attribute, fullName)) - return true; - } - - attribute = null; - return false; - } - - public static bool HasAttributeInSelfOrBases(this ITypeSymbol typeSymbol, AttributeText attributeText) => - HasAttributeInSelfOrBases(typeSymbol, attributeText.FullName); - - public static bool HasAttributeInSelfOrBases(this ITypeSymbol symbol, string fullName) - { - for (var type = symbol; type is not null; type = type.BaseType) - { - if (type.HasAnyAttribute(fullName)) - return true; - } - - return false; - } - - public static bool HasAttributeInSelfOrBases(this ITypeSymbol typeSymbol, AttributeText attributeText, out AttributeData? attribute) => - HasAttributeInSelfOrBases(typeSymbol, attributeText.FullName, out attribute); - - public static bool HasAttributeInSelfOrBases(this ITypeSymbol symbol, string fullName, out AttributeData? attribute) - { - for (var type = symbol; type is not null; type = type.BaseType) - { - if (type.HasAnyAttribute(out attribute, fullName)) - return true; - } - - attribute = null; - return false; - } -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Symbols/TypeSymbolExtensions.BaseType.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Symbols/TypeSymbolExtensions.BaseType.cs deleted file mode 100644 index f2a18e9..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Symbols/TypeSymbolExtensions.BaseType.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System.Linq; -using Microsoft.CodeAnalysis; - -namespace Aspid.Generator.Helpers; - -public static partial class TypeSymbolExtensions -{ - public static bool HasBaseType(this ITypeSymbol symbol, TypeText typeText) => - HasBaseType(symbol, typeText.FullName); - - public static bool HasBaseType(this ITypeSymbol symbol, string baseTypeName) => - HasBaseType(symbol, baseTypeName, out _); - - public static bool HasBaseType(this ITypeSymbol symbol, TypeText typeText, out ITypeSymbol? foundBaseType) => - HasBaseType(symbol, typeText.FullName, out foundBaseType); - - public static bool HasBaseType(this ITypeSymbol symbol, string baseTypeName, out ITypeSymbol? foundBaseType) - { - foundBaseType = null; - - for (var type = symbol; type != null; type = type.BaseType) - { - if (type.ToDisplayString() != baseTypeName) continue; - - foundBaseType = type; - return true; - } - - return false; - } - - public static bool HasBaseType(this ITypeSymbol symbol, params TypeText[] baseTypeNames) => - HasBaseType(symbol, baseTypeNames.Select(baseTypeName => baseTypeName.FullName).ToArray()); - - public static bool HasBaseType(this ITypeSymbol symbol, params string[] baseTypeNames) - { - for (var type = symbol; type != null; type = type.BaseType) - { - if (baseTypeNames.Any(baseTypeName => type.ToDisplayString() == baseTypeName)) - { - return true; - } - } - - return false; - } -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Symbols/TypeSymbolExtensions.Interface.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Symbols/TypeSymbolExtensions.Interface.cs deleted file mode 100644 index 5bbbf87..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Symbols/TypeSymbolExtensions.Interface.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System.Linq; -using Microsoft.CodeAnalysis; - -namespace Aspid.Generator.Helpers; - -public static partial class TypeSymbolExtensions -{ - public static bool HasInterface(this ITypeSymbol type, TypeText typeText) => - type.HasInterface(typeText.FullName); - - public static bool HasInterface(this ITypeSymbol type, string name) => - type.HasInterface(name, out _); - - public static bool HasInterface(this ITypeSymbol type, TypeText typeText, out INamedTypeSymbol? foundInterface) => - type.HasInterface(typeText.FullName, out foundInterface); - - public static bool HasInterface(this ITypeSymbol type, string name, out INamedTypeSymbol? foundInterface) - { - foundInterface = null; - - foreach (var @interface in type.Interfaces) - { - if (@interface.ToDisplayString() != name) continue; - - foundInterface = @interface; - return true; - } - - return false; - } - - public static bool HasInterfaceInBases(this ITypeSymbol type, TypeText typeText) => - type.HasInterfaceInBases(typeText.FullName); - - public static bool HasInterfaceInBases(this ITypeSymbol type, string name) => - type.HasInterfaceInBases(name, out _); - - public static bool HasInterfaceInBases(this ITypeSymbol type, TypeText typeText, out INamedTypeSymbol? foundInterface) => - type.HasInterfaceInBases(typeText.FullName, out foundInterface); - - public static bool HasInterfaceInBases(this ITypeSymbol type, string name, out INamedTypeSymbol? foundInterface) - { - foundInterface = null; - - var baseType = type.BaseType; - if (baseType is null) return false; - - foreach (var @interface in baseType.AllInterfaces) - { - if (@interface.ToDisplayString() != name) continue; - - foundInterface = @interface; - return true; - } - - return false; - } - - public static bool HasInterfaceInSelfOrBases(this ITypeSymbol type, TypeText typeText) => - type.HasInterfaceInSelfOrBases(typeText.FullName); - - public static bool HasInterfaceInSelfOrBases(this ITypeSymbol type, string name) => - type.AllInterfaces.Any(@interface => @interface.ToDisplayString() == name); - - public static bool HasInterfaceInSelfOrBases(this ITypeSymbol type, TypeText typeText, out INamedTypeSymbol? foundInterface) => - type.HasInterfaceInSelfOrBases(typeText.FullName, out foundInterface); - - public static bool HasInterfaceInSelfOrBases(this ITypeSymbol type, string name, out INamedTypeSymbol? foundInterface) - { - foundInterface = null; - - foreach (var @interface in type.AllInterfaces) - { - if (@interface.ToDisplayString() != name) continue; - - foundInterface = @interface; - return true; - } - - return false; - } -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Writer/CodeWriteClassExtension.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Writer/CodeWriteClassExtension.cs deleted file mode 100644 index 24f5e36..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Writer/CodeWriteClassExtension.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; - -namespace Aspid.Generator.Helpers; - -public static class CodeWriteClassExtension -{ - public static CodeWriter AppendClass( - this CodeWriter code, - string @namespace, - DeclarationText declaration, - Action? body, params string[]? baseTypes) - { - code.AppendClassBegin(@namespace, declaration, baseTypes); - body?.Invoke(); - code.AppendClassEnd(@namespace); - - return code; - } - - public static CodeWriter AppendClassBegin( - this CodeWriter code, - string? @namespace, - DeclarationText declaration, - params string[]? baseTypes) - { - var hasNamespace = !string.IsNullOrEmpty(@namespace); - - var baseTypesText = ""; - if (baseTypes is { Length: > 0 }) baseTypesText = $" : {string.Join(",", baseTypes!)}"; - - code.AppendLine("// ") - .AppendChildIf(hasNamespace, () => code - .AppendLine($"namespace {@namespace}") - .BeginBlock()) - .AppendLine($"{declaration}{baseTypesText}") - .BeginBlock(); - - return code; - } - - public static CodeWriter AppendClassBegin( - this CodeWriter code, - string[] imports, - string? @namespace, - DeclarationText declaration, - params string[]? baseTypes) - { - var hasNamespace = !string.IsNullOrEmpty(@namespace); - - var baseTypesText = ""; - if (baseTypes is { Length: > 0 }) baseTypesText = $" : {string.Join(", ", baseTypes!)}"; - - code.AppendLine("// ") - .AppendLine() - .AppendLoop(imports, import => - { - code.AppendLine($"using {import};"); - }) - .AppendLine() - .AppendChildIf(hasNamespace, () => code - .AppendLine($"namespace {@namespace}") - .BeginBlock()) - .AppendLine($"{declaration}{baseTypesText}") - .BeginBlock(); - - return code; - } - - public static CodeWriter AppendClassEnd(this CodeWriter code, string? @namespace) - { - code.AppendClassEnd(!string.IsNullOrEmpty(@namespace)); - return code; - } - - private static CodeWriter AppendClassEnd(this CodeWriter code, bool hasNamespace) - { - code.EndBlock() - .EndBlockIf(hasNamespace); - return code; - } -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Writer/CodeWriteLoopExtensions.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Writer/CodeWriteLoopExtensions.cs deleted file mode 100644 index f3390bb..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Writer/CodeWriteLoopExtensions.cs +++ /dev/null @@ -1,91 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Aspid.Generator.Helpers; - -public static class CodeWriteLoopExtensions -{ - public static CodeWriter AppendLoop(this CodeWriter code, IEnumerable enumerable, Action setValue) - { - foreach (var value in enumerable) - setValue(value); - - return code; - } - - public static CodeWriter AppendLoop(this CodeWriter code, IEnumerable enumerable, Action setValue) - { - var i = 0; - - foreach (var value in enumerable) - { - setValue(i, value); - i++; - } - - return code; - } - - public static CodeWriter AppendLoop(this CodeWriter code, IEnumerable enumerable, Action setValue) - { - foreach (var value in enumerable) - setValue(code, value); - - return code; - } - - public static CodeWriter AppendLoop(this CodeWriter code, IEnumerable enumerable, Action setValue) - { - var i = 0; - - foreach (var value in enumerable) - { - setValue(code, i, value); - i++; - } - - return code; - } - - public static CodeWriter AppendLoop(this CodeWriter code, ReadOnlySpan span, Action setValue) - { - foreach (var value in span) - setValue(value); - - return code; - } - - public static CodeWriter AppendLoop(this CodeWriter code, ReadOnlySpan span, Action setValue) - { - var i = 0; - - foreach (var value in span) - { - setValue(i, value); - i++; - } - - return code; - } - - public static CodeWriter AppendLoop(this CodeWriter code, ReadOnlySpan span, Action setValue) - { - foreach (var value in span) - setValue(code, value); - - return code; - } - - public static CodeWriter AppendLoop(this CodeWriter code, ReadOnlySpan span, Action setValue) - { - var i = 0; - - foreach (var value in span) - { - setValue(code, i, value); - i++; - } - - return code; - } -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Writer/CodeWriterIfExtensions.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Writer/CodeWriterIfExtensions.cs deleted file mode 100644 index 54346be..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Writer/CodeWriterIfExtensions.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; - -namespace Aspid.Generator.Helpers; - -public static class CodeWriterIfExtensions -{ - public static CodeWriter AppendIf(this CodeWriter code, Func condition, string value = "") => - code.AppendIf(condition.Invoke(), value); - - public static CodeWriter AppendIf(this CodeWriter code, bool flag, string value = "") => - !flag ? code : code.Append(value); - - public static CodeWriter AppendLineIf(this CodeWriter code, Func condition, string value = "") => - code.AppendLineIf(condition.Invoke(), value); - - public static CodeWriter AppendLineIf(this CodeWriter code, bool flag, string value = "") => - !flag ? code : code.AppendLine(value); - - public static CodeWriter AppendMultilineIf(this CodeWriter code, Func condition, string value = "") => - code.AppendMultilineIf(condition.Invoke(), value); - - public static CodeWriter AppendMultilineIf(this CodeWriter code, bool flag, string value = "") => - !flag ? code : code.AppendMultiline(value); - - public static CodeWriter AppendChildIf(this CodeWriter code, Func condition, Func childFunctions) => - code.AppendChildIf(condition.Invoke(), childFunctions); - - public static CodeWriter AppendChildIf(this CodeWriter code, bool flag, Func childFunctions) => - !flag ? code : childFunctions.Invoke(); - - public static CodeWriter BeginBlockIf(this CodeWriter code, Func condition) => - code.BeginBlockIf(condition.Invoke()); - - public static CodeWriter BeginBlockIf(this CodeWriter code, bool flag) => - !flag ? code : code.BeginBlock(); - - public static CodeWriter EndBlockIf(this CodeWriter code, Func condition) => - code.EndBlockIf(condition.Invoke()); - - public static CodeWriter EndBlockIf(this CodeWriter code, bool flag) => - !flag ? code : code.EndBlock(); -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/FoundForGenerator.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/FoundForGenerator.cs deleted file mode 100644 index 5a8bfa0..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/FoundForGenerator.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Aspid.Generator.Helpers; - -public readonly struct FoundForGenerator -{ - public readonly bool IsNeed; - public readonly T Container; - - public FoundForGenerator(T container) - { - IsNeed = true; - Container = container; - } -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Data/MembersByGroup.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/MembersByGroup.cs similarity index 97% rename from Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Data/MembersByGroup.cs rename to Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/MembersByGroup.cs index ffff928..f28c590 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Data/MembersByGroup.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/MembersByGroup.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Collections.Immutable; -namespace Aspid.Generator.Helpers; +namespace Aspid.MVVM.Generators.Helpers; public readonly struct MembersByGroup { diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/NamespaceText.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/NamespaceText.cs deleted file mode 100644 index b9f79a9..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/NamespaceText.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Aspid.Generator.Helpers; - -public sealed class NamespaceText(string name, NamespaceText? parent = null) -{ - public string Name { get; } = (parent != null ? $"{parent}." : "") + name; - - public override string ToString() => Name; - - public static implicit operator string(NamespaceText @namespace) => - @namespace.ToString(); -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Symbols/SymbolExtensions.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/SymbolExtensions.cs similarity index 65% rename from Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Symbols/SymbolExtensions.cs rename to Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/SymbolExtensions.cs index beabc6a..71905d0 100644 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/Extensions/Symbols/SymbolExtensions.cs +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/SymbolExtensions.cs @@ -1,28 +1,9 @@ using Microsoft.CodeAnalysis; -namespace Aspid.Generator.Helpers; +namespace Aspid.MVVM.Generators.Helpers; -public static partial class SymbolExtensions +public static class SymbolExtensions { - public static string ToDisplayStringGlobal(this ISymbol symbol) => - symbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); - - public static ITypeSymbol? GetSymbolType(this ISymbol symbol) => symbol switch - { - ITypeSymbol type => type, - IFieldSymbol field => field.Type, - ILocalSymbol local => local.Type, - IEventSymbol @event => @event.Type, - IDiscardSymbol discard => discard.Type, - - // TODO Delete - IMethodSymbol method => method.ReturnType, - - IPropertySymbol property => property.Type, - IParameterSymbol parameter => parameter.Type, - _ => null - }; - public static string GetFieldName(this ISymbol member, in string? prefix = "_") => GetFieldName(member.Name, prefix); diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/TypeText.cs b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/TypeText.cs deleted file mode 100644 index e4f0dfe..0000000 --- a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Helpers/TypeText.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace Aspid.Generator.Helpers; - -public class TypeText(string name, NamespaceText? @namespace = null) -{ - public string Name { get; } = name; - - public NamespaceText? Namespace { get; } = @namespace; - - public string FullName => (Namespace != null ? $"{Namespace}." : "") + Name; - - public string Global => $"global::{FullName}"; - - public override string ToString() => - Global; - - public static implicit operator string(TypeText? type) => - type.ToString(); -} \ No newline at end of file diff --git a/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Properties/launchSettings.json b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Properties/launchSettings.json new file mode 100644 index 0000000..dc7f06f --- /dev/null +++ b/Aspid.MVVM.Generators/Aspid.MVVM.Generators/Properties/launchSettings.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "DebugRoslynSourceGenerator": { + "commandName": "DebugRoslynComponent", + "targetProject": "../Aspid.MVVM.Generators.Sample/Aspid.MVVM.Generators.Sample.csproj" + } + } +} \ No newline at end of file