From b50532ba04b793449d96a3a6804fe8c410d0ebba Mon Sep 17 00:00:00 2001 From: Manuel de la Pena Date: Thu, 23 Jan 2025 12:44:29 -0500 Subject: [PATCH] [Rgen] Renamed CodeChanges to Binding to be more clear. (#22031) Initially the structure was name to make it simpler to understand that it was a code change/update that was detected by the roslyn incremental generator. Now that the structure is shared with the transformer, it makes more sense to rename it to 'Binding'. We have update all the helper classes too. --- .../BindingSourceGeneratorGenerator.cs | 40 ++++----- .../Context/BindingContext.cs | 4 +- ...nges.Generator.cs => Binding.Generator.cs} | 24 ++--- .../DataModel/{CodeChanges.cs => Binding.cs} | 2 +- ...Comparer.cs => BindingEqualityComparer.cs} | 6 +- .../Emitters/CategoryEmitter.cs | 2 +- .../Emitters/ClassEmitter.cs | 2 +- .../Emitters/EmitterFactory.cs | 2 +- .../Emitters/EnumEmitter.cs | 38 ++++---- .../Emitters/ICodeEmitter.cs | 2 +- .../Emitters/InterfaceEmitter.cs | 2 +- .../Emitters/TrampolineEmitter.cs | 2 +- .../Formatters/SmartEnumFormatter.cs | 4 +- .../DataModel/CodeChanges.Transformer.cs | 4 +- ...mparerTests.cs => BindingComparerTests.cs} | 88 +++++++++---------- ...sts.cs => BindingEqualityComparerTests.cs} | 60 ++++++------- .../{CodeChangesTests.cs => BindingTests.cs} | 8 +- ...deChangesTests.cs => ClassBindingTests.cs} | 60 ++++++------- .../EnumDeclarationCodeChangesTests.cs | 4 +- .../DataModel/InterfaceCodeChangesTests.cs | 34 +++---- .../Emitters/EmitterFactoryTests.cs | 4 +- .../Formatters/SmartEnumFormatterTests.cs | 2 +- 22 files changed, 197 insertions(+), 197 deletions(-) rename src/rgen/Microsoft.Macios.Generator/DataModel/{CodeChanges.Generator.cs => Binding.Generator.cs} (91%) rename src/rgen/Microsoft.Macios.Generator/DataModel/{CodeChanges.cs => Binding.cs} (99%) rename src/rgen/Microsoft.Macios.Generator/DataModel/{CodeChangesEqualityComparer.cs => BindingEqualityComparer.cs} (94%) rename tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/{CodeChangesComparerTests.cs => BindingComparerTests.cs} (97%) rename tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/{CodeChangesEqualityComparerTests.cs => BindingEqualityComparerTests.cs} (96%) rename tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/{CodeChangesTests.cs => BindingTests.cs} (95%) rename tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/{ClassCodeChangesTests.cs => ClassBindingTests.cs} (97%) diff --git a/src/rgen/Microsoft.Macios.Generator/BindingSourceGeneratorGenerator.cs b/src/rgen/Microsoft.Macios.Generator/BindingSourceGeneratorGenerator.cs index eb0d8fd6689..efb1beff755 100644 --- a/src/rgen/Microsoft.Macios.Generator/BindingSourceGeneratorGenerator.cs +++ b/src/rgen/Microsoft.Macios.Generator/BindingSourceGeneratorGenerator.cs @@ -24,7 +24,7 @@ namespace Microsoft.Macios.Generator; /// [Generator] public class BindingSourceGeneratorGenerator : IIncrementalGenerator { - static readonly CodeChangesEqualityComparer equalityComparer = new (); + static readonly BindingEqualityComparer equalityComparer = new (); /// public void Initialize (IncrementalGeneratorInitializationContext context) @@ -45,16 +45,16 @@ public void Initialize (IncrementalGeneratorInitializationContext context) static (ctx, _) => GetChangesForSourceGen (ctx)) .Where (tuple => tuple.BindingAttributeFound); - var codeChanges = provider - .Select (static (tuple, _) => tuple.Changes) + var bindings = provider + .Select (static (tuple, _) => tuple.Bindings) .WithComparer (equalityComparer); // ideally we could do a distinct, because each code change can return the same libs, this makes the library // generation more common than what we would like, but it is the smallest code generation. var libraryProvider = provider - .Select ((tuple, _) => (tuple.RootBindingContext, tuple.Changes.LibraryPaths)); + .Select ((tuple, _) => (tuple.RootBindingContext, tuple.Bindings.LibraryPaths)); - context.RegisterSourceOutput (context.CompilationProvider.Combine (codeChanges.Collect ()), + context.RegisterSourceOutput (context.CompilationProvider.Combine (bindings.Collect ()), ((ctx, t) => GenerateCode (ctx, t.Right))); context.RegisterSourceOutput (context.CompilationProvider.Combine (libraryProvider.Collect ()), @@ -71,7 +71,7 @@ public void Initialize (IncrementalGeneratorInitializationContext context) _ => false, }; - static (RootBindingContext RootBindingContext, CodeChanges Changes, bool BindingAttributeFound) GetChangesForSourceGen (GeneratorSyntaxContext context) + static (RootBindingContext RootBindingContext, Binding Bindings, bool BindingAttributeFound) GetChangesForSourceGen (GeneratorSyntaxContext context) { var bindingContext = new RootBindingContext (context.SemanticModel); // we do know that the context node has to be one of the base type declarations @@ -85,14 +85,14 @@ public void Initialize (IncrementalGeneratorInitializationContext context) return (bindingContext, default, false); } - var codeChanges = CodeChanges.FromDeclaration (declarationSyntax, bindingContext); + var binding = Binding.FromDeclaration (declarationSyntax, bindingContext); // if code changes are null, return the default value and a false to later ignore the change - return codeChanges is not null - ? (bindingContext, codeChanges.Value, isBindingType) + return binding is not null + ? (bindingContext, binding.Value, isBindingType) : (bindingContext, default, false); } - static void GenerateCode (SourceProductionContext context, in ImmutableArray changesList) + static void GenerateCode (SourceProductionContext context, in ImmutableArray bindingsList) { // The process is as follows, get all the changes we have received from the incremental generator, // loop over them, and based on the CodeChange.BindingType we are going to build the symbol context @@ -101,20 +101,20 @@ static void GenerateCode (SourceProductionContext context, in ImmutableArray - /// The code changes for a given named type. + /// The code changes for a given named type. /// String builder that will be used for the generated code. /// The emitter that will generate the code. Provides any extra needed namespace. - static void CollectUsingStatements (in CodeChanges codeChanges, TabbedStringBuilder sb, ICodeEmitter emitter) + static void CollectUsingStatements (in Binding binding, TabbedStringBuilder sb, ICodeEmitter emitter) { // collect all using from the syntax tree, add them to a hash to make sure that we don't have duplicates // and add those usings that we do know we need for bindings. - var usingDirectivesToKeep = new SortedSet (codeChanges.UsingDirectives) { + var usingDirectivesToKeep = new SortedSet (binding.UsingDirectives) { // add the using statements that we know we need and print them to the sb }; diff --git a/src/rgen/Microsoft.Macios.Generator/Context/BindingContext.cs b/src/rgen/Microsoft.Macios.Generator/Context/BindingContext.cs index 5b5c03c1e37..b4cf93c8620 100644 --- a/src/rgen/Microsoft.Macios.Generator/Context/BindingContext.cs +++ b/src/rgen/Microsoft.Macios.Generator/Context/BindingContext.cs @@ -14,9 +14,9 @@ readonly struct BindingContext { /// /// Current code changes for the binding context. /// - public CodeChanges Changes { get; } + public Binding Changes { get; } - public BindingContext (TabbedStringBuilder builder, CodeChanges changes) + public BindingContext (TabbedStringBuilder builder, Binding changes) { Builder = builder; Changes = changes; diff --git a/src/rgen/Microsoft.Macios.Generator/DataModel/CodeChanges.Generator.cs b/src/rgen/Microsoft.Macios.Generator/DataModel/Binding.Generator.cs similarity index 91% rename from src/rgen/Microsoft.Macios.Generator/DataModel/CodeChanges.Generator.cs rename to src/rgen/Microsoft.Macios.Generator/DataModel/Binding.Generator.cs index 7f63af7a425..81923a8a6b1 100644 --- a/src/rgen/Microsoft.Macios.Generator/DataModel/CodeChanges.Generator.cs +++ b/src/rgen/Microsoft.Macios.Generator/DataModel/Binding.Generator.cs @@ -14,7 +14,7 @@ namespace Microsoft.Macios.Generator.DataModel; -readonly partial struct CodeChanges { +readonly partial struct Binding { /// /// Represents the type of binding that the code changes are for. @@ -146,7 +146,7 @@ static void GetMembers (TypeDeclarationSyntax baseDeclarationSyntax, Root /// The namespace that contains the named type. /// The fully qualified name of the symbol. /// The platform availability of the named symbol. - internal CodeChanges (BindingInfo bindingInfo, string name, ImmutableArray @namespace, + internal Binding (BindingInfo bindingInfo, string name, ImmutableArray @namespace, string fullyQualifiedSymbol, SymbolAvailability symbolAvailability) { this.bindingInfo = bindingInfo; @@ -157,11 +157,11 @@ internal CodeChanges (BindingInfo bindingInfo, string name, ImmutableArray - /// Creates a new instance of the struct for a given enum declaration. + /// Creates a new instance of the struct for a given enum declaration. /// /// The enum declaration that triggered the change. /// The root binding context of the current compilation. - CodeChanges (EnumDeclarationSyntax enumDeclaration, RootBindingContext context) + Binding (EnumDeclarationSyntax enumDeclaration, RootBindingContext context) { context.SemanticModel.GetSymbolData ( declaration: enumDeclaration, @@ -207,11 +207,11 @@ internal CodeChanges (BindingInfo bindingInfo, string name, ImmutableArray - /// Creates a new instance of the struct for a given class declaration. + /// Creates a new instance of the struct for a given class declaration. /// /// The class declaration that triggered the change. /// The root binding context of the current compilation. - CodeChanges (ClassDeclarationSyntax classDeclaration, RootBindingContext context) + Binding (ClassDeclarationSyntax classDeclaration, RootBindingContext context) { context.SemanticModel.GetSymbolData ( declaration: classDeclaration, @@ -239,11 +239,11 @@ internal CodeChanges (BindingInfo bindingInfo, string name, ImmutableArray - /// Creates a new instance of the struct for a given interface declaration. + /// Creates a new instance of the struct for a given interface declaration. /// /// The interface declaration that triggered the change. /// The root binding context of the current compilation. - CodeChanges (InterfaceDeclarationSyntax interfaceDeclaration, RootBindingContext context) + Binding (InterfaceDeclarationSyntax interfaceDeclaration, RootBindingContext context) { context.SemanticModel.GetSymbolData ( declaration: interfaceDeclaration, @@ -275,13 +275,13 @@ internal CodeChanges (BindingInfo bindingInfo, string name, ImmutableArrayThe declaration syntax whose change we want to calculate. /// The root binding context of the current compilation. /// A code change or null if it could not be calculated. - public static CodeChanges? FromDeclaration (BaseTypeDeclarationSyntax baseTypeDeclarationSyntax, + public static Binding? FromDeclaration (BaseTypeDeclarationSyntax baseTypeDeclarationSyntax, RootBindingContext context) => baseTypeDeclarationSyntax switch { - EnumDeclarationSyntax enumDeclarationSyntax => new CodeChanges (enumDeclarationSyntax, context), - InterfaceDeclarationSyntax interfaceDeclarationSyntax => new CodeChanges (interfaceDeclarationSyntax, + EnumDeclarationSyntax enumDeclarationSyntax => new Binding (enumDeclarationSyntax, context), + InterfaceDeclarationSyntax interfaceDeclarationSyntax => new Binding (interfaceDeclarationSyntax, context), - ClassDeclarationSyntax classDeclarationSyntax => new CodeChanges (classDeclarationSyntax, context), + ClassDeclarationSyntax classDeclarationSyntax => new Binding (classDeclarationSyntax, context), _ => null }; } diff --git a/src/rgen/Microsoft.Macios.Generator/DataModel/CodeChanges.cs b/src/rgen/Microsoft.Macios.Generator/DataModel/Binding.cs similarity index 99% rename from src/rgen/Microsoft.Macios.Generator/DataModel/CodeChanges.cs rename to src/rgen/Microsoft.Macios.Generator/DataModel/Binding.cs index a2e827c22db..a9004343b22 100644 --- a/src/rgen/Microsoft.Macios.Generator/DataModel/CodeChanges.cs +++ b/src/rgen/Microsoft.Macios.Generator/DataModel/Binding.cs @@ -16,7 +16,7 @@ namespace Microsoft.Macios.Generator.DataModel; /// generated code. /// [StructLayout (LayoutKind.Auto)] -readonly partial struct CodeChanges { +readonly partial struct Binding { readonly string name = string.Empty; /// diff --git a/src/rgen/Microsoft.Macios.Generator/DataModel/CodeChangesEqualityComparer.cs b/src/rgen/Microsoft.Macios.Generator/DataModel/BindingEqualityComparer.cs similarity index 94% rename from src/rgen/Microsoft.Macios.Generator/DataModel/CodeChangesEqualityComparer.cs rename to src/rgen/Microsoft.Macios.Generator/DataModel/BindingEqualityComparer.cs index 8231c2c2436..7e2cd6522c4 100644 --- a/src/rgen/Microsoft.Macios.Generator/DataModel/CodeChangesEqualityComparer.cs +++ b/src/rgen/Microsoft.Macios.Generator/DataModel/BindingEqualityComparer.cs @@ -8,9 +8,9 @@ namespace Microsoft.Macios.Generator.DataModel; /// /// Custom code changes comparer used for the Roslyn code generation to invalidate caching. /// -class CodeChangesEqualityComparer : EqualityComparer { +class BindingEqualityComparer : EqualityComparer { /// - public override bool Equals (CodeChanges x, CodeChanges y) + public override bool Equals (Binding x, Binding y) { // order does not matter in the using directives, use a comparer that sorts them @@ -82,7 +82,7 @@ public override bool Equals (CodeChanges x, CodeChanges y) } /// - public override int GetHashCode (CodeChanges obj) + public override int GetHashCode (Binding obj) { return HashCode.Combine (obj.FullyQualifiedSymbol, obj.EnumMembers); } diff --git a/src/rgen/Microsoft.Macios.Generator/Emitters/CategoryEmitter.cs b/src/rgen/Microsoft.Macios.Generator/Emitters/CategoryEmitter.cs index 062ffb94446..d26f286a65c 100644 --- a/src/rgen/Microsoft.Macios.Generator/Emitters/CategoryEmitter.cs +++ b/src/rgen/Microsoft.Macios.Generator/Emitters/CategoryEmitter.cs @@ -10,7 +10,7 @@ namespace Microsoft.Macios.Generator.Emitters; class CategoryEmitter : ICodeEmitter { - public string GetSymbolName (in CodeChanges codeChanges) => string.Empty; + public string GetSymbolName (in Binding binding) => string.Empty; public IEnumerable UsingStatements => []; public bool TryEmit (in BindingContext bindingContext, [NotNullWhen (false)] out ImmutableArray? diagnostics) { diff --git a/src/rgen/Microsoft.Macios.Generator/Emitters/ClassEmitter.cs b/src/rgen/Microsoft.Macios.Generator/Emitters/ClassEmitter.cs index 4c84cf421a1..272c125c3c4 100644 --- a/src/rgen/Microsoft.Macios.Generator/Emitters/ClassEmitter.cs +++ b/src/rgen/Microsoft.Macios.Generator/Emitters/ClassEmitter.cs @@ -17,7 +17,7 @@ namespace Microsoft.Macios.Generator.Emitters; class ClassEmitter : ICodeEmitter { - public string GetSymbolName (in CodeChanges codeChanges) => codeChanges.Name; + public string GetSymbolName (in Binding binding) => binding.Name; public IEnumerable UsingStatements => [ "System", diff --git a/src/rgen/Microsoft.Macios.Generator/Emitters/EmitterFactory.cs b/src/rgen/Microsoft.Macios.Generator/Emitters/EmitterFactory.cs index b0c0e516f46..b1332aeb8b8 100644 --- a/src/rgen/Microsoft.Macios.Generator/Emitters/EmitterFactory.cs +++ b/src/rgen/Microsoft.Macios.Generator/Emitters/EmitterFactory.cs @@ -17,6 +17,6 @@ static class EmitterFactory { { BindingType.Protocol, new InterfaceEmitter () }, { BindingType.Category, new CategoryEmitter () }, }; - public static bool TryCreate (CodeChanges changes, [NotNullWhen (true)] out ICodeEmitter? emitter) + public static bool TryCreate (Binding changes, [NotNullWhen (true)] out ICodeEmitter? emitter) => emitters.TryGetValue (changes.BindingType, out emitter); } diff --git a/src/rgen/Microsoft.Macios.Generator/Emitters/EnumEmitter.cs b/src/rgen/Microsoft.Macios.Generator/Emitters/EnumEmitter.cs index b653c3222b7..64733bd7137 100644 --- a/src/rgen/Microsoft.Macios.Generator/Emitters/EnumEmitter.cs +++ b/src/rgen/Microsoft.Macios.Generator/Emitters/EnumEmitter.cs @@ -12,12 +12,12 @@ namespace Microsoft.Macios.Generator.Emitters; class EnumEmitter : ICodeEmitter { - public string GetSymbolName (in CodeChanges codeChanges) => $"{codeChanges.Name}Extensions"; + public string GetSymbolName (in Binding binding) => $"{binding.Name}Extensions"; public IEnumerable UsingStatements => ["Foundation", "ObjCRuntime", "System"]; - void EmitEnumFieldAtIndex (TabbedStringBuilder classBlock, in CodeChanges codeChanges, int index) + void EmitEnumFieldAtIndex (TabbedStringBuilder classBlock, in Binding binding, int index) { - var enumField = codeChanges.EnumMembers [index]; + var enumField = binding.EnumMembers [index]; if (enumField.FieldInfo is null) return; @@ -33,36 +33,36 @@ void EmitEnumFieldAtIndex (TabbedStringBuilder classBlock, in CodeChanges codeCh } } - bool TryEmit (TabbedStringBuilder classBlock, in CodeChanges codeChanges) + bool TryEmit (TabbedStringBuilder classBlock, in Binding binding) { // keep track of the field symbols, they have to be unique, if we find a duplicate we return false and // abort the code generation var backingFields = new HashSet (); - for (var index = 0; index < codeChanges.EnumMembers.Length; index++) { - if (codeChanges.EnumMembers [index].FieldInfo is null) + for (var index = 0; index < binding.EnumMembers.Length; index++) { + if (binding.EnumMembers [index].FieldInfo is null) continue; - if (!backingFields.Add (codeChanges.EnumMembers [index].FieldInfo!.Value.FieldData.SymbolName)) { + if (!backingFields.Add (binding.EnumMembers [index].FieldInfo!.Value.FieldData.SymbolName)) { return false; } classBlock.AppendLine (); - EmitEnumFieldAtIndex (classBlock, codeChanges, index); + EmitEnumFieldAtIndex (classBlock, binding, index); } return true; } - void EmitExtensionMethods (TabbedStringBuilder classBlock, in CodeChanges codeChanges) + void EmitExtensionMethods (TabbedStringBuilder classBlock, in Binding binding) { - if (codeChanges.EnumMembers.Length == 0) + if (binding.EnumMembers.Length == 0) return; // smart enum require 4 diff methods to be able to retrieve the values // Get constant - using (var getConstantBlock = classBlock.CreateBlock ($"public static NSString? GetConstant (this {codeChanges.Name} self)", true)) { + using (var getConstantBlock = classBlock.CreateBlock ($"public static NSString? GetConstant (this {binding.Name} self)", true)) { getConstantBlock.AppendLine ("IntPtr ptr = IntPtr.Zero;"); using (var switchBlock = getConstantBlock.CreateBlock ("switch ((int) self)", true)) { - for (var index = 0; index < codeChanges.EnumMembers.Length; index++) { - var enumMember = codeChanges.EnumMembers [index]; + for (var index = 0; index < binding.EnumMembers.Length; index++) { + var enumMember = binding.EnumMembers [index]; if (enumMember.FieldInfo is null) continue; var (fieldData, _, _) = enumMember.FieldInfo.Value; @@ -77,15 +77,15 @@ void EmitExtensionMethods (TabbedStringBuilder classBlock, in CodeChanges codeCh classBlock.AppendLine (); // Get value - using (var getValueBlock = classBlock.CreateBlock ($"public static {codeChanges.Name} GetValue (NSString constant)", true)) { + using (var getValueBlock = classBlock.CreateBlock ($"public static {binding.Name} GetValue (NSString constant)", true)) { getValueBlock.AppendLine ("if (constant is null)"); getValueBlock.AppendLine ("\tthrow new ArgumentNullException (nameof (constant));"); - foreach (var enumMember in codeChanges.EnumMembers) { + foreach (var enumMember in binding.EnumMembers) { if (enumMember.FieldInfo is null) continue; var (fieldData, _, _) = enumMember.FieldInfo.Value; getValueBlock.AppendLine ($"if (constant.IsEqualTo ({fieldData.SymbolName}))"); - getValueBlock.AppendLine ($"\treturn {codeChanges.Name}.{enumMember.Name};"); + getValueBlock.AppendLine ($"\treturn {binding.Name}.{enumMember.Name};"); } getValueBlock.AppendLine ( @@ -95,7 +95,7 @@ void EmitExtensionMethods (TabbedStringBuilder classBlock, in CodeChanges codeCh classBlock.AppendLine (); // To ConstantArray classBlock.AppendRaw ( -@$"internal static NSString?[]? ToConstantArray (this {codeChanges.Name}[]? values) +@$"internal static NSString?[]? ToConstantArray (this {binding.Name}[]? values) {{ if (values is null) return null; @@ -110,11 +110,11 @@ void EmitExtensionMethods (TabbedStringBuilder classBlock, in CodeChanges codeCh classBlock.AppendLine (); // ToEnumArray classBlock.AppendRaw ( -@$"internal static {codeChanges.Name}[]? ToEnumArray (this NSString[]? values) +@$"internal static {binding.Name}[]? ToEnumArray (this NSString[]? values) {{ if (values is null) return null; - var rv = new global::System.Collections.Generic.List<{codeChanges.Name}> (); + var rv = new global::System.Collections.Generic.List<{binding.Name}> (); for (var i = 0; i < values.Length; i++) {{ var value = values [i]; rv.Add (GetValue (value)); diff --git a/src/rgen/Microsoft.Macios.Generator/Emitters/ICodeEmitter.cs b/src/rgen/Microsoft.Macios.Generator/Emitters/ICodeEmitter.cs index c389ab7ce75..4392f461def 100644 --- a/src/rgen/Microsoft.Macios.Generator/Emitters/ICodeEmitter.cs +++ b/src/rgen/Microsoft.Macios.Generator/Emitters/ICodeEmitter.cs @@ -13,7 +13,7 @@ namespace Microsoft.Macios.Generator.Emitters; /// Interface to be implemented by all those classes that know how to emit code for a binding. /// interface ICodeEmitter { - string GetSymbolName (in CodeChanges codeChanges); + string GetSymbolName (in Binding binding); bool TryEmit (in BindingContext bindingContext, [NotNullWhen (false)] out ImmutableArray? diagnostics); IEnumerable UsingStatements { get; } } diff --git a/src/rgen/Microsoft.Macios.Generator/Emitters/InterfaceEmitter.cs b/src/rgen/Microsoft.Macios.Generator/Emitters/InterfaceEmitter.cs index 2d20cd8107e..416ec8a1da6 100644 --- a/src/rgen/Microsoft.Macios.Generator/Emitters/InterfaceEmitter.cs +++ b/src/rgen/Microsoft.Macios.Generator/Emitters/InterfaceEmitter.cs @@ -10,7 +10,7 @@ namespace Microsoft.Macios.Generator.Emitters; class InterfaceEmitter : ICodeEmitter { - public string GetSymbolName (in CodeChanges codeChanges) => string.Empty; + public string GetSymbolName (in Binding binding) => string.Empty; public IEnumerable UsingStatements => []; public bool TryEmit (in BindingContext bindingContext, [NotNullWhen (false)] out ImmutableArray? diagnostics) { diff --git a/src/rgen/Microsoft.Macios.Generator/Emitters/TrampolineEmitter.cs b/src/rgen/Microsoft.Macios.Generator/Emitters/TrampolineEmitter.cs index d6c056a733f..f9b114f338a 100644 --- a/src/rgen/Microsoft.Macios.Generator/Emitters/TrampolineEmitter.cs +++ b/src/rgen/Microsoft.Macios.Generator/Emitters/TrampolineEmitter.cs @@ -11,7 +11,7 @@ namespace Microsoft.Macios.Generator.Emitters; class TrampolineEmitter : ICodeEmitter { public string SymbolNamespace => string.Empty; - public string GetSymbolName (in CodeChanges codeChanges) => string.Empty; + public string GetSymbolName (in Binding binding) => string.Empty; public IEnumerable UsingStatements { get; } = []; public bool TryEmit (in BindingContext bindingContext, [NotNullWhen (false)] out ImmutableArray? diagnostics) { diff --git a/src/rgen/Microsoft.Macios.Generator/Formatters/SmartEnumFormatter.cs b/src/rgen/Microsoft.Macios.Generator/Formatters/SmartEnumFormatter.cs index 43ea585f060..e34102170cd 100644 --- a/src/rgen/Microsoft.Macios.Generator/Formatters/SmartEnumFormatter.cs +++ b/src/rgen/Microsoft.Macios.Generator/Formatters/SmartEnumFormatter.cs @@ -16,7 +16,7 @@ static class SmartEnumFormatter { /// The smart enum code change. /// The name to use for the extension class. /// The class declaration for the extension class for a smart enum change. - public static CompilationUnitSyntax ToSmartEnumExtensionDeclaration (this in CodeChanges smartEnumChange, + public static CompilationUnitSyntax ToSmartEnumExtensionDeclaration (this in Binding smartEnumChange, string extensionClassName) { // add to a set to make sure we do no duplicate them and make sure static and partial are present @@ -40,7 +40,7 @@ public static CompilationUnitSyntax ToSmartEnumExtensionDeclaration (this in Cod /// The smart enum code change. /// The name to use for the extension class. /// The class declaration for the extension class for a smart enum change. - public static CompilationUnitSyntax? ToSmartEnumExtensionDeclaration (this in CodeChanges? smartEnumChange, + public static CompilationUnitSyntax? ToSmartEnumExtensionDeclaration (this in Binding? smartEnumChange, string extensionClassName) => smartEnumChange is null ? null : ToSmartEnumExtensionDeclaration (smartEnumChange.Value, extensionClassName); } diff --git a/src/rgen/Microsoft.Macios.Transformer/DataModel/CodeChanges.Transformer.cs b/src/rgen/Microsoft.Macios.Transformer/DataModel/CodeChanges.Transformer.cs index 703f48f9eb4..612c83bf81c 100644 --- a/src/rgen/Microsoft.Macios.Transformer/DataModel/CodeChanges.Transformer.cs +++ b/src/rgen/Microsoft.Macios.Transformer/DataModel/CodeChanges.Transformer.cs @@ -3,7 +3,7 @@ namespace Microsoft.Macios.Generator.DataModel; -readonly partial struct CodeChanges { +readonly partial struct Binding { /// /// Represents the type of binding that the code changes are for. @@ -12,7 +12,7 @@ readonly partial struct CodeChanges { public BindingInfo BindingInfo => throw new NotImplementedException (); - public CodeChanges () + public Binding () { FullyQualifiedSymbol = ""; IsStatic = false; diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/CodeChangesComparerTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/BindingComparerTests.cs similarity index 97% rename from tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/CodeChangesComparerTests.cs rename to tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/BindingComparerTests.cs index 31064acbf94..9a87bfd4693 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/CodeChangesComparerTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/BindingComparerTests.cs @@ -9,19 +9,19 @@ namespace Microsoft.Macios.Generator.Tests.DataModel; -public class CodeChangesComparerTests : BaseGeneratorTestClass { - readonly CodeChangesEqualityComparer comparer = new (); +public class BindingComparerTests : BaseGeneratorTestClass { + readonly BindingEqualityComparer comparer = new (); [Fact] public void CompareDifferentFullyQualifiedSymbol () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name1", @namespace: ["NS"], fullyQualifiedSymbol: "NS.name1", symbolAvailability: new ()); - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name1", @namespace: ["NS"], @@ -33,7 +33,7 @@ public void CompareDifferentFullyQualifiedSymbol () [Fact] public void CompareDifferentBase () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name1", @namespace: ["NS"], @@ -41,7 +41,7 @@ public void CompareDifferentBase () symbolAvailability: new ()) { Base = "Base1" }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name1", @namespace: ["NS"], @@ -55,7 +55,7 @@ public void CompareDifferentBase () [Fact] public void CompareDifferentInterface () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name1", @namespace: ["NS"], @@ -63,7 +63,7 @@ public void CompareDifferentInterface () symbolAvailability: new ()) { Interfaces = ["IBase1"] }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name1", @namespace: ["NS"], @@ -77,13 +77,13 @@ public void CompareDifferentInterface () [Fact] public void CompareDifferentNameSymbol () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name1", @namespace: ["NS"], fullyQualifiedSymbol: "NS.name1", symbolAvailability: new ()); - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name2", @namespace: ["NS"], @@ -95,13 +95,13 @@ public void CompareDifferentNameSymbol () [Fact] public void CompareDifferentNamespaceSymbol () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name1", @namespace: ["NS1"], fullyQualifiedSymbol: "NS.name1", symbolAvailability: new ()); - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name1", @namespace: ["NS2"], @@ -113,13 +113,13 @@ public void CompareDifferentNamespaceSymbol () [Fact] public void CompareDifferentBindingType () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], fullyQualifiedSymbol: "NS.name", symbolAvailability: new ()); - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], @@ -131,13 +131,13 @@ public void CompareDifferentBindingType () [Fact] public void CompareDifferentAttributesLength () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], fullyQualifiedSymbol: "NS.name", symbolAvailability: new ()); - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -153,7 +153,7 @@ public void CompareDifferentAttributesLength () [Fact] public void CompareDifferentAttributes () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -163,7 +163,7 @@ public void CompareDifferentAttributes () new AttributeCodeChange (name: "name", arguments: ["arg1", "arg2"]) ], }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -179,13 +179,13 @@ public void CompareDifferentAttributes () [Fact] public void CompareDifferentMembersLength () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], fullyQualifiedSymbol: "NS.name", symbolAvailability: new ()); - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -207,7 +207,7 @@ public void CompareDifferentMembersLength () [Fact] public void CompareDifferentMembers () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -223,7 +223,7 @@ public void CompareDifferentMembers () attributes: []) ], }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -245,7 +245,7 @@ public void CompareDifferentMembers () [Fact] public void CompareDifferentPropertyLength () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -254,7 +254,7 @@ public void CompareDifferentPropertyLength () EnumMembers = [], Properties = [] }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -301,7 +301,7 @@ public void CompareDifferentPropertyLength () [Fact] public void CompareSamePropertiesDiffOrder () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], fullyQualifiedSymbol: "NS.name", symbolAvailability: new ()) { @@ -367,7 +367,7 @@ public void CompareSamePropertiesDiffOrder () ]), ] }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -441,7 +441,7 @@ public void CompareSamePropertiesDiffOrder () [Fact] public void CompareDifferentProperties () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -509,7 +509,7 @@ public void CompareDifferentProperties () ]), ] }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -582,7 +582,7 @@ public void CompareDifferentProperties () [Fact] public void CompareDifferentEventsLength () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -666,7 +666,7 @@ public void CompareDifferentEventsLength () ]), ] }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -740,7 +740,7 @@ public void CompareDifferentEventsLength () [Fact] public void CompareSameEventsDiffOrder () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -846,7 +846,7 @@ public void CompareSameEventsDiffOrder () ]), ] }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -960,7 +960,7 @@ public void CompareSameEventsDiffOrder () [Fact] public void CompareDifferentEvents () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -1044,7 +1044,7 @@ public void CompareDifferentEvents () ]), ] }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -1137,7 +1137,7 @@ public void CompareDifferentEvents () [Fact] public void CompareDifferentMethodsLength () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -1283,7 +1283,7 @@ public void CompareDifferentMethodsLength () ) ] }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -1420,7 +1420,7 @@ public void CompareDifferentMethodsLength () [Fact] public void CompareSameMethodsDiffOrder () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -1566,7 +1566,7 @@ public void CompareSameMethodsDiffOrder () ) ] }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -1719,7 +1719,7 @@ public void CompareSameMethodsDiffOrder () [Fact] public void CompareDifferentMethods () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -1842,7 +1842,7 @@ public void CompareDifferentMethods () ), ] }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -1984,7 +1984,7 @@ public void CompareSameMethodsDiffAvailability () var builder = SymbolAvailability.CreateBuilder (); builder.Add (new SupportedOSPlatformData ("ios")); builder.Add (new SupportedOSPlatformData ("tvos")); - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -2130,7 +2130,7 @@ public void CompareSameMethodsDiffAvailability () ) ] }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -2278,7 +2278,7 @@ public void CompareSameMethodsSameAvailability () var builder = SymbolAvailability.CreateBuilder (); builder.Add (new SupportedOSPlatformData ("ios")); builder.Add (new SupportedOSPlatformData ("tvos")); - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], @@ -2424,7 +2424,7 @@ public void CompareSameMethodsSameAvailability () ) ] }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/CodeChangesEqualityComparerTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/BindingEqualityComparerTests.cs similarity index 96% rename from tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/CodeChangesEqualityComparerTests.cs rename to tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/BindingEqualityComparerTests.cs index f42934b26bc..27d768a901d 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/CodeChangesEqualityComparerTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/BindingEqualityComparerTests.cs @@ -7,19 +7,19 @@ namespace Microsoft.Macios.Generator.Tests.DataModel; -public class CodeChangesEqualityComparerTests : BaseGeneratorTestClass { - readonly CodeChangesEqualityComparer equalityComparer = new (); +public class BindingEqualityComparerTests : BaseGeneratorTestClass { + readonly BindingEqualityComparer equalityComparer = new (); [Fact] public void CompareDifferentFullyQualifiedSymbol () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name1", @namespace: ["NS"], fullyQualifiedSymbol: "NS.name1", symbolAvailability: new ()); - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name2", @namespace: ["NS"], @@ -31,13 +31,13 @@ public void CompareDifferentFullyQualifiedSymbol () [Fact] public void CompareDifferentBindingType () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.SmartEnum, new ()), name: "name", @namespace: ["NS"], fullyQualifiedSymbol: "NS.name", symbolAvailability: new ()); - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], @@ -49,13 +49,13 @@ public void CompareDifferentBindingType () [Fact] public void CompareDifferentAttributesLength () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], fullyQualifiedSymbol: "NS.name", symbolAvailability: new ()); - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], @@ -71,7 +71,7 @@ public void CompareDifferentAttributesLength () [Fact] public void CompareDifferentAttributes () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], @@ -81,7 +81,7 @@ public void CompareDifferentAttributes () new AttributeCodeChange (name: "name", arguments: ["arg1", "arg2"]) ], }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], @@ -97,13 +97,13 @@ public void CompareDifferentAttributes () [Fact] public void CompareDifferentMembersLength () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], fullyQualifiedSymbol: "NS.name", symbolAvailability: new ()); - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], @@ -125,7 +125,7 @@ public void CompareDifferentMembersLength () [Fact] public void CompareDifferentMembers () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], @@ -141,7 +141,7 @@ public void CompareDifferentMembers () attributes: []) ], }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], @@ -163,7 +163,7 @@ public void CompareDifferentMembers () [Fact] public void CompareDifferentPropertyLength () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], @@ -172,7 +172,7 @@ public void CompareDifferentPropertyLength () EnumMembers = [], Properties = [] }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], @@ -219,7 +219,7 @@ public void CompareDifferentPropertyLength () [Fact] public void CompareSamePropertiesDiffOrder () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], @@ -287,7 +287,7 @@ public void CompareSamePropertiesDiffOrder () ]), ] }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], @@ -361,7 +361,7 @@ public void CompareSamePropertiesDiffOrder () [Fact] public void CompareDifferentProperties () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], @@ -429,7 +429,7 @@ public void CompareDifferentProperties () ]), ] }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], @@ -503,7 +503,7 @@ public void CompareDifferentProperties () [Fact] public void CompareDifferentConstructorLength () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], @@ -572,7 +572,7 @@ public void CompareDifferentConstructorLength () ], Constructors = [], }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], @@ -649,7 +649,7 @@ public void CompareDifferentConstructorLength () [Fact] public void CompareDifferentConstructors () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], @@ -720,7 +720,7 @@ public void CompareDifferentConstructors () new (type: "MyClass", symbolAvailability: new (), attributes: [], modifiers: [], parameters: []) ], }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], @@ -803,7 +803,7 @@ public void CompareDifferentConstructors () [Fact] public void CompareSameConstructors () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], @@ -881,7 +881,7 @@ public void CompareSameConstructors () ]) ], }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], @@ -965,7 +965,7 @@ public void CompareSameConstructors () [Fact] public void CompareSameConstructorsDiffOrder () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], @@ -1043,7 +1043,7 @@ public void CompareSameConstructorsDiffOrder () new (type: "MyClass", symbolAvailability: new (), attributes: [], modifiers: [], parameters: []), ], }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], @@ -1126,7 +1126,7 @@ public void CompareSameConstructorsDiffOrder () [Fact] public void CompareSameDiffModifiers () { - var changes1 = new CodeChanges ( + var changes1 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], @@ -1208,7 +1208,7 @@ public void CompareSameDiffModifiers () new (type: "MyClass", symbolAvailability: new (), attributes: [], modifiers: [], parameters: []), ], }; - var changes2 = new CodeChanges ( + var changes2 = new Binding ( bindingInfo: new (BindingType.Protocol, new ()), name: "name", @namespace: ["NS"], diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/CodeChangesTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/BindingTests.cs similarity index 95% rename from tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/CodeChangesTests.cs rename to tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/BindingTests.cs index 2542637ee4a..74cd09880ac 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/CodeChangesTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/BindingTests.cs @@ -11,7 +11,7 @@ namespace Microsoft.Macios.Generator.Tests.DataModel; -public class CodeChangesTests : BaseGeneratorTestClass { +public class BindingTests : BaseGeneratorTestClass { class TestDataSkipEnumValueDeclaration : IEnumerable { public IEnumerator GetEnumerator () { @@ -74,7 +74,7 @@ public void SkipEnumValueDeclaration (ApplePlatform platform, string inputText, .FirstOrDefault (); Assert.NotNull (node); var semanticModel = compilation.GetSemanticModel (sourceTrees [0]); - Assert.Equal (expected, CodeChanges.Skip (node, semanticModel)); + Assert.Equal (expected, Binding.Skip (node, semanticModel)); } @@ -183,7 +183,7 @@ public void SkipPropertyDeclaration (ApplePlatform platform, string inputText, b .FirstOrDefault (); Assert.NotNull (node); var semanticModel = compilation.GetSemanticModel (sourceTrees [0]); - Assert.Equal (expected, CodeChanges.Skip (node, semanticModel)); + Assert.Equal (expected, Binding.Skip (node, semanticModel)); } class TestDataSkipMethodDeclaration : IEnumerable { @@ -249,6 +249,6 @@ public void SkipMethodDeclaration (ApplePlatform platform, string inputText, boo .FirstOrDefault (); Assert.NotNull (node); var semanticModel = compilation.GetSemanticModel (sourceTrees [0]); - Assert.Equal (expected, CodeChanges.Skip (node, semanticModel)); + Assert.Equal (expected, Binding.Skip (node, semanticModel)); } } diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/ClassCodeChangesTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/ClassBindingTests.cs similarity index 97% rename from tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/ClassCodeChangesTests.cs rename to tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/ClassBindingTests.cs index 652c4e4a037..6d527a1a7fd 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/ClassCodeChangesTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/ClassBindingTests.cs @@ -20,8 +20,8 @@ namespace Microsoft.Macios.Generator.Tests.DataModel; -public class ClassCodeChangesTests : BaseGeneratorTestClass { - readonly CodeChangesEqualityComparer comparer = new (); +public class ClassBindingTests : BaseGeneratorTestClass { + readonly BindingEqualityComparer comparer = new (); class TestDataCodeChangesFromClassDeclaration : IEnumerable { public IEnumerator GetEnumerator () @@ -45,7 +45,7 @@ public partial class MyClass { yield return [ emptyClass, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "MyClass", @namespace: ["NS"], @@ -79,7 +79,7 @@ public partial class MyClass : NSObject { yield return [ emptyClassWithBase, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "MyClass", @namespace: ["NS"], @@ -115,7 +115,7 @@ public partial class MyClass : NSObject, IMyInterface { yield return [ emptyClassWithBaseWithInterface, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "MyClass", @namespace: ["NS"], @@ -149,7 +149,7 @@ internal partial class MyClass { yield return [ internalClass, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "MyClass", @namespace: ["NS"], @@ -187,7 +187,7 @@ public partial class MyClass { yield return [ emptyClassAvailability, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "MyClass", @namespace: ["NS"], @@ -225,7 +225,7 @@ public MyClass () {} yield return [ singleConstructorClass, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "MyClass", @namespace: ["NS"], @@ -275,7 +275,7 @@ public MyClass(string name) { yield return [ multiConstructorClass, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "MyClass", @namespace: ["NS"], @@ -335,7 +335,7 @@ public partial class MyClass { yield return [ singlePropertyClass, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "MyClass", @namespace: ["NS"], @@ -406,7 +406,7 @@ public partial class MyClass { yield return [ singlePropertySmartEnumClass, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "MyClass", @namespace: ["NS"], @@ -476,7 +476,7 @@ public partial class MyClass { yield return [ singlePropertyEnumClass, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "MyClass", @namespace: ["NS"], @@ -542,7 +542,7 @@ public partial class MyClass { yield return [ notificationPropertyClass, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "MyClass", @namespace: ["NS"], @@ -611,7 +611,7 @@ public partial class MyClass { yield return [ fieldPropertyClass, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "MyClass", @namespace: ["NS"], @@ -683,7 +683,7 @@ public partial class MyClass { yield return [ multiPropertyClassMissingExport, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "MyClass", @namespace: ["NS"], @@ -749,7 +749,7 @@ public partial class MyClass { yield return [ customMarshallingProperty, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "MyClass", @namespace: ["NS"], @@ -824,7 +824,7 @@ public partial class MyClass { yield return [ multiPropertyClass, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "MyClass", @namespace: ["NS"], @@ -920,7 +920,7 @@ public partial class MyClass { yield return [ singleMethodClass, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "MyClass", @namespace: ["NS"], @@ -975,7 +975,7 @@ public void SetSurname (string inSurname) {} yield return [ multiMethodClassMissingExport, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "MyClass", @namespace: ["NS"], @@ -1031,7 +1031,7 @@ public partial class MyClass { "; yield return [ multiMethodClass, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "MyClass", @namespace: ["NS"], @@ -1102,7 +1102,7 @@ public partial class MyClass { yield return [ singleEventClass, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "MyClass", @namespace: ["NS"], @@ -1165,7 +1165,7 @@ public partial class MyClass { yield return [ multiEventClass, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "MyClass", @namespace: ["NS"], @@ -1243,7 +1243,7 @@ public partial class MyClass { [Theory] [AllSupportedPlatformsClassData] - void CodeChangesFromClassDeclaration (ApplePlatform platform, string inputText, CodeChanges expected) + void CodeChangesFromClassDeclaration (ApplePlatform platform, string inputText, Binding expected) { var (compilation, sourceTrees) = CreateCompilation (platform, sources: inputText); Assert.Single (sourceTrees); @@ -1254,7 +1254,7 @@ void CodeChangesFromClassDeclaration (ApplePlatform platform, string inputText, .FirstOrDefault (); Assert.NotNull (node); var semanticModel = compilation.GetSemanticModel (sourceTrees [0]); - var changes = CodeChanges.FromDeclaration (node, semanticModel); + var changes = Binding.FromDeclaration (node, semanticModel); Assert.NotNull (changes); Assert.Equal (expected, changes.Value, comparer); } @@ -1262,7 +1262,7 @@ void CodeChangesFromClassDeclaration (ApplePlatform platform, string inputText, [Fact] public void IsStaticPropertyTest () { - var changes = new CodeChanges ( + var changes = new Binding ( bindingInfo: new (new BindingTypeData ()), name: "name1", @namespace: ["NS"], @@ -1271,7 +1271,7 @@ public void IsStaticPropertyTest () Assert.False (changes.IsStatic); - changes = new CodeChanges ( + changes = new Binding ( bindingInfo: new (new BindingTypeData ()), name: "name1", @namespace: ["NS"], @@ -1289,7 +1289,7 @@ public void IsStaticPropertyTest () [Fact] public void IsPartialPropertyTest () { - var changes = new CodeChanges ( + var changes = new Binding ( bindingInfo: new (new BindingTypeData ()), name: "name1", @namespace: ["NS"], @@ -1298,7 +1298,7 @@ public void IsPartialPropertyTest () Assert.False (changes.IsPartial); - changes = new CodeChanges ( + changes = new Binding ( bindingInfo: new (new BindingTypeData ()), name: "name1", @namespace: ["NS"], @@ -1316,7 +1316,7 @@ public void IsPartialPropertyTest () [Fact] public void IsAbstractPropertyTest () { - var changes = new CodeChanges ( + var changes = new Binding ( bindingInfo: new (new BindingTypeData ()), name: "name1", @namespace: ["NS"], @@ -1325,7 +1325,7 @@ public void IsAbstractPropertyTest () Assert.False (changes.IsAbstract); - changes = new CodeChanges ( + changes = new Binding ( bindingInfo: new (new BindingTypeData ()), name: "name1", @namespace: ["NS"], diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/EnumDeclarationCodeChangesTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/EnumDeclarationCodeChangesTests.cs index 17dee7248e2..937a090a4e1 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/EnumDeclarationCodeChangesTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/EnumDeclarationCodeChangesTests.cs @@ -10,7 +10,7 @@ namespace Microsoft.Macios.Generator.Tests.DataModel; public class EnumDeclarationCodeChangesTests : BaseGeneratorTestClass { - CodeChanges CreateCodeChanges (ApplePlatform platform, string name, string inputText) + Binding CreateCodeChanges (ApplePlatform platform, string name, string inputText) { var (compilation, sourceTrees) = CreateCompilation (platform, sources: inputText); Assert.Single (sourceTrees); @@ -20,7 +20,7 @@ CodeChanges CreateCodeChanges (ApplePlatform platform, string name, string input .FirstOrDefault (); Assert.NotNull (enumDeclaration); var semanticModel = compilation.GetSemanticModel (sourceTrees [0]); - var codeChange = CodeChanges.FromDeclaration (enumDeclaration, semanticModel); + var codeChange = Binding.FromDeclaration (enumDeclaration, semanticModel); Assert.NotNull (codeChange); return codeChange.Value; } diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/InterfaceCodeChangesTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/InterfaceCodeChangesTests.cs index 99190ba0bf1..3d1f5431b0d 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/InterfaceCodeChangesTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/DataModel/InterfaceCodeChangesTests.cs @@ -19,7 +19,7 @@ namespace Microsoft.Macios.Generator.Tests.DataModel; public class InterfaceCodeChangesTests : BaseGeneratorTestClass { - readonly CodeChangesEqualityComparer comparer = new (); + readonly BindingEqualityComparer comparer = new (); class TestDataCodeChangesFromClassDeclaration : IEnumerable { public IEnumerator GetEnumerator () @@ -38,7 +38,7 @@ public partial interface IProtocol { yield return [ emptyInterface, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "IProtocol", @namespace: ["NS"], @@ -70,7 +70,7 @@ internal partial interface IProtocol { yield return [ internalInterface, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "IProtocol", @namespace: ["NS"], @@ -102,7 +102,7 @@ public partial interface IProtocol { yield return [ singlePropertyInterface, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "IProtocol", @namespace: ["NS"], @@ -171,7 +171,7 @@ public partial interface IProtocol { yield return [ singlePropertySmartEnumInterface, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "IProtocol", @namespace: ["NS"], @@ -239,7 +239,7 @@ public partial interface IProtocol { yield return [ singlePropertyEnumInterface, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "IProtocol", @namespace: ["NS"], @@ -303,7 +303,7 @@ public partial interface IProtocol { yield return [ notificationPropertyInterface, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "IProtocol", @namespace: ["NS"], @@ -371,7 +371,7 @@ public partial interface IProtocol { yield return [ multiPropertyInterfaceMissingExport, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "IProtocol", @namespace: ["NS"], @@ -435,7 +435,7 @@ public partial interface MyClass { yield return [ customMarshallingProperty, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "MyClass", @namespace: ["NS"], @@ -510,7 +510,7 @@ public partial interface IProtocol { yield return [ multiPropertyInterface, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "IProtocol", @namespace: ["NS"], @@ -604,7 +604,7 @@ public partial interface IProtocol { yield return [ singleMethodInterface, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "IProtocol", @namespace: ["NS"], @@ -657,7 +657,7 @@ public void SetSurname (string inSurname) {} yield return [ multiMethodInterfaceMissingExport, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "IProtocol", @namespace: ["NS"], @@ -711,7 +711,7 @@ public partial interface IProtocol { "; yield return [ multiMethodInterface, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "IProtocol", @namespace: ["NS"], @@ -780,7 +780,7 @@ public partial interface IProtocol { yield return [ singleEventInterface, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "IProtocol", @namespace: ["NS"], @@ -841,7 +841,7 @@ public partial interface IProtocol { yield return [ multiEventInterface, - new CodeChanges ( + new Binding ( bindingInfo: new (new BindingTypeData ()), name: "IProtocol", @namespace: ["NS"], @@ -917,7 +917,7 @@ public partial interface IProtocol { [Theory] [AllSupportedPlatformsClassData] - void CodeChangesFromInterfaceDeclaration (ApplePlatform platform, string inputText, CodeChanges expected) + void CodeChangesFromInterfaceDeclaration (ApplePlatform platform, string inputText, Binding expected) { var (compilation, sourceTrees) = CreateCompilation (platform, sources: inputText); @@ -929,7 +929,7 @@ void CodeChangesFromInterfaceDeclaration (ApplePlatform platform, string inputTe .FirstOrDefault (); Assert.NotNull (node); var semanticModel = compilation.GetSemanticModel (sourceTrees [0]); - var changes = CodeChanges.FromDeclaration (node, semanticModel); + var changes = Binding.FromDeclaration (node, semanticModel); Assert.NotNull (changes); Assert.Equal (expected, changes.Value, comparer); } diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Emitters/EmitterFactoryTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Emitters/EmitterFactoryTests.cs index 63af590719e..125e423f486 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Emitters/EmitterFactoryTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Emitters/EmitterFactoryTests.cs @@ -12,7 +12,7 @@ namespace Microsoft.Macios.Generator.Tests.Emitters; public class EmitterFactoryTests : BaseGeneratorTestClass { - CodeChanges CreateSymbol (ApplePlatform platform, string inputText) where T : BaseTypeDeclarationSyntax + Binding CreateSymbol (ApplePlatform platform, string inputText) where T : BaseTypeDeclarationSyntax { var (compilation, syntaxTrees) = CreateCompilation (platform, sources: inputText); Assert.Single (syntaxTrees); @@ -25,7 +25,7 @@ CodeChanges CreateSymbol (ApplePlatform platform, string inputText) where T : var semanticModel = compilation.GetSemanticModel (syntaxTrees [0]); var symbol = semanticModel.GetDeclaredSymbol (declaration); Assert.NotNull (symbol); - var changes = CodeChanges.FromDeclaration (declaration, semanticModel); + var changes = Binding.FromDeclaration (declaration, semanticModel); Assert.NotNull (changes); return changes.Value; } diff --git a/tests/rgen/Microsoft.Macios.Generator.Tests/Formatters/SmartEnumFormatterTests.cs b/tests/rgen/Microsoft.Macios.Generator.Tests/Formatters/SmartEnumFormatterTests.cs index 3293894cb3b..a75616cfc6e 100644 --- a/tests/rgen/Microsoft.Macios.Generator.Tests/Formatters/SmartEnumFormatterTests.cs +++ b/tests/rgen/Microsoft.Macios.Generator.Tests/Formatters/SmartEnumFormatterTests.cs @@ -73,7 +73,7 @@ public void ToDeclarationTests (ApplePlatform platform, string inputText, string Assert.NotNull (declaration); var semanticModel = compilation.GetSemanticModel (syntaxTrees [0]); Assert.NotNull (semanticModel); - var changes = CodeChanges.FromDeclaration (declaration, semanticModel); + var changes = Binding.FromDeclaration (declaration, semanticModel); Assert.NotNull (changes); var classDeclaration = changes.ToSmartEnumExtensionDeclaration (className); Assert.NotNull (classDeclaration);