1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-01 08:00:48 +00:00
plantuml/src/net/sourceforge/plantuml/command/CommandPackageEmpty.java

117 lines
4.4 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.command;
2019-06-26 19:24:49 +00:00
import net.sourceforge.plantuml.LineLocation;
2015-09-28 20:42:17 +00:00
import net.sourceforge.plantuml.StringUtils;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram;
2019-06-26 19:24:49 +00:00
import net.sourceforge.plantuml.command.regex.IRegex;
import net.sourceforge.plantuml.command.regex.RegexConcat;
import net.sourceforge.plantuml.command.regex.RegexLeaf;
import net.sourceforge.plantuml.command.regex.RegexOptional;
import net.sourceforge.plantuml.command.regex.RegexResult;
2013-12-10 19:36:50 +00:00
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;
2019-12-10 21:45:49 +00:00
import net.sourceforge.plantuml.cucadiagram.Ident;
2018-03-09 21:37:34 +00:00
import net.sourceforge.plantuml.cucadiagram.NamespaceStrategy;
2015-09-28 20:42:17 +00:00
import net.sourceforge.plantuml.graphic.color.ColorType;
2021-02-02 10:12:15 +00:00
import net.sourceforge.plantuml.ugraphic.color.NoSuchColorException;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.utils.UniqueSequence;
2013-12-10 19:36:50 +00:00
2019-06-26 19:24:49 +00:00
public class CommandPackageEmpty extends SingleLineCommand2<AbstractEntityDiagram> {
2013-12-10 19:36:50 +00:00
public CommandPackageEmpty() {
2019-06-26 19:24:49 +00:00
super(getRegexConcat());
}
static IRegex getRegexConcat() {
return RegexConcat.build(CommandPackageEmpty.class.getName(), RegexLeaf.start(), //
new RegexLeaf("package"), //
RegexLeaf.spaceOneOrMore(), //
new RegexLeaf("DISPLAY", "([%g][^%g]+[%g]|[^#%s{}]*)"), //
new RegexOptional( //
new RegexConcat( //
RegexLeaf.spaceOneOrMore(), //
new RegexLeaf("as"), //
RegexLeaf.spaceOneOrMore(), //
new RegexLeaf("CODE", "([\\p{L}0-9_.]+)") //
)), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("COLOR", "(#[0-9a-fA-F]{6}|#?\\w+)?"), //
RegexLeaf.spaceZeroOrMore(), //
2019-07-14 20:09:26 +00:00
new RegexLeaf("\\{"), //
RegexLeaf.spaceZeroOrMore(), //
new RegexLeaf("\\}"), //
RegexLeaf.end()); //
2013-12-10 19:36:50 +00:00
}
@Override
2021-05-06 21:23:05 +00:00
protected CommandExecutionResult executeArg(AbstractEntityDiagram diagram, LineLocation location, RegexResult arg)
throws NoSuchColorException {
2019-12-10 21:45:49 +00:00
final String idShort;
2013-12-10 19:36:50 +00:00
final String display;
2019-06-26 19:24:49 +00:00
if (arg.get("CODE", 0) == null) {
if (StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("DISPLAY", 0)).length() == 0) {
2019-12-10 21:45:49 +00:00
idShort = "##" + UniqueSequence.getValue();
2013-12-10 19:36:50 +00:00
display = null;
} else {
2019-12-10 21:45:49 +00:00
idShort = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("DISPLAY", 0));
2020-01-12 22:13:17 +00:00
display = idShort;
2013-12-10 19:36:50 +00:00
}
} else {
2019-06-26 19:24:49 +00:00
display = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("DISPLAY", 0));
2019-12-10 21:45:49 +00:00
idShort = arg.get("CODE", 0);
2013-12-10 19:36:50 +00:00
}
final IGroup currentPackage = diagram.getCurrentGroup();
2020-01-12 22:13:17 +00:00
final Ident ident = diagram.buildLeafIdent(idShort);
final Code code = diagram.V1972() ? ident : diagram.buildCode(idShort);
diagram.gotoGroup(ident, code, Display.getWithNewlines(display), GroupType.PACKAGE, currentPackage,
2018-03-09 21:37:34 +00:00
NamespaceStrategy.SINGLE);
final IEntity p = diagram.getCurrentGroup();
2019-06-26 19:24:49 +00:00
final String color = arg.get("COLOR", 0);
2013-12-10 19:36:50 +00:00
if (color != null) {
2018-03-09 21:37:34 +00:00
p.setSpecificColorTOBEREMOVED(ColorType.BACK,
2021-05-06 21:23:05 +00:00
diagram.getSkinParam().getIHtmlColorSet().getColor(diagram.getSkinParam().getThemeStyle(), color));
2013-12-10 19:36:50 +00:00
}
diagram.endGroup();
return CommandExecutionResult.ok();
}
}