diff --git a/src/SuperFluid.Tests/DemoApiDefinition.fluid.yml b/src/DemoProject/DemoApiDefinition.fluid.yml similarity index 100% rename from src/SuperFluid.Tests/DemoApiDefinition.fluid.yml rename to src/DemoProject/DemoApiDefinition.fluid.yml diff --git a/src/DemoProject/DemoProject.csproj b/src/DemoProject/DemoProject.csproj new file mode 100644 index 0000000..72fb391 --- /dev/null +++ b/src/DemoProject/DemoProject.csproj @@ -0,0 +1,18 @@ + + + + Exe + net7.0 + enable + enable + + + + + + + + + + + diff --git a/src/DemoProject/Program.cs b/src/DemoProject/Program.cs new file mode 100644 index 0000000..a73d17d --- /dev/null +++ b/src/DemoProject/Program.cs @@ -0,0 +1,62 @@ +using SuperFluid.Tests.Cars; + +string builtString = Test.Initialize() + .Unlock() + .Enter() + .Start() + .Stop() + .Exit() + .Lock() + .Unlock() + .Enter() + .Start() + .Build(); + +Console.WriteLine(builtString); + +public class Test : ICarActor +{ + + private readonly List _calls = new(); + + public ICanUnlock Lock() + { + _calls.Add("Lock!"); + return this; + } + + public ICanStartOrExit Enter() + { + _calls.Add("Enter!"); + return this; + } + + + public ICanLockOrEnter Unlock() + { + _calls.Add("Unlock!"); + return this; + } + + public ICanStopOrBuild Start() + { + _calls.Add("Start!"); + return this; + } + + public ICanLockOrEnter Exit() + { + _calls.Add("Exit!"); + return this; + } + + public ICanStartOrExit Stop() + { + _calls.Add("Stop!"); + return this; + } + + public string Build() => string.Join('\n', _calls); + + public static ICanUnlock Initialize() => new Test(); +} diff --git a/src/SuperFluid.Tests/Parsers/FluidApiDefinitionParserTests.cs b/src/SuperFluid.Tests/Parsers/FluidApiDefinitionParserTests.cs index c3727a6..9942ee6 100644 --- a/src/SuperFluid.Tests/Parsers/FluidApiDefinitionParserTests.cs +++ b/src/SuperFluid.Tests/Parsers/FluidApiDefinitionParserTests.cs @@ -87,13 +87,6 @@ public class FluidApiDefinitionParserTests CanTransitionTo = new() }; - private readonly FluidApiMethodDefinition _build = new() - { - Name = "Build", - ReturnType = "string", - CanTransitionTo = new() - }; - [Fact] public void CanDeserializeSimpleCase() { diff --git a/src/SuperFluid.Tests/SuperFluid.Tests.csproj b/src/SuperFluid.Tests/SuperFluid.Tests.csproj index 71497ed..9fd9d11 100644 --- a/src/SuperFluid.Tests/SuperFluid.Tests.csproj +++ b/src/SuperFluid.Tests/SuperFluid.Tests.csproj @@ -7,7 +7,6 @@ false default Library - true @@ -31,10 +30,4 @@ - - - - - - diff --git a/src/SuperFluid.sln b/src/SuperFluid.sln index 26f2556..58691e4 100644 --- a/src/SuperFluid.sln +++ b/src/SuperFluid.sln @@ -4,6 +4,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperFluid", "SuperFluid\Su EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperFluid.Tests", "SuperFluid.Tests\SuperFluid.Tests.csproj", "{6C2B21F8-301C-4062-9C12-608DAF4C0E16}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DemoProject", "DemoProject\DemoProject.csproj", "{FA0C7E98-6910-4226-A706-B9B0A0D529A2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -22,5 +24,9 @@ Global {F49EE144-4D5A-4C5A-93ED-1BE64AFF5D7D}.Debug|Any CPU.Build.0 = Debug|Any CPU {F49EE144-4D5A-4C5A-93ED-1BE64AFF5D7D}.Release|Any CPU.ActiveCfg = Release|Any CPU {F49EE144-4D5A-4C5A-93ED-1BE64AFF5D7D}.Release|Any CPU.Build.0 = Release|Any CPU + {FA0C7E98-6910-4226-A706-B9B0A0D529A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FA0C7E98-6910-4226-A706-B9B0A0D529A2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FA0C7E98-6910-4226-A706-B9B0A0D529A2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FA0C7E98-6910-4226-A706-B9B0A0D529A2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/src/SuperFluid/Internal/Model/FluidApiMethod.cs b/src/SuperFluid/Internal/Model/FluidApiMethod.cs index b8b0234..db516d1 100644 --- a/src/SuperFluid/Internal/Model/FluidApiMethod.cs +++ b/src/SuperFluid/Internal/Model/FluidApiMethod.cs @@ -12,8 +12,8 @@ public FluidApiMethod(string name, string? returnType, IEnumerable CanTransitionTo { get; init; } = new(); } diff --git a/src/SuperFluid/Internal/Services/FluidGeneratorService.cs b/src/SuperFluid/Internal/Services/FluidGeneratorService.cs index 5cc229d..3988b60 100644 --- a/src/SuperFluid/Internal/Services/FluidGeneratorService.cs +++ b/src/SuperFluid/Internal/Services/FluidGeneratorService.cs @@ -23,10 +23,25 @@ public Dictionary Generate(string rawYml) FluidApiModel model = _definitionParser.Parse(definition); Dictionary newSourceFiles = model.States.ToDictionary(s => $"{s.Name}.fluid.g.cs", s => GenerateStateSource(s, model)); + + newSourceFiles.Add($"{model.Name}.fluid.g.cs", GenerateCompoundInterface(model)); return newSourceFiles; } + private string GenerateCompoundInterface(FluidApiModel model) + { + string source = $$""" + namespace {{model.Namespace}}; + + public interface {{model.Name}}: {{string.Join(',', model.States.Select(s => s.Name))}} + { + public static abstract {{model.InitializerMethodReturnState.Name}} {{model.InitialMethod.Name}}(); + } + """; + return source; + } + private string GenerateStateSource(FluidApiState fluidApiState, FluidApiModel model) { IEnumerable methodDeclarations = fluidApiState.MethodTransitions.Select(kvp