2010-11-15 20:35:36 +00:00
|
|
|
/* ========================================================================
|
|
|
|
* PlantUML : a free UML diagram generator
|
|
|
|
* ========================================================================
|
|
|
|
*
|
|
|
|
* (C) Copyright 2009, Arnaud Roques
|
|
|
|
*
|
|
|
|
* Project Info: http://plantuml.sourceforge.net
|
|
|
|
*
|
|
|
|
* 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 Lesser 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.
|
|
|
|
*
|
|
|
|
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
|
|
|
|
* in the United States and other countries.]
|
|
|
|
*
|
|
|
|
* Original Author: Arnaud Roques
|
|
|
|
*
|
|
|
|
* Revision $Revision: 4762 $
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package net.sourceforge.plantuml.activitydiagram.command;
|
|
|
|
|
2011-01-05 18:23:06 +00:00
|
|
|
import java.util.Map;
|
2010-11-15 20:35:36 +00:00
|
|
|
|
|
|
|
import net.sourceforge.plantuml.Direction;
|
|
|
|
import net.sourceforge.plantuml.StringUtils;
|
|
|
|
import net.sourceforge.plantuml.activitydiagram.ActivityDiagram;
|
|
|
|
import net.sourceforge.plantuml.command.CommandExecutionResult;
|
2011-01-05 18:23:06 +00:00
|
|
|
import net.sourceforge.plantuml.command.SingleLineCommand2;
|
|
|
|
import net.sourceforge.plantuml.command.regex.RegexConcat;
|
|
|
|
import net.sourceforge.plantuml.command.regex.RegexLeaf;
|
|
|
|
import net.sourceforge.plantuml.command.regex.RegexOr;
|
|
|
|
import net.sourceforge.plantuml.command.regex.RegexPartialMatch;
|
2010-11-15 20:35:36 +00:00
|
|
|
import net.sourceforge.plantuml.cucadiagram.IEntity;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.Link;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.LinkDecor;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.LinkType;
|
|
|
|
|
2011-01-05 18:23:06 +00:00
|
|
|
public class CommandIf extends SingleLineCommand2<ActivityDiagram> {
|
2010-11-15 20:35:36 +00:00
|
|
|
|
|
|
|
public CommandIf(ActivityDiagram diagram) {
|
2011-01-05 18:23:06 +00:00
|
|
|
super(diagram, getRegexConcat());
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|
|
|
|
|
2011-01-05 18:23:06 +00:00
|
|
|
static RegexConcat getRegexConcat() {
|
|
|
|
return new RegexConcat(new RegexLeaf("^"),
|
|
|
|
new RegexOr("FIRST", true,
|
2011-02-14 11:56:34 +00:00
|
|
|
new RegexLeaf("STAR", "(\\(\\*(top)?\\))"),
|
2011-01-05 18:23:06 +00:00
|
|
|
new RegexLeaf("CODE", "([\\p{L}0-9_.]+)"),
|
|
|
|
new RegexLeaf("BAR", "(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)"),
|
|
|
|
new RegexLeaf("QUOTED", "\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?")),
|
|
|
|
new RegexLeaf("\\s*"),
|
2011-02-14 11:56:34 +00:00
|
|
|
new RegexLeaf("ARROW", "([=-]+(?:(left|right|up|down|le?|ri?|up?|do?)(?=[-=.]))?[=-]*\\>)?"),
|
2011-01-05 18:23:06 +00:00
|
|
|
new RegexLeaf("\\s*"),
|
|
|
|
new RegexLeaf("BRACKET", "(?:\\[([^\\]*]+[^\\]]*)\\])?"),
|
|
|
|
new RegexLeaf("\\s*"),
|
2011-01-11 07:42:49 +00:00
|
|
|
new RegexLeaf("IF", "if\\s*\"([^\"]*)\"\\s*(?:as\\s+([\\p{L}0-9_.]+)\\s+)?(?:then)?$"));
|
2011-01-05 18:23:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-15 20:35:36 +00:00
|
|
|
@Override
|
2011-01-05 18:23:06 +00:00
|
|
|
protected CommandExecutionResult executeArg(Map<String, RegexPartialMatch> arg) {
|
|
|
|
final IEntity entity1 = CommandLinkActivity.getEntity(getSystem(), arg, true);
|
2010-11-15 20:35:36 +00:00
|
|
|
|
2011-01-05 18:23:06 +00:00
|
|
|
getSystem().startIf(arg.get("IF").get(1));
|
2010-11-15 20:35:36 +00:00
|
|
|
|
|
|
|
int lenght = 2;
|
|
|
|
|
2011-01-05 18:23:06 +00:00
|
|
|
if (arg.get("ARROW").get(0) != null) {
|
|
|
|
final String arrow = StringUtils.manageArrowForCuca(arg.get("ARROW").get(0));
|
2010-11-15 20:35:36 +00:00
|
|
|
lenght = arrow.length() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
final IEntity branch = getSystem().getCurrentContext().getBranch();
|
|
|
|
|
2011-01-05 18:23:06 +00:00
|
|
|
Link link = new Link(entity1, branch, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), arg.get("BRACKET").get(0),
|
|
|
|
lenght, null, arg.get("IF").get(0), getSystem().getLabeldistance(), getSystem().getLabelangle());
|
|
|
|
if (arg.get("ARROW").get(0) != null) {
|
|
|
|
final Direction direction = StringUtils.getArrowDirection(arg.get("ARROW").get(0));
|
2010-11-15 20:35:36 +00:00
|
|
|
if (direction == Direction.LEFT || direction == Direction.UP) {
|
|
|
|
link = link.getInv();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getSystem().addLink(link);
|
|
|
|
|
|
|
|
return CommandExecutionResult.ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|