From 570d056f3d2982a1d574ea2fe6c5afb7ae58ea94 Mon Sep 17 00:00:00 2001 From: Dietrich Travkin Date: Fri, 27 Oct 2023 11:23:43 +0200 Subject: [PATCH] #1475 Fix show statement --- .../plantuml/abel/EntityGender.java | 2 + .../plantuml/abel/EntityGenderUtils.java | 54 +++++++++++++++++++ .../command/CommandHideShowByGender.java | 47 ++++++++-------- 3 files changed, 82 insertions(+), 21 deletions(-) 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..6c644a44d 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(); + } }; } @@ -63,6 +73,11 @@ public class EntityGenderUtils { } return stereotype.equals(test.getStereotype().getLabel(Guillemet.DOUBLE_COMPARATOR)); } + + @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,7 +147,26 @@ public class EntityGenderUtils { public boolean contains(Entity test) { return test.getBodier().getFieldsToDisplay().size() == 0; } + + @Override + public String getGender() { + return null; + } + }; } + static public EntityGender byClassName(String className) { + return new EntityGender() { + @Override + public boolean contains(Entity test) { + return className.equals(test.getName()); + } + + @Override + public String getGender() { + return className; + } + }; + } } diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandHideShowByGender.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandHideShowByGender.java index 6e9e22219..e31829dad 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandHideShowByGender.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandHideShowByGender.java @@ -190,30 +190,35 @@ public class CommandHideShowByGender extends SingleLineCommand2 { } else { arg1 = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg1); final Quark quark = diagram.quarkInContext(true, diagram.cleanId(arg1)); - Entity entity = quark.getData(); - if (entity == null) - return CommandExecutionResult.error("No such element " + quark.getName()); - gender = EntityGenderUtils.byEntityAlone(entity); - } - if (gender != null) { - final boolean empty = arg.get("EMPTY", 0) != null; - final boolean emptyMembers = empty && portion == EntityPortion.MEMBER; - if (empty == true && emptyMembers == false) - gender = EntityGenderUtils.and(gender, emptyByGender(portion)); - - if (diagram.getCurrentGroup().isRoot() == false) - gender = EntityGenderUtils.and(gender, EntityGenderUtils.byPackage(diagram.getCurrentGroup())); - - if (emptyMembers) { - diagram.hideOrShow(EntityGenderUtils.and(gender, emptyByGender(EntityPortion.FIELD)), - EntityPortion.FIELD, arg.get("COMMAND", 0).equalsIgnoreCase("show")); - diagram.hideOrShow(EntityGenderUtils.and(gender, emptyByGender(EntityPortion.METHOD)), - EntityPortion.METHOD, arg.get("COMMAND", 0).equalsIgnoreCase("show")); + if (quark == null) { + return CommandExecutionResult.error("No such quark " + arg1); + } + if (portion == EntityPortion.METHOD) { + gender = EntityGenderUtils.byClassName(arg1); } else { - diagram.hideOrShow(gender, portion, arg.get("COMMAND", 0).equalsIgnoreCase("show")); + Entity entity = quark.getData(); + if (entity == null) + return CommandExecutionResult.error("No such element " + quark.getName()); + gender = EntityGenderUtils.byEntityAlone(entity); } } - return CommandExecutionResult.ok(); + final boolean empty = arg.get("EMPTY", 0) != null; + final boolean emptyMembers = empty && portion == EntityPortion.MEMBER; + if (empty && !emptyMembers) + gender = EntityGenderUtils.and(gender, emptyByGender(portion)); + + if (!diagram.getCurrentGroup().isRoot()) + gender = EntityGenderUtils.and(gender, EntityGenderUtils.byPackage(diagram.getCurrentGroup())); + + if (emptyMembers) { + diagram.hideOrShow(EntityGenderUtils.and(gender, emptyByGender(EntityPortion.FIELD)), + EntityPortion.FIELD, arg.get("COMMAND", 0).equalsIgnoreCase("show")); + diagram.hideOrShow(EntityGenderUtils.and(gender, emptyByGender(EntityPortion.METHOD)), + EntityPortion.METHOD, arg.get("COMMAND", 0).equalsIgnoreCase("show")); + } else { + diagram.hideOrShow(gender, portion, arg.get("COMMAND", 0).equalsIgnoreCase("show")); + } + return CommandExecutionResult.ok(); } private EntityPortion getEntityPortion(String s) {