-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(FluentSkippable): FluentSkippable attribute * feat(FluentSkippable): make SkippableMemberClass test work * refactor(BuilderStepMethodCreator): create static methods from BuilderStepMethods * refactor(BuilderStepMethodCreator): cleanup * feat(FluentSkippable): make SkippableFirstMemberClass test work * test: SkippableSeveralMembersClass * fix(SkippableSeveralMembersClass): remove blank line * feat(FluentSkippable): last step cannot be skipped diagnostic * test: add failing test SkippableLoopClass * Test(SkippableLoopClass): add expected code * test(SkippableLoopClass): add desired CreatedStudent.g.cs * feat(FluentSkippable): BuilderStepsGenerator new version * feat(FluentSkippable): loop handling classes * feat(FluentSkippable): make SkippableLoopClass test work * fix: remove obsolete EmptyInterfaceBuilderMethod class * refactor: rename BuilderStepsGeneration folder and namespace * fix: rename file * test: CanExecuteSkippableLoopClass * fix: rename FirstStepBuilderMethod and SingleStepBuilderMethod classes * test: TarjansSccAlgorithmTests * test: ContinueWithInForkClass * test: SkippableFirstTwoMembersClass * test: SkippableTwoLoopsClass * test: SkippableForkMembersClass * fix: address resharper warnings * feat(FluentSkippable): adjust examples and storybook * docs(Readme): add FluentSkippable * chore: increase nuget versions to 1.6.0
- Loading branch information
Showing
170 changed files
with
3,824 additions
and
932 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...entApi.Generator/CodeGeneration/CodeBoardActors/BuilderMethodsGeneration/BaseInterface.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace M31.FluentApi.Generator.CodeGeneration.CodeBoardActors.BuilderMethodsGeneration; | ||
|
||
internal class BaseInterface | ||
{ | ||
public BaseInterface(string name, int step) | ||
{ | ||
Name = name; | ||
Step = step; | ||
} | ||
|
||
public string Name { get; } | ||
public int Step { get; } | ||
} |
97 changes: 97 additions & 0 deletions
97
...Api.Generator/CodeGeneration/CodeBoardActors/BuilderMethodsGeneration/BuilderGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using M31.FluentApi.Generator.CodeBuilding; | ||
using M31.FluentApi.Generator.CodeGeneration.CodeBoardElements; | ||
|
||
namespace M31.FluentApi.Generator.CodeGeneration.CodeBoardActors.BuilderMethodsGeneration; | ||
|
||
internal class BuilderGenerator : ICodeBoardActor | ||
{ | ||
public void Modify(CodeBoard codeBoard) | ||
{ | ||
BuilderMethods builderMethods = | ||
BuilderMethodsCreator.CreateBuilderMethods(codeBoard.Forks, codeBoard.CancellationToken); | ||
|
||
foreach (BuilderStepMethod staticMethod in builderMethods.StaticMethods) | ||
{ | ||
if (codeBoard.CancellationToken.IsCancellationRequested) | ||
{ | ||
break; | ||
} | ||
|
||
Method method = CreateMethod(staticMethod, codeBoard); | ||
codeBoard.BuilderClass.AddMethod(method); | ||
} | ||
|
||
List<Interface> interfaces = new List<Interface>(builderMethods.Interfaces.Count); | ||
interfaces.Add(CreateInitialStepInterface(builderMethods, codeBoard)); | ||
|
||
foreach (BuilderInterface builderInterface in builderMethods.Interfaces) | ||
{ | ||
if (codeBoard.CancellationToken.IsCancellationRequested) | ||
{ | ||
break; | ||
} | ||
|
||
Interface @interface = | ||
new Interface(codeBoard.Info.DefaultAccessModifier, builderInterface.InterfaceName); | ||
|
||
foreach (InterfaceBuilderMethod interfaceMethod in builderInterface.Methods) | ||
{ | ||
Method method = CreateMethod(interfaceMethod, codeBoard); | ||
codeBoard.BuilderClass.AddMethod(method); | ||
@interface.AddMethodSignature(method.MethodSignature.ToSignatureForInterface()); | ||
} | ||
|
||
@interface.AddBaseInterfaces(builderInterface.BaseInterfaces); | ||
interfaces.Add(@interface); | ||
} | ||
|
||
AddInterfacesToBuilderClass( | ||
interfaces, | ||
codeBoard.BuilderClass, | ||
codeBoard.Info.BuilderClassNameWithTypeParameters); | ||
AddInterfaceDefinitionsToBuilderClass(interfaces, codeBoard.BuilderClass); | ||
} | ||
|
||
private Method CreateMethod(BuilderStepMethod builderStepMethod, CodeBoard codeBoard) | ||
{ | ||
ReservedVariableNames reservedVariableNames = codeBoard.ReservedVariableNames.NewLocalScope(); | ||
reservedVariableNames.ReserveLocalVariableNames(builderStepMethod.Parameters.Select(p => p.Name)); | ||
|
||
Method method = builderStepMethod.BuildMethodCode( | ||
codeBoard.Info, | ||
reservedVariableNames); | ||
|
||
return method; | ||
} | ||
|
||
private Interface CreateInitialStepInterface(BuilderMethods builderMethods, CodeBoard codeBoard) | ||
{ | ||
string? firstInterfaceName = builderMethods.Interfaces.FirstOrDefault()?.InterfaceName; | ||
|
||
Interface initialStepInterface = | ||
new Interface(codeBoard.Info.DefaultAccessModifier, codeBoard.Info.InitialStepInterfaceName); | ||
|
||
if (firstInterfaceName != null) | ||
{ | ||
initialStepInterface.AddBaseInterface(firstInterfaceName); | ||
} | ||
|
||
return initialStepInterface; | ||
} | ||
|
||
private void AddInterfacesToBuilderClass(List<Interface> interfaces, Class builderClass, string prefix) | ||
{ | ||
foreach (Interface @interface in interfaces) | ||
{ | ||
builderClass.AddInterface($"{prefix}.{@interface.Name}"); | ||
} | ||
} | ||
|
||
private void AddInterfaceDefinitionsToBuilderClass(List<Interface> interfaces, Class builderClass) | ||
{ | ||
foreach (Interface @interface in interfaces) | ||
{ | ||
builderClass.AddDefinition(@interface); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...Api.Generator/CodeGeneration/CodeBoardActors/BuilderMethodsGeneration/BuilderInterface.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace M31.FluentApi.Generator.CodeGeneration.CodeBoardActors.BuilderMethodsGeneration; | ||
|
||
internal class BuilderInterface | ||
{ | ||
internal BuilderInterface( | ||
string interfaceName, | ||
IReadOnlyCollection<string> baseInterfaces, | ||
IReadOnlyCollection<InterfaceBuilderMethod> methods) | ||
{ | ||
InterfaceName = interfaceName; | ||
BaseInterfaces = baseInterfaces; | ||
Methods = methods; | ||
} | ||
|
||
public string InterfaceName { get; } | ||
public IReadOnlyCollection<string> BaseInterfaces { get; } | ||
public IReadOnlyCollection<InterfaceBuilderMethod> Methods { get; } | ||
} |
56 changes: 56 additions & 0 deletions
56
...ntApi.Generator/CodeGeneration/CodeBoardActors/BuilderMethodsGeneration/BuilderMethods.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using M31.FluentApi.Generator.Commons; | ||
|
||
namespace M31.FluentApi.Generator.CodeGeneration.CodeBoardActors.BuilderMethodsGeneration; | ||
|
||
internal class BuilderMethods | ||
{ | ||
public BuilderMethods( | ||
IReadOnlyCollection<BuilderStepMethod> staticMethods, | ||
IReadOnlyCollection<BuilderInterface> interfaces) | ||
{ | ||
Interfaces = interfaces; | ||
StaticMethods = staticMethods; | ||
} | ||
|
||
internal IReadOnlyCollection<BuilderInterface> Interfaces { get; } | ||
internal IReadOnlyCollection<BuilderStepMethod> StaticMethods { get; } | ||
|
||
internal static IReadOnlyCollection<BuilderInterface> CreateInterfaces( | ||
IReadOnlyCollection<InterfaceBuilderMethod> interfaceMethods, | ||
CancellationToken cancellationToken) | ||
{ | ||
List<BuilderInterface> interfaces = new List<BuilderInterface>(); | ||
|
||
IGrouping<string, InterfaceBuilderMethod>[] methodsGroupedByInterface = | ||
interfaceMethods.GroupBy(m => m.InterfaceName).ToArray(); | ||
|
||
foreach (IGrouping<string, InterfaceBuilderMethod> group in methodsGroupedByInterface) | ||
{ | ||
if (cancellationToken.IsCancellationRequested) | ||
{ | ||
break; | ||
} | ||
|
||
string interfaceName = group.Key; | ||
|
||
List<BaseInterface> baseInterfaces = new List<BaseInterface>(); | ||
|
||
foreach (InterfaceBuilderMethod method in group) | ||
{ | ||
if (method.BaseInterface != null) | ||
{ | ||
baseInterfaces.Add(method.BaseInterface); | ||
} | ||
} | ||
|
||
string[] baseInterfaceNames = baseInterfaces | ||
.DistinctBy(i => i.Name) | ||
.OrderBy(i => i.Step) | ||
.Select(i => i.Name).ToArray(); | ||
|
||
interfaces.Add(new BuilderInterface(interfaceName, baseInterfaceNames, group.ToArray())); | ||
} | ||
|
||
return interfaces; | ||
} | ||
} |
Oops, something went wrong.