Skip to content

Commit 26883c1

Browse files
[WIP] Supports multiple alternatives with NonTerminal & Assignment + Terminal & Assignment
1 parent aa7c0ac commit 26883c1

File tree

10 files changed

+540
-71
lines changed

10 files changed

+540
-71
lines changed

SysML2.NET.CodeGenerator/HandleBarHelpers/RulesHelper.cs

Lines changed: 138 additions & 38 deletions
Large diffs are not rendered by default.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// -------------------------------------------------------------------------------------------------
2+
// <copyright file="FeatureMembership.cs" company="Starion Group S.A.">
3+
//
4+
// Copyright 2022-2026 Starion Group S.A.
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// </copyright>
19+
// ------------------------------------------------------------------------------------------------
20+
21+
namespace SysML2.NET.Core.POCO.Core.Types
22+
{
23+
using System.Linq;
24+
25+
using SysML2.NET.Core.POCO.Root.Elements;
26+
using SysML2.NET.Core.POCO.Systems.Connections;
27+
using SysML2.NET.Core.POCO.Systems.DefinitionAndUsage;
28+
using SysML2.NET.Core.POCO.Systems.Occurrences;
29+
30+
/// <summary>
31+
/// A FeatureMembership is an OwningMembership between an ownedMemberFeature and an owningType. If the
32+
/// ownedMemberFeature has isVariable = false, then the FeatureMembership implies that the owningType is
33+
/// also a featuringType of the ownedMemberFeature. If the ownedMemberFeature has isVariable = true,
34+
/// then the FeatureMembership implies that the ownedMemberFeature is featured by the snapshots of the
35+
/// owningType, which must specialize the Kernel Semantic Library base class Occurrence.
36+
/// </summary>
37+
public partial class FeatureMembership
38+
{
39+
/// <summary>
40+
/// Asserts that this <see cref="FeatureMembership" /> contais at least <see cref="ISuccessionAsUsage" /> element into the
41+
/// <see cref="OwnedRelatedElement" /> collection
42+
/// </summary>
43+
/// <returns>True if it contains one <see cref="ISuccessionAsUsage" /></returns>
44+
internal bool IsValidForSourceSuccessionMember()
45+
{
46+
return this.HasRelatedElementOfType<ISuccessionAsUsage>();
47+
}
48+
49+
/// <summary>
50+
/// Asserts that this <see cref="FeatureMembership" /> contais at least <see cref="IUsage" /> element into the
51+
/// <see cref="OwnedRelatedElement" /> collection but none of them are <see cref="IOccurrenceUsage" />
52+
/// </summary>
53+
/// <returns>True if it contains one <see cref="IUsage" /> but no <see cref="IOccurrenceUsage" /></returns>
54+
internal bool IsValidForNonOccurrenceUsageMember()
55+
{
56+
return !this.IsValidForOccurrenceUsageMember() && this.HasRelatedElementOfType<IUsage>();
57+
}
58+
59+
/// <summary>
60+
/// Asserts that this <see cref="FeatureMembership" /> contais at least <see cref="IOccurrenceUsage" /> element into the
61+
/// <see cref="OwnedRelatedElement" /> collection
62+
/// </summary>
63+
/// <returns>True if it contains one <see cref="IOccurrenceUsage" /></returns>
64+
internal bool IsValidForOccurrenceUsageMember()
65+
{
66+
return this.HasRelatedElementOfType<IOccurrenceUsage>();
67+
}
68+
69+
/// <summary>
70+
/// Asserts that the <see cref="OwnedRelatedElement" /> contains at least one <typeparamref name="T" /> element
71+
/// </summary>
72+
/// <typeparam name="T">Any <see cref="IElement" /></typeparam>
73+
/// <returns>True if the <see cref="OwnedRelatedElement" /> contains one <typeparamref name="T" /> element </returns>
74+
private bool HasRelatedElementOfType<T>() where T : IElement
75+
{
76+
return this.OwnedRelatedElement.OfType<T>().Any();
77+
}
78+
}
79+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// -------------------------------------------------------------------------------------------------
2+
// <copyright file="OwningMembership.cs" company="Starion Group S.A.">
3+
//
4+
// Copyright 2022-2026 Starion Group S.A.
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// </copyright>
19+
// ------------------------------------------------------------------------------------------------
20+
21+
namespace SysML2.NET.Core.POCO.Root.Namespaces
22+
{
23+
using System.Linq;
24+
25+
using SysML2.NET.Core.POCO.Core.Features;
26+
27+
/// <summary>
28+
/// An OwningMembership is a Membership that owns its memberElement as a ownedRelatedElement. The
29+
/// ownedMemberElement becomes an ownedMember of the membershipOwningNamespace.
30+
/// </summary>
31+
public partial class OwningMembership
32+
{
33+
/// <summary>
34+
/// Asserts that the current <see cref="OwningMembership"/> contains at least one <see cref="IFeature" /> inside the <see cref="OwnedRelatedElement"/> collection
35+
/// </summary>
36+
/// <returns>True if one <see cref="IFeature"/> is contained into the <see cref="OwnedRelatedElement"/></returns>
37+
internal bool IsValidForNonFeatureMember()
38+
{
39+
return this.OwnedRelatedElement.OfType<IFeature>().Any();
40+
}
41+
42+
/// <summary>
43+
/// Asserts that the current <see cref="OwningMembership"/> does not contains any <see cref="IFeature" /> inside the <see cref="OwnedRelatedElement"/> collection
44+
/// </summary>
45+
/// <returns>True if none <see cref="IFeature"/> is contained into the <see cref="OwnedRelatedElement"/></returns>
46+
internal bool IsValidForFeatureMember()
47+
{
48+
return !this.IsValidForNonFeatureMember();
49+
}
50+
}
51+
}

SysML2.NET/TextualNotation/AutoGenTextualNotationBuilder/FeatureTextualNotationBuilder.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,6 @@ public static void BuildChainingPart(SysML2.NET.Core.POCO.Core.Features.IFeature
569569
{
570570
using var ownedRelationshipOfFeatureChainingIterator = poco.OwnedRelationship.OfType<SysML2.NET.Core.POCO.Core.Features.FeatureChaining>().GetEnumerator();
571571
stringBuilder.Append("chains ");
572-
573572
if (ownedRelationshipOfFeatureChainingIterator.MoveNext())
574573
{
575574

SysML2.NET/TextualNotation/AutoGenTextualNotationBuilder/InvariantTextualNotationBuilder.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,15 @@ public static void BuildInvariant(SysML2.NET.Core.POCO.Kernel.Functions.IInvaria
5757
}
5858

5959
stringBuilder.Append("inv ");
60-
throw new System.NotSupportedException("Multiple alternatives with only one of the different type not implemented yet - TerminalElement,AssignmentElement");
60+
if (!poco.IsNegated)
61+
{
62+
stringBuilder.Append("true ");
63+
64+
}
65+
else
66+
{
67+
stringBuilder.Append(" false ");
68+
}
6169
FeatureTextualNotationBuilder.BuildFeatureDeclaration(poco, stringBuilder);
6270
FeatureTextualNotationBuilder.BuildValuePart(poco, stringBuilder);
6371
TypeTextualNotationBuilder.BuildFunctionBody(poco, stringBuilder);

SysML2.NET/TextualNotation/AutoGenTextualNotationBuilder/InvocationExpressionTextualNotationBuilder.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,26 @@ public static void BuildFunctionOperationExpression(SysML2.NET.Core.POCO.Kernel.
5858
{
5959
BuildInvocationTypeMember(ownedRelationshipOfInvocationExpressionIterator.Current, stringBuilder);
6060
}
61-
throw new System.NotSupportedException("Multiple alternatives with only one of the different type not implemented yet - AssignmentElement,NonTerminalElement");
61+
if (ownedRelationshipOfParameterMembershipIterator.MoveNext())
62+
{
63+
64+
if (ownedRelationshipOfParameterMembershipIterator.Current != null)
65+
{
66+
ParameterMembershipTextualNotationBuilder.BuildBodyArgumentMember(ownedRelationshipOfParameterMembershipIterator.Current, stringBuilder);
67+
}
68+
}
69+
else if (ownedRelationshipOfParameterMembershipIterator.MoveNext())
70+
{
71+
72+
if (ownedRelationshipOfParameterMembershipIterator.Current != null)
73+
{
74+
ParameterMembershipTextualNotationBuilder.BuildFunctionReferenceArgumentMember(ownedRelationshipOfParameterMembershipIterator.Current, stringBuilder);
75+
}
76+
}
77+
else
78+
{
79+
FeatureTextualNotationBuilder.BuildArgumentList(poco, stringBuilder);
80+
}
6281
stringBuilder.Append(' ');
6382
ownedRelationshipOfReturnParameterMembershipIterator.MoveNext();
6483

SysML2.NET/TextualNotation/AutoGenTextualNotationBuilder/TypeTextualNotationBuilder.cs

Lines changed: 95 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,22 @@ public static void BuildCalculationBodyPart(SysML2.NET.Core.POCO.Core.Types.ITyp
154154
/// <param name="stringBuilder">The <see cref="StringBuilder" /> that contains the entire textual notation</param>
155155
public static void BuildCalculationBodyItem(SysML2.NET.Core.POCO.Core.Types.IType poco, StringBuilder stringBuilder)
156156
{
157-
throw new System.NotSupportedException("Multiple alternatives with only one of the different type not implemented yet - NonTerminalElement,AssignmentElement");
157+
var ownedRelationship = poco.OwnedRelationship.ToList();
158+
159+
for (var ownedRelationshipIndex = 0; ownedRelationshipIndex < ownedRelationship.Count; ownedRelationshipIndex++)
160+
{
161+
var ownedRelationshipElement = ownedRelationship[ownedRelationshipIndex];
162+
163+
switch (ownedRelationshipElement)
164+
{
165+
case SysML2.NET.Core.POCO.Kernel.Functions.ReturnParameterMembership returnParameterMembership:
166+
ReturnParameterMembershipTextualNotationBuilder.BuildReturnParameterMember(returnParameterMembership, stringBuilder); break;
167+
default:
168+
ownedRelationshipIndex = BuildActionBodyItem(ownedRelationshipIndex, ownedRelationship, stringBuilder);
169+
break;
170+
171+
}
172+
}
158173
}
159174

160175
/// <summary>
@@ -176,7 +191,32 @@ public static void BuildRequirementBody(SysML2.NET.Core.POCO.Core.Types.IType po
176191
/// <param name="stringBuilder">The <see cref="StringBuilder" /> that contains the entire textual notation</param>
177192
public static void BuildRequirementBodyItem(SysML2.NET.Core.POCO.Core.Types.IType poco, StringBuilder stringBuilder)
178193
{
179-
throw new System.NotSupportedException("Multiple alternatives with only one of the different type not implemented yet - NonTerminalElement,AssignmentElement");
194+
var ownedRelationship = poco.OwnedRelationship.ToList();
195+
196+
for (var ownedRelationshipIndex = 0; ownedRelationshipIndex < ownedRelationship.Count; ownedRelationshipIndex++)
197+
{
198+
var ownedRelationshipElement = ownedRelationship[ownedRelationshipIndex];
199+
200+
switch (ownedRelationshipElement)
201+
{
202+
case SysML2.NET.Core.POCO.Systems.Requirements.SubjectMembership subjectMembership:
203+
SubjectMembershipTextualNotationBuilder.BuildSubjectMember(subjectMembership, stringBuilder); break;
204+
case SysML2.NET.Core.POCO.Systems.Requirements.RequirementConstraintMembership requirementConstraintMembership:
205+
RequirementConstraintMembershipTextualNotationBuilder.BuildRequirementConstraintMember(requirementConstraintMembership, stringBuilder); break;
206+
case SysML2.NET.Core.POCO.Systems.Requirements.FramedConcernMembership framedConcernMembership:
207+
FramedConcernMembershipTextualNotationBuilder.BuildFramedConcernMember(framedConcernMembership, stringBuilder); break;
208+
case SysML2.NET.Core.POCO.Systems.VerificationCases.RequirementVerificationMembership requirementVerificationMembership:
209+
RequirementVerificationMembershipTextualNotationBuilder.BuildRequirementVerificationMember(requirementVerificationMembership, stringBuilder); break;
210+
case SysML2.NET.Core.POCO.Systems.Requirements.ActorMembership actorMembership:
211+
ActorMembershipTextualNotationBuilder.BuildActorMember(actorMembership, stringBuilder); break;
212+
case SysML2.NET.Core.POCO.Systems.Requirements.StakeholderMembership stakeholderMembership:
213+
StakeholderMembershipTextualNotationBuilder.BuildStakeholderMember(stakeholderMembership, stringBuilder); break;
214+
default:
215+
ownedRelationshipIndex = BuildDefinitionBodyItem(ownedRelationshipIndex, ownedRelationship, stringBuilder);
216+
break;
217+
218+
}
219+
}
180220
}
181221

182222
/// <summary>
@@ -198,7 +238,26 @@ public static void BuildCaseBody(SysML2.NET.Core.POCO.Core.Types.IType poco, Str
198238
/// <param name="stringBuilder">The <see cref="StringBuilder" /> that contains the entire textual notation</param>
199239
public static void BuildCaseBodyItem(SysML2.NET.Core.POCO.Core.Types.IType poco, StringBuilder stringBuilder)
200240
{
201-
throw new System.NotSupportedException("Multiple alternatives with only one of the different type not implemented yet - NonTerminalElement,AssignmentElement");
241+
var ownedRelationship = poco.OwnedRelationship.ToList();
242+
243+
for (var ownedRelationshipIndex = 0; ownedRelationshipIndex < ownedRelationship.Count; ownedRelationshipIndex++)
244+
{
245+
var ownedRelationshipElement = ownedRelationship[ownedRelationshipIndex];
246+
247+
switch (ownedRelationshipElement)
248+
{
249+
case SysML2.NET.Core.POCO.Systems.Requirements.SubjectMembership subjectMembership:
250+
SubjectMembershipTextualNotationBuilder.BuildSubjectMember(subjectMembership, stringBuilder); break;
251+
case SysML2.NET.Core.POCO.Systems.Requirements.ActorMembership actorMembership:
252+
ActorMembershipTextualNotationBuilder.BuildActorMember(actorMembership, stringBuilder); break;
253+
case SysML2.NET.Core.POCO.Systems.Cases.ObjectiveMembership objectiveMembership:
254+
ObjectiveMembershipTextualNotationBuilder.BuildObjectiveMember(objectiveMembership, stringBuilder); break;
255+
default:
256+
ownedRelationshipIndex = BuildActionBodyItem(ownedRelationshipIndex, ownedRelationship, stringBuilder);
257+
break;
258+
259+
}
260+
}
202261
}
203262

204263
/// <summary>
@@ -269,9 +328,7 @@ public static void BuildTypeDeclaration(SysML2.NET.Core.POCO.Core.Types.IType po
269328
stringBuilder.Append(' ');
270329
}
271330

272-
{
273-
throw new System.NotSupportedException("Multiple alternatives with same referenced rule type not implemented yet");
274-
}
331+
throw new System.NotSupportedException("Multiple alternatives with same referenced rule type not implemented yet");
275332
stringBuilder.Append(' ');
276333
BuildTypeRelationshipPart(poco, stringBuilder);
277334

@@ -477,7 +534,25 @@ public static void BuildTypeBody(SysML2.NET.Core.POCO.Core.Types.IType poco, Str
477534
/// <param name="stringBuilder">The <see cref="StringBuilder" /> that contains the entire textual notation</param>
478535
public static void BuildTypeBodyElement(SysML2.NET.Core.POCO.Core.Types.IType poco, StringBuilder stringBuilder)
479536
{
480-
BuildTypeBodyElementAlternatives(poco, stringBuilder);
537+
foreach (var elementInOwnedRelationship in poco.OwnedRelationship)
538+
{
539+
switch (elementInOwnedRelationship)
540+
{
541+
case SysML2.NET.Core.POCO.Root.Namespaces.OwningMembership owningMembership when owningMembership.IsValidForNonFeatureMember():
542+
OwningMembershipTextualNotationBuilder.BuildNonFeatureMember(owningMembership, stringBuilder);
543+
break;
544+
case SysML2.NET.Core.POCO.Root.Namespaces.OwningMembership owningMembership when owningMembership.IsValidForFeatureMember():
545+
OwningMembershipTextualNotationBuilder.BuildFeatureMember(owningMembership, stringBuilder);
546+
break;
547+
case SysML2.NET.Core.POCO.Root.Namespaces.Membership membership:
548+
MembershipTextualNotationBuilder.BuildAliasMember(membership, stringBuilder);
549+
break;
550+
case SysML2.NET.Core.POCO.Root.Namespaces.IImport import:
551+
ImportTextualNotationBuilder.BuildImport(import, stringBuilder);
552+
break;
553+
}
554+
}
555+
481556
}
482557

483558
/// <summary>
@@ -501,10 +576,21 @@ public static void BuildFunctionBodyPart(SysML2.NET.Core.POCO.Core.Types.IType p
501576
{
502577
using var ownedRelationshipOfReturnParameterMembershipIterator = poco.OwnedRelationship.OfType<SysML2.NET.Core.POCO.Kernel.Functions.ReturnParameterMembership>().GetEnumerator();
503578
using var ownedRelationshipOfResultExpressionMembershipIterator = poco.OwnedRelationship.OfType<SysML2.NET.Core.POCO.Kernel.Functions.ResultExpressionMembership>().GetEnumerator();
579+
var ownedRelationship = poco.OwnedRelationship.ToList();
504580

505-
while (ownedRelationshipOfReturnParameterMembershipIterator.MoveNext())
581+
for (var ownedRelationshipIndex = 0; ownedRelationshipIndex < ownedRelationship.Count; ownedRelationshipIndex++)
506582
{
507-
throw new System.NotSupportedException("Multiple alternatives with only one of the different type not implemented yet - NonTerminalElement,AssignmentElement");
583+
var ownedRelationshipElement = ownedRelationship[ownedRelationshipIndex];
584+
585+
switch (ownedRelationshipElement)
586+
{
587+
case SysML2.NET.Core.POCO.Kernel.Functions.ReturnParameterMembership returnParameterMembership:
588+
ReturnParameterMembershipTextualNotationBuilder.BuildReturnFeatureMember(returnParameterMembership, stringBuilder); break;
589+
default:
590+
ownedRelationshipIndex = BuildTypeBodyElement(ownedRelationshipIndex, ownedRelationship, stringBuilder);
591+
break;
592+
593+
}
508594
}
509595

510596
if (ownedRelationshipOfResultExpressionMembershipIterator.MoveNext())

0 commit comments

Comments
 (0)