Skip to content

Commit

Permalink
Improve source generator output
Browse files Browse the repository at this point in the history
  • Loading branch information
C0nquistadore committed Oct 1, 2022
1 parent c9f28d9 commit 62b322a
Show file tree
Hide file tree
Showing 18 changed files with 268 additions and 83 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System;

namespace PhoneBox.Generators
namespace PhoneBox.Generators
{
[AttributeUsage(AttributeTargets.Assembly)]
internal sealed class SignalRHubGenerationAttribute : Attribute
[global::System.AttributeUsage(global::System.AttributeTargets.Assembly)]
internal sealed class SignalRHubGenerationAttribute : global::System.Attribute
{
public SignalRHubGenerationOutputs OutputFilter { get; }
public global::PhoneBox.Generators.SignalRHubGenerationOutputs OutputFilter { get; }

public SignalRHubGenerationAttribute(SignalRHubGenerationOutputs outputFilter = SignalRHubGenerationOutputs.All)
public SignalRHubGenerationAttribute(global::PhoneBox.Generators.SignalRHubGenerationOutputs outputFilter = global::PhoneBox.Generators.SignalRHubGenerationOutputs.All)
{
OutputFilter = outputFilter;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;

namespace PhoneBox.Generators
namespace PhoneBox.Generators
{
[Flags]
[global::System.Flags]
internal enum SignalRHubGenerationOutputs
{
None = 0,
Expand Down
1 change: 1 addition & 0 deletions src/PhoneBox.Generators/PhoneBox.Generators.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<ItemGroup>
<Compile Include="..\..\shared\Guard.cs" Link="Diagnostics\Guard.cs" />
<Compile Include="..\..\shared\Extensions\CollectionExtensions.cs" Link="Extensions\CollectionExtensions.cs" />
<Compile Include="..\..\shared\Extensions\EnumerableExtensions.cs" Link="Extensions\EnumerableExtensions.cs" />
<EmbeddedResource Include="EmbeddedSources\**" Link="%(Identity)" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/Daemon/ConfigureAwaitAnalysisMode/@EntryValue">Library</s:String>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=embeddedsources/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=embeddedsources/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=utilities/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
176 changes: 124 additions & 52 deletions src/PhoneBox.Generators/SignalRHubGenerator.cs

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions src/PhoneBox.Generators/Utilities/Annotation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Collections.Generic;

namespace PhoneBox.Generators
{
internal readonly struct Annotation
{
public string Name { get; }
public string? Arguments { get; }

public static Annotation GeneratedCode = new Annotation("global::System.CodeDom.Compiler.GeneratedCode", $"(\"{(ThisAssembly.AssemblyTitle)}\", \"{(ThisAssembly.AssemblyFileVersion)}\")");
public static Annotation DebuggerNonUserCode = new Annotation("global::System.Diagnostics.DebuggerNonUserCode");
public static Annotation ExcludeFromCodeCoverage = new Annotation("global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage");
public static IEnumerable<Annotation> All
{
get
{
yield return GeneratedCode;
yield return DebuggerNonUserCode;
yield return ExcludeFromCodeCoverage;
}
}

private Annotation(string name, string? arguments = null)
{
this.Name = name;
this.Arguments = arguments;
}
}
}
2 changes: 1 addition & 1 deletion tests/PhoneBox.Generators.Tests/GeneratorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private Compilation RunGenerator(SignalRHubGenerationOutputs filter, string? met
string actualCode = outputSyntaxTree.ToString();
this.AddResultFile(outputFile.Name, actualCode);
Assert.AreEqual(expectedFiles[i - 1], outputFile.Name);
string expectedCode = this.GetEmbeddedResourceContent(outputFile.Name);
string expectedCode = this.GetEmbeddedResourceContent(outputFile.Name).Replace("%GENERATORVERSION%", ThisAssembly.AssemblyFileVersion);
this.AssertEqual(expectedCode, actualCode, outputName: Path.GetFileNameWithoutExtension(outputFile.Name), extension: outputFile.Extension.TrimStart('.'));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/Daemon/ConfigureAwaitAnalysisMode/@EntryValue">Library</s:String></wpf:ResourceDictionary>
<s:String x:Key="/Default/CodeInspection/Daemon/ConfigureAwaitAnalysisMode/@EntryValue">Library</s:String>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=utilities/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace PhoneBox.Abstractions
{
[global::System.CodeDom.Compiler.GeneratedCode("PhoneBox.Generators", "%GENERATORVERSION%")]
[global::System.Diagnostics.DebuggerNonUserCode]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public sealed class CallConnectedEvent
{
public string PhoneNumber { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace PhoneBox.Abstractions
{
[global::System.CodeDom.Compiler.GeneratedCode("PhoneBox.Generators", "%GENERATORVERSION%")]
[global::System.Diagnostics.DebuggerNonUserCode]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public sealed class CallDisconnectedEvent
{
public string PhoneNumber { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace PhoneBox.Abstractions
{
[global::System.CodeDom.Compiler.GeneratedCode("PhoneBox.Generators", "%GENERATORVERSION%")]
public enum CallHangUpReason
{
None = 0,
Expand Down
10 changes: 10 additions & 0 deletions tests/PhoneBox.Generators.Tests/Resources/CallState.generated.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace PhoneBox.Abstractions
{
[global::System.CodeDom.Compiler.GeneratedCode("PhoneBox.Generators", "%GENERATORVERSION%")]
public enum CallState
{
None = 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
using Microsoft.AspNetCore.Routing;
using PhoneBox.Generators.Tests;
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Microsoft.AspNetCore.Builder
{
[global::System.CodeDom.Compiler.GeneratedCode("PhoneBox.Generators", "%GENERATORVERSION%")]
[global::System.Diagnostics.DebuggerNonUserCode]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
internal static class HubEndpointRouteBuilderExtensions
{
public static HubEndpointConventionBuilder MapHub<THub>(this IEndpointRouteBuilder endpoints) where THub : TelephonyHub
public static global::Microsoft.AspNetCore.Builder.HubEndpointConventionBuilder MapHub<THub>(this global::Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints) where THub : global::PhoneBox.Generators.Tests.TelephonyHub
{
return endpoints.MapHub<THub>("/TelephonyHub");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
using System.Threading.Tasks;
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace PhoneBox.Abstractions
{
[global::System.CodeDom.Compiler.GeneratedCode("PhoneBox.Generators", "%GENERATORVERSION%")]
public interface ITelephonyHub
{
Task ReceiveCallConnected(CallConnectedEvent content);
Task ReceiveCallDisconnected(CallDisconnectedEvent content);
global::System.Threading.Tasks.Task ReceiveCallConnected(global::PhoneBox.Abstractions.CallConnectedEvent content);
global::System.Threading.Tasks.Task ReceiveCallDisconnected(global::PhoneBox.Abstractions.CallDisconnectedEvent content);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
using System;
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace PhoneBox.Generators
{
[AttributeUsage(AttributeTargets.Assembly)]
internal sealed class SignalRHubGenerationAttribute : Attribute
[global::System.CodeDom.Compiler.GeneratedCode("PhoneBox.Generators", "%GENERATORVERSION%")]
[global::System.Diagnostics.DebuggerNonUserCode]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::System.AttributeUsage(global::System.AttributeTargets.Assembly)]
internal sealed class SignalRHubGenerationAttribute : global::System.Attribute
{
public SignalRHubGenerationOutputs OutputFilter { get; }
public global::PhoneBox.Generators.SignalRHubGenerationOutputs OutputFilter { get; }

public SignalRHubGenerationAttribute(SignalRHubGenerationOutputs outputFilter = SignalRHubGenerationOutputs.All)
public SignalRHubGenerationAttribute(global::PhoneBox.Generators.SignalRHubGenerationOutputs outputFilter = global::PhoneBox.Generators.SignalRHubGenerationOutputs.All)
{
OutputFilter = outputFilter;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
using System;
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace PhoneBox.Generators
{
[Flags]
[global::System.CodeDom.Compiler.GeneratedCode("PhoneBox.Generators", "%GENERATORVERSION%")]
[global::System.Flags]
internal enum SignalRHubGenerationOutputs
{
None = 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
using Microsoft.AspNetCore.SignalR;
using PhoneBox.Abstractions;
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace PhoneBox.Generators.Tests
{
public partial class TelephonyHub : Hub<ITelephonyHub>
public partial class TelephonyHub : global::Microsoft.AspNetCore.SignalR.Hub<global::PhoneBox.Abstractions.ITelephonyHub>
{
}
}

0 comments on commit 62b322a

Please sign in to comment.