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.cucadiagram;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import net.sourceforge.plantuml.FontParam;
|
|
|
|
import net.sourceforge.plantuml.ISkinParam;
|
2015-05-31 18:56:03 +00:00
|
|
|
import net.sourceforge.plantuml.StringUtils;
|
2015-06-07 10:23:10 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.TextBlock;
|
2016-11-04 21:39:29 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.TextBlockLineBefore;
|
2015-06-20 10:54:49 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.TextBlockUtils;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.skin.VisibilityModifier;
|
|
|
|
|
|
|
|
public class Bodier {
|
|
|
|
|
|
|
|
private final List<String> rawBody = new ArrayList<String>();
|
|
|
|
private final Set<VisibilityModifier> hides;
|
2016-01-09 12:15:40 +00:00
|
|
|
private LeafType type;
|
2013-12-10 19:36:50 +00:00
|
|
|
private List<Member> methodsToDisplay;
|
|
|
|
private List<Member> fieldsToDisplay;
|
|
|
|
private final boolean manageModifier;
|
2016-12-14 21:01:03 +00:00
|
|
|
private ILeaf leaf;
|
2013-12-10 19:36:50 +00:00
|
|
|
|
2016-01-09 12:15:40 +00:00
|
|
|
public void muteClassToObject() {
|
|
|
|
methodsToDisplay = null;
|
|
|
|
fieldsToDisplay = null;
|
|
|
|
type = LeafType.OBJECT;
|
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
public Bodier(LeafType type, Set<VisibilityModifier> hides) {
|
|
|
|
this.hides = hides;
|
|
|
|
this.type = type;
|
|
|
|
this.manageModifier = type == null ? false : type.manageModifier();
|
|
|
|
}
|
|
|
|
|
2018-04-06 20:36:30 +00:00
|
|
|
public void setLeaf(ILeaf leaf) {
|
|
|
|
if (leaf == null) {
|
|
|
|
throw new IllegalArgumentException();
|
|
|
|
}
|
|
|
|
this.leaf = leaf;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-12-14 21:01:03 +00:00
|
|
|
public void addFieldOrMethod(String s, IEntity leaf) {
|
|
|
|
if (leaf == null) {
|
|
|
|
throw new IllegalArgumentException();
|
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
// Empty cache
|
|
|
|
methodsToDisplay = null;
|
|
|
|
fieldsToDisplay = null;
|
|
|
|
rawBody.add(s);
|
2016-12-14 21:01:03 +00:00
|
|
|
if (leaf instanceof ILeaf) {
|
|
|
|
if (this.leaf != null && this.leaf != leaf) {
|
|
|
|
throw new IllegalArgumentException();
|
|
|
|
}
|
|
|
|
this.leaf = (ILeaf) leaf;
|
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
|
|
|
|
2015-06-07 10:23:10 +00:00
|
|
|
private boolean isBodyEnhanced() {
|
2013-12-10 19:36:50 +00:00
|
|
|
for (String s : rawBody) {
|
|
|
|
if (BodyEnhanced.isBlockSeparator(s)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isMethod(String s) {
|
2015-06-07 10:23:10 +00:00
|
|
|
if (type == LeafType.ANNOTATION || type == LeafType.ABSTRACT_CLASS || type == LeafType.CLASS
|
|
|
|
|| type == LeafType.INTERFACE || type == LeafType.ENUM) {
|
2020-02-18 21:24:31 +00:00
|
|
|
return Member.isMethod(s);
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<Member> getMethodsToDisplay() {
|
|
|
|
if (methodsToDisplay == null) {
|
|
|
|
methodsToDisplay = new ArrayList<Member>();
|
|
|
|
for (int i = 0; i < rawBody.size(); i++) {
|
|
|
|
final String s = rawBody.get(i);
|
|
|
|
if (isMethod(i, rawBody) == false) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (s.length() == 0 && methodsToDisplay.size() == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-02-18 21:24:31 +00:00
|
|
|
final Member m = new Member(s, true, manageModifier);
|
2013-12-10 19:36:50 +00:00
|
|
|
if (hides == null || hides.contains(m.getVisibilityModifier()) == false) {
|
|
|
|
methodsToDisplay.add(m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
removeFinalEmptyMembers(methodsToDisplay);
|
|
|
|
}
|
|
|
|
return Collections.unmodifiableList(methodsToDisplay);
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isMethod(int i, List<String> rawBody) {
|
|
|
|
if (i > 0 && i < rawBody.size() - 1 && rawBody.get(i).length() == 0 && isMethod(rawBody.get(i - 1))
|
|
|
|
&& isMethod(rawBody.get(i + 1))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return isMethod(rawBody.get(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<Member> getFieldsToDisplay() {
|
|
|
|
if (fieldsToDisplay == null) {
|
|
|
|
fieldsToDisplay = new ArrayList<Member>();
|
|
|
|
for (String s : rawBody) {
|
|
|
|
if (isMethod(s) == true) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (s.length() == 0 && fieldsToDisplay.size() == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2020-02-18 21:24:31 +00:00
|
|
|
final Member m = new Member(s, false, manageModifier);
|
2013-12-10 19:36:50 +00:00
|
|
|
if (hides == null || hides.contains(m.getVisibilityModifier()) == false) {
|
|
|
|
fieldsToDisplay.add(m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
removeFinalEmptyMembers(fieldsToDisplay);
|
|
|
|
}
|
|
|
|
return Collections.unmodifiableList(fieldsToDisplay);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void removeFinalEmptyMembers(List<Member> result) {
|
2015-05-31 18:56:03 +00:00
|
|
|
while (result.size() > 0 && StringUtils.trin(result.get(result.size() - 1).getDisplay(false)).length() == 0) {
|
2013-12-10 19:36:50 +00:00
|
|
|
result.remove(result.size() - 1);
|
|
|
|
}
|
|
|
|
}
|
2015-04-07 18:18:37 +00:00
|
|
|
|
|
|
|
public boolean hasUrl() {
|
|
|
|
for (Member m : getFieldsToDisplay()) {
|
|
|
|
if (m.hasUrl()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (Member m : getMethodsToDisplay()) {
|
|
|
|
if (m.hasUrl()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2017-09-03 16:59:24 +00:00
|
|
|
return false;
|
2015-04-07 18:18:37 +00:00
|
|
|
}
|
2015-06-07 10:23:10 +00:00
|
|
|
|
2017-04-26 17:48:37 +00:00
|
|
|
private List<String> rawBodyWithoutHidden() {
|
|
|
|
if (hides == null || hides.size() == 0) {
|
|
|
|
return rawBody;
|
|
|
|
}
|
|
|
|
final List<String> result = new ArrayList<String>();
|
|
|
|
for (String s : rawBody) {
|
2020-02-18 21:24:31 +00:00
|
|
|
final Member m = new Member(s, isMethod(s), manageModifier);
|
2017-04-26 17:48:37 +00:00
|
|
|
if (hides.contains(m.getVisibilityModifier()) == false) {
|
|
|
|
result.add(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-06-07 10:23:10 +00:00
|
|
|
public TextBlock getBody(final FontParam fontParam, final ISkinParam skinParam, final boolean showMethods,
|
2016-03-06 16:47:34 +00:00
|
|
|
final boolean showFields, Stereotype stereotype) {
|
2015-06-07 10:23:10 +00:00
|
|
|
if (type.isLikeClass() && isBodyEnhanced()) {
|
2015-07-11 09:32:49 +00:00
|
|
|
if (showMethods || showFields) {
|
2017-04-26 17:48:37 +00:00
|
|
|
return new BodyEnhanced(rawBodyWithoutHidden(), fontParam, skinParam, manageModifier, stereotype, leaf);
|
2015-06-07 10:23:10 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2018-04-06 20:36:30 +00:00
|
|
|
if (leaf == null) {
|
|
|
|
throw new IllegalStateException();
|
|
|
|
}
|
2016-11-04 21:39:29 +00:00
|
|
|
final MethodsOrFieldsArea fields = new MethodsOrFieldsArea(getFieldsToDisplay(), fontParam, skinParam,
|
2016-12-14 21:01:03 +00:00
|
|
|
stereotype, leaf);
|
2015-06-07 10:23:10 +00:00
|
|
|
if (type == LeafType.OBJECT) {
|
2016-11-04 21:39:29 +00:00
|
|
|
if (showFields == false) {
|
|
|
|
return new TextBlockLineBefore(TextBlockUtils.empty(0, 0));
|
|
|
|
}
|
2015-06-07 10:23:10 +00:00
|
|
|
return fields.asBlockMemberImpl();
|
|
|
|
}
|
|
|
|
if (type.isLikeClass() == false) {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
2016-11-04 21:39:29 +00:00
|
|
|
final MethodsOrFieldsArea methods = new MethodsOrFieldsArea(getMethodsToDisplay(), fontParam, skinParam,
|
2016-12-14 21:01:03 +00:00
|
|
|
stereotype, leaf);
|
2015-06-07 10:23:10 +00:00
|
|
|
if (showFields && showMethods == false) {
|
|
|
|
return fields.asBlockMemberImpl();
|
|
|
|
} else if (showMethods && showFields == false) {
|
|
|
|
return methods.asBlockMemberImpl();
|
2015-06-20 10:54:49 +00:00
|
|
|
} else if (showFields == false && showMethods == false) {
|
|
|
|
return TextBlockUtils.empty(0, 0);
|
2015-06-07 10:23:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
final TextBlock bb1 = fields.asBlockMemberImpl();
|
|
|
|
final TextBlock bb2 = methods.asBlockMemberImpl();
|
2016-11-04 21:39:29 +00:00
|
|
|
return TextBlockUtils.mergeTB(bb1, bb2, HorizontalAlignment.LEFT);
|
2015-06-07 10:23:10 +00:00
|
|
|
}
|
|
|
|
|
2017-04-05 17:37:42 +00:00
|
|
|
public List<String> getRawBody() {
|
|
|
|
return Collections.unmodifiableList(rawBody);
|
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|