diff --git a/packages/http-client-csharp/eng/scripts/Generate.ps1 b/packages/http-client-csharp/eng/scripts/Generate.ps1 index fc7bb04d9..7332ea45e 100644 --- a/packages/http-client-csharp/eng/scripts/Generate.ps1 +++ b/packages/http-client-csharp/eng/scripts/Generate.ps1 @@ -151,6 +151,7 @@ if ($null -eq $filter) { $mgcExe = "`$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.exe" $sampleExe = "`$(SolutionDir)/../generator/artifacts/bin/SamplePlugin/Debug/net8.0/Microsoft.Generator.CSharp.exe" $unbrandedSpec = "TestProjects/Local/Unbranded-TypeSpec" + $unbrandedPluginSpec = "TestProjects/Plugin/Unbranded-TypeSpec" $launchSettings = @{} $launchSettings.Add("profiles", @{}) @@ -159,7 +160,7 @@ if ($null -eq $filter) { $launchSettings["profiles"]["Unbranded-TypeSpec"].Add("commandName", "Executable") $launchSettings["profiles"]["Unbranded-TypeSpec"].Add("executablePath", $mgcExe) $launchSettings["profiles"].Add("Debug-Plugin-Test-TypeSpec", @{}) - $launchSettings["profiles"]["Debug-Plugin-Test-TypeSpec"].Add("commandLineArgs", "`$(SolutionDir)/$unbrandedSpec -p SampleCodeModelPlugin") + $launchSettings["profiles"]["Debug-Plugin-Test-TypeSpec"].Add("commandLineArgs", "`$(SolutionDir)/$unbrandedPluginSpec -p SampleCodeModelPlugin") $launchSettings["profiles"]["Debug-Plugin-Test-TypeSpec"].Add("commandName", "Executable") $launchSettings["profiles"]["Debug-Plugin-Test-TypeSpec"].Add("executablePath", $sampleExe) diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel.StubLibrary/src/StubLibraryPlugin.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel.StubLibrary/src/StubLibraryPlugin.cs index c322a2059..0508d5b7c 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel.StubLibrary/src/StubLibraryPlugin.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel.StubLibrary/src/StubLibraryPlugin.cs @@ -14,7 +14,7 @@ namespace Microsoft.Generator.CSharp.ClientModel.StubLibrary public override void Configure() { - AddVisitor(new StubVisitor()); + AddVisitor(new StubLibraryVisitor()); } } } diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel.StubLibrary/src/StubVisitor.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel.StubLibrary/src/StubLibraryVisitor.cs similarity index 98% rename from packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel.StubLibrary/src/StubVisitor.cs rename to packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel.StubLibrary/src/StubLibraryVisitor.cs index 2de6fb039..ed2fad93d 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel.StubLibrary/src/StubVisitor.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel.StubLibrary/src/StubLibraryVisitor.cs @@ -9,7 +9,7 @@ using static Microsoft.Generator.CSharp.Snippets.Snippet; namespace Microsoft.Generator.CSharp.ClientModel.StubLibrary { - internal class StubVisitor : ScmVisitor + internal class StubLibraryVisitor : ScmLibraryVisitor { private readonly ValueExpression _throwNull = ThrowExpression(Null); private readonly XmlDocProvider _emptyDocs = new(); diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/ClientModelPlugin.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/ClientModelPlugin.cs index 6a8c8340f..acb5739b6 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/ClientModelPlugin.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/ClientModelPlugin.cs @@ -33,7 +33,7 @@ namespace Microsoft.Generator.CSharp.ClientModel public override void Configure() { - AddVisitor(new DefaultScmVisitor()); + AddVisitor(new DefaultScmLibraryVisitor()); } } } diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/DefaultScmVisitor.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/DefaultScmLibraryVisitor.cs similarity index 71% rename from packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/DefaultScmVisitor.cs rename to packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/DefaultScmLibraryVisitor.cs index 15a5d4ac6..d443a735f 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/DefaultScmVisitor.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/DefaultScmLibraryVisitor.cs @@ -3,7 +3,7 @@ namespace Microsoft.Generator.CSharp.ClientModel { - internal class DefaultScmVisitor : ScmVisitor + internal class DefaultScmLibraryVisitor : ScmLibraryVisitor { } } diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/ScmVisitor.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/ScmLibraryVisitor.cs similarity index 90% rename from packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/ScmVisitor.cs rename to packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/ScmLibraryVisitor.cs index be48d48da..d0e3c251c 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/ScmVisitor.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/ScmLibraryVisitor.cs @@ -7,7 +7,7 @@ using Microsoft.Generator.CSharp.Providers; namespace Microsoft.Generator.CSharp.ClientModel { - public abstract class ScmVisitor : LibraryVisitor + public abstract class ScmLibraryVisitor : LibraryVisitor { protected internal virtual MethodProviderCollection? Visit(InputOperation operation, TypeProvider enclosingType, diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/ScmTypeFactory.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/ScmTypeFactory.cs index 98fb444e0..65b5ed3fa 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/ScmTypeFactory.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/ScmTypeFactory.cs @@ -75,7 +75,7 @@ namespace Microsoft.Generator.CSharp.ClientModel foreach (var visitor in visitors) { - if (visitor is ScmVisitor scmVisitor) + if (visitor is ScmLibraryVisitor scmVisitor) { methods = scmVisitor.Visit(operation, enclosingType, methods); } diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/InputLibraryVisitorTests.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/InputLibraryVisitorTests.cs index 34bc360d2..841e2a8ef 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/InputLibraryVisitorTests.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/InputLibraryVisitorTests.cs @@ -16,7 +16,7 @@ namespace Microsoft.Generator.CSharp.ClientModel.Tests { #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. private Mock _mockPlugin; - private Mock _mockVisitor; + private Mock _mockVisitor; private Mock _mockInputLibrary; #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. @@ -25,7 +25,7 @@ namespace Microsoft.Generator.CSharp.ClientModel.Tests { _mockInputLibrary = new Mock(); _mockPlugin = MockHelpers.LoadMockPlugin(createInputLibrary: () => _mockInputLibrary.Object); - _mockVisitor = new Mock { CallBase = true }; + _mockVisitor = new Mock { CallBase = true }; } [Test] diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Properties/launchSettings.json b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Properties/launchSettings.json index ad264857e..2dec05074 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Properties/launchSettings.json +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Properties/launchSettings.json @@ -1,7 +1,7 @@ { "profiles": { "Debug-Plugin-Test-TypeSpec": { - "commandLineArgs": "$(SolutionDir)/TestProjects/Local/Unbranded-TypeSpec -p SampleCodeModelPlugin", + "commandLineArgs": "$(SolutionDir)/TestProjects/Plugin/Unbranded-TypeSpec -p SampleCodeModelPlugin", "commandName": "Executable", "executablePath": "$(SolutionDir)/../generator/artifacts/bin/SamplePlugin/Debug/net8.0/Microsoft.Generator.CSharp.exe" }, diff --git a/packages/http-client-csharp/generator/SamplePlugin/src/OutputTypes/SamplePluginLibraryVisitor.cs b/packages/http-client-csharp/generator/SamplePlugin/src/OutputTypes/SamplePluginLibraryLibraryVisitor.cs similarity index 68% rename from packages/http-client-csharp/generator/SamplePlugin/src/OutputTypes/SamplePluginLibraryVisitor.cs rename to packages/http-client-csharp/generator/SamplePlugin/src/OutputTypes/SamplePluginLibraryLibraryVisitor.cs index 563b8eff3..6d49f70e2 100644 --- a/packages/http-client-csharp/generator/SamplePlugin/src/OutputTypes/SamplePluginLibraryVisitor.cs +++ b/packages/http-client-csharp/generator/SamplePlugin/src/OutputTypes/SamplePluginLibraryLibraryVisitor.cs @@ -2,14 +2,16 @@ // Licensed under the MIT License. using Microsoft.Generator.CSharp; +using Microsoft.Generator.CSharp.ClientModel; using Microsoft.Generator.CSharp.ClientModel.Providers; using Microsoft.Generator.CSharp.Input; using Microsoft.Generator.CSharp.Primitives; using Microsoft.Generator.CSharp.Providers; +using SamplePlugin.Providers; namespace SamplePlugin { - public class SamplePluginLibraryVisitor : LibraryVisitor + public class SamplePluginLibraryLibraryVisitor : ScmLibraryVisitor { protected override MethodProvider Visit(TypeProvider typeProvider, MethodProvider methodProvider) { @@ -26,5 +28,12 @@ namespace SamplePlugin { return new SamplePluginPropertyProvider(property); } + + protected override MethodProviderCollection Visit(InputOperation operation, + TypeProvider enclosingType, + MethodProviderCollection? methodProvider) + { + return new SamplePluginMethodProviderCollection(operation, enclosingType); + } } } diff --git a/packages/http-client-csharp/generator/SamplePlugin/src/SampleCodeModelPlugin.cs b/packages/http-client-csharp/generator/SamplePlugin/src/SampleCodeModelPlugin.cs index 357d3a3c4..e13ae27f4 100644 --- a/packages/http-client-csharp/generator/SamplePlugin/src/SampleCodeModelPlugin.cs +++ b/packages/http-client-csharp/generator/SamplePlugin/src/SampleCodeModelPlugin.cs @@ -12,11 +12,9 @@ namespace SamplePlugin [method: ImportingConstructor] public class SampleCodeModelPlugin(GeneratorContext context) : ClientModelPlugin(context) { - public override SamplePluginTypeFactory TypeFactory { get; } = new SamplePluginTypeFactory(); - public override void Configure() { - AddVisitor(new SamplePluginLibraryVisitor()); + AddVisitor(new SamplePluginLibraryLibraryVisitor()); } } } diff --git a/packages/http-client-csharp/generator/SamplePlugin/src/SamplePluginTypeFactory.cs b/packages/http-client-csharp/generator/SamplePlugin/src/SamplePluginTypeFactory.cs deleted file mode 100644 index eeebea6bd..000000000 --- a/packages/http-client-csharp/generator/SamplePlugin/src/SamplePluginTypeFactory.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Microsoft.Generator.CSharp.ClientModel; -using Microsoft.Generator.CSharp.Input; -using Microsoft.Generator.CSharp.Providers; -using SamplePlugin.Providers; - -namespace SamplePlugin -{ - public class SamplePluginTypeFactory : ScmTypeFactory - { - /// - /// Creates a for the given operation. If the operation is a operation, - /// a method collection will be created. Otherwise, null will be returned. - /// - /// The input operation to create methods for. - /// The enclosing type of the operation. - public override MethodProviderCollection CreateMethods(InputOperation operation, TypeProvider enclosingType) => new SamplePluginMethodProviderCollection(operation, enclosingType); - } -}