1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-02 00:20:49 +00:00
plantuml/src/net/sourceforge/plantuml/descdiagram/DescriptionDiagram.java

135 lines
5.0 KiB
Java
Raw Normal View History

2013-12-10 19:36:50 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, Arnaud Roques
2013-12-10 19:36:50 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
*
2017-03-15 19:13:31 +00:00
* If you like this project or if you find it useful, you can support us at:
*
2017-03-15 19:13:31 +00:00
* 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
*
2013-12-10 19:36:50 +00:00
*
*/
package net.sourceforge.plantuml.descdiagram;
2022-09-20 20:35:41 +00:00
import java.util.Map;
2021-05-14 08:42:57 +00:00
import java.util.Objects;
2022-12-17 11:10:05 +00:00
import net.sourceforge.plantuml.StringUtils;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.UmlDiagramType;
2022-11-07 19:27:11 +00:00
import net.sourceforge.plantuml.baraye.ILeaf;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram;
2021-05-23 15:35:13 +00:00
import net.sourceforge.plantuml.core.UmlSource;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.Code;
2019-12-10 21:45:49 +00:00
import net.sourceforge.plantuml.cucadiagram.Ident;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.LeafType;
import net.sourceforge.plantuml.graphic.USymbol;
2022-02-17 18:27:32 +00:00
import net.sourceforge.plantuml.graphic.USymbols;
2013-12-10 19:36:50 +00:00
public class DescriptionDiagram extends AbstractEntityDiagram {
2019-12-10 21:45:49 +00:00
2022-09-20 20:35:41 +00:00
public DescriptionDiagram(UmlSource source, Map<String, String> skinParam) {
2022-09-18 17:08:06 +00:00
super(source, UmlDiagramType.DESCRIPTION, skinParam);
2019-06-26 19:24:49 +00:00
}
2020-01-12 22:13:17 +00:00
@Override
public Ident cleanIdent(Ident ident) {
String codeString = ident.getName();
if (codeString.startsWith("[") && codeString.endsWith("]")) {
return ident.eventuallyRemoveStartingAndEndingDoubleQuote("\"([:");
}
if (codeString.startsWith(":") && codeString.endsWith(":")) {
return ident.eventuallyRemoveStartingAndEndingDoubleQuote("\"([:");
}
if (codeString.startsWith("()")) {
codeString = StringUtils.trin(codeString.substring(2));
codeString = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(codeString);
return ident.parent().add(Ident.empty().add(codeString, null));
}
return ident;
}
2013-12-10 19:36:50 +00:00
@Override
2019-12-10 21:45:49 +00:00
public ILeaf getOrCreateLeaf(Ident ident, Code code, LeafType type, USymbol symbol) {
2021-05-14 08:42:57 +00:00
Objects.requireNonNull(ident);
2013-12-10 19:36:50 +00:00
if (type == null) {
2019-12-10 21:45:49 +00:00
String codeString = code.getName();
if (codeString.startsWith("[") && codeString.endsWith("]")) {
2021-01-10 20:52:19 +00:00
final USymbol sym = getSkinParam().componentStyle().toUSymbol();
2019-12-10 21:45:49 +00:00
final Ident idNewLong = ident.eventuallyRemoveStartingAndEndingDoubleQuote("\"([:");
2020-01-12 22:13:17 +00:00
return getOrCreateLeafDefault(idNewLong, idNewLong.toCode(this), LeafType.DESCRIPTION, sym);
2013-12-10 19:36:50 +00:00
}
2019-12-10 21:45:49 +00:00
if (codeString.startsWith(":") && codeString.endsWith(":")) {
final Ident idNewLong = ident.eventuallyRemoveStartingAndEndingDoubleQuote("\"([:");
2020-06-14 20:35:42 +00:00
return getOrCreateLeafDefault(idNewLong, idNewLong.toCode(this), LeafType.DESCRIPTION,
2020-06-21 20:31:45 +00:00
getSkinParam().actorStyle().toUSymbol());
2013-12-10 19:36:50 +00:00
}
2019-12-10 21:45:49 +00:00
if (codeString.startsWith("()")) {
codeString = StringUtils.trin(codeString.substring(2));
codeString = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(codeString);
final Ident idNewLong = buildLeafIdent(codeString);
2023-01-11 21:47:15 +00:00
final Code code99 = buildCode(codeString);
2022-02-17 18:27:32 +00:00
return getOrCreateLeafDefault(idNewLong, code99, LeafType.DESCRIPTION, USymbols.INTERFACE);
2013-12-10 19:36:50 +00:00
}
2020-01-12 22:13:17 +00:00
final String tmp4 = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(code.getName(), "\"([:");
2019-12-10 21:45:49 +00:00
final Ident idNewLong = ident.eventuallyRemoveStartingAndEndingDoubleQuote("\"([:");
2023-01-11 21:47:15 +00:00
code = buildCode(tmp4);
2019-12-10 21:45:49 +00:00
return getOrCreateLeafDefault(idNewLong, code, LeafType.STILL_UNKNOWN, symbol);
2013-12-10 19:36:50 +00:00
}
2019-12-10 21:45:49 +00:00
return getOrCreateLeafDefault(ident, code, type, symbol);
2013-12-10 19:36:50 +00:00
}
private boolean isUsecase() {
2015-04-07 18:18:37 +00:00
for (ILeaf leaf : getLeafsvalues()) {
2017-04-05 17:37:42 +00:00
final LeafType type = leaf.getLeafType();
2013-12-10 19:36:50 +00:00
final USymbol usymbol = leaf.getUSymbol();
2020-06-21 20:31:45 +00:00
if (type == LeafType.USECASE || usymbol == getSkinParam().actorStyle().toUSymbol()) {
2013-12-10 19:36:50 +00:00
return true;
}
}
return false;
}
@Override
public void makeDiagramReady() {
2015-04-07 18:18:37 +00:00
super.makeDiagramReady();
final LeafType defaultType = LeafType.DESCRIPTION;
2022-02-17 18:27:32 +00:00
final USymbol defaultSymbol = isUsecase() ? getSkinParam().actorStyle().toUSymbol() : USymbols.INTERFACE;
2015-04-07 18:18:37 +00:00
for (ILeaf leaf : getLeafsvalues()) {
2017-04-05 17:37:42 +00:00
if (leaf.getLeafType() == LeafType.STILL_UNKNOWN) {
2015-04-07 18:18:37 +00:00
leaf.muteToType(defaultType, defaultSymbol);
2013-12-10 19:36:50 +00:00
}
}
}
2016-05-31 19:41:55 +00:00
@Override
public String checkFinalError() {
this.applySingleStrategy();
return super.checkFinalError();
}
2013-12-10 19:36:50 +00:00
}