Skip to content

Commit 6ee629e

Browse files
[WIP] Reference property with ValueLiteral supported
1 parent a27b1b4 commit 6ee629e

13 files changed

Lines changed: 117 additions & 22 deletions

SysML2.NET.CodeGenerator.Tests/Generators/UmlHandleBarsGenerators/UmlCoreTextualNotationBuilderGeneratorTestFixture.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ namespace SysML2.NET.CodeGenerator.Tests.Generators.UmlHandleBarsGenerators
3030
using SysML2.NET.CodeGenerator.Grammar;
3131
using SysML2.NET.CodeGenerator.Grammar.Model;
3232

33-
using uml4net.CommonStructure;
34-
3533
[TestFixture]
3634
public class UmlCoreTextualNotationBuilderGeneratorTestFixture
3735
{

SysML2.NET.CodeGenerator/Grammar/Model/ValueLiteralElement.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public class ValueLiteralElement: RuleElement
2828
/// <summary>
2929
/// Gets or sets the literal value
3030
/// </summary>
31-
public string Value { get; set; }
31+
public string Value { get; init; }
32+
33+
/// <summary>
34+
/// Asserts that this value literal is to
35+
/// </summary>
36+
/// <returns></returns>
37+
public bool QueryIsQualifiedName() => this.Value == "[QualifiedName]";
3238
}
3339
}

SysML2.NET.CodeGenerator/HandleBarHelpers/RulesHelper.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,11 @@ private static void ProcessRuleElement(EncodedTextWriter writer, IClass umlClass
290290
}
291291
else
292292
{
293+
var targetPropertyName = targetProperty.QueryPropertyNameBasedOnUmlProperties();
294+
293295
if (targetProperty.QueryIsString())
294296
{
295-
writer.WriteSafeString($"stringBuilder.Append(poco.{targetProperty.Name.CapitalizeFirstLetter()});");
297+
writer.WriteSafeString($"stringBuilder.Append(poco.{targetPropertyName});");
296298
}
297299
else if (targetProperty.QueryIsBool())
298300
{
@@ -302,22 +304,30 @@ private static void ProcessRuleElement(EncodedTextWriter writer, IClass umlClass
302304
}
303305
else
304306
{
305-
writer.WriteSafeString($"stringBuilder.Append(poco.{targetProperty.QueryPropertyNameBasedOnUmlProperties()}.ToString().ToLower());");
307+
writer.WriteSafeString($"stringBuilder.Append(poco.{targetPropertyName}.ToString().ToLower());");
306308
}
307309
}
308310
else if (targetProperty.QueryIsEnum())
309311
{
310-
writer.WriteSafeString($"stringBuilder.Append(poco.{targetProperty.Name.CapitalizeFirstLetter()}.ToString().ToLower());");
312+
writer.WriteSafeString($"stringBuilder.Append(poco.{targetPropertyName}.ToString().ToLower());");
311313
}
312314
else if(targetProperty.QueryIsReferenceProperty())
313315
{
314316
if (assignmentElement.Value is NonTerminalElement nonTerminalElement)
315317
{
316318
var previousCaller = ruleGenerationContext.CallerRule;
317319
ruleGenerationContext.CallerRule = nonTerminalElement;
318-
ProcessNonTerminalElement(writer, targetProperty.Type as IClass, nonTerminalElement, $"poco.{targetProperty.QueryPropertyNameBasedOnUmlProperties()}", ruleGenerationContext);
320+
ProcessNonTerminalElement(writer, targetProperty.Type as IClass, nonTerminalElement, $"poco.{targetPropertyName}", ruleGenerationContext);
319321
ruleGenerationContext.CallerRule = previousCaller;
320322
}
323+
else if (assignmentElement.Value is ValueLiteralElement valueLiteralElement && valueLiteralElement.QueryIsQualifiedName())
324+
{
325+
writer.WriteSafeString($"{Environment.NewLine}if (poco.{targetPropertyName} != null){Environment.NewLine}");
326+
writer.WriteSafeString($"{{{Environment.NewLine}");
327+
writer.WriteSafeString($"stringBuilder.Append(poco.{targetPropertyName}.qualifiedName);{Environment.NewLine}");
328+
writer.WriteSafeString("stringBuilder.Append(' ');");
329+
writer.WriteSafeString($"{Environment.NewLine}}}");
330+
}
321331
else
322332
{
323333
writer.WriteSafeString("throw new System.NotSupportedException(\"Assigment of reference element not supported yet for this case\");");
@@ -340,7 +350,15 @@ private static void ProcessRuleElement(EncodedTextWriter writer, IClass umlClass
340350
writer.WriteSafeString($"// NonParsing Assignment Element : {nonParsingAssignmentElement.PropertyName} {nonParsingAssignmentElement.Operator} {nonParsingAssignmentElement.Value} => Does not have to be process");
341351
break;
342352
case ValueLiteralElement valueLiteralElement:
343-
writer.WriteSafeString(valueLiteralElement.Value == "[QualifiedName]" ? "stringBuilder.Append(poco.qualifiedName);" : "throw new System.NotSupportedException(\"Value Literal different than QualifiedName not supported\");");
353+
if (valueLiteralElement.QueryIsQualifiedName())
354+
{
355+
writer.WriteSafeString($"stringBuilder.Append(poco.qualifiedName);{Environment.NewLine}");
356+
writer.WriteSafeString("stringBuilder.Append(' ');");
357+
}
358+
else
359+
{
360+
writer.WriteSafeString("throw new System.NotSupportedException(\"Value Literal different than QualifiedName not supported\");");
361+
}
344362

345363
break;
346364
default:

SysML2.NET/TextualNotation/AutoGenTextualNotationBuilder/AnnotationTextualNotationBuilder.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ public static void BuildPrefixMetadataAnnotation(SysML2.NET.Core.POCO.Root.Annot
8585
/// <param name="stringBuilder">The <see cref="StringBuilder" /> that contains the entire textual notation</param>
8686
public static void BuildAnnotation(SysML2.NET.Core.POCO.Root.Annotations.IAnnotation poco, StringBuilder stringBuilder)
8787
{
88-
throw new System.NotSupportedException("Assigment of reference element not supported yet for this case");
88+
89+
if (poco.AnnotatedElement != null)
90+
{
91+
stringBuilder.Append(poco.AnnotatedElement.qualifiedName);
92+
stringBuilder.Append(' ');
93+
}
8994

9095
}
9196
}

SysML2.NET/TextualNotation/AutoGenTextualNotationBuilder/FeatureChainingTextualNotationBuilder.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ public static partial class FeatureChainingTextualNotationBuilder
4242
/// <param name="stringBuilder">The <see cref="StringBuilder" /> that contains the entire textual notation</param>
4343
public static void BuildOwnedFeatureChaining(SysML2.NET.Core.POCO.Core.Features.IFeatureChaining poco, StringBuilder stringBuilder)
4444
{
45-
throw new System.NotSupportedException("Assigment of reference element not supported yet for this case");
45+
46+
if (poco.ChainingFeature != null)
47+
{
48+
stringBuilder.Append(poco.ChainingFeature.qualifiedName);
49+
stringBuilder.Append(' ');
50+
}
4651

4752
}
4853
}

SysML2.NET/TextualNotation/AutoGenTextualNotationBuilder/FeatureTextualNotationBuilder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ public static void BuildFunctionReferenceArgument(SysML2.NET.Core.POCO.Core.Feat
729729
public static void BuildFeatureReference(SysML2.NET.Core.POCO.Core.Features.IFeature poco, StringBuilder stringBuilder)
730730
{
731731
stringBuilder.Append(poco.qualifiedName);
732+
stringBuilder.Append(' ');
732733

733734
}
734735

SysML2.NET/TextualNotation/AutoGenTextualNotationBuilder/FeatureTypingTextualNotationBuilder.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ public static void BuildOwnedFeatureTyping(SysML2.NET.Core.POCO.Core.Features.IF
5353
/// <param name="stringBuilder">The <see cref="StringBuilder" /> that contains the entire textual notation</param>
5454
public static void BuildReferenceTyping(SysML2.NET.Core.POCO.Core.Features.IFeatureTyping poco, StringBuilder stringBuilder)
5555
{
56-
throw new System.NotSupportedException("Assigment of reference element not supported yet for this case");
56+
57+
if (poco.Type != null)
58+
{
59+
stringBuilder.Append(poco.Type.qualifiedName);
60+
stringBuilder.Append(' ');
61+
}
5762

5863
}
5964

SysML2.NET/TextualNotation/AutoGenTextualNotationBuilder/MembershipImportTextualNotationBuilder.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ public static partial class MembershipImportTextualNotationBuilder
4242
/// <param name="stringBuilder">The <see cref="StringBuilder" /> that contains the entire textual notation</param>
4343
public static void BuildMembershipImport(SysML2.NET.Core.POCO.Root.Namespaces.IMembershipImport poco, StringBuilder stringBuilder)
4444
{
45-
throw new System.NotSupportedException("Assigment of reference element not supported yet for this case");
45+
46+
if (poco.ImportedMembership != null)
47+
{
48+
stringBuilder.Append(poco.ImportedMembership.qualifiedName);
49+
stringBuilder.Append(' ');
50+
}
4651

4752
if (poco.IsRecursive)
4853
{

SysML2.NET/TextualNotation/AutoGenTextualNotationBuilder/MembershipTextualNotationBuilder.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ public static void BuildAliasMember(SysML2.NET.Core.POCO.Root.Namespaces.IMember
7979
}
8080

8181
stringBuilder.Append("for ");
82-
throw new System.NotSupportedException("Assigment of reference element not supported yet for this case");
82+
83+
if (poco.MemberElement != null)
84+
{
85+
stringBuilder.Append(poco.MemberElement.qualifiedName);
86+
stringBuilder.Append(' ');
87+
}
8388
RelationshipTextualNotationBuilder.BuildRelationshipBody(poco, stringBuilder);
8489

8590
}
@@ -107,6 +112,7 @@ public static void BuildFeatureReferenceMember(SysML2.NET.Core.POCO.Root.Namespa
107112
if (poco.MemberElement != null)
108113
{
109114
stringBuilder.Append(poco.qualifiedName);
115+
stringBuilder.Append(' ');
110116

111117
}
112118

@@ -120,7 +126,12 @@ public static void BuildFeatureReferenceMember(SysML2.NET.Core.POCO.Root.Namespa
120126
/// <param name="stringBuilder">The <see cref="StringBuilder" /> that contains the entire textual notation</param>
121127
public static void BuildElementReferenceMember(SysML2.NET.Core.POCO.Root.Namespaces.IMembership poco, StringBuilder stringBuilder)
122128
{
123-
throw new System.NotSupportedException("Assigment of reference element not supported yet for this case");
129+
130+
if (poco.MemberElement != null)
131+
{
132+
stringBuilder.Append(poco.MemberElement.qualifiedName);
133+
stringBuilder.Append(' ');
134+
}
124135

125136
}
126137

SysML2.NET/TextualNotation/AutoGenTextualNotationBuilder/RedefinitionTextualNotationBuilder.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ public static void BuildOwnedRedefinition(SysML2.NET.Core.POCO.Core.Features.IRe
5353
/// <param name="stringBuilder">The <see cref="StringBuilder" /> that contains the entire textual notation</param>
5454
public static void BuildFlowFeatureRedefinition(SysML2.NET.Core.POCO.Core.Features.IRedefinition poco, StringBuilder stringBuilder)
5555
{
56-
throw new System.NotSupportedException("Assigment of reference element not supported yet for this case");
56+
57+
if (poco.RedefinedFeature != null)
58+
{
59+
stringBuilder.Append(poco.RedefinedFeature.qualifiedName);
60+
stringBuilder.Append(' ');
61+
}
5762

5863
}
5964

@@ -65,7 +70,12 @@ public static void BuildFlowFeatureRedefinition(SysML2.NET.Core.POCO.Core.Featur
6570
/// <param name="stringBuilder">The <see cref="StringBuilder" /> that contains the entire textual notation</param>
6671
public static void BuildParameterRedefinition(SysML2.NET.Core.POCO.Core.Features.IRedefinition poco, StringBuilder stringBuilder)
6772
{
68-
throw new System.NotSupportedException("Assigment of reference element not supported yet for this case");
73+
74+
if (poco.RedefinedFeature != null)
75+
{
76+
stringBuilder.Append(poco.RedefinedFeature.qualifiedName);
77+
stringBuilder.Append(' ');
78+
}
6979

7080
}
7181

0 commit comments

Comments
 (0)