Skip to content

Commit

Permalink
Improve code organization (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceroypenguin authored Oct 12, 2024
1 parent 1cf58ca commit fde50b9
Show file tree
Hide file tree
Showing 35 changed files with 1,218 additions and 1,243 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using Microsoft.CodeAnalysis;

namespace Immediate.Handlers.Generators;
namespace Immediate.Handlers;

internal static class ITypeSymbolExtensions
{
Expand Down Expand Up @@ -90,4 +91,42 @@ typeSymbol is INamedTypeSymbol
}
}
};

public static bool IsBehaviorsAttribute(this ITypeSymbol? typeSymbol) =>
typeSymbol is
{
Name: "BehaviorsAttribute",
ContainingNamespace:
{
Name: "Shared",
ContainingNamespace:
{
Name: "Handlers",
ContainingNamespace:
{
Name: "Immediate",
ContainingNamespace.IsGlobalNamespace: true,
},
},
},
};

public static bool IsIHandler([NotNullWhen(true)] this ITypeSymbol? typeSymbol) =>
typeSymbol is INamedTypeSymbol
{
MetadataName: "IHandler`2",
ContainingNamespace:
{
Name: "Shared",
ContainingNamespace:
{
Name: "Handlers",
ContainingNamespace:
{
Name: "Immediate",
ContainingNamespace.IsGlobalNamespace: true,
},
},
},
};
}
83 changes: 0 additions & 83 deletions src/Immediate.Handlers.Analyzers/ITypeSymbolExtensions.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<IsRoslynComponent>true</IsRoslynComponent>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<IsRoslynComponent>true</IsRoslynComponent>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
<PackageReference Include="MinVer" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<Compile Include="../Common/*.cs" Link="Common/%(Filename).cs" />
</ItemGroup>

<PropertyGroup Label="MinVer">
<MinVerAutoIncrement>minor</MinVerAutoIncrement>
<MinVerDefaultPreReleaseIdentifiers>preview.0</MinVerDefaultPreReleaseIdentifiers>
<MinVerTagPrefix>v</MinVerTagPrefix>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
<PackageReference Include="MinVer" PrivateAssets="all" />
</ItemGroup>

<PropertyGroup Label="MinVer">
<MinVerAutoIncrement>minor</MinVerAutoIncrement>
<MinVerDefaultPreReleaseIdentifiers>preview.0</MinVerDefaultPreReleaseIdentifiers>
<MinVerTagPrefix>v</MinVerTagPrefix>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<IsRoslynComponent>true</IsRoslynComponent>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<IsRoslynComponent>true</IsRoslynComponent>
</PropertyGroup>

<ItemGroup>
<Compile Include="../Immediate.Handlers.Analyzers/DiagnosticIds.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="../Common/*.cs" Link="Common/%(Filename).cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" />
<PackageReference Include="MinVer" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<Compile Include="../Immediate.Handlers.Analyzers/DiagnosticIds.cs" />
</ItemGroup>

<PropertyGroup Label="MinVer">
<MinVerAutoIncrement>minor</MinVerAutoIncrement>
<MinVerDefaultPreReleaseIdentifiers>preview.0</MinVerDefaultPreReleaseIdentifiers>
<MinVerTagPrefix>v</MinVerTagPrefix>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" />
<PackageReference Include="MinVer" PrivateAssets="all" />
</ItemGroup>

<PropertyGroup Label="MinVer">
<MinVerAutoIncrement>minor</MinVerAutoIncrement>
<MinVerDefaultPreReleaseIdentifiers>preview.0</MinVerDefaultPreReleaseIdentifiers>
<MinVerTagPrefix>v</MinVerTagPrefix>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<IsRoslynComponent>true</IsRoslynComponent>
<NoWarn>$(NoWarn);CA1716</NoWarn>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<IsRoslynComponent>true</IsRoslynComponent>
<NoWarn>$(NoWarn);CA1716</NoWarn>
</PropertyGroup>

<ItemGroup>
<None Remove="Templates/*.sbntxt" />
<EmbeddedResource Include="Templates/*.sbntxt" />
</ItemGroup>
<ItemGroup>
<Compile Include="../Common/*.cs" Link="Common/%(Filename).cs" />
</ItemGroup>

<ItemGroup>
<None Remove="Templates/*.sbntxt" />
<EmbeddedResource Include="Templates/*.sbntxt" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Bcl.HashCode" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" />
<PackageReference Include="Scriban" PrivateAssets="all" GeneratePathProperty="true" />
<PackageReference Include="MinVer" PrivateAssets="all" />
</ItemGroup>

<PropertyGroup>
<GetTargetPathDependsOn>$(GetTargetPathDependsOn);GetDependencyTargetPaths</GetTargetPathDependsOn>
</PropertyGroup>

<Target Name="GetDependencyTargetPaths">
<ItemGroup>
<PackageReference Include="Microsoft.Bcl.HashCode" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" />
<PackageReference Include="Scriban" PrivateAssets="all" GeneratePathProperty="true" />
<PackageReference Include="MinVer" PrivateAssets="all" />
<TargetPathWithTargetPlatformMoniker Include="$(PkgScriban)/lib/netstandard2.0/Scriban.dll" IncludeRuntimeDependency="false" />
</ItemGroup>
</Target>

<PropertyGroup>
<GetTargetPathDependsOn>$(GetTargetPathDependsOn);GetDependencyTargetPaths</GetTargetPathDependsOn>
</PropertyGroup>

<Target Name="GetDependencyTargetPaths">
<ItemGroup>
<TargetPathWithTargetPlatformMoniker Include="$(PkgScriban)/lib/netstandard2.0/Scriban.dll" IncludeRuntimeDependency="false" />
</ItemGroup>
</Target>

<PropertyGroup Label="MinVer">
<MinVerAutoIncrement>minor</MinVerAutoIncrement>
<MinVerDefaultPreReleaseIdentifiers>preview.0</MinVerDefaultPreReleaseIdentifiers>
<MinVerTagPrefix>v</MinVerTagPrefix>
</PropertyGroup>
<PropertyGroup Label="MinVer">
<MinVerAutoIncrement>minor</MinVerAutoIncrement>
<MinVerDefaultPreReleaseIdentifiers>preview.0</MinVerDefaultPreReleaseIdentifiers>
<MinVerTagPrefix>v</MinVerTagPrefix>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ CancellationToken cancellationToken
private static EquatableReadOnlyList<Behavior?>? GetOverrideBehaviors(
INamedTypeSymbol symbol,
CancellationToken cancellationToken) =>
symbol.GetAttribute("Immediate.Handlers.Shared.BehaviorsAttribute")
symbol.GetBehaviorsAttribute()
is { } ba
? ParseBehaviors(ba, cancellationToken)
: null;
Expand Down Expand Up @@ -129,3 +129,11 @@ private static void AddBaseTypes(ITypeSymbol type, List<string> implements)
AddBaseTypes(i, implements);
}
}

file static class Extensions
{
public static AttributeData? GetBehaviorsAttribute(this INamedTypeSymbol symbol) =>
symbol
.GetAttributes()
.FirstOrDefault(a => a.AttributeClass.IsBehaviorsAttribute());
}
7 changes: 0 additions & 7 deletions src/Immediate.Handlers.Generators/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ internal static class Utility
? ((INamedTypeSymbol)method.ReturnType).TypeArguments.FirstOrDefault()
: null;

public static AttributeData? GetAttribute(this INamedTypeSymbol symbol, string attribute) =>
symbol
.GetAttributes()
.FirstOrDefault(a =>
a.AttributeClass?.ToString() == attribute
);

public static string? NullIf(this string value, string check) =>
value.Equals(check, StringComparison.Ordinal) ? null : value;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using Immediate.Handlers.Tests.Helpers;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp.Testing;
Expand All @@ -20,8 +21,8 @@ public static class CodeFixTestHelper
""";

public static CSharpCodeFixTest<TAnalyzer, TCodeFix, DefaultVerifier> CreateCodeFixTest<TAnalyzer, TCodeFix>(
string inputSource,
string fixedSource,
[StringSyntax("c#-test")] string inputSource,
[StringSyntax("c#-test")] string fixedSource,
DriverReferenceAssemblies assemblies,
int codeActionIndex = 0
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Immediate.Handlers.CodeFixes;
using Immediate.Handlers.Tests.Helpers;

namespace Immediate.Handlers.Tests.CodeFixTests.HandlerClassCodeFixTests;
namespace Immediate.Handlers.Tests.CodeFixTests;

[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1724:Type names should not match namespaces", Justification = "Not being consumed by other code")]
public partial class Tests
Expand Down
Loading

0 comments on commit fde50b9

Please sign in to comment.