Skip to content

Commit

Permalink
Reorganize folders and drop xml for now (#3394)
Browse files Browse the repository at this point in the history
Using a simple flat folder structure vs the deeply nested structure in
autorest.csharp.

Under src we will have

- Expressions - Classes that inherit from ValueExpression
- OutputTypes - Types constructed from output library like
propertydeclaration, modeltypeprovider, etc
- PostProcessing - Classes that deal with roslyn post processing of
csharp files
- Snippets - Helper classes for expressions / statements
- SourceInput - Roslyn existing / custom code representation / converter
/ helper
- StartUp - Start up process for loading plugins and initiating the
generation
- Statements - Classes that inherit from MethodBodyStatement
- Utilities - Any extension on system types or general utilities
- Writers - Writers to convert output types into csharp files
  • Loading branch information
m-nash authored May 17, 2024
1 parent 94c6d1c commit e56969c
Show file tree
Hide file tree
Showing 164 changed files with 29 additions and 239 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
Expand Down Expand Up @@ -63,11 +63,6 @@ public override MethodBodyStatement DeclareContentWithUtf8JsonWriter(out TypedVa
return Snippets.Var(contentVar, Snippets.New.Instance(typeof(Utf8JsonRequestBody)));
}

public override MethodBodyStatement DeclareContentWithXmlWriter(out TypedValueExpression content, out XmlWriterExpression writer)
{
throw new NotImplementedException("Xml serialization isn't supported in System.Net.ClientModel yet");
}

public override MethodBodyStatement InvokeServiceOperationCallAndReturnHeadAsBool(TypedValueExpression pipeline, TypedValueExpression message, TypedValueExpression clientDiagnostics, bool async)
{
var resultVar = new VariableReference(typeof(NullableResult<bool>), "result");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
Expand All @@ -9,8 +9,6 @@ namespace Microsoft.Generator.CSharp.ClientModel.Expressions
internal partial class SystemExtensibleSnippets : ExtensibleSnippets
{
public override JsonElementSnippets JsonElement { get; } = new SystemJsonElementSnippets();
public override XElementSnippets XElement => throw new NotImplementedException("XElement extensions aren't supported in ClientModel plugin yet.");
public override XmlWriterSnippets XmlWriter => throw new NotImplementedException("XmlWriter extensions aren't supported in ClientModel plugin yet.");
public override RestOperationsSnippets RestOperations { get; } = new SystemRestOperationsSnippets();
public override ModelSnippets Model { get; } = new SystemModelSnippets();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace Microsoft.Generator.CSharp
namespace Microsoft.Generator.CSharp.Input
{
/// <summary>
/// Represents the set of known serialization formats.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Generator.CSharp.Writers;

namespace Microsoft.Generator.CSharp
{
public sealed class CSharpGen
{
private static readonly string[] _filesToKeep = [Constants.DefaultCodeModelFileName, Constants.DefaultConfigurationFileName];
private const string ConfigurationFileName = "Configuration.json";
private const string CodeModelFileName = "tspCodeModel.json";

private static readonly string[] _filesToKeep = [ConfigurationFileName, CodeModelFileName];

/// <summary>
/// Executes the generator task with the <see cref="CodeModelPlugin"/> instance.
Expand All @@ -21,7 +23,7 @@ public async Task ExecuteAsync()
{
GeneratedCodeWorkspace.Initialize();
var outputPath = CodeModelPlugin.Instance.Configuration.OutputDirectory;
var generatedTestOutputPath = Path.Combine(outputPath, "..", "..", "tests", Constants.DefaultGeneratedCodeFolderName);
var generatedTestOutputPath = Path.Combine(outputPath, "..", "..", "tests", "Generated");

GeneratedCodeWorkspace workspace = await GeneratedCodeWorkspace.Create();

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
Expand All @@ -18,8 +18,8 @@ namespace Microsoft.Generator.CSharp
{
internal class GeneratedCodeWorkspace
{
public static readonly string GeneratedFolder = Constants.DefaultGeneratedCodeFolderName;
public static readonly string GeneratedTestFolder = Constants.DefaultGeneratedTestFolderName;
private const string GeneratedFolder = "Generated";
private const string GeneratedCodeProjectName = "GeneratedCode";

private static readonly Lazy<IReadOnlyList<MetadataReference>> _assemblyMetadataReferences = new(() => new List<MetadataReference>()
{ MetadataReference.CreateFromFile(typeof(object).Assembly.Location) });
Expand Down Expand Up @@ -116,7 +116,7 @@ private static Project CreateGeneratedCodeProject()
var workspace = new AdhocWorkspace();
var newOptionSet = workspace.Options.WithChangedOption(FormattingOptions.NewLine, LanguageNames.CSharp, _newLine);
workspace.TryApplyChanges(workspace.CurrentSolution.WithOptions(newOptionSet));
Project generatedCodeProject = workspace.AddProject(Constants.DefaultGeneratedCodeProjectFolderName, LanguageNames.CSharp);
Project generatedCodeProject = workspace.AddProject(GeneratedCodeProjectName, LanguageNames.CSharp);

generatedCodeProject = generatedCodeProject
.AddMetadataReferences(_assemblyMetadataReferences.Value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
Expand All @@ -18,7 +18,6 @@ public abstract class RestOperationsSnippets

public abstract MethodBodyStatement DeclareHttpMessage(MethodSignatureBase createRequestMethodSignature, out TypedValueExpression message);
public abstract MethodBodyStatement DeclareContentWithUtf8JsonWriter(out TypedValueExpression content, out Utf8JsonWriterExpression writer);
public abstract MethodBodyStatement DeclareContentWithXmlWriter(out TypedValueExpression content, out XmlWriterExpression writer);
public abstract MethodBodyStatement InvokeServiceOperationCallAndReturnHeadAsBool(TypedValueExpression pipeline, TypedValueExpression message, TypedValueExpression clientDiagnostics, bool async);
public abstract StreamExpression GetContentStream(TypedValueExpression response);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace Microsoft.Generator.CSharp.Expressions
Expand All @@ -8,8 +8,6 @@ public abstract partial class ExtensibleSnippets
public abstract JsonElementSnippets JsonElement { get; }
public abstract ModelSnippets Model { get; }
public abstract RestOperationsSnippets RestOperations { get; }
public abstract XElementSnippets XElement { get; }
public abstract XmlWriterSnippets XmlWriter { get; }

protected static InvokeStaticMethodExpression InvokeExtension(CSharpType extensionType, ValueExpression instance, string methodName)
=> new(extensionType, methodName, new[] { instance }, CallAsAsync: false, CallAsExtension: true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
Expand Down Expand Up @@ -73,9 +73,6 @@ public static MethodBodyStatement Var(string name, StringExpression value, out S
public static MethodBodyStatement Var(string name, Utf8JsonWriterExpression value, out Utf8JsonWriterExpression variable)
=> Var(name, value, d => new Utf8JsonWriterExpression(d), out variable);

public static MethodBodyStatement Var(string name, XDocumentExpression value, out XDocumentExpression variable)
=> Var(name, value, d => new XDocumentExpression(d), out variable);

public static MethodBodyStatement Var(string name, TypedValueExpression value, out TypedValueExpression variable)
{
var reference = new VariableReference(value.Type, name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ public static TypedValueExpression RemoveAllNullConditional(TypedValueExpression
public static BoolExpression Equal(ValueExpression left, ValueExpression right) => new(new BinaryOperatorExpression("==", left, right));
public static BoolExpression NotEqual(ValueExpression left, ValueExpression right) => new(new BinaryOperatorExpression("!=", left, right));

public static BoolExpression Is(XElementExpression value, string name, out XElementExpression xElement)
=> Is<XElementExpression>(value, name, d => new XElementExpression(d), out xElement);
public static BoolExpression Is(XAttributeExpression value, string name, out XAttributeExpression xAttribute)
=> Is<XAttributeExpression>(value, name, d => new XAttributeExpression(d), out xAttribute);
public static BoolExpression Is(ValueExpression left, ValueExpression right)
=> new(new BinaryOperatorExpression("is", left, right));

Expand Down
Loading

0 comments on commit e56969c

Please sign in to comment.