-
Notifications
You must be signed in to change notification settings - Fork 1
Add UML support #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Add UML support #13
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/DendroDocs.Client/Uml/Extensions/IHaveModifiersExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using DendroDocs.Extensions; | ||
using PlantUml.Builder; | ||
|
||
namespace DendroDocs.Uml.Extensions; | ||
|
||
/// <summary> | ||
/// Provides extension methods for objects implementing the <see cref="IHaveModifiers"/> interface, enabling conversion | ||
/// of visibility modifiers to their PlantUML equivalents. | ||
/// </summary> | ||
/// <remarks>This class contains methods that simplify the process of mapping visibility modifiers from objects | ||
/// implementing <see cref="IHaveModifiers"/> to corresponding UML visibility representations, such as public, | ||
/// protected, private, and internal.</remarks> | ||
public static class IHaveModifiersExtensions | ||
{ | ||
/// <summary> | ||
/// Converts the visibility modifiers of the specified object to a PlantUML visibility modifier. | ||
/// </summary> | ||
/// <param name="modifiers">An object implementing <see cref="IHaveModifiers"/> that provides access to visibility modifiers.</param> | ||
/// <returns>A <see cref="VisibilityModifier"/> value representing the UML visibility equivalent of the object's modifiers. | ||
/// Returns <see cref="VisibilityModifier.Public"/> for public visibility, <see | ||
/// cref="VisibilityModifier.PackagePrivate"/> for internal visibility, <see cref="VisibilityModifier.Protected"/> | ||
/// for protected visibility, <see cref="VisibilityModifier.Private"/> for private visibility, or <see | ||
/// cref="VisibilityModifier.None"/> if no visibility modifier is applicable.</returns> | ||
public static VisibilityModifier ToPlantUmlVisibility(this IHaveModifiers modifiers) | ||
{ | ||
ArgumentNullException.ThrowIfNull(modifiers); | ||
|
||
if (modifiers.IsPublic()) | ||
{ | ||
return VisibilityModifier.Public; | ||
} | ||
|
||
if (modifiers.IsInternal()) | ||
{ | ||
return VisibilityModifier.PackagePrivate; | ||
} | ||
|
||
if (modifiers.IsProtected()) | ||
{ | ||
return VisibilityModifier.Protected; | ||
} | ||
|
||
if (modifiers.IsPrivate()) | ||
{ | ||
return VisibilityModifier.Private; | ||
} | ||
|
||
return VisibilityModifier.None; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Diagnostics; | ||
|
||
namespace DendroDocs.Uml.Fragments; | ||
|
||
/// <summary> | ||
/// Represents a group with 1 or more sections, like <c>alt</c>, <c>par</c>, <c>loop</c>, etc.. | ||
/// </summary> | ||
[DebuggerDisplay("Alt")] | ||
public class Alt : InteractionFragment | ||
{ | ||
private readonly List<AltSection> sections = []; | ||
|
||
/// <summary> | ||
/// Gets all sections. | ||
/// </summary> | ||
public IReadOnlyList<AltSection> Sections => this.sections; | ||
|
||
/// <summary> | ||
/// Add a sections to this alt. | ||
/// </summary> | ||
/// <param name="section">The section to add.</param> | ||
public void AddSection(AltSection section) | ||
{ | ||
ArgumentNullException.ThrowIfNull(section); | ||
|
||
section.Parent = this; | ||
|
||
this.sections.Add(section); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Diagnostics; | ||
|
||
namespace DendroDocs.Uml.Fragments; | ||
|
||
/// <summary> | ||
/// Represents a section in a larger group. | ||
/// </summary> | ||
[DebuggerDisplay("AltSection {GroupType} {Label}")] | ||
public class AltSection : InteractionFragment | ||
{ | ||
/// <summary> | ||
/// The type of group, like <c>alt</c>, <c>else</c>, etc.. | ||
/// </summary> | ||
public string? GroupType { get; set; } | ||
|
||
/// <summary> | ||
/// The label of this section. | ||
/// </summary> | ||
public string? Label { get; set; } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Diagnostics; | ||
|
||
namespace DendroDocs.Uml.Fragments; | ||
|
||
/// <summary> | ||
/// Represents an arrow between 2 participants. | ||
/// </summary> | ||
[DebuggerDisplay("{Source} -> {Target} : {Name}")] | ||
public class Arrow : InteractionFragment | ||
{ | ||
/// <summary> | ||
/// The left participant of the arrow. | ||
/// </summary> | ||
public string? Source { get; set; } | ||
|
||
/// <summary> | ||
/// The right participant of the arrow. | ||
/// </summary> | ||
public string? Target { get; set; } | ||
|
||
/// <summary> | ||
/// The optional color of the arrow. | ||
/// </summary> | ||
public string? Color { get; set; } | ||
|
||
/// <summary> | ||
/// Whether the arrow is dashed. | ||
/// </summary> | ||
public bool Dashed { get; set; } | ||
|
||
/// <summary> | ||
/// The message with the arrow. | ||
/// </summary> | ||
public string? Name { get; set; } | ||
} |
80 changes: 80 additions & 0 deletions
80
src/DendroDocs.Client/Uml/Fragments/Extensions/InteractionFragmentExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
namespace DendroDocs.Uml.Fragments.Extensions; | ||
|
||
/// <summary> | ||
/// Provides extension methods for querying and navigating through collections of <see cref="InteractionFragment"/> | ||
/// objects. | ||
/// </summary> | ||
/// <remarks>This static class includes methods for retrieving descendants, ancestors, and sibling fragments | ||
/// within a hierarchy of <see cref="InteractionFragment"/> objects. These methods are designed to facilitate traversal | ||
/// and filtering of interaction fragments in a structured manner.</remarks> | ||
public static class InteractionFragmentExtensions | ||
{ | ||
/// <summary> | ||
/// Query all descendants from this level down. | ||
/// </summary> | ||
/// <typeparam name="TFragment">The type of fragment to filter on.</typeparam> | ||
/// <returns>Returns a readonly list of child fragments.</returns> | ||
public static IReadOnlyList<TFragment> Descendants<TFragment>(this IEnumerable<InteractionFragment> nodes) | ||
where TFragment : InteractionFragment | ||
{ | ||
ArgumentNullException.ThrowIfNull(nodes); | ||
|
||
var result = new List<TFragment>(); | ||
|
||
foreach (var node in nodes) | ||
{ | ||
switch (node) | ||
{ | ||
case TFragment t: | ||
result.Add(t); | ||
break; | ||
|
||
case Alt a: | ||
result.AddRange(a.Sections.SelectMany(s => s.Fragments).Descendants<TFragment>()); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// Query all parent fragments from this fragment up. | ||
/// </summary> | ||
/// <returns>Returns a list of parent fragments.</returns> | ||
public static IReadOnlyList<InteractionFragment> Ancestors(this InteractionFragment fragment) | ||
{ | ||
ArgumentNullException.ThrowIfNull(fragment); | ||
|
||
var result = new List<InteractionFragment>(); | ||
|
||
var parent = fragment.Parent; | ||
while (parent is not null) | ||
{ | ||
result.Add(parent); | ||
|
||
parent = parent.Parent; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// Query all sibling before the current fragment. | ||
/// </summary> | ||
/// <returns>Returns a readonly list of siblings comming before this fragment.</returns> | ||
public static IReadOnlyList<InteractionFragment> StatementsBeforeSelf(this InteractionFragment fragment) | ||
{ | ||
ArgumentNullException.ThrowIfNull(fragment); | ||
|
||
if (fragment.Parent != null) | ||
{ | ||
return [.. fragment.Parent.Fragments.TakeWhile(s => s != fragment)]; | ||
} | ||
|
||
return []; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/DendroDocs.Client/Uml/Fragments/InteractionFragment.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
namespace DendroDocs.Uml.Fragments; | ||
|
||
/// <summary> | ||
/// Represents interaction fragments in a sequence diagram. | ||
/// </summary> | ||
public abstract class InteractionFragment | ||
{ | ||
private readonly List<InteractionFragment> interactionFragments = []; | ||
|
||
/// <summary> | ||
/// The parent of this fragment. | ||
/// </summary> | ||
public InteractionFragment? Parent { get; set; } | ||
|
||
/// <summary> | ||
/// The children of this fragment. | ||
/// </summary> | ||
public virtual IReadOnlyList<InteractionFragment> Fragments => this.interactionFragments; | ||
|
||
/// <summary> | ||
/// Add a fragment to this level. | ||
/// </summary> | ||
/// <param name="fragment">The fragment to add.</param> | ||
public void AddFragment(InteractionFragment fragment) | ||
{ | ||
ArgumentNullException.ThrowIfNull(fragment); | ||
|
||
fragment.Parent = this; | ||
|
||
this.interactionFragments.Add(fragment); | ||
} | ||
|
||
/// <summary> | ||
/// Add a list of fragments to this level. | ||
/// </summary> | ||
/// <param name="fragments">The fragments to add.</param> | ||
public void AddFragments(IEnumerable<InteractionFragment> fragments) | ||
{ | ||
ArgumentNullException.ThrowIfNull(fragments); | ||
|
||
foreach (var fragment in fragments) | ||
{ | ||
this.AddFragment(fragment); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace DendroDocs.Uml.Fragments; | ||
|
||
/// <summary> | ||
/// Represents a list of fragments on the same level. | ||
/// </summary> | ||
public class Interactions : InteractionFragment | ||
{ | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.