Skip to content

Commit

Permalink
Foreignkeys (#123)
Browse files Browse the repository at this point in the history
* prep work to use a different interface per generator

* more prep for foreign keys

* pkg updates

* initial work to split out the core gen model

* fix break in build

* fixed issue with analyzer causing codegen to fail

Microsoft.CodeAnalysis.Analyzers 3.3.2 is using a v2 roslyn dll

* #128 debug filename change

* remove some redundant logic from old gen model

* more cleanup

* test coverage

* stylecop and versioning

* removed some async work
  • Loading branch information
dpvreony authored Jun 14, 2021
1 parent 65b2250 commit 94826b1
Show file tree
Hide file tree
Showing 102 changed files with 1,090 additions and 371 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<ItemGroup>
<PackageReference Include="Dhgms.AspNetCoreContrib.Controllers" Version="4.1.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.9.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.7" />
</ItemGroup>

Expand All @@ -20,4 +21,20 @@
<ProjectReference Include="..\Dhgms.Nucleotide.ModelTests\Dhgms.Nucleotide.ModelTests.csproj" OutputItemType="Analyzer" />
</ItemGroup>

<Target Name="DeleteOldGeneratedFiles" BeforeTargets="BeforeBuild" Condition="$(SaveSourceGeneratorOutput) == 'true' and $(IntermediateOutputPath) != ''">
<ItemGroup>
<FilesToDelete Include="$(IntermediateOutputPath)Generated\*.g.cs" />
</ItemGroup>
<Delete Files="@(FilesToDelete)" />
</Target>

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

<Target Name="GetDependencyTargetPaths">
<ItemGroup>
<TargetPathWithTargetPlatformMoniker Include="$(Outdir)Dhgms.Nucleotide.Generators.dll" IncludeRuntimeDependency="false" />
</ItemGroup>
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2" PrivateAssets="none" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" PrivateAssets="none" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.9.0" PrivateAssets="none" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using Dhgms.Nucleotide.Generators.Generators;
using Dhgms.Nucleotide.Generators.Models;
using Microsoft.CodeAnalysis;

namespace Dhgms.Nucleotide.Generators.Features.Cqrs
{
/// <summary>
/// Generator for Command Factory Interface
/// </summary>
public abstract class CommandFactoryInterfaceGenerator : BaseInterfaceLevelCodeGenerator<CommandFactoryInterfaceFeatureFlags, CommandFactoryInterfaceGeneratorProcessor>
public abstract class CommandFactoryInterfaceGenerator : BaseInterfaceLevelCodeGenerator<CommandFactoryInterfaceFeatureFlags, CommandFactoryInterfaceGeneratorProcessor, IEntityGenerationModel>
{
protected override string GetNamespace()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Dhgms.Nucleotide.Generators.Features.Cqrs
/// <summary>
/// Generator for Command Factory Interface
/// </summary>
public sealed class CommandFactoryInterfaceGeneratorProcessor : BaseInterfaceLevelCodeGeneratorProcessor
public sealed class CommandFactoryInterfaceGeneratorProcessor : BaseInterfaceLevelCodeGeneratorProcessor<IEntityGenerationModel>
{
protected override string GetClassSuffix()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using Dhgms.Nucleotide.Generators.Generators;
using Dhgms.Nucleotide.Generators.Models;
using Microsoft.CodeAnalysis;

namespace Dhgms.Nucleotide.Generators.Features.Cqrs
{
public abstract class CommandInterfaceGenerator : BaseInterfaceLevelCodeGenerator<CommandInterfaceFeatureFlags, CommandInterfaceGeneratorProcessor>
public abstract class CommandInterfaceGenerator : BaseInterfaceLevelCodeGenerator<CommandInterfaceFeatureFlags, CommandInterfaceGeneratorProcessor, IEntityGenerationModel>
{
protected override string GetNamespace() => "Commands";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Dhgms.Nucleotide.Generators.Features.Cqrs
{
public sealed class CommandInterfaceGeneratorProcessor : BaseInterfaceLevelCodeGeneratorProcessor
public sealed class CommandInterfaceGeneratorProcessor : BaseInterfaceLevelCodeGeneratorProcessor<IEntityGenerationModel>
{
protected override string[] GetClassPrefixes() => new []{ "Add", "Delete", "Update" };

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using Dhgms.Nucleotide.Generators.Generators;
using Dhgms.Nucleotide.Generators.Models;
using Microsoft.CodeAnalysis;

namespace Dhgms.Nucleotide.Generators.Features.Cqrs
{
/// <summary>
/// Generator for Query Factory Interface
/// </summary>
public abstract class QueryFactoryInterfaceGenerator : BaseInterfaceLevelCodeGenerator<QueryFactoryInterfaceFeatureFlags, QueryFactoryInterfaceGeneratorProcessor>
public abstract class QueryFactoryInterfaceGenerator : BaseInterfaceLevelCodeGenerator<QueryFactoryInterfaceFeatureFlags, QueryFactoryInterfaceGeneratorProcessor, IEntityGenerationModel>
{
protected override string GetNamespace()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Dhgms.Nucleotide.Generators.Features.Cqrs
/// <summary>
/// Generator for Query Factory Interface
/// </summary>
public sealed class QueryFactoryInterfaceGeneratorProcessor : BaseInterfaceLevelCodeGeneratorProcessor
public sealed class QueryFactoryInterfaceGeneratorProcessor : BaseInterfaceLevelCodeGeneratorProcessor<IEntityGenerationModel>
{
protected override string[] GetClassPrefixes() => Array.Empty<string>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using Dhgms.Nucleotide.Generators.Generators;
using Dhgms.Nucleotide.Generators.Models;
using Microsoft.CodeAnalysis;

namespace Dhgms.Nucleotide.Generators.Features.Cqrs
{
/// <summary>
/// Generator for Query Interface
/// </summary>
public abstract class QueryInterfaceGenerator : BaseInterfaceLevelCodeGenerator<QueryInterfaceFeatureFlag, QueryInterfaceGeneratorProcessor>
public abstract class QueryInterfaceGenerator : BaseInterfaceLevelCodeGenerator<QueryInterfaceFeatureFlag, QueryInterfaceGeneratorProcessor, IEntityGenerationModel>
{
protected override string GetNamespace() => "Queries";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Dhgms.Nucleotide.Generators.Features.Cqrs
/// <summary>
/// Generator for Query Interface
/// </summary>
public sealed class QueryInterfaceGeneratorProcessor : BaseInterfaceLevelCodeGeneratorProcessor
public sealed class QueryInterfaceGeneratorProcessor : BaseInterfaceLevelCodeGeneratorProcessor<IEntityGenerationModel>
{
protected override string[] GetClassPrefixes() => new []{ "List", "View" };

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Dhgms.Nucleotide.Generators.Features.Database
{
public sealed class ForiegnKeyInterfaceFeatureFlags
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Dhgms.Nucleotide.Generators.Generators;
using Dhgms.Nucleotide.Generators.Models;

namespace Dhgms.Nucleotide.Generators.Features.Database
{
public abstract class ForiegnKeyInterfaceGenerator : BaseGenerator<ForiegnKeyInterfaceFeatureFlags, ForiegnKeyInterfaceGeneratorProcessor, IEntityGenerationModel>
{
/// <inheritdoc />
protected override string GetNamespace()
{
return "Database";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using Dhgms.Nucleotide.Generators.GeneratorProcessors;
using Dhgms.Nucleotide.Generators.Models;
using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace Dhgms.Nucleotide.Generators.Features.Database
{
public sealed class ForiegnKeyInterfaceGeneratorProcessor : BaseInterfaceLevelCodeGeneratorProcessor<IEntityGenerationModel>
{
/// <inheritdoc />
protected override string[] GetClassPrefixes()
{
throw new NotImplementedException();
}

/// <inheritdoc />
protected override string GetClassSuffix()
{
return "ForeignKey";
}

/// <inheritdoc />
protected override string[] GetInterfaceSummary(IEntityGenerationModel entityDeclaration)
{
return new[]
{
$"Represents a foreign key relationship to the {entityDeclaration.ClassName} entity."
};
}

/// <inheritdoc />
protected override PropertyDeclarationSyntax[] GetPropertyDeclarations(IEntityGenerationModel entityGenerationModel, string prefix)
{
throw new NotImplementedException();
}

/// <inheritdoc />
protected override MethodDeclarationSyntax[] GetMethodDeclarations(string className, string prefix)
{
throw new NotImplementedException();
}

/// <inheritdoc />
protected override string[] GetBaseInterfaces(IEntityGenerationModel entityGenerationModel, string prefix)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Dhgms.Nucleotide.Generators.Features.Database
{
public sealed class ReferencedByEntityFeatureFlags
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Dhgms.Nucleotide.Generators.Generators;
using Dhgms.Nucleotide.Generators.Models;

namespace Dhgms.Nucleotide.Generators.Features.Database
{
public abstract class ReferencedByEntityGenerator : BaseGenerator<ReferencedByEntityFeatureFlags, ReferencedByEntityGeneratorProcessor, IEntityGenerationModel>
{
/// <inheritdoc />
protected override string GetNamespace()
{
return "Database";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using Dhgms.Nucleotide.Generators.GeneratorProcessors;
using Dhgms.Nucleotide.Generators.Models;
using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace Dhgms.Nucleotide.Generators.Features.Database
{
public sealed class ReferencedByEntityGeneratorProcessor : BaseInterfaceLevelCodeGeneratorProcessor<IEntityGenerationModel>
{
/// <inheritdoc />
protected override string[] GetClassPrefixes()
{
return null;
}

/// <inheritdoc />
protected override string GetClassSuffix()
{
return "ReferencedByEntity";
}

/// <inheritdoc />
protected override string[] GetInterfaceSummary(IEntityGenerationModel entityDeclaration)
{
return new[]
{
"Represents a entity",
};
}

/// <inheritdoc />
protected override PropertyDeclarationSyntax[] GetPropertyDeclarations(IEntityGenerationModel entityGenerationModel, string prefix)
{
throw new NotImplementedException();
}

/// <inheritdoc />
protected override MethodDeclarationSyntax[] GetMethodDeclarations(string className, string prefix)
{
throw new NotImplementedException();
}

/// <inheritdoc />
protected override string[] GetBaseInterfaces(IEntityGenerationModel entityGenerationModel, string prefix)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Dhgms.Nucleotide.Generators.Features.Dto
{
public sealed class RequestDtoClassGeneratorProcessor : BaseClassLevelCodeGeneratorProcessor
public sealed class RequestDtoClassGeneratorProcessor : BaseClassLevelCodeGeneratorProcessor<IEntityGenerationModel>
{
protected override bool GetWhetherClassShouldBePartialClass() => true;

Expand Down Expand Up @@ -51,7 +51,7 @@ protected override IList<Tuple<string, IList<string>>> GetClassAttributes(IEntit

public override async Task<NamespaceDeclarationSyntax> GenerateObjects(
NamespaceDeclarationSyntax namespaceDeclaration,
INucleotideGenerationModel nucleotideGenerationModel)
INucleotideGenerationModel<IEntityGenerationModel> nucleotideGenerationModel)
{
var generationModelEntityGenerationModel = nucleotideGenerationModel.EntityGenerationModel;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Dhgms.Nucleotide.Generators.Features.Dto
{
public sealed class ResponseDtoClassGeneratorProcessor : BaseClassLevelCodeGeneratorProcessor
public sealed class ResponseDtoClassGeneratorProcessor : BaseClassLevelCodeGeneratorProcessor<IEntityGenerationModel>
{
protected override bool GetWhetherClassShouldBePartialClass() => true;

Expand Down Expand Up @@ -75,7 +75,7 @@ protected override IList<Tuple<string, IList<string>>> GetClassAttributes(IEntit

public override async Task<NamespaceDeclarationSyntax> GenerateObjects(
NamespaceDeclarationSyntax namespaceDeclaration,
INucleotideGenerationModel nucleotideGenerationModel)
INucleotideGenerationModel<IEntityGenerationModel> nucleotideGenerationModel)
{
var generationModelEntityGenerationModel = nucleotideGenerationModel.EntityGenerationModel;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using Dhgms.Nucleotide.Generators.Generators;
using Dhgms.Nucleotide.Generators.Models;
using Microsoft.CodeAnalysis;

namespace Dhgms.Nucleotide.Generators.Features.EntityFramework
{
/// <summary>
/// Code Generator for Entity Framework DB Context
/// </summary>
public abstract class EntityFrameworkDbContextGenerator : BaseGenerator<EntityFrameworkDbContextFeatureFlags, EntityFrameworkDbContextGeneratorProcessor>
public abstract class EntityFrameworkDbContextGenerator : BaseGenerator<EntityFrameworkDbContextFeatureFlags, EntityFrameworkDbContextGeneratorProcessor, IEntityGenerationModel>
{
protected override string GetNamespace()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ namespace Dhgms.Nucleotide.Generators.Features.EntityFramework
/// <summary>
/// Code Generator for Entity Framework DB Context
/// </summary>
public sealed class EntityFrameworkDbContextGeneratorProcessor : BaseGeneratorProcessor
public sealed class EntityFrameworkDbContextGeneratorProcessor : BaseGeneratorProcessor<IEntityGenerationModel>
{
public override async Task<NamespaceDeclarationSyntax> GenerateObjects(
NamespaceDeclarationSyntax namespaceDeclaration,
INucleotideGenerationModel nucleotideGenerationModel)
INucleotideGenerationModel<IEntityGenerationModel> nucleotideGenerationModel)
{
var generationModelEntityGenerationModel = nucleotideGenerationModel.EntityGenerationModel;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Dhgms.Nucleotide.Generators.Features.EntityFramework
{
public class EntityFrameworkEntityTypeConfigurationGeneratorProcessor : BaseClassLevelCodeGeneratorProcessor
public class EntityFrameworkEntityTypeConfigurationGeneratorProcessor : BaseClassLevelCodeGeneratorProcessor<IEntityGenerationModel>
{
protected override bool GetWhetherClassShouldBePartialClass() => false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Dhgms.Nucleotide.Generators.Features.EntityFramework
{
public sealed class EntityFrameworkModelGeneratorProcessor : BaseClassLevelCodeGeneratorProcessor
public sealed class EntityFrameworkModelGeneratorProcessor : BaseClassLevelCodeGeneratorProcessor<IEntityGenerationModel>
{
protected override bool GetWhetherClassShouldBePartialClass() => true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Dhgms.Nucleotide.Generators.Features.Model
/// <summary>
/// Generates models
/// </summary>
public class KeyedModelClassGeneratorProcessor : BaseClassLevelCodeGeneratorProcessor
public class KeyedModelClassGeneratorProcessor : BaseClassLevelCodeGeneratorProcessor<IEntityGenerationModel>
{

protected override bool GetWhetherClassShouldBePartialClass() => false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using Dhgms.Nucleotide.Generators.Generators;
using Dhgms.Nucleotide.Generators.Models;
using Microsoft.CodeAnalysis;

namespace Dhgms.Nucleotide.Generators.Features.Model
{
public abstract class KeyedModelInterfaceGenerator : BaseInterfaceLevelCodeGenerator<KeyedModelInterfaceFeatureFlags, KeyedModelInterfaceGeneratorProcessor>
public abstract class KeyedModelInterfaceGenerator : BaseInterfaceLevelCodeGenerator<KeyedModelInterfaceFeatureFlags, KeyedModelInterfaceGeneratorProcessor, IEntityGenerationModel>
{
protected override string GetNamespace()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Dhgms.Nucleotide.Generators.Features.Model
{
public sealed class KeyedModelInterfaceGeneratorProcessor : BaseInterfaceLevelCodeGeneratorProcessor
public sealed class KeyedModelInterfaceGeneratorProcessor : BaseInterfaceLevelCodeGeneratorProcessor<IEntityGenerationModel>
{
protected override string GetClassSuffix()
{
Expand Down
Loading

0 comments on commit 94826b1

Please sign in to comment.