Skip to content

Commit 7b63122

Browse files
author
samatrhea
committed
[Update] code generators to use ECoreNetto.HandleBars version 0.4.1
1 parent 4cb529d commit 7b63122

File tree

12 files changed

+46
-549
lines changed

12 files changed

+46
-549
lines changed

SysML2.NET.CodeGenerator.Tests/Extensions/EcoreExtensionsTestFixture.cs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
1-
namespace SysML2.NET.CodeGenerator.Tests.Extensions
1+
// -------------------------------------------------------------------------------------------------
2+
// <copyright file="EcoreExtensionsTestFixture.cs" company="RHEA System S.A.">
3+
//
4+
// Copyright 2022 RHEA System 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.Tests.Extensions
222
{
3-
using System;
423
using System.Collections.Generic;
524
using System.Linq;
6-
using System.Text;
7-
using System.Threading.Tasks;
825

926
using ECoreNetto;
1027
using NUnit.Framework;
@@ -60,17 +77,5 @@ public void Verify_that_QueryDocumentation_gracefully_returns()
6077
}
6178
}, Throws.Nothing);
6279
}
63-
64-
[Test]
65-
public void Verify_QueryStructuralFeatureNameEqualsEnclosingType_returns_expected_results()
66-
{
67-
var conjugatedPortDefinition = this.ePackage.EClassifiers.OfType<EClass>().Single(x => x.Name == "ConjugatedPortDefinition") ;
68-
69-
var features = conjugatedPortDefinition.AllEStructuralFeatures.ToList();
70-
71-
var feature = features.Single(x => x.Name == "conjugatedPortDefinition");
72-
73-
Assert.That(feature.QueryStructuralFeatureNameEqualsEnclosingType(conjugatedPortDefinition), Is.True);
74-
}
7580
}
7681
}

SysML2.NET.CodeGenerator.Tests/SysML2.NET.CodeGenerator.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
<ItemGroup>
4949
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
50-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
50+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
5151
<PackageReference Include="NUnit" Version="3.13.3" />
5252
<PackageReference Include="NUnit.Console" Version="3.16.0" />
5353
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1" />

SysML2.NET.CodeGenerator/Extensions/EcoreExtensions.cs

Lines changed: 3 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace SysML2.NET.CodeGenerator.Extensions
2525
using System.Linq;
2626

2727
using ECoreNetto;
28+
using ECoreNetto.Extensions;
2829

2930
using HtmlAgilityPack;
3031

@@ -77,26 +78,7 @@ public static string QueryTypeName(this EStructuralFeature eStructuralFeature)
7778

7879
return typeName;
7980
}
80-
81-
/// <summary>
82-
/// Queries whether the type of the <see cref="EStructuralFeature"/> is an <see cref="EEnum"/>
83-
/// </summary>
84-
/// <param name="eStructuralFeature">
85-
/// The subject <see cref="EStructuralFeature"/>
86-
/// </param>
87-
/// <returns>
88-
/// true of the type is a <see cref="EEnum"/>, false if not
89-
/// </returns>
90-
public static bool QueryIsEnum(this EStructuralFeature eStructuralFeature)
91-
{
92-
if (eStructuralFeature is EAttribute eAttribute)
93-
{
94-
return eAttribute.EType is EEnum;
95-
}
9681

97-
return false;
98-
}
99-
10082
/// <summary>
10183
/// Queries whether the <see cref="EStructuralFeature"/> Type maps to a C# bool
10284
/// </summary>
@@ -159,21 +141,7 @@ public static IEnumerable<ENamedElement> QuerySortedByName(IEnumerable<ENamedEle
159141
{
160142
return namedElements.OrderBy(x => x.Name).ToList();
161143
}
162-
163-
/// <summary>
164-
/// Queries whether the <see cref="EStructuralFeature"/> is Enumerable
165-
/// </summary>
166-
/// <param name="eStructuralFeature">
167-
/// The subject <see cref="EStructuralFeature"/>
168-
/// </param>
169-
/// <returns>
170-
/// true if <see cref="EStructuralFeature.UpperBound"/> = -1 or > 1, false if not
171-
/// </returns>
172-
public static bool QueryIsEnumerable(this EStructuralFeature eStructuralFeature)
173-
{
174-
return eStructuralFeature.UpperBound is -1 or > 1;
175-
}
176-
144+
177145
/// <summary>
178146
/// Queries whether the <see cref="EStructuralFeature"/> is nullable
179147
/// </summary>
@@ -211,78 +179,7 @@ public static bool QueryIsScalar(this EStructuralFeature eStructuralFeature)
211179

212180
return eStructuralFeature.LowerBound == 1 && eStructuralFeature.UpperBound == 1;
213181
}
214-
215-
/// <summary>
216-
/// Queries whether the <see cref="EStructuralFeature"/> is an <see cref="EAttribute"/> or not
217-
/// </summary>
218-
/// <param name="structuralFeature">
219-
/// The subject <see cref="EStructuralFeature"/>
220-
/// </param>
221-
/// <returns>
222-
/// true when the <paramref name="structuralFeature"/> is an instance of <see cref="EAttribute"/>, false if not.
223-
/// </returns>
224-
public static bool QueryIsAttribute(this EStructuralFeature structuralFeature)
225-
{
226-
if (structuralFeature is EAttribute)
227-
{
228-
return true;
229-
}
230-
231-
return false;
232-
}
233-
234-
/// <summary>
235-
/// Queries whether the <see cref="EStructuralFeature"/> is an <see cref="EReference"/> or not
236-
/// </summary>
237-
/// <param name="structuralFeature">
238-
/// The subject <see cref="EStructuralFeature"/>
239-
/// </param>
240-
/// <returns>
241-
/// true when the <paramref name="structuralFeature"/> is an instance of <see cref="EReference"/>, false if not.
242-
/// </returns>
243-
public static bool QueryIsReference(this EStructuralFeature structuralFeature)
244-
{
245-
if (structuralFeature is EReference)
246-
{
247-
return true;
248-
}
249-
250-
return false;
251-
}
252-
253-
/// <summary>
254-
/// Queries whether the <see cref="EStructuralFeature.Name"/> is equal to the name of the containing <see cref="EClass"/>
255-
/// </summary>
256-
/// <param name="structuralFeature">
257-
/// The subject <see cref="EStructuralFeature"/>
258-
/// </param>
259-
/// <returns>
260-
/// true when the <paramref name="structuralFeature"/> name equals the name of the containing <see cref="EClass"/>, false if not.
261-
/// </returns>
262-
public static bool QueryStructuralFeatureNameEqualsEnclosingType(this EStructuralFeature structuralFeature, EClass @class)
263-
{
264-
if (structuralFeature.Name.ToLower() == @class.Name.ToLower())
265-
{
266-
return true;
267-
}
268-
269-
return false;
270-
}
271-
272-
/// <summary>
273-
/// Queries whether the <see cref="EStructuralFeature"/> is has a default value
274-
/// </summary>
275-
/// <param name="eStructuralFeature">
276-
/// The subject <see cref="EStructuralFeature"/>
277-
/// </param>
278-
/// <returns>
279-
/// true when the <see cref="EStructuralFeature.DefaultValueLiteral"/> contains a value
280-
/// </returns>
281-
public static bool QueryHasDefaultValue(this EStructuralFeature eStructuralFeature)
282-
{
283-
return !string.IsNullOrEmpty(eStructuralFeature.DefaultValueLiteral);
284-
}
285-
182+
286183
/// <summary>
287184
/// Queries whether the <see cref="EStructuralFeature"/> is has a default value
288185
/// </summary>
@@ -386,38 +283,5 @@ public static string RemoveUnwantedHtmlTags(this string html, List<string> unwan
386283

387284
return document.DocumentNode.InnerHtml;
388285
}
389-
390-
/// <summary>
391-
/// splits a string into multiple lines
392-
/// </summary>
393-
/// <param name="input">
394-
/// the subject input string
395-
/// </param>
396-
/// <param name="maximumLineLength">
397-
/// the maximum length of a line
398-
/// </param>
399-
/// <returns>
400-
/// an <see cref="IEnumerable{string}"/>
401-
/// </returns>
402-
public static IEnumerable<string> SplitToLines(this string input, int maximumLineLength)
403-
{
404-
var words = input.Split(' ');
405-
var line = words.First();
406-
foreach (var word in words.Skip(1))
407-
{
408-
var test = $"{line} {word}";
409-
if (test.Length > maximumLineLength)
410-
{
411-
yield return line;
412-
line = word;
413-
}
414-
else
415-
{
416-
line = test;
417-
}
418-
}
419-
420-
yield return line.Trim();
421-
}
422286
}
423287
}

SysML2.NET.CodeGenerator/Generators/HandleBarsGenerators/DtoDeSerializerGenerator.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
// </copyright>
1919
// ------------------------------------------------------------------------------------------------
2020

21+
22+
2123
namespace SysML2.NET.CodeGenerator.Generators.HandleBarsGenerators
2224
{
2325
using System.Linq;
@@ -143,11 +145,13 @@ public async Task GenerateDeSerializationProvider(EPackage package, DirectoryInf
143145
/// </summary>
144146
protected override void RegisterHelpers()
145147
{
148+
ECoreNetto.HandleBars.StringHelper.RegisterStringHelper(this.Handlebars);
149+
ECoreNetto.HandleBars.StructuralFeatureHelper.RegisterStructuralFeatureHelper(this.Handlebars);
150+
ECoreNetto.HandleBars.GeneralizationHelper.RegisterGeneralizationHelper(this.Handlebars);
151+
146152
this.Handlebars.RegisteredDocumentationHelper();
147153
this.Handlebars.RegisterTypeNameHelper();
148-
this.Handlebars.RegisterGeneralizationHelper();
149154
this.Handlebars.RegisterStructuralFeatureHelper();
150-
this.Handlebars.RegisterStringHelper();
151155
}
152156

153157
/// <summary>

SysML2.NET.CodeGenerator/Generators/HandleBarsGenerators/DtoGenerator.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,12 @@ public async Task GenerateClasses(EPackage package, DirectoryInfo outputDirector
9191
/// </summary>
9292
protected override void RegisterHelpers()
9393
{
94+
ECoreNetto.HandleBars.StringHelper.RegisterStringHelper(this.Handlebars);
95+
ECoreNetto.HandleBars.StructuralFeatureHelper.RegisterStructuralFeatureHelper(this.Handlebars);
96+
ECoreNetto.HandleBars.GeneralizationHelper.RegisterGeneralizationHelper(this.Handlebars);
97+
9498
this.Handlebars.RegisteredDocumentationHelper();
9599
this.Handlebars.RegisterTypeNameHelper();
96-
this.Handlebars.RegisterGeneralizationHelper();
97100
this.Handlebars.RegisterStructuralFeatureHelper();
98101
}
99102

SysML2.NET.CodeGenerator/Generators/HandleBarsGenerators/DtoSerializerGenerator.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,13 @@ public async Task GenerateSerializationProvider(EPackage package, DirectoryInfo
114114
/// </summary>
115115
protected override void RegisterHelpers()
116116
{
117+
ECoreNetto.HandleBars.StringHelper.RegisterStringHelper(this.Handlebars);
118+
ECoreNetto.HandleBars.StructuralFeatureHelper.RegisterStructuralFeatureHelper(this.Handlebars);
119+
ECoreNetto.HandleBars.GeneralizationHelper.RegisterGeneralizationHelper(this.Handlebars);
120+
117121
this.Handlebars.RegisteredDocumentationHelper();
118122
this.Handlebars.RegisterTypeNameHelper();
119-
this.Handlebars.RegisterGeneralizationHelper();
120123
this.Handlebars.RegisterStructuralFeatureHelper();
121-
this.Handlebars.RegisterStringHelper();
122124
}
123125

124126
/// <summary>

SysML2.NET.CodeGenerator/Generators/HandleBarsGenerators/PocoGenerator.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,12 @@ public async Task GenerateClasses(EPackage package, DirectoryInfo outputDirector
115115
/// </summary>
116116
protected override void RegisterHelpers()
117117
{
118+
ECoreNetto.HandleBars.StringHelper.RegisterStringHelper(this.Handlebars);
119+
ECoreNetto.HandleBars.StructuralFeatureHelper.RegisterStructuralFeatureHelper(this.Handlebars);
120+
ECoreNetto.HandleBars.GeneralizationHelper.RegisterGeneralizationHelper(this.Handlebars);
121+
118122
this.Handlebars.RegisteredDocumentationHelper();
119123
this.Handlebars.RegisterTypeNameHelper();
120-
this.Handlebars.RegisterGeneralizationHelper();
121124
this.Handlebars.RegisterStructuralFeatureHelper();
122125
}
123126

SysML2.NET.CodeGenerator/HandleBarHelpers/GeneralizationHelper.cs

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)