1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-06 18:30:52 +00:00
plantuml/src/net/sourceforge/plantuml/descdiagram/command/CommandPackageWithUSymbol.java

144 lines
5.5 KiB
Java
Raw Normal View History

2013-12-10 19:36:50 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2019-01-16 18:34:41 +00:00
* (C) Copyright 2009-2020, Arnaud Roques
2013-12-10 19:36:50 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2013-12-10 19:36:50 +00:00
*
2017-03-15 19:13:31 +00:00
* If you like this project or if you find it useful, you can support us at:
*
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
*
2013-12-10 19:36:50 +00:00
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
*
*
*/
package net.sourceforge.plantuml.descdiagram.command;
2015-09-06 17:28:59 +00:00
import net.sourceforge.plantuml.StringUtils;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.UrlBuilder;
import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram;
2018-03-09 21:37:34 +00:00
import net.sourceforge.plantuml.classdiagram.command.CommandCreateClassMultilines;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand2;
import net.sourceforge.plantuml.command.regex.RegexConcat;
import net.sourceforge.plantuml.command.regex.RegexLeaf;
2017-04-05 17:37:42 +00:00
import net.sourceforge.plantuml.command.regex.RegexOr;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.command.regex.RegexResult;
import net.sourceforge.plantuml.cucadiagram.Code;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.cucadiagram.GroupType;
import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.IGroup;
2018-03-09 21:37:34 +00:00
import net.sourceforge.plantuml.cucadiagram.NamespaceStrategy;
import net.sourceforge.plantuml.cucadiagram.Stereotag;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.Stereotype;
import net.sourceforge.plantuml.graphic.USymbol;
2015-09-06 17:28:59 +00:00
import net.sourceforge.plantuml.graphic.color.ColorParser;
2015-09-28 20:42:17 +00:00
import net.sourceforge.plantuml.graphic.color.ColorType;
2017-12-11 21:02:10 +00:00
import net.sourceforge.plantuml.graphic.color.Colors;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.utils.UniqueSequence;
2013-12-10 19:36:50 +00:00
public class CommandPackageWithUSymbol extends SingleLineCommand2<AbstractEntityDiagram> {
public CommandPackageWithUSymbol() {
super(getRegexConcat());
}
private static RegexConcat getRegexConcat() {
return new RegexConcat(new RegexLeaf("^"), //
2017-04-05 17:37:42 +00:00
new RegexLeaf("SYMBOL",
"(package|rectangle|node|artifact|folder|file|frame|cloud|database|storage|component|card|together)"), //
2015-04-07 18:18:37 +00:00
new RegexLeaf("[%s]+"), //
2017-04-05 17:37:42 +00:00
new RegexOr(//
new RegexConcat( //
2018-05-01 17:26:04 +00:00
new RegexLeaf("DISPLAY1", "([%g].+?[%g])"), //
2017-04-05 17:37:42 +00:00
new RegexLeaf("STEREOTYPE1", "(?:[%s]+(\\<\\<.+\\>\\>))?"), //
new RegexLeaf("[%s]*as[%s]+"), //
new RegexLeaf("CODE1", "([^#%s{}]+)") //
), //
new RegexConcat( //
new RegexLeaf("CODE2", "([^#%s{}%g]+)"), //
new RegexLeaf("STEREOTYPE2", "(?:[%s]+(\\<\\<.+\\>\\>))?"), //
new RegexLeaf("[%s]*as[%s]+"), //
2018-05-01 17:26:04 +00:00
new RegexLeaf("DISPLAY2", "([%g].+?[%g])") //
2017-04-05 17:37:42 +00:00
), //
new RegexConcat( //
new RegexLeaf("DISPLAY3", "([^#%s{}%g]+)"), //
new RegexLeaf("STEREOTYPE3", "(?:[%s]+(\\<\\<.+\\>\\>))?"), //
new RegexLeaf("[%s]*as[%s]+"), //
new RegexLeaf("CODE3", "([^#%s{}%g]+)") //
), //
new RegexLeaf("CODE8", "([%g][^%g]+[%g])"), //
new RegexLeaf("CODE9", "([^#%s{}%g]*)") //
), //
2015-04-07 18:18:37 +00:00
new RegexLeaf("[%s]*"), //
2013-12-10 19:36:50 +00:00
new RegexLeaf("STEREOTYPE", "(\\<\\<.*\\>\\>)?"), //
2015-04-07 18:18:37 +00:00
new RegexLeaf("[%s]*"), //
2018-03-09 21:37:34 +00:00
new RegexLeaf("TAGS", Stereotag.pattern() + "?"), //
new RegexLeaf("[%s]*"), //
2013-12-10 19:36:50 +00:00
new RegexLeaf("URL", "(" + UrlBuilder.getRegexp() + ")?"), //
2015-04-07 18:18:37 +00:00
new RegexLeaf("[%s]*"), //
2017-12-11 21:02:10 +00:00
color().getRegex(), //
2015-04-07 18:18:37 +00:00
new RegexLeaf("[%s]*\\{$"));
2013-12-10 19:36:50 +00:00
}
2017-12-11 21:02:10 +00:00
private static ColorParser color() {
return ColorParser.simpleColor(ColorType.BACK);
}
2013-12-10 19:36:50 +00:00
@Override
protected CommandExecutionResult executeArg(AbstractEntityDiagram diagram, RegexResult arg) {
2017-04-05 17:37:42 +00:00
final String codeRaw = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.getLazzy("CODE", 0));
final String displayRaw = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.getLazzy("DISPLAY", 0));
2013-12-10 19:36:50 +00:00
final Code code;
final String display;
2017-04-05 17:37:42 +00:00
if (codeRaw.length() == 0) {
code = UniqueSequence.getCode("##");
display = null;
} else {
code = Code.of(codeRaw);
if (displayRaw == null) {
2015-04-07 18:18:37 +00:00
display = code.getFullName();
2017-04-05 17:37:42 +00:00
} else {
display = displayRaw;
2013-12-10 19:36:50 +00:00
}
}
2017-04-05 17:37:42 +00:00
2013-12-10 19:36:50 +00:00
final IGroup currentPackage = diagram.getCurrentGroup();
2018-03-09 21:37:34 +00:00
diagram.gotoGroup2(code, Display.getWithNewlines(display), GroupType.PACKAGE, currentPackage,
NamespaceStrategy.SINGLE);
final IEntity p = diagram.getCurrentGroup();
2013-12-10 19:36:50 +00:00
p.setUSymbol(USymbol.getFromString(arg.get("SYMBOL", 0)));
2017-09-03 16:59:24 +00:00
final String stereotype = arg.getLazzy("STEREOTYPE", 0);
2013-12-10 19:36:50 +00:00
if (stereotype != null) {
p.setStereotype(new Stereotype(stereotype, false));
}
2018-03-09 21:37:34 +00:00
CommandCreateClassMultilines.addTags(p, arg.get("TAGS", 0));
2017-12-11 21:02:10 +00:00
final Colors colors = color().getColor(arg, diagram.getSkinParam().getIHtmlColorSet());
p.setColors(colors);
2013-12-10 19:36:50 +00:00
return CommandExecutionResult.ok();
}
}