Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the issue with nested Invocation Expressions when generating AaC from CSharp #98

Merged
merged 4 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
49 changes: 31 additions & 18 deletions C4InterFlow.Automation/Writers/CSharpToAnyCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private static void HandleUsingStatement(
{
foreach (var variable in usingStatement.Declaration?.Variables)
{
foreach (var invocationExpression in variable.Initializer?.DescendantNodes().OfType<InvocationExpressionSyntax>().ToArray())
foreach (var invocationExpression in variable.Initializer?.DescendantNodes().OfType<InvocationExpressionSyntax>().Reverse())
{
var invocationExpressionBlockCode = HandleInvocationExpression(
invocationExpression,
Expand Down Expand Up @@ -283,32 +283,45 @@ private static void HandleReturnStatement(
}
else
{
foreach (var invocationExpression in returnStatement.DescendantNodes().OfType<InvocationExpressionSyntax>())
if (returnStatement.Expression is InvocationExpressionSyntax invocationExpression)
{
blockCode = HandleInvocationExpression(
invocationExpression,
methodDeclaration,
architectureAsCodeContext,
writer,
alternativeInvocationMappers);
invocationExpression,
methodDeclaration,
architectureAsCodeContext,
writer,
alternativeInvocationMappers);

if (!string.IsNullOrEmpty(blockCode))
{
break;
result.AppendLine(blockCode);
}
else
{
result.AppendLine(CodeWriter.GetReturnFlowCode(invocationExpression.Expression.ToFullString()));
}
}

if (!string.IsNullOrEmpty(blockCode))
{
result.AppendLine(blockCode);
}
else if (returnStatement.Expression is InvocationExpressionSyntax invocationExpression)
{
result.AppendLine(CodeWriter.GetReturnFlowCode(invocationExpression.Expression.ToFullString()));
}
else if (returnStatement.Expression is IdentifierNameSyntax identifierNameSyntax)
{
result.AppendLine(CodeWriter.GetReturnFlowCode(identifierNameSyntax.Identifier.Text));
}
else
{
foreach (var innerInvocationExpression in returnStatement.DescendantNodes().OfType<InvocationExpressionSyntax>().Reverse())
{
blockCode = HandleInvocationExpression(
innerInvocationExpression,
methodDeclaration,
architectureAsCodeContext,
writer,
alternativeInvocationMappers);

if (!string.IsNullOrEmpty(blockCode))
{
result.AppendLine(blockCode);
}
}
}
}
}

Expand Down Expand Up @@ -415,7 +428,7 @@ private static void HandleOtherStatements(
CSharpToAnyAaCWriter writer,
IEnumerable<NetToAnyAlternativeInvocationMapperConfig>? alternativeInvocationMappers = null)
{
foreach (var invocationExpression in statement.DescendantNodes().OfType<InvocationExpressionSyntax>())
foreach (var invocationExpression in statement.DescendantNodes().OfType<InvocationExpressionSyntax>().Reverse())
{
var blockCode = HandleInvocationExpression(
invocationExpression,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Text;
using System.Threading.Tasks;

namespace dotnet.eShop.Architecture.Cli
namespace DotNetEShop.Cli
{
public class CSharpToCSharpBasketApiAaCGenerator : CSharpToCSharpAaCWriterStrategy
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Text;
using System.Threading.Tasks;

namespace dotnet.eShop.Architecture.Cli
namespace DotNetEShop.Cli
{
public class CSharpToCSharpCatalogApiAaCGenerator : CSharpToCSharpAaCWriterStrategy
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Text;
using System.Threading.Tasks;

namespace dotnet.eShop.Architecture.Cli
namespace DotNetEShop.Cli
{
public class CSharpToYamlBasketApiAaCGenerator : CSharpToYamlAaCWriterStrategy
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Text;
using System.Threading.Tasks;

namespace dotnet.eShop.Architecture.Cli
namespace DotNetEShop.Cli
{
public class CSharpToYamlCatalogApiAaCGenerator : CSharpToYamlAaCWriterStrategy
{
Expand Down
23 changes: 23 additions & 0 deletions Samples/dotnet.eShop/DotNetEShop.Cli/DotNetEShop.Cli.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.8.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.8.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\C4InterFlow.Automation\C4InterFlow.Automation.csproj" />
<ProjectReference Include="..\DotNetEShop\DotNetEShop.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"dotnet.eShop.Architecture.Cli": {
"commandName": "Project",
"commandLineArgs": "execute-aac-strategy --aac-root-namespace \"dotnet.eShop.Architecture\" --aac-output-path \"C:\\C4InterFlow\\Samples\\dotnet.eShop\\dotnet.eShop.Architecture\\Yaml\" --aac-writer-strategy \"dotnet.eShop.Architecture.Cli.CSharpToYamlBasketApiAaCGenerator, dotnet.eShop.Architecture.Cli\" --params software-system-source-path=\"C:\\Data\\Projects\\C4InterFlow\\eShop-main\\src\\Basket.API\\Basket.API.csproj\" --params software-system-name=\"BasketApi\""
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Text.RegularExpressions;
using C4InterFlow.Automation.Writers;

namespace dotnet.eShop.Architecture.Cli
namespace DotNetEShop.Cli
{
internal class Utils
{
Expand Down
43 changes: 43 additions & 0 deletions Samples/dotnet.eShop/DotNetEShop.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34309.116
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetEShop", "DotNetEShop\DotNetEShop.csproj", "{F18C0E05-2B41-4508-B91D-3B84E0535E99}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetEShop.Cli", "DotNetEShop.Cli\DotNetEShop.Cli.csproj", "{0DEABC5C-3A2C-42FE-91B6-E326BA6CF65D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "C4InterFlow", "..\..\C4InterFlow\C4InterFlow.csproj", "{C7E5280A-0FD1-4916-BB13-7F57A5E5274B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "C4InterFlow.Automation", "..\..\C4InterFlow.Automation\C4InterFlow.Automation.csproj", "{E47ACFF1-7BAC-4538-9558-D7AA04939546}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F18C0E05-2B41-4508-B91D-3B84E0535E99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F18C0E05-2B41-4508-B91D-3B84E0535E99}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F18C0E05-2B41-4508-B91D-3B84E0535E99}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F18C0E05-2B41-4508-B91D-3B84E0535E99}.Release|Any CPU.Build.0 = Release|Any CPU
{0DEABC5C-3A2C-42FE-91B6-E326BA6CF65D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0DEABC5C-3A2C-42FE-91B6-E326BA6CF65D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0DEABC5C-3A2C-42FE-91B6-E326BA6CF65D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0DEABC5C-3A2C-42FE-91B6-E326BA6CF65D}.Release|Any CPU.Build.0 = Release|Any CPU
{C7E5280A-0FD1-4916-BB13-7F57A5E5274B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C7E5280A-0FD1-4916-BB13-7F57A5E5274B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C7E5280A-0FD1-4916-BB13-7F57A5E5274B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C7E5280A-0FD1-4916-BB13-7F57A5E5274B}.Release|Any CPU.Build.0 = Release|Any CPU
{E47ACFF1-7BAC-4538-9558-D7AA04939546}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E47ACFF1-7BAC-4538-9558-D7AA04939546}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E47ACFF1-7BAC-4538-9558-D7AA04939546}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E47ACFF1-7BAC-4538-9558-D7AA04939546}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2C727580-ED93-4CC0-9CAF-A1DFE0590CB4}
EndGlobalSection
EndGlobal
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
@startuml
!include .c4s\C4_Component.puml

AddElementTag("c4interflow:lifecycle:new", $bgColor=green, $fontColor=#ffffff, $borderColor=green, $shadowing="False")
AddElementTag("c4interflow:lifecycle:changed", $bgColor=orange, $fontColor=#ffffff, $borderColor=orange, $shadowing="False")
AddElementTag("c4interflow:lifecycle:removed", $bgColor=red, $fontColor=#ffffff, $borderColor=red, $shadowing="False")

AddRelTag("c4interflow:lifecycle:new", $textColor=green, $lineColor=green)
AddRelTag("c4interflow:lifecycle:changed", $textColor=orange, $lineColor=orange)
AddRelTag("c4interflow:lifecycle:removed", $textColor=red, $lineColor=red)

SHOW_PERSON_PORTRAIT()
LAYOUT_TOP_DOWN()

skinparam linetype polyline

title All Software Systems - C4 Static - Component level


System_Boundary(DotNetEShop.SoftwareSystems.BasketApi, "Basket Api") {

Container_Boundary(DotNetEShop.SoftwareSystems.BasketApi.Containers.Data, "Data") {
Component(DotNetEShop.SoftwareSystems.BasketApi.Containers.Data.Components.RedisBasketRepository, "Redis Basket Repository", "", "")
Component(DotNetEShop.SoftwareSystems.BasketApi.Containers.Data.Components.RedisDatabase, "Redis Database", "", "")
}

Container_Boundary(DotNetEShop.SoftwareSystems.BasketApi.Containers.Grpc, "Grpc") {
Component(DotNetEShop.SoftwareSystems.BasketApi.Containers.Grpc.Components.BasketService, "Basket Service", "", "")
}
}

System_Boundary(DotNetEShop.SoftwareSystems.CatalogApi, "Catalog Api") {

Container_Boundary(DotNetEShop.SoftwareSystems.CatalogApi.Containers.Api, "Api") {
Component(DotNetEShop.SoftwareSystems.CatalogApi.Containers.Api.Components.CatalogApi, "Catalog Api", "", "")
}

Container_Boundary(DotNetEShop.SoftwareSystems.CatalogApi.Containers.Infrastructure, "Infrastructure") {
Component(DotNetEShop.SoftwareSystems.CatalogApi.Containers.Infrastructure.Components.CatalogContext, "Catalog Context", "", "")
}
}

Rel(DotNetEShop.SoftwareSystems.BasketApi.Containers.Data.Components.RedisBasketRepository, DotNetEShop.SoftwareSystems.BasketApi.Containers.Data.Components.RedisDatabase, "Uses")
Rel(DotNetEShop.SoftwareSystems.BasketApi.Containers.Grpc.Components.BasketService, DotNetEShop.SoftwareSystems.BasketApi.Containers.Data.Components.RedisBasketRepository, "Uses")
Rel(DotNetEShop.SoftwareSystems.CatalogApi.Containers.Api.Components.CatalogApi, DotNetEShop.SoftwareSystems.CatalogApi.Containers.Infrastructure.Components.CatalogContext, "Uses")


SHOW_LEGEND()
@enduml
Loading