Skip to content

Commit 12c013d

Browse files
[Add] uml xmi of PrimitiveTypes, Kerml and SysML
[Add\ UmlHandleBarsGenerator and helper classes [Add] uml based decorators
1 parent dd42260 commit 12c013d

17 files changed

+33394
-0
lines changed

Resources/KerML_only_xmi.uml

Lines changed: 7858 additions & 0 deletions
Large diffs are not rendered by default.

Resources/PrimitiveTypes.xmi

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xmi:XMI xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.omg.org/spec/UML/20161101" xmlns:mofext="http://www.omg.org/spec/MOF/20131001">
3+
<uml:Package xmi:type="uml:Package" xmi:id="_0" name="PrimitiveTypes" URI="http://www.omg.org/spec/PrimitiveTypes/20161101">
4+
<packagedElement xmi:type="uml:PrimitiveType" xmi:id="Boolean" name="Boolean">
5+
<ownedComment xmi:type="uml:Comment" xmi:id="Boolean-_ownedComment.0" annotatedElement="Boolean">
6+
<body>Boolean is used for logical expressions, consisting of the predefined values true and false.</body>
7+
</ownedComment>
8+
</packagedElement>
9+
<packagedElement xmi:type="uml:PrimitiveType" xmi:id="Integer" name="Integer">
10+
<ownedComment xmi:type="uml:Comment" xmi:id="Integer-_ownedComment.0" annotatedElement="Integer">
11+
<body>Integer is a primitive type representing integer values.</body>
12+
</ownedComment>
13+
</packagedElement>
14+
<packagedElement xmi:type="uml:PrimitiveType" xmi:id="Real" name="Real">
15+
<ownedComment xmi:type="uml:Comment" xmi:id="Real-_ownedComment.0" annotatedElement="Real">
16+
<body>Real is a primitive type representing the mathematical concept of real.</body>
17+
</ownedComment>
18+
</packagedElement>
19+
<packagedElement xmi:type="uml:PrimitiveType" xmi:id="String" name="String">
20+
<ownedComment xmi:type="uml:Comment" xmi:id="String-_ownedComment.0" annotatedElement="String">
21+
<body>String is a sequence of characters in some suitable character set used to display information about the model. Character sets may include non-Roman alphabets and characters.</body>
22+
</ownedComment>
23+
</packagedElement>
24+
<packagedElement xmi:type="uml:PrimitiveType" xmi:id="UnlimitedNatural" name="UnlimitedNatural">
25+
<ownedComment xmi:type="uml:Comment" xmi:id="UnlimitedNatural-_ownedComment.0" annotatedElement="UnlimitedNatural">
26+
<body>UnlimitedNatural is a primitive type representing unlimited natural values.</body>
27+
</ownedComment>
28+
</packagedElement>
29+
</uml:Package>
30+
<mofext:Tag xmi:type="mofext:Tag" xmi:id="_1" name="org.omg.xmi.nsPrefix" value="primitives" element="_0"/>
31+
<mofext:Tag xmi:type="mofext:Tag" xmi:id="_2" name="org.omg.xmi.schemaType" value="http://www.w3.org/2001/XMLSchema#boolean" element="Boolean"/>
32+
<mofext:Tag xmi:type="mofext:Tag" xmi:id="_3" name="org.omg.xmi.schemaType" value="http://www.w3.org/2001/XMLSchema#integer" element="Integer"/>
33+
<mofext:Tag xmi:type="mofext:Tag" xmi:id="_4" name="org.omg.xmi.schemaType" value="http://www.w3.org/2001/XMLSchema#double" element="Real"/>
34+
<mofext:Tag xmi:type="mofext:Tag" xmi:id="_5" name="org.omg.xmi.schemaType" value="http://www.w3.org/2001/XMLSchema#string" element="String"/>
35+
<mofext:Tag xmi:type="mofext:Tag" xmi:id="_6" name="org.omg.xmi.schemaType" value="http://www.w3.org/2001/XMLSchema#string" element="UnlimitedNatural"/>
36+
</xmi:XMI>

Resources/SysML_only_xmi.uml

Lines changed: 8543 additions & 0 deletions
Large diffs are not rendered by default.

Resources/SysML_xmi.uml

Lines changed: 16098 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// -------------------------------------------------------------------------------------------------
2+
// <copyright file="ReservedCSharpNameMapper.cs" company="Starion Group S.A.">
3+
//
4+
// Copyright 2022-2025 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.CodeGenerator.Extensions
22+
{
23+
/// <summary>
24+
/// The purpose of the <see cref="ReservedCSharpNameMapper"/> is to map strings that are keywords used in C#
25+
/// </summary>
26+
public static class ReservedCSharpNameMapper
27+
{
28+
/// <summary>
29+
/// Maps a reserved keyword in c# to a string that can be used in code
30+
/// </summary>
31+
/// <param name="input">
32+
/// The input string
33+
/// </param>
34+
/// <returns></returns>
35+
public static string Map(string input)
36+
{
37+
switch (input)
38+
{
39+
case "in":
40+
return "@in";
41+
case "out":
42+
return "@out";
43+
case "ref":
44+
return "@ref";
45+
case "var":
46+
return "@var";
47+
case "<":
48+
return "LT";
49+
case "<=":
50+
return "LTEQ";
51+
case ">":
52+
return "GT";
53+
case ">=":
54+
return "GTEQ";
55+
case "=":
56+
return "EQ";
57+
case "true":
58+
return "True";
59+
case "false":
60+
return "False";
61+
default:
62+
return input;
63+
}
64+
}
65+
66+
/// <summary>
67+
/// Queries whether the input string is a reserved keyword in C#
68+
/// </summary>
69+
/// <param name="input">
70+
/// The string that is to be queried
71+
/// </param>
72+
/// <returns>
73+
/// true when reserved, false if not
74+
/// </returns>
75+
public static bool QueryIsReserved(string input)
76+
{
77+
switch (input)
78+
{
79+
case "in":
80+
case "out":
81+
case "ref":
82+
case "var":
83+
case "<":
84+
case "<=":
85+
case ">":
86+
case ">=":
87+
case "=":
88+
case "true":
89+
case "false":
90+
return true;
91+
default:
92+
return false;
93+
}
94+
}
95+
}
96+
}

SysML2.NET.CodeGenerator/Generators/Generator.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
namespace SysML2.NET.CodeGenerator.Generators
2222
{
23+
using System;
2324
using System.IO;
2425
using System.Reflection;
2526
using System.Text;
@@ -90,5 +91,39 @@ protected static async Task Write(string generatedCode, DirectoryInfo outputDire
9091

9192
await File.WriteAllTextAsync(filePath, generatedCode, Encoding.UTF8);
9293
}
94+
95+
/// <summary>
96+
/// Writes the generated code to disk
97+
/// </summary>
98+
/// <param name="generatedCode">
99+
/// he generated code that needs to be written to disk
100+
/// </param>
101+
/// <param name="outputDirectory">
102+
/// The target <see cref="DirectoryInfo"/>
103+
/// </param>
104+
/// <param name="fileName">
105+
/// The name of the file
106+
/// </param>
107+
/// <returns>
108+
/// an awaitable <see cref="Task"/>
109+
/// </returns>
110+
protected static async Task WriteAsync(string generatedCode, DirectoryInfo outputDirectory, string fileName)
111+
{
112+
if (string.IsNullOrEmpty(generatedCode))
113+
{
114+
throw new ArgumentException(nameof(generatedCode));
115+
}
116+
117+
ArgumentNullException.ThrowIfNull(outputDirectory);
118+
119+
if (string.IsNullOrEmpty(fileName))
120+
{
121+
throw new ArgumentException(nameof(fileName));
122+
}
123+
124+
var filePath = Path.Combine(outputDirectory.FullName, fileName);
125+
126+
await File.WriteAllTextAsync(filePath, generatedCode, Encoding.UTF8);
127+
}
93128
}
94129
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// -------------------------------------------------------------------------------------------------
2+
// <copyright file="EnumerationLiteralHelper.cs" company="Starion Group S.A.">
3+
//
4+
// Copyright 2022-2025 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.CodeGenerator.UmlHandleBarHelpers
22+
{
23+
using HandlebarsDotNet;
24+
using SysML2.NET.CodeGenerator.Extensions;
25+
using System;
26+
using System.Linq;
27+
using uml4net;
28+
using uml4net.Extensions;
29+
using uml4net.SimpleClassifiers;
30+
31+
/// <summary>
32+
/// A block helper to support the generation of <see cref="Enumeration"/> and <see cref="EnumerationLiteral"/>
33+
/// </summary>
34+
public static class EnumerationLiteralHelper
35+
{
36+
/// <summary>
37+
/// Registers the <see cref="EnumerationLiteralHelper"/>
38+
/// </summary>
39+
/// <param name="handlebars">
40+
/// The <see cref="IHandlebars"/> context with which the helper needs to be registered
41+
/// </param>
42+
public static void RegisterTypeNameHelper(this IHandlebars handlebars)
43+
{
44+
handlebars.RegisterHelper("EnumerationLiteral.Write", (writer, context, arguments) =>
45+
{
46+
if (arguments.Length != 1)
47+
{
48+
throw new HandlebarsException("{{#EnumerationLiteral.Write}} helper must have exactly one argument");
49+
}
50+
51+
var enumerationLiteral = arguments.Single() as EnumerationLiteral;
52+
53+
var name = StringExtensions.CapitalizeFirstLetter(enumerationLiteral.Name);
54+
55+
if (ReservedCSharpNameMapper.QueryIsReserved(name))
56+
{
57+
name = ReservedCSharpNameMapper.Map(name);
58+
}
59+
60+
writer.WriteSafeString(name);
61+
});
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)