Skip to content

Commit 8f13ca0

Browse files
[WIP] Element Extensions
1 parent e00b75f commit 8f13ca0

1 file changed

Lines changed: 30 additions & 17 deletions

File tree

SysML2.NET/Extend/ElementExtensions.cs

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ namespace SysML2.NET.Core.POCO.Root.Elements
2222
{
2323
using System;
2424
using System.Collections.Generic;
25+
using System.Linq;
26+
using System.Runtime.CompilerServices;
27+
using System.Threading;
2528

29+
using SysML2.NET.Core.POCO.Kernel.Packages;
2630
using SysML2.NET.Core.POCO.Root.Annotations;
2731
using SysML2.NET.Core.POCO.Root.Namespaces;
2832

@@ -41,10 +45,9 @@ internal static class ElementExtensions
4145
/// <returns>
4246
/// the computed result
4347
/// </returns>
44-
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
4548
internal static List<IDocumentation> ComputeDocumentation(this IElement elementSubject)
4649
{
47-
throw new NotSupportedException("Create a GitHub issue when this method is required");
50+
return [..elementSubject.ownedElement.OfType<IDocumentation>()];
4851
}
4952

5053
/// <summary>
@@ -56,10 +59,21 @@ internal static List<IDocumentation> ComputeDocumentation(this IElement elementS
5659
/// <returns>
5760
/// the computed result
5861
/// </returns>
59-
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
6062
internal static bool ComputeIsLibraryElement(this IElement elementSubject)
6163
{
62-
throw new NotSupportedException("Create a GitHub issue when this method is required");
64+
var owner = elementSubject.owner;
65+
66+
while (owner != null)
67+
{
68+
if (owner is ILibraryPackage)
69+
{
70+
return true;
71+
}
72+
73+
owner = owner.owner;
74+
}
75+
76+
return false;
6377
}
6478

6579
/// <summary>
@@ -86,10 +100,9 @@ internal static string ComputeName(this IElement elementSubject)
86100
/// <returns>
87101
/// the computed result
88102
/// </returns>
89-
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
90103
internal static List<IAnnotation> ComputeOwnedAnnotation(this IElement elementSubject)
91104
{
92-
throw new NotSupportedException("Create a GitHub issue when this method is required");
105+
return [..elementSubject.OwnedRelationship.OfType<IAnnotation>().Where(x => x.AnnotatedElement == elementSubject)];
93106
}
94107

95108
/// <summary>
@@ -101,10 +114,9 @@ internal static List<IAnnotation> ComputeOwnedAnnotation(this IElement elementSu
101114
/// <returns>
102115
/// the computed result
103116
/// </returns>
104-
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
105117
internal static List<IElement> ComputeOwnedElement(this IElement elementSubject)
106118
{
107-
throw new NotSupportedException("Create a GitHub issue when this method is required");
119+
return [..elementSubject.OwnedRelationship.SelectMany(x => x.OwnedRelatedElement)];
108120
}
109121

110122
/// <summary>
@@ -116,10 +128,9 @@ internal static List<IElement> ComputeOwnedElement(this IElement elementSubject)
116128
/// <returns>
117129
/// the computed result
118130
/// </returns>
119-
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
120131
internal static IElement ComputeOwner(this IElement elementSubject)
121132
{
122-
throw new NotSupportedException("Create a GitHub issue when this method is required");
133+
return elementSubject.OwningRelationship?.OwningRelatedElement;
123134
}
124135

125136
/// <summary>
@@ -131,10 +142,9 @@ internal static IElement ComputeOwner(this IElement elementSubject)
131142
/// <returns>
132143
/// the computed result
133144
/// </returns>
134-
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
135145
internal static IOwningMembership ComputeOwningMembership(this IElement elementSubject)
136146
{
137-
throw new NotSupportedException("Create a GitHub issue when this method is required");
147+
return elementSubject.OwningRelationship as IOwningMembership;
138148
}
139149

140150
/// <summary>
@@ -146,10 +156,9 @@ internal static IOwningMembership ComputeOwningMembership(this IElement elementS
146156
/// <returns>
147157
/// the computed result
148158
/// </returns>
149-
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
150159
internal static INamespace ComputeOwningNamespace(this IElement elementSubject)
151160
{
152-
throw new NotSupportedException("Create a GitHub issue when this method is required");
161+
return elementSubject.owningMembership?.membershipOwningNamespace;
153162
}
154163

155164
/// <summary>
@@ -191,12 +200,16 @@ internal static string ComputeShortName(this IElement elementSubject)
191200
/// <returns>
192201
/// the computed result
193202
/// </returns>
194-
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
195203
internal static List<ITextualRepresentation> ComputeTextualRepresentation(this IElement elementSubject)
196204
{
197-
throw new NotSupportedException("Create a GitHub issue when this method is required");
198-
}
205+
if (elementSubject == null)
206+
{
207+
throw new ArgumentNullException(nameof(elementSubject));
208+
}
199209

210+
return [..elementSubject.ownedElement.OfType<ITextualRepresentation>()];
211+
}
212+
200213
/// <summary>
201214
/// Return name, if that is not null, otherwise the shortName, if that is not null, otherwise null. If
202215
/// the returned value is non-null, it is returned as-is if it has the form of a basic name, or,

0 commit comments

Comments
 (0)