1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-11-22 13:05:09 +00:00

Minor refactoring

This commit is contained in:
Arnaud Roques 2022-04-02 14:56:05 +02:00
parent c88448d3da
commit bbf173962a
2 changed files with 19 additions and 23 deletions

View File

@ -63,7 +63,7 @@ public class CommandReferenceMultilinesOverSeveral extends CommandMultilines<Seq
} }
private static RegexConcat getConcat() { private static RegexConcat getConcat() {
return RegexConcat.build(CommandReferenceMultilinesOverSeveral.class.getName(), return RegexConcat.build(CommandReferenceMultilinesOverSeveral.class.getName(), //
RegexLeaf.start(), // RegexLeaf.start(), //
new RegexLeaf("ref"), // new RegexLeaf("ref"), //
new RegexLeaf("REF", "(#\\w+)?"), // new RegexLeaf("REF", "(#\\w+)?"), //
@ -73,23 +73,23 @@ public class CommandReferenceMultilinesOverSeveral extends CommandMultilines<Seq
new RegexLeaf("PARTS", "((?:[%pLN_.@]+|[%g][^%g]+[%g])(?:[%s]*,[%s]*(?:[%pLN_.@]+|[%g][^%g]+[%g]))*)"), // new RegexLeaf("PARTS", "((?:[%pLN_.@]+|[%g][^%g]+[%g])(?:[%s]*,[%s]*(?:[%pLN_.@]+|[%g][^%g]+[%g]))*)"), //
RegexLeaf.spaceZeroOrMore(), // RegexLeaf.spaceZeroOrMore(), //
new RegexOptional(new RegexLeaf("URL", "(\\[\\[.*?\\]\\])")), // new RegexOptional(new RegexLeaf("URL", "(\\[\\[.*?\\]\\])")), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("UNUSED", "(#\\w+)?"), //
RegexLeaf.end()); RegexLeaf.end());
} }
@Override @Override
public String getPatternEnd() { public String getPatternEnd() {
return "^end[%s]?(ref)?$"; return "^end[%s]?(ref)?$";
} }
public CommandExecutionResult execute(final SequenceDiagram diagram, BlocLines lines) throws NoSuchColorException { public CommandExecutionResult execute(final SequenceDiagram diagram, BlocLines lines) throws NoSuchColorException {
String firstLine = lines.getFirst().getTrimmed().getString(); final String firstLine = lines.getFirst().getTrimmed().getString();
RegexResult arg = getConcat().matcher(firstLine); final RegexResult arg = getConcat().matcher(firstLine);
if (arg == null) { if (arg == null)
return CommandExecutionResult.error("Cannot parse line " + firstLine); return CommandExecutionResult.error("Cannot parse line " + firstLine);
}
String s1 = arg.get("REF", 0); final String s1 = arg.get("REF", 0);
final HColor backColorElement = s1 == null ? null final HColor backColorElement = s1 == null ? null
: diagram.getSkinParam().getIHtmlColorSet().getColor(diagram.getSkinParam().getThemeStyle(), s1); : diagram.getSkinParam().getIHtmlColorSet().getColor(diagram.getSkinParam().getThemeStyle(), s1);
// final HtmlColor backColorGeneral = // final HtmlColor backColorGeneral =
@ -97,20 +97,18 @@ public class CommandReferenceMultilinesOverSeveral extends CommandMultilines<Seq
final List<String> participants = StringUtils.splitComma(arg.get("PARTS", 0)); final List<String> participants = StringUtils.splitComma(arg.get("PARTS", 0));
final List<Participant> p = new ArrayList<>(); final List<Participant> p = new ArrayList<>();
for (String s : participants) { for (String s : participants)
p.add(diagram.getOrCreateParticipant(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(s))); p.add(diagram.getOrCreateParticipant(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(s)));
}
lines = lines.subExtract(1, 1); lines = lines.subExtract(1, 1);
lines = lines.removeEmptyColumns(); lines = lines.removeEmptyColumns();
Display strings = lines.toDisplay(); final Display strings = lines.toDisplay();
String url = arg.get("URL", 0); final String url = arg.get("URL", 0);
final UrlBuilder b = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), UrlMode.STRICT); final UrlBuilder b = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), UrlMode.STRICT);
Url u = null; Url u = null;
if (url != null) { if (url != null)
u = b.getUrl(url); u = b.getUrl(url);
}
final HColor backColorGeneral = null; final HColor backColorGeneral = null;
final Reference ref = new Reference(p, u, strings, backColorGeneral, backColorElement, final Reference ref = new Reference(p, u, strings, backColorGeneral, backColorElement,
@ -119,4 +117,4 @@ public class CommandReferenceMultilinesOverSeveral extends CommandMultilines<Seq
return CommandExecutionResult.ok(); return CommandExecutionResult.ok();
} }
} }

View File

@ -63,14 +63,14 @@ public class CommandReferenceOverSeveral extends SingleLineCommand2<SequenceDiag
} }
private static RegexConcat getConcat() { private static RegexConcat getConcat() {
return RegexConcat.build(CommandReferenceOverSeveral.class.getName(), RegexLeaf.start(), // return RegexConcat.build(CommandReferenceOverSeveral.class.getName(), //
RegexLeaf.start(), //
new RegexLeaf("ref"), // new RegexLeaf("ref"), //
new RegexLeaf("REF", "(#\\w+)?"), // new RegexLeaf("REF", "(#\\w+)?"), //
RegexLeaf.spaceOneOrMore(), // RegexLeaf.spaceOneOrMore(), //
new RegexLeaf("over"), // new RegexLeaf("over"), //
RegexLeaf.spaceOneOrMore(), // RegexLeaf.spaceOneOrMore(), //
new RegexLeaf("PARTS", new RegexLeaf("PARTS", "(([%pLN_.@]+|[%g][^%g]+[%g])([%s]*,[%s]*([%pLN_.@]+|[%g][^%g]+[%g]))*)"), //
"(([%pLN_.@]+|[%g][^%g]+[%g])([%s]*,[%s]*([%pLN_.@]+|[%g][^%g]+[%g]))*)"), //
RegexLeaf.spaceZeroOrMore(), // RegexLeaf.spaceZeroOrMore(), //
new RegexOptional(new RegexLeaf("URL", "(\\[\\[.*?\\]\\])")), // new RegexOptional(new RegexLeaf("URL", "(\\[\\[.*?\\]\\])")), //
RegexLeaf.spaceZeroOrMore(), // RegexLeaf.spaceZeroOrMore(), //
@ -82,7 +82,7 @@ public class CommandReferenceOverSeveral extends SingleLineCommand2<SequenceDiag
@Override @Override
protected CommandExecutionResult executeArg(SequenceDiagram diagram, LineLocation location, RegexResult arg) protected CommandExecutionResult executeArg(SequenceDiagram diagram, LineLocation location, RegexResult arg)
throws NoSuchColorException { throws NoSuchColorException {
String s1 = arg.get("REF", 0); final String s1 = arg.get("REF", 0);
final HColor backColorElement = s1 == null ? null final HColor backColorElement = s1 == null ? null
: diagram.getSkinParam().getIHtmlColorSet().getColor(diagram.getSkinParam().getThemeStyle(), s1); : diagram.getSkinParam().getIHtmlColorSet().getColor(diagram.getSkinParam().getThemeStyle(), s1);
// final HtmlColor backColorGeneral = // final HtmlColor backColorGeneral =
@ -93,17 +93,15 @@ public class CommandReferenceOverSeveral extends SingleLineCommand2<SequenceDiag
final String text = StringUtils.trin(arg.get("TEXT", 0)); final String text = StringUtils.trin(arg.get("TEXT", 0));
final List<Participant> p = new ArrayList<>(); final List<Participant> p = new ArrayList<>();
for (String s : participants) { for (String s : participants)
p.add(diagram.getOrCreateParticipant(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(s))); p.add(diagram.getOrCreateParticipant(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(s)));
}
final Display strings = Display.getWithNewlines(text); final Display strings = Display.getWithNewlines(text);
final UrlBuilder b = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), UrlMode.STRICT); final UrlBuilder b = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), UrlMode.STRICT);
Url u = null; Url u = null;
if (url != null) { if (url != null)
u = b.getUrl(url); u = b.getUrl(url);
}
final HColor backColorGeneral = null; final HColor backColorGeneral = null;
final Reference ref = new Reference(p, u, strings, backColorGeneral, backColorElement, final Reference ref = new Reference(p, u, strings, backColorGeneral, backColorElement,
@ -112,4 +110,4 @@ public class CommandReferenceOverSeveral extends SingleLineCommand2<SequenceDiag
return CommandExecutionResult.ok(); return CommandExecutionResult.ok();
} }
} }