From 710fd3274dbc8f6a9874a98d7cfb5fb331f27212 Mon Sep 17 00:00:00 2001 From: Ramon Date: Mon, 17 Jul 2023 08:25:04 +0200 Subject: [PATCH] Derivedfromgenerator add only flat --- Rop.DerivedFrom.Annotations/IDerivedFrom.cs | 3 +++ .../Rop.DerivedFrom.Annotations.csproj | 2 +- .../DerivedFromGenerator.cs | 24 ++++++++++++------- .../ProxyPartialClassToAugment.cs | 6 ++--- .../Rop.DerivedFromGenerator.csproj | 2 +- Rop.Generators.Shared/SyntaxHelper.cs | 20 ++++++++++++++++ Rop.Generators.sln | 7 +++--- Rop.ProxyGenerator/ProxyGenerator.cs | 4 ++-- Rop.ProxyGenerator/Rop.ProxyGenerator.csproj | 2 +- .../Rop.StaticExtensionGenerator.csproj | 2 +- .../StaticExtensionGenerator.cs | 10 ++++---- 11 files changed, 58 insertions(+), 24 deletions(-) diff --git a/Rop.DerivedFrom.Annotations/IDerivedFrom.cs b/Rop.DerivedFrom.Annotations/IDerivedFrom.cs index 1bd7dde..885f190 100644 --- a/Rop.DerivedFrom.Annotations/IDerivedFrom.cs +++ b/Rop.DerivedFrom.Annotations/IDerivedFrom.cs @@ -12,4 +12,7 @@ public interface IDerivedFrom public interface IFormDerivedFrom { } + public interface IFormFlat + { + } } diff --git a/Rop.DerivedFrom.Annotations/Rop.DerivedFrom.Annotations.csproj b/Rop.DerivedFrom.Annotations/Rop.DerivedFrom.Annotations.csproj index 40cca55..088fa13 100644 --- a/Rop.DerivedFrom.Annotations/Rop.DerivedFrom.Annotations.csproj +++ b/Rop.DerivedFrom.Annotations/Rop.DerivedFrom.Annotations.csproj @@ -7,7 +7,7 @@ helper-classes;winforms;annotations Annotations for DerivedFrom Generator true - 1.0.3 + 1.0.5 Ramon Ordiales Plaza Ramon Ordiales Plaza 2022 Ramon Ordiales diff --git a/Rop.DerivedFromGenerator/DerivedFromGenerator.cs b/Rop.DerivedFromGenerator/DerivedFromGenerator.cs index 7c1fa53..0a4d70b 100644 --- a/Rop.DerivedFromGenerator/DerivedFromGenerator.cs +++ b/Rop.DerivedFromGenerator/DerivedFromGenerator.cs @@ -27,6 +27,7 @@ public void Execute(GeneratorExecutionContext context) if (collector==null) return; var normal=collector.GetNormalClassesToAugment(); var forms=collector.GetFormClassesToAugment(); + var formscomplet=collector.GetFormClassesToAugmentComplet(); var namespacenormalflatten = ""; var namespaceformflatten = ""; if (normal.Count != 0) @@ -44,7 +45,7 @@ public void Execute(GeneratorExecutionContext context) generateCode(context, classtoaugment,namespacenormalflatten); } } - if (forms.Count != 0 && namespaceformflatten!="") + if (formscomplet.Count != 0 && namespaceformflatten!="") { foreach (var classtoaugment in collector.ClassesToAugment) { @@ -118,6 +119,10 @@ private string generateSpecialFlatten(GeneratorExecutionContext context, List GetNormalClassesToAugment() { - return ClassesToAugment.Where(c=>!c.IsFormDerivedFrom).ToList(); + return ClassesToAugment.Where(c=>c.DerivedType=="IDerivedFrom").ToList(); } public List GetFormClassesToAugment() { - return ClassesToAugment.Where(c => c.IsFormDerivedFrom).ToList(); + return ClassesToAugment.Where(c => c.DerivedType!="IDerivedFrom").ToList(); + } + + public List GetFormClassesToAugmentComplet() + { + return ClassesToAugment.Where(c => c.DerivedType!="IFormDerivedFrom").ToList(); } } } diff --git a/Rop.DerivedFromGenerator/ProxyPartialClassToAugment.cs b/Rop.DerivedFromGenerator/ProxyPartialClassToAugment.cs index 435967a..aee9926 100644 --- a/Rop.DerivedFromGenerator/ProxyPartialClassToAugment.cs +++ b/Rop.DerivedFromGenerator/ProxyPartialClassToAugment.cs @@ -8,12 +8,12 @@ public class ProxyPartialClassToAugment public PartialClassToAugment Original { get; } public TypeSyntax BaseToFlat { get; } public string FlatBaseName { get; } - public bool IsFormDerivedFrom { get; } - public ProxyPartialClassToAugment(PartialClassToAugment original, TypeSyntax baseToFlat, bool isFormDerivedFrom) + public string DerivedType { get; } + public ProxyPartialClassToAugment(PartialClassToAugment original, TypeSyntax baseToFlat, string derivedtype) { Original = original; BaseToFlat = baseToFlat; - IsFormDerivedFrom = isFormDerivedFrom; + DerivedType = derivedtype; FlatBaseName = new string(baseToFlat.ToString().Select(c => char.IsLetterOrDigit(c) ? c : '_').ToArray()); } } diff --git a/Rop.DerivedFromGenerator/Rop.DerivedFromGenerator.csproj b/Rop.DerivedFromGenerator/Rop.DerivedFromGenerator.csproj index 6162d9d..61b7e06 100644 --- a/Rop.DerivedFromGenerator/Rop.DerivedFromGenerator.csproj +++ b/Rop.DerivedFromGenerator/Rop.DerivedFromGenerator.csproj @@ -8,7 +8,7 @@ extensions;generics;winforms;source-generator;roslyn Source generator to derive form from generic true - 1.0.6 + 1.0.7 Ramon Ordiales Plaza Ramon Ordiales Plaza 2023 Ramon Ordiales diff --git a/Rop.Generators.Shared/SyntaxHelper.cs b/Rop.Generators.Shared/SyntaxHelper.cs index f119442..b625897 100644 --- a/Rop.Generators.Shared/SyntaxHelper.cs +++ b/Rop.Generators.Shared/SyntaxHelper.cs @@ -50,6 +50,26 @@ public static List GenericBasesOfType(this ClassDeclarationSy } return res; } + public static List GenericBasesOfAny(this ClassDeclarationSyntax cds,params string[] typename) + { + var res=new List(); + if (cds.BaseList is null) return res; + foreach (var type in cds.BaseList.Types) + { + if (type.Type is GenericNameSyntax gns) + { + var id=gns.Identifier.ToString(); + if (typename.Contains(id)) + { + res.Add(gns); + } + } + } + return res; + } + + + public static string ToStringValue(this ExpressionSyntax expression) { switch (expression) diff --git a/Rop.Generators.sln b/Rop.Generators.sln index 57b33b2..c7eaa2f 100644 --- a/Rop.Generators.sln +++ b/Rop.Generators.sln @@ -54,11 +54,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test.DerivedFrom.SubForms", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test.DerivedFrom.FormDerived", "Test\Test.DerivedFrom.FormDerived\Test.DerivedFrom.FormDerived.csproj", "{BECC3846-2D46-4586-84C4-7E1AE321A96C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rop.ObservableGenerator", "Rop.ObservableGenerator\Rop.ObservableGenerator.csproj", "{0D404D6A-D05F-4163-BD7B-4DAA7D85F81D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Rop.ObservableGenerator", "Rop.ObservableGenerator\Rop.ObservableGenerator.csproj", "{0D404D6A-D05F-4163-BD7B-4DAA7D85F81D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rop.ObservableGenerator.Annotations", "Rop.ObservableGenerator.Annotations\Rop.ObservableGenerator.Annotations.csproj", "{5EFA3272-F68D-41D3-93AE-BCAD2C41C7DB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Rop.ObservableGenerator.Annotations", "Rop.ObservableGenerator.Annotations\Rop.ObservableGenerator.Annotations.csproj", "{5EFA3272-F68D-41D3-93AE-BCAD2C41C7DB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test.ObservableGenerator", "Test\Test.ObservableGenerator\Test.ObservableGenerator.csproj", "{DFA586D4-8B90-4F2B-BED1-2263BB5DDCFA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test.ObservableGenerator", "Test\Test.ObservableGenerator\Test.ObservableGenerator.csproj", "{DFA586D4-8B90-4F2B-BED1-2263BB5DDCFA}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -186,6 +186,7 @@ Global Rop.Generators.Shared\Rop.Generators.Shared.projitems*{10ed2d2d-6d3d-4570-b78c-f61b52328596}*SharedItemsImports = 5 Rop.Generators.Shared\Rop.Generators.Shared.projitems*{568ee803-f01b-4f45-ba81-70642128a797}*SharedItemsImports = 5 Rop.Generators.Shared\Rop.Generators.Shared.projitems*{59cbdaf7-857a-47d6-ae57-0d069f5d925f}*SharedItemsImports = 5 + Rop.Generators.Shared\Rop.Generators.Shared.projitems*{5a2bdd1d-9a9b-42bf-b00c-4104ceb957f6}*SharedItemsImports = 5 Rop.Generators.Shared\Rop.Generators.Shared.projitems*{86231b22-cb3a-4de0-af41-c26710435cc9}*SharedItemsImports = 5 Rop.Generators.Shared\Rop.Generators.Shared.projitems*{8f79abde-e5ad-421d-be65-0042f27b104b}*SharedItemsImports = 5 Rop.Generators.Shared\Rop.Generators.Shared.projitems*{b6fa2a36-63eb-4074-b174-3e85b96e4265}*SharedItemsImports = 13 diff --git a/Rop.ProxyGenerator/ProxyGenerator.cs b/Rop.ProxyGenerator/ProxyGenerator.cs index 5197bc7..08163e7 100644 --- a/Rop.ProxyGenerator/ProxyGenerator.cs +++ b/Rop.ProxyGenerator/ProxyGenerator.cs @@ -194,10 +194,10 @@ void MethodBody(bool prebase,bool postbase, string pnames , string retstr) $"base.{name}({pnames});"); if (!postbase) sb.AppendLines(3, - $"{retstr}{field}.{name}({pnames});"); + $"{retstr}{field}?.{name}({pnames});"); else sb.AppendLines(3, - $"{field}.{name}({pnames});", + $"{field}?.{name}({pnames});", $"{retstr}base.{name}({pnames});"); } diff --git a/Rop.ProxyGenerator/Rop.ProxyGenerator.csproj b/Rop.ProxyGenerator/Rop.ProxyGenerator.csproj index 6d64d41..e20fba3 100644 --- a/Rop.ProxyGenerator/Rop.ProxyGenerator.csproj +++ b/Rop.ProxyGenerator/Rop.ProxyGenerator.csproj @@ -8,7 +8,7 @@ extensions;proxy;source-generator;roslyn Source generator to create ProxyClasses true - 1.0.27 + 1.0.28 Ramon Ordiales Plaza Ramon Ordiales Plaza 2022 Ramon Ordiales diff --git a/Rop.StaticExtensionGenerator/Rop.StaticExtensionGenerator.csproj b/Rop.StaticExtensionGenerator/Rop.StaticExtensionGenerator.csproj index b280dae..d57aaa9 100644 --- a/Rop.StaticExtensionGenerator/Rop.StaticExtensionGenerator.csproj +++ b/Rop.StaticExtensionGenerator/Rop.StaticExtensionGenerator.csproj @@ -9,7 +9,7 @@ extensions;generics;static;winforms;source-generator;roslyn Source generator to create static extensions true - 1.0.9 + 1.0.11 Ramon Ordiales Plaza Ramon Ordiales Plaza 2023 Ramon Ordiales diff --git a/Rop.StaticExtensionGenerator/StaticExtensionGenerator.cs b/Rop.StaticExtensionGenerator/StaticExtensionGenerator.cs index cd00f3a..cffac37 100644 --- a/Rop.StaticExtensionGenerator/StaticExtensionGenerator.cs +++ b/Rop.StaticExtensionGenerator/StaticExtensionGenerator.cs @@ -37,13 +37,12 @@ private void generateCode(GeneratorExecutionContext context, PartialClassToAugme var baseclase=classmodel.BaseType; if (baseclase is null||baseclase.Name=="Object") { - var iderived=classmodel.Interfaces.FirstOrDefault(i=>i.Name=="IDerived"); + var iderived=classmodel.Interfaces.FirstOrDefault(i=>i.Name=="IDerivedFrom" || i.Name=="IFormDerivedFrom"); if (iderived != null) { baseclase= iderived.TypeArguments[0] as INamedTypeSymbol; } } - var (staticMethods,path)=GetStaticMethods(baseclase,classmodel,model,receiver); var sb = new StringBuilder(); sb.AppendLine("// Autogenerated code for StaticMethods"); @@ -59,13 +58,16 @@ private void generateCode(GeneratorExecutionContext context, PartialClassToAugme sb.AppendLines(classtoaugment.GetHeader(new string []{})); foreach (var symbol in staticMethods) { - var name = symbol.Name; + var prename = symbol.Name; + var name = prename; + if (name.StartsWith("_")) name = name.Substring(1); + if (char.IsLower(name[0])) name = char.ToUpper(name[0]) + name.Substring(1); var returntype = symbol.ReturnType.ToString(); var par=symbol.Parameters; var pardef=string.Join(",",par.Select(p=>p.ToString())); var parnames =string.Join(",",par.Select(p => p.Name)); var clasebelongs=symbol.ContainingType; - sb.AppendLines($"\t\tpublic static {returntype} {name}({pardef})=>{clasebelongs.ToDisplayString()}.{name}<{formname}>({parnames});"); + sb.AppendLines($"\t\tpublic static {returntype} {name}({pardef})=>{clasebelongs.ToDisplayString()}.{prename}<{formname}>({parnames});"); } sb.AppendLines(classtoaugment.GetFooter()); var final = sb.ToString();