Skip to content

Commit

Permalink
[Refactor] reference serializer to be inline with KERML spec; fixes #29
Browse files Browse the repository at this point in the history
  • Loading branch information
samatrhea committed Sep 1, 2023
1 parent 402c5ec commit d4c5ee1
Show file tree
Hide file tree
Showing 170 changed files with 2,105 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ public static void Serialize(IElement iElement, Utf8JsonWriter writer, Serializa
writer.WriteStartArray("ownedRelationship");
foreach (var item in iElement.OwnedRelationship)
{
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(item);
writer.WriteEndObject();
}
writer.WriteEndArray();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ public static void Serialize(ITriggerInvocationExpression iTriggerInvocationExpr
{
writer.WriteStartObject();

writer.WritePropertyName("@id");
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(iTriggerInvocationExpression.Id);

writer.WritePropertyName("@type");
writer.WritePropertyName("@type"u8);
writer.WriteStringValue("TriggerInvocationExpression");

writer.WritePropertyName("kind");
writer.WritePropertyName("kind"u8);
writer.WriteStringValue(iTriggerInvocationExpression.Kind.ToString().ToUpper());

writer.WritePropertyName("direction");
writer.WritePropertyName("direction"u8);
if (iTriggerInvocationExpression.Direction.HasValue)
{
writer.WriteStringValue(iTriggerInvocationExpression.Direction.Value.ToString().ToUpper());
Expand All @@ -69,54 +69,54 @@ public static void Serialize(ITriggerInvocationExpression iTriggerInvocationExpr
writer.WriteNullValue();
}

writer.WritePropertyName("isComposite");
writer.WritePropertyName("isComposite"u8);
writer.WriteBooleanValue(iTriggerInvocationExpression.IsComposite);

writer.WritePropertyName("isDerived");
writer.WritePropertyName("isDerived"u8);
writer.WriteBooleanValue(iTriggerInvocationExpression.IsDerived);

writer.WritePropertyName("isEnd");
writer.WritePropertyName("isEnd"u8);
writer.WriteBooleanValue(iTriggerInvocationExpression.IsEnd);

writer.WritePropertyName("isOrdered");
writer.WritePropertyName("isOrdered"u8);
writer.WriteBooleanValue(iTriggerInvocationExpression.IsOrdered);

writer.WritePropertyName("isPortion");
writer.WritePropertyName("isPortion"u8);
writer.WriteBooleanValue(iTriggerInvocationExpression.IsPortion);

writer.WritePropertyName("isReadOnly");
writer.WritePropertyName("isReadOnly"u8);
writer.WriteBooleanValue(iTriggerInvocationExpression.IsReadOnly);

writer.WritePropertyName("isUnique");
writer.WritePropertyName("isUnique"u8);
writer.WriteBooleanValue(iTriggerInvocationExpression.IsUnique);

writer.WritePropertyName("isAbstract");
writer.WritePropertyName("isAbstract"u8);
writer.WriteBooleanValue(iTriggerInvocationExpression.IsAbstract);

writer.WritePropertyName("isSufficient");
writer.WritePropertyName("isSufficient"u8);
writer.WriteBooleanValue(iTriggerInvocationExpression.IsSufficient);

writer.WriteStartArray("aliasIds");
writer.WriteStartArray("aliasIds"u8);
foreach (var item in iTriggerInvocationExpression.AliasIds)
{
writer.WriteStringValue(item);
}
writer.WriteEndArray();

writer.WritePropertyName("elementId");
writer.WritePropertyName("elementId"u8);
writer.WriteStringValue(iTriggerInvocationExpression.ElementId);

writer.WritePropertyName("name");
writer.WritePropertyName("name"u8);
writer.WriteStringValue(iTriggerInvocationExpression.Name);

writer.WriteStartArray("ownedRelationship");
writer.WriteStartArray("ownedRelationship"u8);
foreach (var item in iTriggerInvocationExpression.OwnedRelationship)
{
writer.WriteStringValue(item);
}
writer.WriteEndArray();

writer.WritePropertyName("owningRelationship");
writer.WritePropertyName("owningRelationship"u8);
if (iTriggerInvocationExpression.OwningRelationship.HasValue)
{
writer.WriteStringValue(iTriggerInvocationExpression.OwningRelationship.Value);
Expand All @@ -126,7 +126,7 @@ public static void Serialize(ITriggerInvocationExpression iTriggerInvocationExpr
writer.WriteNullValue();
}

writer.WritePropertyName("shortName");
writer.WritePropertyName("shortName"u8);
writer.WriteStringValue(iTriggerInvocationExpression.ShortName);

writer.WriteEndObject();
Expand Down
4 changes: 2 additions & 2 deletions SysML2.NET.CodeGenerator/SysML2.NET.CodeGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ECoreNetto.HandleBars" Version="1.0.0" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.46" />
<PackageReference Include="ECoreNetto.HandleBars" Version="1.1.0" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.52" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.5.0" />
<PackageReference Include="RHEA.OpenApi" Version="0.4.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ namespace SysML2.NET.Serializer.Json.Core.DTO
writer.WriteStartArray("{{String.LowerCaseFirstLetter structuralFeature.Name }}"u8);
foreach (var item in i{{EClass.Name}}.{{String.CapitalizeFirstLetter structuralFeature.Name}})
{
{{#if (StructuralFeature.QueryIsBool structuralFeature )}}
{{#if (structuralFeature.QueryIsReference structuralFeature)}}
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(item);
writer.WriteEndObject();
{{else if (StructuralFeature.QueryIsBool structuralFeature )}}
writer.WriteBooleanValue(item);
{{else if (StructuralFeature.QueryIsNumeric structuralFeature )}}
writer.WriteNumberValue(item);
Expand All @@ -91,7 +96,12 @@ namespace SysML2.NET.Serializer.Json.Core.DTO
{{ else }}
if (i{{EClass.Name}}.{{String.CapitalizeFirstLetter structuralFeature.Name }}.HasValue)
{
{{#if (StructuralFeature.QueryIsBool structuralFeature )}}
{{#if (structuralFeature.QueryIsReference structuralFeature)}}
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(i{{EClass.Name}}.{{String.CapitalizeFirstLetter structuralFeature.Name }}.Value);
writer.WriteEndObject();
{{else if (StructuralFeature.QueryIsBool structuralFeature )}}
writer.WriteBooleanValue(i{{EClass.Name}}.{{String.CapitalizeFirstLetter structuralFeature.Name }}.Value);
{{else if (StructuralFeature.QueryIsNumeric structuralFeature )}}
writer.WriteNumberValue(i{{EClass.Name}}.{{String.CapitalizeFirstLetter structuralFeature.Name }}.Value);
Expand All @@ -108,7 +118,12 @@ namespace SysML2.NET.Serializer.Json.Core.DTO
{{/if}}
{{ else if (StructuralFeature.QueryIsScalar structuralFeature)}}
writer.WritePropertyName("{{ String.LowerCaseFirstLetter structuralFeature.Name }}"u8);
{{#if (StructuralFeature.QueryIsBool structuralFeature )}}
{{#if (structuralFeature.QueryIsReference structuralFeature)}}
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(i{{EClass.Name}}.{{String.CapitalizeFirstLetter structuralFeature.Name }});
writer.WriteEndObject();
{{else if (StructuralFeature.QueryIsBool structuralFeature )}}
writer.WriteBooleanValue(i{{EClass.Name}}.{{String.CapitalizeFirstLetter structuralFeature.Name }});
{{else if (StructuralFeature.QueryIsString structuralFeature )}}
writer.WriteStringValue(i{{EClass.Name}}.{{String.CapitalizeFirstLetter structuralFeature.Name }});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,20 @@ internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationM
writer.WriteStartArray("ownedRelationship"u8);
foreach (var item in iAcceptActionUsage.OwnedRelationship)
{
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(item);
writer.WriteEndObject();
}
writer.WriteEndArray();

writer.WritePropertyName("owningRelationship"u8);
if (iAcceptActionUsage.OwningRelationship.HasValue)
{
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(iAcceptActionUsage.OwningRelationship.Value);
writer.WriteEndObject();
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,20 @@ internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationM
writer.WriteStartArray("ownedRelationship"u8);
foreach (var item in iActionDefinition.OwnedRelationship)
{
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(item);
writer.WriteEndObject();
}
writer.WriteEndArray();

writer.WritePropertyName("owningRelationship"u8);
if (iActionDefinition.OwningRelationship.HasValue)
{
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(iActionDefinition.OwningRelationship.Value);
writer.WriteEndObject();
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,20 @@ internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationM
writer.WriteStartArray("ownedRelationship"u8);
foreach (var item in iActionUsage.OwnedRelationship)
{
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(item);
writer.WriteEndObject();
}
writer.WriteEndArray();

writer.WritePropertyName("owningRelationship"u8);
if (iActionUsage.OwningRelationship.HasValue)
{
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(iActionUsage.OwningRelationship.Value);
writer.WriteEndObject();
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationM
writer.WriteStringValue(iActorMembership.ElementId);

writer.WritePropertyName("feature"u8);
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(iActorMembership.Feature);
writer.WriteEndObject();

writer.WritePropertyName("isImplied"u8);
writer.WriteBooleanValue(iActorMembership.IsImplied);
Expand All @@ -88,7 +91,10 @@ internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationM
writer.WriteBooleanValue(iActorMembership.IsImpliedIncluded);

writer.WritePropertyName("memberElement"u8);
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(iActorMembership.MemberElement);
writer.WriteEndObject();

writer.WritePropertyName("memberName"u8);
writer.WriteStringValue(iActorMembership.MemberName);
Expand All @@ -97,21 +103,30 @@ internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationM
writer.WriteStartArray("ownedRelatedElement"u8);
foreach (var item in iActorMembership.OwnedRelatedElement)
{
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(item);
writer.WriteEndObject();
}
writer.WriteEndArray();

writer.WriteStartArray("ownedRelationship"u8);
foreach (var item in iActorMembership.OwnedRelationship)
{
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(item);
writer.WriteEndObject();
}
writer.WriteEndArray();

writer.WritePropertyName("owningRelatedElement"u8);
if (iActorMembership.OwningRelatedElement.HasValue)
{
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(iActorMembership.OwningRelatedElement.Value);
writer.WriteEndObject();
}
else
{
Expand All @@ -120,7 +135,10 @@ internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationM
writer.WritePropertyName("owningRelationship"u8);
if (iActorMembership.OwningRelationship.HasValue)
{
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(iActorMembership.OwningRelationship.Value);
writer.WriteEndObject();
}
else
{
Expand All @@ -129,19 +147,28 @@ internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationM
writer.WriteStartArray("source"u8);
foreach (var item in iActorMembership.Source)
{
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(item);
writer.WriteEndObject();
}
writer.WriteEndArray();

writer.WriteStartArray("target"u8);
foreach (var item in iActorMembership.Target)
{
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(item);
writer.WriteEndObject();
}
writer.WriteEndArray();

writer.WritePropertyName("type"u8);
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(iActorMembership.Type);
writer.WriteEndObject();

writer.WritePropertyName("visibility"u8);
writer.WriteStringValue(iActorMembership.Visibility.ToString().ToLower());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,30 @@ internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationM
writer.WriteStartArray("ownedRelatedElement"u8);
foreach (var item in iAllocationDefinition.OwnedRelatedElement)
{
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(item);
writer.WriteEndObject();
}
writer.WriteEndArray();

writer.WriteStartArray("ownedRelationship"u8);
foreach (var item in iAllocationDefinition.OwnedRelationship)
{
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(item);
writer.WriteEndObject();
}
writer.WriteEndArray();

writer.WritePropertyName("owningRelatedElement"u8);
if (iAllocationDefinition.OwningRelatedElement.HasValue)
{
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(iAllocationDefinition.OwningRelatedElement.Value);
writer.WriteEndObject();
}
else
{
Expand All @@ -122,7 +131,10 @@ internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationM
writer.WritePropertyName("owningRelationship"u8);
if (iAllocationDefinition.OwningRelationship.HasValue)
{
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(iAllocationDefinition.OwningRelationship.Value);
writer.WriteEndObject();
}
else
{
Expand All @@ -131,14 +143,20 @@ internal static void Serialize(object obj, Utf8JsonWriter writer, SerializationM
writer.WriteStartArray("source"u8);
foreach (var item in iAllocationDefinition.Source)
{
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(item);
writer.WriteEndObject();
}
writer.WriteEndArray();

writer.WriteStartArray("target"u8);
foreach (var item in iAllocationDefinition.Target)
{
writer.WriteStartObject();
writer.WritePropertyName("@id"u8);
writer.WriteStringValue(item);
writer.WriteEndObject();
}
writer.WriteEndArray();

Expand Down
Loading

0 comments on commit d4c5ee1

Please sign in to comment.