From a5952259b7722a01741bc0c2ca264de543369d59 Mon Sep 17 00:00:00 2001 From: Arnaud Roques Date: Tue, 31 May 2022 18:31:10 +0200 Subject: [PATCH] Minor bug fixes --- .../command/CommandCreateElementFull2.java | 22 ++-- .../plantuml/command/CommandMultilines.java | 16 ++- .../plantuml/command/CommandMultilines2.java | 28 +++-- .../plantuml/command/CommandMultilines3.java | 24 ++--- .../command/CommandMultilinesBracket.java | 38 ++++--- .../plantuml/command/SingleLineCommand2.java | 50 +++++---- .../plantuml/creole/SheetBlock2.java | 15 ++- .../plantuml/creole/legacy/CreoleParser.java | 9 +- .../cucadiagram/BodierLikeClassOrObject.java | 100 ++++++++---------- .../plantuml/cucadiagram/BodyEnhanced1.java | 30 ++++-- .../cucadiagram/BodyEnhancedAbstract.java | 16 +-- .../command/CommandCreateJson.java | 19 ---- .../plantuml/svek/image/EntityImageState.java | 4 +- .../svek/image/EntityImageStateCommon.java | 8 +- .../EntityImageStateEmptyDescription.java | 2 +- .../sourceforge/plantuml/version/Version.java | 2 +- 16 files changed, 184 insertions(+), 199 deletions(-) diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateElementFull2.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateElementFull2.java index 7cfabad53..66b213876 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateElementFull2.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateElementFull2.java @@ -146,18 +146,18 @@ public class CommandCreateElementFull2 extends SingleLineCommand2 @Override final protected boolean isForbidden(CharSequence line) { - if (line.toString().matches("^[\\p{L}0-9_.]+$")) { + if (line.toString().matches("^[\\p{L}0-9_.]+$")) return true; - } + return false; } @Override protected CommandExecutionResult executeArg(ClassDiagram diagram, LineLocation location, RegexResult arg) throws NoSuchColorException { - if (mode == Mode.NORMAL_KEYWORD && diagram.isAllowMixing() == false) { + if (mode == Mode.NORMAL_KEYWORD && diagram.isAllowMixing() == false) return CommandExecutionResult.error("Use 'allowmixing' if you want to mix classes and other UML elements."); - } + String codeRaw = arg.getLazzy("CODE", 0); final String displayRaw = arg.getLazzy("DISPLAY", 0); final char codeChar = getCharEncoding(codeRaw); @@ -188,34 +188,36 @@ public class CommandCreateElementFull2 extends SingleLineCommand2 } else if (symbol.equalsIgnoreCase("usecase")) { type = LeafType.USECASE; usymbol = null; + } else if (symbol.equalsIgnoreCase("usecase/")) { + type = LeafType.USECASE_BUSINESS; + usymbol = null; } else if (symbol.equalsIgnoreCase("state")) { type = LeafType.STATE; usymbol = null; } else { type = LeafType.DESCRIPTION; usymbol = USymbols.fromString(symbol, diagram.getSkinParam()); - if (usymbol == null) { + if (usymbol == null) throw new IllegalStateException(); - } } final String idShort = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(codeRaw); final Ident ident = diagram.buildLeafIdent(idShort); final Code code = diagram.V1972() ? ident : diagram.buildCode(idShort); String display = displayRaw; - if (display == null) { + if (display == null) display = code.getName(); - } + display = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(display); final String stereotype = arg.getLazzy("STEREOTYPE", 0); final IEntity entity = diagram.getOrCreateLeaf(ident, code, type, usymbol); entity.setDisplay(Display.getWithNewlines(display)); entity.setUSymbol(usymbol); - if (stereotype != null) { + if (stereotype != null) entity.setStereotype(Stereotype.build(stereotype, diagram.getSkinParam().getCircledCharacterRadius(), diagram.getSkinParam().getFont(null, false, FontParam.CIRCLED_CHARACTER), diagram.getSkinParam().getIHtmlColorSet())); - } + CommandCreateClassMultilines.addTags(entity, arg.get("TAGS", 0)); final String urlString = arg.get("URL", 0); diff --git a/src/net/sourceforge/plantuml/command/CommandMultilines.java b/src/net/sourceforge/plantuml/command/CommandMultilines.java index 7060db96f..79007fa72 100644 --- a/src/net/sourceforge/plantuml/command/CommandMultilines.java +++ b/src/net/sourceforge/plantuml/command/CommandMultilines.java @@ -43,7 +43,7 @@ import net.sourceforge.plantuml.core.Diagram; public abstract class CommandMultilines implements Command { private final Pattern2 starting; - + public CommandMultilines(String patternStart) { if (patternStart.startsWith("^") == false || patternStart.endsWith("$") == false) { throw new IllegalArgumentException("Bad pattern " + patternStart); @@ -58,21 +58,19 @@ public abstract class CommandMultilines implements Command } final public CommandControl isValid(BlocLines lines) { - if (isCommandForbidden()) { + if (isCommandForbidden()) return CommandControl.NOT_OK; - } + Matcher2 m1 = starting.matcher(lines.getFirst().getTrimmed().getString()); - if (m1.matches() == false) { + if (m1.matches() == false) return CommandControl.NOT_OK; - } - if (lines.size() == 1) { + + if (lines.size() == 1) return CommandControl.OK_PARTIAL; - } m1 = MyPattern.cmpile(getPatternEnd()).matcher(lines.getLast().getTrimmed().getString()); - if (m1.matches() == false) { + if (m1.matches() == false) return CommandControl.OK_PARTIAL; - } actionIfCommandValid(); return CommandControl.OK; diff --git a/src/net/sourceforge/plantuml/command/CommandMultilines2.java b/src/net/sourceforge/plantuml/command/CommandMultilines2.java index 215966ac6..7bc1dc30f 100644 --- a/src/net/sourceforge/plantuml/command/CommandMultilines2.java +++ b/src/net/sourceforge/plantuml/command/CommandMultilines2.java @@ -47,7 +47,7 @@ public abstract class CommandMultilines2 implements Command implements Command implements Command implements Command implements Command implements Command { private final Pattern2 starting; - + public CommandMultilinesBracket(String patternStart) { - if (patternStart.startsWith("^") == false || patternStart.endsWith("$") == false) { + if (patternStart.startsWith("^") == false || patternStart.endsWith("$") == false) throw new IllegalArgumentException("Bad pattern " + patternStart); - } + this.starting = MyPattern.cmpile(patternStart); } protected boolean isCommandForbidden() { return false; } - + public String[] getDescription() { return new String[] { "BRACKET: " + starting.pattern() }; } @@ -68,37 +68,35 @@ public abstract class CommandMultilinesBracket implements Com } final public CommandControl isValid(BlocLines lines) { - if (isCommandForbidden()) { + if (isCommandForbidden()) return CommandControl.NOT_OK; - } + final Matcher2 m1 = starting.matcher(lines.getFirst().getTrimmed().getString()); - if (m1.matches() == false) { + if (m1.matches() == false) return CommandControl.NOT_OK; - } - if (lines.size() == 1) { + + if (lines.size() == 1) return CommandControl.OK_PARTIAL; - } int level = 1; for (StringLocated cs : lines.subExtract(1, 0)) { final String s = cs.getTrimmed().getString(); - if (isLineConsistent(s, level) == false) { + if (isLineConsistent(s, level) == false) return CommandControl.NOT_OK; - } - if (s.endsWith("{")) { + + if (s.endsWith("{")) level++; - } - if (s.endsWith("}")) { + + if (s.endsWith("}")) level--; - } - if (level < 0) { + + if (level < 0) return CommandControl.NOT_OK; - } + } - if (level != 0) { + if (level != 0) return CommandControl.OK_PARTIAL; - } actionIfCommandValid(); return CommandControl.OK; diff --git a/src/net/sourceforge/plantuml/command/SingleLineCommand2.java b/src/net/sourceforge/plantuml/command/SingleLineCommand2.java index fbc264585..95723c695 100644 --- a/src/net/sourceforge/plantuml/command/SingleLineCommand2.java +++ b/src/net/sourceforge/plantuml/command/SingleLineCommand2.java @@ -70,50 +70,51 @@ public abstract class SingleLineCommand2 implements Command implements Command(); for (int i = 0; i < rawBody.size(); i++) { final CharSequence s = rawBody.get(i); - if (isMethod(i, rawBody) == false) { + if (isMethod(i, rawBody) == false) continue; - } - if (s.length() == 0 && methodsToDisplay.size() == 0) { + + if (s.length() == 0 && methodsToDisplay.size() == 0) continue; - } + final Member m = Member.method(s); - if (hides == null || hides.contains(m.getVisibilityModifier()) == false) { + if (hides == null || hides.contains(m.getVisibilityModifier()) == false) methodsToDisplay.add(m); - } + } removeFinalEmptyMembers(methodsToDisplay); } @@ -150,16 +150,16 @@ public class BodierLikeClassOrObject implements Bodier { if (fieldsToDisplay == null) { fieldsToDisplay = new ArrayList<>(); for (CharSequence s : rawBody) { - if (type != LeafType.OBJECT && isMethod(s) == true) { + if (type != LeafType.OBJECT && isMethod(s) == true) continue; - } - if (s.length() == 0 && fieldsToDisplay.size() == 0) { + + if (s.length() == 0 && fieldsToDisplay.size() == 0) continue; - } + final Member m = Member.field(s); - if (hides == null || hides.contains(m.getVisibilityModifier()) == false) { + if (hides == null || hides.contains(m.getVisibilityModifier()) == false) fieldsToDisplay.add(m); - } + } removeFinalEmptyMembers(fieldsToDisplay); } @@ -167,29 +167,28 @@ public class BodierLikeClassOrObject implements Bodier { } private void removeFinalEmptyMembers(List result) { - while (result.size() > 0 && StringUtils.trin(result.get(result.size() - 1).getDisplay(false)).length() == 0) { + while (result.size() > 0 && StringUtils.trin(result.get(result.size() - 1).getDisplay(false)).length() == 0) result.remove(result.size() - 1); - } + } @Override public boolean hasUrl() { - for (CharSequence cs : getFieldsToDisplay()) { + for (CharSequence cs : getFieldsToDisplay()) if (cs instanceof Member) { final Member m = (Member) cs; - if (m.hasUrl()) { + if (m.hasUrl()) return true; - } + } - } - for (CharSequence cs : getMethodsToDisplay()) { + + for (CharSequence cs : getMethodsToDisplay()) if (cs instanceof Member) { final Member m = (Member) cs; - if (m.hasUrl()) { + if (m.hasUrl()) return true; - } + } - } return false; } @@ -197,14 +196,13 @@ public class BodierLikeClassOrObject implements Bodier { final List result = new ArrayList<>(); for (CharSequence s : rawBody) { final Member m; - if (isMethod(s)) { + if (isMethod(s)) m = Member.method(s); - } else { + else m = Member.field(s); - } - if (hides.contains(m.getVisibilityModifier()) == false) { + + if (hides.contains(m.getVisibilityModifier()) == false) result.add(m); - } } return result; @@ -214,41 +212,37 @@ public class BodierLikeClassOrObject implements Bodier { public TextBlock getBody(FontParam fontParam, ISkinParam skinParam, boolean showMethods, boolean showFields, Stereotype stereotype, Style style, FontConfiguration fontConfiguration) { - if (BodyFactory.BODY3) { + if (BodyFactory.BODY3) return new Body3(rawBody, fontParam, skinParam, stereotype, style); - } if (type.isLikeClass() && isBodyEnhanced()) { - if (showMethods || showFields) { + if (showMethods || showFields) return BodyFactory.create1(skinParam.getDefaultTextAlignment(HorizontalAlignment.LEFT), rawBodyWithoutHidden(), skinParam, stereotype, leaf, style); - } + return null; } - if (leaf == null) { + if (leaf == null) throw new IllegalStateException(); - } + if (type == LeafType.OBJECT) { - if (showFields == false) { + if (showFields == false) return new TextBlockLineBefore(style.value(PName.LineThickness).asDouble(), TextBlockUtils.empty(0, 0)); - } + return BodyFactory.create1(skinParam.getDefaultTextAlignment(HorizontalAlignment.LEFT), rawBodyWithoutHidden(), skinParam, stereotype, leaf, style); } assert type.isLikeClass(); - final MethodsOrFieldsArea fields = new MethodsOrFieldsArea(getFieldsToDisplay(), skinParam, leaf, - style); + final MethodsOrFieldsArea fields = new MethodsOrFieldsArea(getFieldsToDisplay(), skinParam, leaf, style); - final MethodsOrFieldsArea methods = new MethodsOrFieldsArea(getMethodsToDisplay(), skinParam, leaf, - style); - if (showFields && showMethods == false) { + final MethodsOrFieldsArea methods = new MethodsOrFieldsArea(getMethodsToDisplay(), skinParam, leaf, style); + if (showFields && showMethods == false) return fields.asBlockMemberImpl(); - } else if (showMethods && showFields == false) { + else if (showMethods && showFields == false) return methods.asBlockMemberImpl(); - } else if (showFields == false && showMethods == false) { + else if (showFields == false && showMethods == false) return TextBlockUtils.empty(0, 0); - } final TextBlock bb1 = fields.asBlockMemberImpl(); final TextBlock bb2 = methods.asBlockMemberImpl(); diff --git a/src/net/sourceforge/plantuml/cucadiagram/BodyEnhanced1.java b/src/net/sourceforge/plantuml/cucadiagram/BodyEnhanced1.java index d13edaae1..6ed57597c 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/BodyEnhanced1.java +++ b/src/net/sourceforge/plantuml/cucadiagram/BodyEnhanced1.java @@ -131,35 +131,40 @@ public class BodyEnhanced1 extends BodyEnhancedAbstract implements TextBlock, Wi char separator = lineFirst ? '_' : 0; TextBlock title = null; - Display display = Display.empty(); + Display display = null; for (ListIterator it = rawBody2.iterator(); it.hasNext();) { final CharSequence cs = it.next(); if (cs instanceof EmbeddedDiagram) { + if (display == null) + display = Display.empty(); if (display.size() > 0 || separator != 0) { blocks.add(decorate(stringBounder, new MethodsOrFieldsArea(display, skinParam, align, entity, style), separator, title)); separator = 0; title = null; - display = Display.empty(); + display = null; } - blocks.add(((EmbeddedDiagram) cs).asDraw(skinParam)); + blocks.add(TextBlockUtils.withMargin(((EmbeddedDiagram) cs).asDraw(skinParam), 2, 2)); } else { final String s = cs.toString(); if (isBlockSeparator(s)) { + if (display == null) + display = Display.empty(); blocks.add(decorate(stringBounder, new MethodsOrFieldsArea(display, skinParam, align, entity, style), separator, title)); separator = s.charAt(0); title = getTitle(s, skinParam); - display = Display.empty(); + display = null; } else if (isTreeOrTable(s)) { final boolean isTable = CreoleParser.isTableLine(s); - if (display.size() > 0) - blocks.add(decorate(stringBounder, - new MethodsOrFieldsArea(display, skinParam, align, entity, style), separator, title)); + if (display == null) + display = Display.empty(); + blocks.add(decorate(stringBounder, + new MethodsOrFieldsArea(display, skinParam, align, entity, style), separator, title)); separator = 0; title = null; - display = Display.empty(); + display = null; final List allTree = buildTreeOrTable(s, it); final FontConfiguration fontConfiguration = style.getFontConfiguration(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet()); @@ -170,6 +175,8 @@ public class BodyEnhanced1 extends BodyEnhancedAbstract implements TextBlock, Wi blocks.add(bloc); } else { + if (display == null) + display = Display.empty(); display = display.add(cs); if (cs instanceof Member && ((Member) cs).getUrl() != null) urls.add(((Member) cs).getUrl()); @@ -177,9 +184,12 @@ public class BodyEnhanced1 extends BodyEnhancedAbstract implements TextBlock, Wi } } } - if (inEllipse && display.size() == 0) { + + if (display == null) + display = Display.empty(); + if (inEllipse && display.size() == 0) display = display.add(""); - } + blocks.add(decorate(stringBounder, new MethodsOrFieldsArea(display, skinParam, align, entity, style), separator, title)); diff --git a/src/net/sourceforge/plantuml/cucadiagram/BodyEnhancedAbstract.java b/src/net/sourceforge/plantuml/cucadiagram/BodyEnhancedAbstract.java index cb827a24c..103486f61 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/BodyEnhancedAbstract.java +++ b/src/net/sourceforge/plantuml/cucadiagram/BodyEnhancedAbstract.java @@ -64,18 +64,18 @@ public abstract class BodyEnhancedAbstract extends AbstractTextBlock implements public static boolean isBlockSeparator(CharSequence cs) { final String s = cs.toString(); - if (s.startsWith("--") && s.endsWith("--")) { + if (s.startsWith("--") && s.endsWith("--")) return true; - } - if (s.startsWith("==") && s.endsWith("==")) { + + if (s.startsWith("==") && s.endsWith("==")) return true; - } - if (s.startsWith("..") && s.endsWith("..") && s.equals("...") == false) { + + if (s.startsWith("..") && s.endsWith("..") && s.equals("...") == false) return true; - } - if (s.startsWith("__") && s.endsWith("__")) { + + if (s.startsWith("__") && s.endsWith("__")) return true; - } + return false; } diff --git a/src/net/sourceforge/plantuml/objectdiagram/command/CommandCreateJson.java b/src/net/sourceforge/plantuml/objectdiagram/command/CommandCreateJson.java index 1faa9ad4f..39d5f4ea0 100644 --- a/src/net/sourceforge/plantuml/objectdiagram/command/CommandCreateJson.java +++ b/src/net/sourceforge/plantuml/objectdiagram/command/CommandCreateJson.java @@ -104,31 +104,12 @@ public class CommandCreateJson extends CommandMultilines2 0; System.err.println("l=" + line); sb.append(line); -// entity1.getBodier().addFieldOrMethod(line); -// if (BodierMap.getLinkedEntry(line) != null) { -// final String linkStr = BodierMap.getLinkedEntry(line); -// final int x = line.indexOf(linkStr); -// final String key = line.substring(0, x).trim(); -// final String dest = line.substring(x + linkStr.length()).trim(); -// final Ident ident2 = diagram.buildLeafIdentSpecial(dest); -// final ILeaf entity2 = diagram.getEntityFactory().getLeafStrict(ident2); -// if (entity2 == null) -// return CommandExecutionResult.error("No such entity " + ident2.getName()); -// -// final LinkType linkType = new LinkType(LinkDecor.ARROW, LinkDecor.NONE); -// final int length = linkStr.length() - 2; -// final Link link = new Link(entity1, entity2, linkType, Display.NULL, length, -// diagram.getSkinParam().getCurrentStyleBuilder()); -// link.setPortMembers(key, null); -// diagram.addLink(link); -// } } sb.append("}"); final DefaultHandler handler = new DefaultHandler(); new JsonParser(handler).parse(sb.toString()); final JsonValue json = handler.getValue(); - System.err.println("foo=" + json); ((BodierJSon) entity1.getBodier()).setJson(json); return CommandExecutionResult.ok(); diff --git a/src/net/sourceforge/plantuml/svek/image/EntityImageState.java b/src/net/sourceforge/plantuml/svek/image/EntityImageState.java index 9c97373e0..41996f9d5 100644 --- a/src/net/sourceforge/plantuml/svek/image/EntityImageState.java +++ b/src/net/sourceforge/plantuml/svek/image/EntityImageState.java @@ -104,9 +104,9 @@ public class EntityImageState extends EntityImageStateCommon { final Dimension2D dimTotal = calculateDimension(stringBounder); final Dimension2D dimDesc = desc.calculateDimension(stringBounder); - final UStroke stroke = getStyleState().getStroke(); + final UStroke stroke = getStyleState().getStroke(lineConfig.getColors()); - ug = applyColorAndStroke(ug); + ug = applyColor(ug); ug = ug.apply(stroke); ug.draw(getShape(dimTotal)); diff --git a/src/net/sourceforge/plantuml/svek/image/EntityImageStateCommon.java b/src/net/sourceforge/plantuml/svek/image/EntityImageStateCommon.java index 52c402102..61fe326ae 100644 --- a/src/net/sourceforge/plantuml/svek/image/EntityImageStateCommon.java +++ b/src/net/sourceforge/plantuml/svek/image/EntityImageStateCommon.java @@ -68,8 +68,8 @@ public abstract class EntityImageStateCommon extends AbstractEntityImage { this.lineConfig = entity; - final FontConfiguration fontConfiguration = getStyleStateHeader() - .getFontConfiguration(getSkinParam().getThemeStyle(), getSkinParam().getIHtmlColorSet()); + final FontConfiguration fontConfiguration = getStyleStateHeader().getFontConfiguration( + getSkinParam().getThemeStyle(), getSkinParam().getIHtmlColorSet(), entity.getColors()); this.desc = entity.getDisplay().create8(fontConfiguration, HorizontalAlignment.CENTER, skinParam, CreoleMode.FULL, skinParam.wrapWidth()); @@ -109,7 +109,7 @@ public abstract class EntityImageStateCommon extends AbstractEntityImage { return rect; } - final protected UGraphic applyColorAndStroke(UGraphic ug) { + final protected UGraphic applyColor(UGraphic ug) { HColor border = lineConfig.getColors().getColor(ColorType.LINE); if (border == null) @@ -117,7 +117,7 @@ public abstract class EntityImageStateCommon extends AbstractEntityImage { getSkinParam().getIHtmlColorSet()); ug = ug.apply(border); - HColor backcolor = getEntity().getColors().getColor(ColorType.BACK); + HColor backcolor = lineConfig.getColors().getColor(ColorType.BACK); if (backcolor == null) backcolor = getStyleState().value(PName.BackGroundColor).asColor(getSkinParam().getThemeStyle(), getSkinParam().getIHtmlColorSet()); diff --git a/src/net/sourceforge/plantuml/svek/image/EntityImageStateEmptyDescription.java b/src/net/sourceforge/plantuml/svek/image/EntityImageStateEmptyDescription.java index f5e6940e4..97d3ec65c 100644 --- a/src/net/sourceforge/plantuml/svek/image/EntityImageStateEmptyDescription.java +++ b/src/net/sourceforge/plantuml/svek/image/EntityImageStateEmptyDescription.java @@ -70,7 +70,7 @@ public class EntityImageStateEmptyDescription extends EntityImageStateCommon { final UStroke stroke = getStyleState().getStroke(); - ug = applyColorAndStroke(ug); + ug = applyColor(ug); ug = ug.apply(stroke); ug.draw(getShape(dimTotal)); diff --git a/src/net/sourceforge/plantuml/version/Version.java b/src/net/sourceforge/plantuml/version/Version.java index 14353d8e4..8adf14f32 100644 --- a/src/net/sourceforge/plantuml/version/Version.java +++ b/src/net/sourceforge/plantuml/version/Version.java @@ -80,7 +80,7 @@ public class Version { } public static int beta() { - final int beta = 4; + final int beta = 5; return beta; }