Skip to content

Commit

Permalink
[Add] MultiplicityElementExtensions
Browse files Browse the repository at this point in the history
[Update] PropertyExtensions
[Change] namespace of extensions methods in uml4net core library to not cause conflct on unl4net.extensions
[Refactor] Assembler.TryGetReferencedElement
[Implement] ModelInspector
  • Loading branch information
samatstariongroup committed Nov 10, 2024
1 parent a3c2bff commit 5b871f7
Show file tree
Hide file tree
Showing 224 changed files with 1,159 additions and 1,028 deletions.
77 changes: 77 additions & 0 deletions uml4net.Extensions/MultiplicityElementExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// -------------------------------------------------------------------------------------------------
// <copyright file="MultiplicityElementExtensions.cs" company="Starion Group S.A.">
//
// Copyright 2019-2024 Starion Group S.A.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, softwareUseCases
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// </copyright>
// ------------------------------------------------------------------------------------------------

namespace uml4net.Extensions
{
using System;

using uml4net.POCO.CommonStructure;
using uml4net.POCO.Values;

/// <summary>
/// Extension methods for <see cref="IMultiplicityElement"/> interface
/// </summary>
public static class MultiplicityElementExtensions
{
/// <summary>
/// Queries the upper value of the <paramref name="multiplicityElement"/>
/// </summary>
/// <param name="multiplicityElement">
/// The <see cref="IMultiplicityElement"/> for which the lower value is queried
/// </param>
/// <returns>
/// an integer
/// </returns>
public static string QueryUpperValue(this IMultiplicityElement multiplicityElement)
{
switch (multiplicityElement.UpperValue)
{
case null:
return "1";

case ILiteralInteger literalInteger:

return literalInteger.Value.ToString();

case ILiteralUnlimitedNatural unlimitedNatural:

if (!unlimitedNatural.Value.HasValue)
{
return "0";
}
else
{
if (unlimitedNatural.Value == int.MaxValue)
{
return "*";
}
else
{
return unlimitedNatural.Value.ToString();
}
}

default:
throw new NotSupportedException("");
}

}
}
}
36 changes: 34 additions & 2 deletions uml4net.Extensions/PropertyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,21 @@ public static class PropertyExtensions
/// </returns>
public static bool QueryIsEnum(this IProperty property)
{
return property.DataType is IEnumeration;
return property.Type is IEnumeration;
}

/// <summary>
/// Queries whether the type of the <see cref="IProperty"/> is an <see cref="IPrimitiveType"/>
/// </summary>
/// <param name="property">
/// The subject <see cref="IProperty"/>
/// </param>
/// <returns>
/// true of the type is a <see cref="IPrimitiveType"/>, false if not
/// </returns>
public static bool QueryIsPrimitiveType(this IProperty property)
{
return property.Type is IPrimitiveType;
}

/// <summary>
Expand Down Expand Up @@ -140,9 +154,27 @@ public static string QueryTypeName(this IProperty property)
/// <returns>
/// A <see cref="bool"/>
/// </returns>
/// <remarks>
/// The <see cref="IPrimitiveType"/> and <see cref="IEnumeration"/> are concrete subtypes of the
/// concrete <see cref="IDataType"/> type
/// </remarks>
public static bool QueryIsValueProperty(this IProperty property)
{
return property.Type is IPrimitiveType or IEnumeration;
return property.Type is IDataType;
}

/// <summary>
/// Queries a value indicating whether the specified <see cref="IProperty"/> is a reference type
/// </summary>
/// <param name="property">
/// The subject <see cref="IProperty"/>
/// </param>
/// <returns>
/// A <see cref="bool"/>
/// </returns>
public static bool QueryIsReferenceProperty(this IProperty property)
{
return property.Type is not IDataType;
}

/// <summary>
Expand Down
81 changes: 80 additions & 1 deletion uml4net.Reporting.Tests/Generators/ModelInspectorTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,30 @@

namespace uml4net.Reporting.Tests.Generators
{
using System;
using System.IO;
using System.Linq;
using Microsoft.Extensions.Logging;

using NUnit.Framework;

using POCO.Packages;
using Reporting.Generators;
using Serilog;
using xmi;

[TestFixture]
public class ModelInspectorTestFixture
{
private ILoggerFactory loggerFactory;

private ModelInspector modelInspector;

private string modelPath;

private FileInfo modelFileInfo;

private FileInfo reportFileInfo;

[OneTimeSetUp]
public void OneTimeSetUp()
{
Expand All @@ -44,5 +57,71 @@ public void OneTimeSetUp()
builder.AddSerilog();
});
}

[SetUp]
public void SetUp()
{
this.modelPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "UML.xmi");
this.modelFileInfo = new FileInfo(modelPath);

var reportPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "inspection-report.txt");
this.reportFileInfo = new FileInfo(reportPath);
}

[Test]
public void Verify_that_Inspection_report_can_be_executed()
{
var rootPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData");

var reader = XmiReaderBuilder.Create()
.UsingSettings(x => x.LocalReferenceBasePath = rootPath)
.WithLogger(this.loggerFactory)
.Build();

var packages = reader.Read(Path.Combine(rootPath, "UML.xmi"));

var rootPackage = packages.Single();

this.modelInspector = new ModelInspector(this.loggerFactory);

var report = this.modelInspector.Inspect(rootPackage, true);

Log.Logger.Information(report);

Assert.That(report, Is.Not.Null.Or.Empty);
}

[Test]
public void Verify_that_Inspection_report_can_be_generated()
{
this.modelInspector = new ModelInspector(this.loggerFactory);

Assert.That(() => this.modelInspector.GenerateReport(this.modelFileInfo, this.reportFileInfo), Throws.Nothing);
}

[Test]
public void Verify_that_inspect_class_returns_expected_result()
{
var rootPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData");

var reader = XmiReaderBuilder.Create()
.UsingSettings(x => x.LocalReferenceBasePath = rootPath)
.WithLogger(this.loggerFactory)
.Build();

var packages = reader.Read(Path.Combine(rootPath, "UML.xmi"));

var rootPackage = packages.Single();

var classificationPackage = rootPackage.PackagedElement.OfType<IPackage>().Single(x => x.Name == "Classification") ;

this.modelInspector = new ModelInspector(this.loggerFactory);

var inspectionReport = this.modelInspector.Inspect(classificationPackage, "Property");

Assert.That(inspectionReport, Is.Not.Empty);

Log.Logger.Information(inspectionReport);
}
}
}
12 changes: 12 additions & 0 deletions uml4net.Reporting.Tests/uml4net.Reporting.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,16 @@
<ProjectReference Include="..\uml4net.Reporting\uml4net.Reporting.csproj" />
</ItemGroup>

<ItemGroup>
<Content Include="..\resources\UML\PrimitiveTypes.xmi.xml" Link="TestData\PrimitiveTypes.xmi">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="..\resources\UML\UML.xmi.xml" Link="TestData\UML.xmi">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="..\resources\SySML2\SysML.uml" Link="TestData\SysML.uml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions uml4net.Reporting/Generators/HtmlReportGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public string QueryReportType()
/// Generates a table that contains all classes, attributes and their documentation
/// </summary>
/// <param name="modelPath">
/// /// the path to the Ecore model of which the report is to be generated.
/// /// the path to the UML model of which the report is to be generated.
/// </param>
/// <returns>
/// the content of an HTML report in a string
Expand All @@ -77,7 +77,7 @@ public string GenerateReport(FileInfo modelPath)
/// Generates a table that contains all classes, attributes and their documentation
/// </summary>
/// <param name="modelPath">
/// the path to the Ecore model of which the report is to be generated.
/// the path to the UML model of which the report is to be generated.
/// </param>
/// <param name="outputPath">
/// the path, including filename, where the output is to be generated.
Expand Down
4 changes: 2 additions & 2 deletions uml4net.Reporting/Generators/IHtmlReportGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ namespace uml4net.Reporting.Generators

/// <summary>
/// The purpose of the <see cref="IHtmlReportGenerator"/> is to generate an HTML report of an
/// Ecore Model
/// UML Model
/// </summary>
public interface IHtmlReportGenerator : IReportGenerator
{
/// <summary>
/// Generates a table that contains all classes, attributes and their documentation
/// </summary>
/// <param name="modelPath">
/// /// the path to the Ecore model of which the report is to be generated.
/// /// the path to the UML model of which the report is to be generated.
/// </param>
/// <returns>
/// the content of an HTML report in a string
Expand Down
4 changes: 2 additions & 2 deletions uml4net.Reporting/Generators/IMarkdownReportGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ namespace uml4net.Reporting.Generators

/// <summary>
/// The purpose of the <see cref="IMarkdownReportGenerator"/> is to generate a Markdown report of an
/// Ecore Model
/// UML Model
/// </summary>
public interface IMarkdownReportGenerator : IReportGenerator
{
/// <summary>
/// Generates a Markdown document with a table that contains all classes, attributes and their documentation
/// </summary>
/// <param name="modelPath">
/// the path to the Ecore model of which the report is to be generated.
/// the path to the UML model of which the report is to be generated.
/// </param>
/// <returns>
/// the content of a Markdown report in a string
Expand Down
4 changes: 2 additions & 2 deletions uml4net.Reporting/Generators/IModelInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace uml4net.Reporting.Generators

/// <summary>
/// The purpose of the <see cref="IModelInspector"/> is to iterate through the model and report on the various kinds of
/// patters that exist in the ECore model that need to be taken into account for code-generation
/// patters that exist in the UML model that need to be taken into account for code-generation
/// </summary>
public interface IModelInspector : IReportGenerator
{
Expand Down Expand Up @@ -67,7 +67,7 @@ public interface IModelInspector : IReportGenerator
/// The <see cref="IPackage"/> which needs to be inspected
/// </param>
/// <param name="recursive">
/// A value indicating whether the sub <see cref="EPackage"/>s need to be Analyzed as well
/// A value indicating whether the sub <see cref="IPackage"/>s need to be Analyzed as well
/// </param>
/// <returns>
/// returns a report of the classes and properties that do not contain any documentation
Expand Down
4 changes: 2 additions & 2 deletions uml4net.Reporting/Generators/IReportGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ namespace uml4net.Reporting.Generators

/// <summary>
/// The purpose of the <see cref="IReportGenerator"/> is to generate a report of an
/// Ecore Model
/// UML Model
/// </summary>
public interface IReportGenerator
{
/// <summary>
/// Generates a report that contains all classes, attributes and their documentation
/// </summary>
/// <param name="modelPath">
/// the path to the Ecore model of which the report is to be generated.
/// the path to the UML model of which the report is to be generated.
/// </param>
/// <param name="outputPath">
/// the path, including filename, where the output is to be generated.
Expand Down
2 changes: 1 addition & 1 deletion uml4net.Reporting/Generators/IXlReportGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace uml4net.Reporting.Generators
{
/// <summary>
/// The purpose of the <see cref="IXlReportGenerator"/> is to generate reports of an
/// Ecore Model
/// UML Model
/// </summary>
public interface IXlReportGenerator : IReportGenerator
{
Expand Down
6 changes: 3 additions & 3 deletions uml4net.Reporting/Generators/MarkdownReportGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace uml4net.Reporting.Generators

/// <summary>
/// The purpose of the <see cref="MarkdownReportGenerator"/> is to generate a Markdown report of an
/// Ecore Model
/// UML Model
/// </summary>
public class MarkdownReportGenerator : HandleBarsReportGenerator, IMarkdownReportGenerator
{
Expand Down Expand Up @@ -64,7 +64,7 @@ public string QueryReportType()
/// Generates a table that contains all classes, attributes and their documentation
/// </summary>
/// <param name="modelPath">
/// /// the path to the Ecore model of which the report is to be generated.
/// /// the path to the UML model of which the report is to be generated.
/// </param>
/// <returns>
/// the content of an HTML report in a string
Expand All @@ -78,7 +78,7 @@ public string GenerateReport(FileInfo modelPath)
/// Generates a Markdown document with a table that contains all classes, attributes and their documentation
/// </summary>
/// <param name="modelPath">
/// the path to the Ecore model of which the report is to be generated.
/// the path to the UML model of which the report is to be generated.
/// </param>
/// <param name="outputPath">
/// the path, including filename, where the output is to be generated.
Expand Down
Loading

0 comments on commit 5b871f7

Please sign in to comment.