Skip to content

Commit fa2e057

Browse files
authored
Merge pull request #922 from FirelyTeam/copilot/fix-921
Fix generated C# to correctly attribute functions vs expressions and implement functional DefinitionFilter approach
2 parents 9eec403 + d5f171f commit fa2e057

File tree

140 files changed

+2332
-2105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+2332
-2105
lines changed

Cql/CodeGeneration.NET/LibrarySetCSharpCodeGenerator.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -258,42 +258,51 @@ private void WriteNamespaceFileScope()
258258

259259
private void WriteMethods()
260260
{
261-
string lastDefinitionType = "";
261+
string lastDefinitionRegion = "";
262262

263263
// Assumption: definitions are already sorted by definition type
264264
foreach (var definition in Definitions)
265265
{
266266
// Assumption: type name will be Cql....Definition
267267
Debug.Assert(definition.GetType().Name is { } name && name.StartsWith("Cql") && name.EndsWith("Definition"));
268-
string definitionType = definition.GetType().Name["Cql".Length..^"Definition".Length];
268+
string definitionRegion =
269+
definition switch
270+
{
271+
// CqlFunctionDefinition is a CqlExpressionDefinition
272+
// We combine them into one region otherwise we would have too many segments switching between Function and Expression
273+
CqlExpressionDefinition => "Functions and Expressions",
274+
275+
// Extract the region name from the definition type name e.g. Cql[Parameter]Definition => Parameters
276+
_ => $"{definition.GetType().Name["Cql".Length..^"Definition".Length]}s"
277+
};
269278

270-
if (lastDefinitionType != definitionType)
279+
if (lastDefinitionRegion != definitionRegion)
271280
{
272-
if (lastDefinitionType != "")
281+
if (lastDefinitionRegion != "")
273282
{
274283
IndentedTextWriter.WriteLine($"""
275-
#endregion {lastDefinitionType}s
284+
#endregion {lastDefinitionRegion}
276285
277286
""");
278287
}
279288

280289
IndentedTextWriter.WriteLine($"""
281-
#region {definitionType}s
290+
#region {definitionRegion}
282291
283292
""");
284293
}
285294

286-
lastDefinitionType = definitionType;
295+
lastDefinitionRegion = definitionRegion;
287296

288297
var methodWriter = new DefinitionWriter(this, definition);
289298
methodWriter.WriteDefinition();
290299
IndentedTextWriter.WriteLine();
291300
}
292301

293-
if (lastDefinitionType != "")
302+
if (lastDefinitionRegion != "")
294303
{
295304
IndentedTextWriter.WriteLine($"""
296-
#endregion {lastDefinitionType}s
305+
#endregion {lastDefinitionRegion}
297306
298307
""");
299308
}

Cql/CoreTests/CSharp/ConceptDefTest-1.0.0.g.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private ConceptDefTest_1_0_0() {}
8181

8282
#endregion Concepts
8383

84-
#region Expressions
84+
#region Functions and Expressions
8585

8686
[CqlExpressionDefinition("Patient")]
8787
public Patient Patient(CqlContext context)
@@ -93,6 +93,6 @@ public Patient Patient(CqlContext context)
9393
}
9494

9595

96-
#endregion Expressions
96+
#endregion Functions and Expressions
9797

9898
}

Cql/CoreTests/CSharp/CqlBooleanTest-1.0.000.g.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private CqlBooleanTest_1_0_000() {}
2828

2929
#endregion ILibrary Implementation
3030

31-
#region Expressions
31+
#region Functions and Expressions
3232

3333
[CqlExpressionDefinition("SomethingTrueEqualsTrue")]
3434
public bool? SomethingTrueEqualsTrue(CqlContext context)
@@ -40,6 +40,6 @@ private CqlBooleanTest_1_0_000() {}
4040
}
4141

4242

43-
#endregion Expressions
43+
#endregion Functions and Expressions
4444

4545
}

Cql/CoreTests/CSharp/CqlNestedTupleTest-1.0.0.g.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private CqlNestedTupleTest_1_0_0() {}
2828

2929
#endregion ILibrary Implementation
3030

31-
#region Expressions
31+
#region Functions and Expressions
3232

3333
[CqlExpressionDefinition("Result")]
3434
public (CqlTupleMetadata, string status, (CqlTupleMetadata, string result1, string result2)? result)? Result(CqlContext context)
@@ -40,7 +40,7 @@ private CqlNestedTupleTest_1_0_0() {}
4040
}
4141

4242

43-
#endregion Expressions
43+
#endregion Functions and Expressions
4444

4545
#region CqlTupleMetadata Properties
4646

0 commit comments

Comments
 (0)