From f47ca8c3394db57f854350b6789cdd18ce757f6b Mon Sep 17 00:00:00 2001 From: Dietrich Travkin Date: Fri, 27 Oct 2023 11:00:17 +0200 Subject: [PATCH 1/4] #1580 Fix hiding stereotypes --- src/net/atmp/CucaDiagram.java | 32 ++++++++++++++ .../plantuml/abel/EntityGender.java | 2 + .../plantuml/abel/EntityGenderUtils.java | 43 ++++++++++++++++++- .../plantuml/cucadiagram/PortionShower.java | 4 ++ src/net/sourceforge/plantuml/dot/DotData.java | 10 +++++ .../svek/image/EntityImageClassHeader.java | 7 ++- 6 files changed, 95 insertions(+), 3 deletions(-) diff --git a/src/net/atmp/CucaDiagram.java b/src/net/atmp/CucaDiagram.java index 39cd59929..a062d034c 100644 --- a/src/net/atmp/CucaDiagram.java +++ b/src/net/atmp/CucaDiagram.java @@ -46,6 +46,7 @@ import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.FileFormatOption; @@ -84,10 +85,12 @@ import net.sourceforge.plantuml.security.SecurityUtils; import net.sourceforge.plantuml.skin.UmlDiagramType; import net.sourceforge.plantuml.skin.VisibilityModifier; import net.sourceforge.plantuml.statediagram.StateDiagram; +import net.sourceforge.plantuml.stereo.Stereotype; import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft; import net.sourceforge.plantuml.svek.CucaDiagramFileMaker; import net.sourceforge.plantuml.svek.CucaDiagramFileMakerSvek; import net.sourceforge.plantuml.text.BackSlash; +import net.sourceforge.plantuml.text.Guillemet; import net.sourceforge.plantuml.xmi.CucaDiagramXmiMaker; import net.sourceforge.plantuml.xmlsc.StateDiagramScxmlMaker; @@ -523,6 +526,35 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, return result; } + @Override + public List getVisibleStereotypeLabels(Entity entity) { + Stereotype stereotype = entity.getStereotype(); + + if (stereotype == null) { + return null; + } + + List commands = hideOrShows.stream() + .filter(cmd -> cmd.portion == EntityPortion.STEREOTYPE) + .collect(Collectors.toList()); + + return entity.getStereotype() + .getLabels(Guillemet.DOUBLE_COMPARATOR) + .stream() + .filter(stereoTypeLabel -> isHiddenStereotypeLabel(stereoTypeLabel, commands)) + .collect(Collectors.toList()); + } + + private boolean isHiddenStereotypeLabel(String stereoTypeLabel, List commands) { + for (EntityHideOrShow cmd : commands) { + String gender = cmd.gender.getGender(); + if (gender != null && gender.equals(stereoTypeLabel)) { + return false; + } + } + return true; + } + public final void hideOrShow(EntityGender gender, EntityPortion portions, boolean show) { for (EntityPortion portion : portions.asSet()) this.hideOrShows.add(new EntityHideOrShow(gender, portion, show)); diff --git a/src/net/sourceforge/plantuml/abel/EntityGender.java b/src/net/sourceforge/plantuml/abel/EntityGender.java index 52fbfcf2f..fcfd43f2a 100644 --- a/src/net/sourceforge/plantuml/abel/EntityGender.java +++ b/src/net/sourceforge/plantuml/abel/EntityGender.java @@ -37,4 +37,6 @@ package net.sourceforge.plantuml.abel; public interface EntityGender { public boolean contains(Entity test); + + public String getGender(); } diff --git a/src/net/sourceforge/plantuml/abel/EntityGenderUtils.java b/src/net/sourceforge/plantuml/abel/EntityGenderUtils.java index cea3074a3..340ed627f 100644 --- a/src/net/sourceforge/plantuml/abel/EntityGenderUtils.java +++ b/src/net/sourceforge/plantuml/abel/EntityGenderUtils.java @@ -44,6 +44,11 @@ public class EntityGenderUtils { public boolean contains(Entity test) { return test.getLeafType() == type; } + + @Override + public String getGender() { + return type.name(); + } }; } @@ -52,6 +57,11 @@ public class EntityGenderUtils { public boolean contains(Entity test) { return test.getUid().equals(entity.getUid()); } + + @Override + public String getGender() { + return entity.getUid(); + } }; } @@ -61,7 +71,12 @@ public class EntityGenderUtils { if (test.getStereotype() == null) { return false; } - return stereotype.equals(test.getStereotype().getLabel(Guillemet.DOUBLE_COMPARATOR)); + return test.getStereotype().getLabels(Guillemet.DOUBLE_COMPARATOR).stream().anyMatch(stereotype::equals); + } + + @Override + public String getGender() { + return stereotype; } }; } @@ -80,6 +95,11 @@ public class EntityGenderUtils { } return false; } + + @Override + public String getGender() { + return null; + } }; } @@ -88,6 +108,11 @@ public class EntityGenderUtils { public boolean contains(Entity test) { return g1.contains(test) && g2.contains(test); } + + @Override + public String getGender() { + return null; + } }; } @@ -96,6 +121,11 @@ public class EntityGenderUtils { public boolean contains(Entity test) { return true; } + + @Override + public String getGender() { + return null; + } }; } @@ -104,6 +134,11 @@ public class EntityGenderUtils { public boolean contains(Entity test) { return test.getBodier().getMethodsToDisplay().size() == 0; } + + @Override + public String getGender() { + return null; + } }; } @@ -112,6 +147,12 @@ public class EntityGenderUtils { public boolean contains(Entity test) { return test.getBodier().getFieldsToDisplay().size() == 0; } + + @Override + public String getGender() { + return null; + } + }; } diff --git a/src/net/sourceforge/plantuml/cucadiagram/PortionShower.java b/src/net/sourceforge/plantuml/cucadiagram/PortionShower.java index c3d2a375e..0cb7cb926 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/PortionShower.java +++ b/src/net/sourceforge/plantuml/cucadiagram/PortionShower.java @@ -38,7 +38,11 @@ package net.sourceforge.plantuml.cucadiagram; import net.sourceforge.plantuml.abel.Entity; import net.sourceforge.plantuml.abel.EntityPortion; +import java.util.List; + public interface PortionShower { boolean showPortion(EntityPortion portion, Entity entity); + + List getVisibleStereotypeLabels(Entity entity); } diff --git a/src/net/sourceforge/plantuml/dot/DotData.java b/src/net/sourceforge/plantuml/dot/DotData.java index 5b35c7ad0..95a30aaab 100644 --- a/src/net/sourceforge/plantuml/dot/DotData.java +++ b/src/net/sourceforge/plantuml/dot/DotData.java @@ -37,6 +37,7 @@ package net.sourceforge.plantuml.dot; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -101,6 +102,11 @@ final public class DotData implements PortionShower { public boolean showPortion(EntityPortion portion, Entity entity) { return true; } + + public List getVisibleStereotypeLabels(Entity entity) { + return Collections.emptyList(); + } + }, entityFactory, isHideEmptyDescriptionForState, dotMode, namespaceSeparator, pragma); } @@ -136,6 +142,10 @@ final public class DotData implements PortionShower { return portionShower.showPortion(portion, entity); } + public List getVisibleStereotypeLabels(Entity entity) { + return portionShower.getVisibleStereotypeLabels(entity); + } + public Entity getRootGroup() { return entityFactory.getRootGroup(); } diff --git a/src/net/sourceforge/plantuml/svek/image/EntityImageClassHeader.java b/src/net/sourceforge/plantuml/svek/image/EntityImageClassHeader.java index d6b885e53..b4cc279ce 100644 --- a/src/net/sourceforge/plantuml/svek/image/EntityImageClassHeader.java +++ b/src/net/sourceforge/plantuml/svek/image/EntityImageClassHeader.java @@ -68,6 +68,8 @@ import net.sourceforge.plantuml.svek.HeaderLayout; import net.sourceforge.plantuml.svek.ShapeType; import net.sourceforge.plantuml.text.Guillemet; +import java.util.List; + public class EntityImageClassHeader extends AbstractEntityImage { final private HeaderLayout headerLayout; @@ -112,11 +114,12 @@ public class EntityImageClassHeader extends AbstractEntityImage { } final TextBlock stereo; + List stereotypeLabels = portionShower.getVisibleStereotypeLabels(entity); if (stereotype == null || stereotype.getLabel(Guillemet.DOUBLE_COMPARATOR) == null - || portionShower.showPortion(EntityPortion.STEREOTYPE, entity) == false) + || stereotypeLabels.isEmpty()) stereo = null; else - stereo = TextBlockUtils.withMargin(Display.create(stereotype.getLabels(skinParam.guillemet())).create( + stereo = TextBlockUtils.withMargin(Display.create(stereotypeLabels).create( FontConfiguration.create(getSkinParam(), FontParam.CLASS_STEREOTYPE, stereotype), HorizontalAlignment.CENTER, skinParam), 1, 0); From 8b87aa0c1c84026408b1b07de2a196146f38e603 Mon Sep 17 00:00:00 2001 From: Dietrich Travkin Date: Mon, 30 Oct 2023 10:18:27 +0100 Subject: [PATCH 2/4] #1580 Make source code compatible to Java 1.7 --- src/net/atmp/CucaDiagram.java | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/net/atmp/CucaDiagram.java b/src/net/atmp/CucaDiagram.java index a062d034c..22ac06271 100644 --- a/src/net/atmp/CucaDiagram.java +++ b/src/net/atmp/CucaDiagram.java @@ -534,15 +534,21 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, return null; } - List commands = hideOrShows.stream() - .filter(cmd -> cmd.portion == EntityPortion.STEREOTYPE) - .collect(Collectors.toList()); + List commands = new ArrayList<>(); + for (EntityHideOrShow hideOrShowEntry : hideOrShows) { + if (hideOrShowEntry.portion == EntityPortion.STEREOTYPE) { + commands.add(hideOrShowEntry); + } + } - return entity.getStereotype() - .getLabels(Guillemet.DOUBLE_COMPARATOR) - .stream() - .filter(stereoTypeLabel -> isHiddenStereotypeLabel(stereoTypeLabel, commands)) - .collect(Collectors.toList()); + List visibleStereotypeLabels = new ArrayList<>(); + for (String stereoTypeLabel: entity.getStereotype().getLabels(Guillemet.DOUBLE_COMPARATOR)) { + if (isHiddenStereotypeLabel(stereoTypeLabel, commands)) { + visibleStereotypeLabels.add(stereoTypeLabel); + } + } + + return visibleStereotypeLabels; } private boolean isHiddenStereotypeLabel(String stereoTypeLabel, List commands) { From 263662d6d3cca0865f8d1320a9f5825758f968c2 Mon Sep 17 00:00:00 2001 From: Dietrich Travkin Date: Mon, 30 Oct 2023 10:39:34 +0100 Subject: [PATCH 3/4] #1580 Make source code compatible to Java 1.7 (forgot one stream usage) --- src/net/sourceforge/plantuml/abel/EntityGenderUtils.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/net/sourceforge/plantuml/abel/EntityGenderUtils.java b/src/net/sourceforge/plantuml/abel/EntityGenderUtils.java index 340ed627f..4c10b60fc 100644 --- a/src/net/sourceforge/plantuml/abel/EntityGenderUtils.java +++ b/src/net/sourceforge/plantuml/abel/EntityGenderUtils.java @@ -71,7 +71,14 @@ public class EntityGenderUtils { if (test.getStereotype() == null) { return false; } - return test.getStereotype().getLabels(Guillemet.DOUBLE_COMPARATOR).stream().anyMatch(stereotype::equals); + + for (String label : test.getStereotype().getLabels(Guillemet.DOUBLE_COMPARATOR)) { + if (label.equals(stereotype)) { + return true; + } + } + + return false; } @Override From 0a795acbb355994a00bbe2973a408a5fb873f503 Mon Sep 17 00:00:00 2001 From: Dietrich Travkin Date: Mon, 30 Oct 2023 10:48:47 +0100 Subject: [PATCH 4/4] Fix merge problem --- src/net/sourceforge/plantuml/abel/EntityGenderUtils.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/net/sourceforge/plantuml/abel/EntityGenderUtils.java b/src/net/sourceforge/plantuml/abel/EntityGenderUtils.java index 032cd2d67..4561c98f3 100644 --- a/src/net/sourceforge/plantuml/abel/EntityGenderUtils.java +++ b/src/net/sourceforge/plantuml/abel/EntityGenderUtils.java @@ -85,11 +85,6 @@ public class EntityGenderUtils { public String getGender() { return stereotype; } - - @Override - public String getGender() { - return stereotype; - } }; }