Skip to content

Commit ceecb4e

Browse files
author
Pascal Dal Farra
committed
feat: improve NameGetter (AopProxyUtils) + add 'ignoredTransitions' + make 'Connection' cComparable
1 parent bbab08e commit ceecb4e

File tree

4 files changed

+243
-156
lines changed

4 files changed

+243
-156
lines changed

spring-statemachine-uml/src/main/java/org/springframework/statemachine/plantuml/PlantUmlWriter.java

Lines changed: 67 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public String toPlantUml(
191191
);
192192
}
193193

194-
sb.append(plantUmlWriterParameters.getHiddenTransitions());
194+
sb.append(plantUmlWriterParameters.getAdditionalHiddenTransitions());
195195

196196
sb.append("\n@enduml");
197197

@@ -362,8 +362,8 @@ private void processCompositeOrOrthogonalState(
362362
Map<State<S, E>, List<S>> exitToSourceStates
363363
) {
364364
sb.append("""
365-
%s {
366-
"""
365+
%s {
366+
"""
367367
.formatted(stateToString(indent, regionState.getId(), currentState, plantUmlWriterParameters))
368368
.stripIndent());
369369

@@ -386,15 +386,15 @@ public boolean test(Transition<S, E> transition) {
386386
processExits(currentState, subRegion.getStates(), exitToSourceStates, plantUmlWriterParameters, sb, regionIndent);
387387
// using "--" caused problem ... how to solve this..?
388388
/*
389-
if (i != nRegions - 1) {
390-
// Separating regions. see "États concurrents [--, ||]" https://plantuml.com/fr/state-diagram#73b918d90b24a6c6
391-
sb.append(regionIndent).append("--\n");
392-
}
389+
if (i != nRegions - 1) {
390+
// Separating regions. see "Etats concurrents [--, ||]" https://plantuml.com/fr/state-diagram#73b918d90b24a6c6
391+
sb.append(regionIndent).append("--\n");
392+
}
393393
*/
394394
}
395395
sb.append("""
396-
%s}
397-
""".formatted(indent));
396+
%s}
397+
""".formatted(indent));
398398
}
399399

400400
private void processSubmachine(
@@ -408,17 +408,17 @@ private void processSubmachine(
408408
Map<State<S, E>, List<S>> exitToSourceStates
409409
) {
410410
sb.append("""
411-
%s {
412-
"""
411+
%s {
412+
"""
413413
.formatted(stateToString(indent, abstractState.getId(), currentState, plantUmlWriterParameters))
414414
.stripIndent());
415415
final String regionIndent = indent + INDENT_INCREMENT;
416416
processRegion(abstractState.getSubmachine(), stateContext, plantUmlWriterParameters, sb, regionIndent, null);
417417
processEntries(currentState, abstractState.getSubmachine().getStates(), entryToTargetStates, plantUmlWriterParameters, sb, regionIndent);
418418
processExits(currentState, abstractState.getSubmachine().getStates(), exitToSourceStates, plantUmlWriterParameters, sb, regionIndent);
419419
sb.append("""
420-
%s}
421-
""".formatted(indent));
420+
%s}
421+
""".formatted(indent));
422422
}
423423

424424
private void processSimpleState(
@@ -434,8 +434,8 @@ private void processSimpleState(
434434
// TODO allow plantUmlWriterParameters to add links in description ??
435435
// eg: state "CarWithWheel [[http://plantuml.com/state-diagram]]" as CarWithWheel
436436
sb.append("""
437-
%s
438-
"""
437+
%s
438+
"""
439439
.formatted(stateToString(indent, state.getId(), currentState, plantUmlWriterParameters))
440440
.stripIndent());
441441
}
@@ -483,8 +483,8 @@ private void processPseudoState(
483483
case INITIAL -> {
484484
if (StateMachineUtils.isPseudoState(state, PseudoStateKind.INITIAL)) {
485485
sb.append("""
486-
%s
487-
"""
486+
%s
487+
"""
488488
.formatted(stateToString(indent, state.getId(), currentState, plantUmlWriterParameters))
489489
.stripIndent());
490490
}
@@ -496,18 +496,18 @@ private void processPseudoState(
496496
// see historyStatesToHistoryId and historyTransitions
497497
}
498498
case ENTRY, EXIT -> sb.append("""
499-
%sstate %s <<%s>>
500-
"""
499+
%sstate %s <<%s>>
500+
"""
501501
.formatted(
502502
indent,
503503
state.getId(),
504504
getPseudoStatePlantUmlStereotype(pseudoStateKind)
505505
).stripIndent());
506506
case END, CHOICE, FORK, JOIN, JUNCTION -> sb.append("""
507-
%s'%s <<%s>>
508-
%sstate %s <<%s>>
509-
%snote left of %s %s: %s
510-
"""
507+
%s'%s <<%s>>
508+
%sstate %s <<%s>>
509+
%snote left of %s %s: %s
510+
"""
511511
.formatted(
512512
indent,
513513
state.getId(),
@@ -525,7 +525,7 @@ private void processPseudoState(
525525

526526
/**
527527
* Return a PlantUML stereotype for a given PseudoStateKind<BR/>
528-
* we use <<start>> stereotype for JUNCTION<BR/>
528+
* we use <code>&lt;&lt;start&gt;&gt;</code> stereotype to represent {@link PseudoStateKind#JUNCTION} in PlantUML diagram<BR/>
529529
* see <a href="https://sparxsystems.com/resources/tutorials/uml2/state-diagram.html">UML 2 - State Machine Diagram</a>
530530
*
531531
* @param pseudoStateKind pseudoStateKind
@@ -559,8 +559,8 @@ private void processStateDescription(
559559
) {
560560
for (E deferredEvent : state.getDeferredEvents()) {
561561
sb.append("""
562-
%s%s : %s /defer
563-
"""
562+
%s%s : %s /defer
563+
"""
564564
.formatted(
565565
indent,
566566
state.getId(),
@@ -571,8 +571,8 @@ private void processStateDescription(
571571
}
572572
for (Function<StateContext<S, E>, Mono<Void>> entryAction : state.getEntryActions()) {
573573
sb.append("""
574-
%s%s : /entry %s
575-
"""
574+
%s%s : /entry %s
575+
"""
576576
.formatted(
577577
indent,
578578
state.getId(),
@@ -583,8 +583,8 @@ private void processStateDescription(
583583
}
584584
for (Function<StateContext<S, E>, Mono<Void>> stateAction : state.getStateActions()) {
585585
sb.append("""
586-
%s%s : /do %s
587-
"""
586+
%s%s : /do %s
587+
"""
588588
.formatted(
589589
indent,
590590
state.getId(),
@@ -595,8 +595,8 @@ private void processStateDescription(
595595
}
596596
for (Function<StateContext<S, E>, Mono<Void>> exitAction : state.getExitActions()) {
597597
sb.append("""
598-
%s%s : /exit %s
599-
"""
598+
%s%s : /exit %s
599+
"""
600600
.formatted(
601601
indent,
602602
state.getId(),
@@ -660,10 +660,13 @@ private void processPseudoStatesTransition(
660660
) {
661661
S source = sourceState.getId();
662662
S target = targetState.getId();
663+
if (plantUmlWriterParameters.isTransitionIgnored(source, target)) {
664+
return;
665+
}
663666
sb.append("""
664-
%s%s
665-
%s%s -%s%s-> %s %s
666-
"""
667+
%s%s
668+
%s%s -%s%s-> %s %s
669+
"""
667670
.formatted(
668671
indent,
669672
historyIdGetter == null ? "" : "'" + source + " -> " + target, // if history transition, add a comment with 'real' state names
@@ -729,11 +732,11 @@ private void processTransitions(
729732
case EXTERNAL, INTERNAL, LOCAL -> {
730733
String arrowColor = plantUmlWriterParameters.getArrowColor(
731734
currentContextTransition != null
732-
&& transition.getTrigger() != null
733-
&& (
734-
currentContextTransition.getSource() == source
735-
&& currentContextTransition.getEvent() == transition.getTrigger().getEvent()
736-
&& currentContextTransition.getTarget() == target
735+
&& transition.getTrigger() != null
736+
&& (
737+
currentContextTransition.getSource() == source
738+
&& currentContextTransition.getEvent() == transition.getTrigger().getEvent()
739+
&& currentContextTransition.getTarget() == target
737740
)
738741
);
739742
addTransition(sb, indent, source.toString(), source, target, plantUmlWriterParameters, arrowColor, transition);
@@ -756,31 +759,33 @@ private void addTransition(
756759
String arrowColor,
757760
Transition<S, E> transition
758761
) {
759-
sb.append("""
760-
%s%s -%s%s-> %s %s
761-
"""
762-
.formatted(
763-
indent,
764-
sourceLabel,
765-
source == null ? "" : plantUmlWriterParameters.getDirection(source, target),
766-
arrowColor,
767-
target,
768-
TransactionHelper.getTransitionDescription(transition, plantUmlWriterParameters)
769-
)
770-
.stripIndent()
771-
);
772-
if (StringUtils.isNotBlank(transition.getName())) {
762+
if (!plantUmlWriterParameters.isTransitionIgnored(source, target)) {
773763
sb.append("""
774-
%snote on link
775-
%s %s
776-
%send note
777-
"""
764+
%s%s -%s%s-> %s %s
765+
"""
778766
.formatted(
779767
indent,
780-
indent,
781-
transition.getName(),
782-
indent
783-
));
768+
sourceLabel,
769+
source == null ? "" : plantUmlWriterParameters.getDirection(source, target),
770+
arrowColor,
771+
target,
772+
TransactionHelper.getTransitionDescription(transition, plantUmlWriterParameters)
773+
)
774+
.stripIndent()
775+
);
776+
if (StringUtils.isNotBlank(transition.getName())) {
777+
sb.append("""
778+
%snote on link
779+
%s %s
780+
%send note
781+
"""
782+
.formatted(
783+
indent,
784+
indent,
785+
transition.getName(),
786+
indent
787+
));
788+
}
784789
}
785790
}
786791

0 commit comments

Comments
 (0)