Skip to content

Commit 6023b18

Browse files
author
samatrhea
committed
[Refactor] generation of abstract DTO and POCO; fixes #14
1 parent fb8ab15 commit 6023b18

File tree

144 files changed

+230
-4849
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+230
-4849
lines changed

SysML2.NET.CodeGenerator.Tests/Expected/AutGenPoco/Connector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ public List<FeatureMembership> QueryOwnedFeatureMembership()
449449
/// <summary>
450450
/// Queries the derived property OwnedImport
451451
/// </summary>
452-
public List<Import> QueryOwnedImport()
452+
public List<IImport> QueryOwnedImport()
453453
{
454454
throw new NotImplementedException("Derived property OwnedImport not yet supported");
455455
}

SysML2.NET.CodeGenerator.Tests/Expected/AutGenPoco/Feature.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ public List<FeatureMembership> QueryOwnedFeatureMembership()
435435
/// <summary>
436436
/// Queries the derived property OwnedImport
437437
/// </summary>
438-
public List<Import> QueryOwnedImport()
438+
public List<IImport> QueryOwnedImport()
439439
{
440440
throw new NotImplementedException("Derived property OwnedImport not yet supported");
441441
}

SysML2.NET.CodeGenerator.Tests/Expected/AutGenPoco/LiteralInteger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ public List<FeatureMembership> QueryOwnedFeatureMembership()
434434
/// <summary>
435435
/// Queries the derived property OwnedImport
436436
/// </summary>
437-
public List<Import> QueryOwnedImport()
437+
public List<IImport> QueryOwnedImport()
438438
{
439439
throw new NotImplementedException("Derived property OwnedImport not yet supported");
440440
}

SysML2.NET.CodeGenerator.Tests/Expected/AutGenPoco/LiteralRational.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ public List<FeatureMembership> QueryOwnedFeatureMembership()
432432
/// <summary>
433433
/// Queries the derived property OwnedImport
434434
/// </summary>
435-
public List<Import> QueryOwnedImport()
435+
public List<IImport> QueryOwnedImport()
436436
{
437437
throw new NotImplementedException("Derived property OwnedImport not yet supported");
438438
}

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// -------------------------------------------------------------------------------------------------
22
// <copyright file="DtoGenerator.cs" company="RHEA System S.A.">
33
//
4-
// Copyright 2022 RHEA System S.A.
4+
// Copyright 2022-2023 RHEA System S.A.
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
2020

2121
namespace SysML2.NET.CodeGenerator.Generators.HandleBarsGenerators
2222
{
23+
using System;
2324
using System.Linq;
2425
using System.Threading.Tasks;
2526

@@ -90,8 +91,8 @@ public async Task<string> GenerateInterface(EPackage package, DirectoryInfo outp
9091
public async Task GenerateClasses(EPackage package, DirectoryInfo outputDirectory)
9192
{
9293
var template = this.Templates["dto-class-template"];
93-
94-
foreach (var eClass in package.EClassifiers.OfType<EClass>())
94+
95+
foreach (var eClass in package.EClassifiers.OfType<EClass>().Where(x => !x.Abstract))
9596
{
9697
var generatedClass = template(eClass);
9798

@@ -108,7 +109,12 @@ public async Task<string> GenerateClass(EPackage package, DirectoryInfo outputDi
108109
var template = this.Templates["dto-class-template"];
109110

110111
var eClass = package.EClassifiers.OfType<EClass>().Single(x => x.Name == className);
111-
112+
113+
if (eClass.Abstract)
114+
{
115+
throw new InvalidOperationException("DTO should not be abstract");
116+
}
117+
112118
var generatedClass = template(eClass);
113119

114120
generatedClass = CodeCleanup(generatedClass);

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// -------------------------------------------------------------------------------------------------
22
// <copyright file="PocoGenerator.cs" company="RHEA System S.A.">
33
//
4-
// Copyright 2022 RHEA System S.A.
4+
// Copyright 2022-2023 RHEA System S.A.
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@ namespace SysML2.NET.CodeGenerator.Generators.HandleBarsGenerators
2929

3030
using SysML2.NET.CodeGenerator.Extensions;
3131
using SysML2.NET.CodeGenerator.HandleBarHelpers;
32+
using System;
3233

3334
/// <summary>
3435
/// A Handlebars based POCO code generator
@@ -127,7 +128,7 @@ public async Task GenerateClasses(EPackage package, DirectoryInfo outputDirector
127128
{
128129
var template = this.Templates["poco-class-template"];
129130

130-
foreach (var eClass in package.EClassifiers.OfType<EClass>())
131+
foreach (var eClass in package.EClassifiers.OfType<EClass>().Where(x => !x.Abstract))
131132
{
132133
var generatedCode = template(eClass);
133134

@@ -156,7 +157,12 @@ public async Task<string> GenerateClass(EPackage package, DirectoryInfo outputDi
156157
var template = this.Templates["poco-class-template"];
157158

158159
var eClass = package.EClassifiers.OfType<EClass>().Single(x => x.Name == className);
159-
160+
161+
if (eClass.Abstract)
162+
{
163+
throw new InvalidOperationException("POCO should not be abstract");
164+
}
165+
160166
var generatedCode = template(eClass);
161167

162168
generatedCode = CodeCleanup(generatedCode);

SysML2.NET.CodeGenerator/HandleBarHelpers/TypeNameHelper.cs

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

21+
using Microsoft.CodeAnalysis.VisualBasic.Syntax;
22+
2123
namespace SysML2.NET.CodeGenerator.HandleBarHelpers
2224
{
2325
using System;
@@ -113,6 +115,13 @@ public static void RegisterTypeNameHelper(this IHandlebars handlebars)
113115
}
114116
else if (eStructuralFeature is EReference)
115117
{
118+
var @class = eStructuralFeature.QueryClass();
119+
120+
if (@class.Abstract)
121+
{
122+
typeName = $"I{typeName}";
123+
}
124+
116125
if (enumerable)
117126
{
118127
writer.WriteSafeString($"List<{typeName}>");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</PropertyGroup>
2020

2121
<ItemGroup>
22-
<PackageReference Include="ECoreNetto.HandleBars" Version="0.3.1" />
22+
<PackageReference Include="ECoreNetto.HandleBars" Version="0.4.0" />
2323
<PackageReference Include="HtmlAgilityPack" Version="1.11.46" />
2424
<PackageReference Include="RazorLight" Version="2.3.0" />
2525
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.4.0" />

SysML2.NET.CodeGenerator/Templates/dto-class-template.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace SysML2.NET.Core.DTO
3030
using SysML2.NET.Core;
3131

3232
{{ #Documentation this }}
33-
public {{#if this.Abstract}}abstract {{/if}}partial class {{ this.Name }} : I{{ this.Name }}
33+
public partial class {{ this.Name }} : I{{ this.Name }}
3434
{
3535
/// <summary>
3636
/// Initializes a new instance of the <see cref="{{ this.Name }}"/> class.

SysML2.NET.CodeGenerator/Templates/poco-class-template.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ namespace SysML2.NET.Core.POCO
3030
using SysML2.NET.Core;
3131

3232
{{ #Documentation this }}
33-
public {{#if this.Abstract}}abstract {{/if}}partial class {{ this.Name }} : I{{ this.Name }}
33+
public partial class {{ this.Name }} : I{{ this.Name }}
3434
{
3535
/// <summary>
3636
/// Initializes a new instance of the <see cref="{{ this.Name }}"/> class.
3737
/// </summary>
38-
{{#if this.Abstract}}protected {{else}}public{{/if}} {{ this.Name }}()
38+
public {{ this.Name }}()
3939
{
4040
{{#each this.AllEStructuralFeaturesOrderByName as | structuralFeature |}}
4141
{{#unless structuralFeature.Derived }}

0 commit comments

Comments
 (0)