1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-03 09:00:48 +00:00
plantuml/src/net/sourceforge/plantuml/PSystemError.java

590 lines
20 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2019-01-16 18:34:41 +00:00
* (C) Copyright 2009-2020, Arnaud Roques
2010-11-15 20:35:36 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2010-11-15 20:35:36 +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
*
2010-11-15 20:35:36 +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
2013-12-10 19:36:50 +00:00
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
2010-11-15 20:35:36 +00:00
* 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;
2017-03-15 19:13:31 +00:00
import java.awt.Color;
2016-12-21 22:10:29 +00:00
import java.awt.geom.Dimension2D;
2017-03-15 19:13:31 +00:00
import java.awt.geom.Rectangle2D;
2018-09-23 12:15:14 +00:00
import java.awt.image.BufferedImage;
2010-11-15 20:35:36 +00:00
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
2017-06-05 11:27:21 +00:00
import java.util.Iterator;
2010-11-15 20:35:36 +00:00
import java.util.LinkedHashSet;
import java.util.List;
2018-05-01 17:26:04 +00:00
import net.sourceforge.plantuml.api.ImageDataAbstract;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.api.ImageDataSimple;
import net.sourceforge.plantuml.asciiart.UmlCharArea;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.core.UmlSource;
2018-09-23 12:15:14 +00:00
import net.sourceforge.plantuml.cucadiagram.Display;
2017-03-15 19:13:31 +00:00
import net.sourceforge.plantuml.eggs.PSystemWelcome;
2018-09-23 12:15:14 +00:00
import net.sourceforge.plantuml.flashcode.FlashCodeFactory;
import net.sourceforge.plantuml.flashcode.FlashCodeUtils;
import net.sourceforge.plantuml.graphic.FontConfiguration;
2017-03-12 17:22:02 +00:00
import net.sourceforge.plantuml.graphic.GraphicPosition;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.graphic.GraphicStrings;
2017-03-15 19:13:31 +00:00
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
import net.sourceforge.plantuml.graphic.HtmlColor;
2018-09-23 12:15:14 +00:00
import net.sourceforge.plantuml.graphic.HtmlColorSetSimple;
2017-03-15 19:13:31 +00:00
import net.sourceforge.plantuml.graphic.HtmlColorSimple;
2018-09-23 12:15:14 +00:00
import net.sourceforge.plantuml.graphic.HtmlColorUtils;
2017-04-05 17:37:42 +00:00
import net.sourceforge.plantuml.graphic.InnerStrategy;
2017-03-15 19:13:31 +00:00
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.graphic.TextBlockUtils;
2018-09-23 12:15:14 +00:00
import net.sourceforge.plantuml.graphic.VerticalAlignment;
2016-11-18 21:12:09 +00:00
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
2017-11-20 16:10:36 +00:00
import net.sourceforge.plantuml.ugraphic.MinMax;
2018-09-23 12:15:14 +00:00
import net.sourceforge.plantuml.ugraphic.UFont;
2016-12-21 22:10:29 +00:00
import net.sourceforge.plantuml.ugraphic.UGraphic;
2017-03-15 19:13:31 +00:00
import net.sourceforge.plantuml.ugraphic.UImage;
2016-12-21 22:10:29 +00:00
import net.sourceforge.plantuml.ugraphic.UTranslate;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt;
2018-09-23 12:15:14 +00:00
import net.sourceforge.plantuml.version.LicenseInfo;
2017-03-15 19:13:31 +00:00
import net.sourceforge.plantuml.version.PSystemVersion;
2010-11-15 20:35:36 +00:00
public class PSystemError extends AbstractPSystem {
2017-06-05 11:27:21 +00:00
private final LineLocation higherErrorPosition;
2011-01-13 21:52:37 +00:00
private final List<ErrorUml> printedErrors;
2015-05-31 18:56:03 +00:00
private final List<String> debugLines = new ArrayList<String>();
public PSystemError(UmlSource source, ErrorUml singleError, List<String> debugLines) {
this(source, Collections.singletonList(singleError), debugLines);
}
2010-11-15 20:35:36 +00:00
2015-05-31 18:56:03 +00:00
private PSystemError(UmlSource source, List<ErrorUml> all, List<String> debugLines) {
2010-11-15 20:35:36 +00:00
this.setSource(source);
2017-06-05 11:27:21 +00:00
final LineLocation execution = getHigherErrorPosition2(ErrorUmlType.EXECUTION_ERROR, all);
final LineLocation syntax = getHigherErrorPosition2(ErrorUmlType.SYNTAX_ERROR, all);
2011-01-13 21:52:37 +00:00
2017-06-05 11:27:21 +00:00
if (execution == null && syntax == null) {
2011-01-09 19:00:05 +00:00
throw new IllegalStateException();
}
2017-06-05 11:27:21 +00:00
if (execution != null && (syntax == null || execution.compareTo(syntax) >= 0)) {
higherErrorPosition = execution;
printedErrors = getErrorsAt2(execution, ErrorUmlType.EXECUTION_ERROR, all);
2010-11-15 20:35:36 +00:00
} else {
2017-06-05 11:27:21 +00:00
// assert syntax.compareTo(execution) > 0;
higherErrorPosition = syntax;
printedErrors = getErrorsAt2(syntax, ErrorUmlType.SYNTAX_ERROR, all);
2010-11-15 20:35:36 +00:00
}
2015-05-31 18:56:03 +00:00
if (debugLines != null) {
this.debugLines.addAll(debugLines);
}
2010-11-15 20:35:36 +00:00
}
2015-05-31 18:56:03 +00:00
private String getSuggestColor(boolean useRed) {
if (useRed) {
return "black";
}
return "white";
}
private String getRed(boolean useRed) {
if (useRed) {
return "#CD0A0A";
}
return "red";
2010-11-15 20:35:36 +00:00
}
2016-12-01 20:29:25 +00:00
@Override
2017-04-19 18:30:16 +00:00
final protected ImageData exportDiagramNow(OutputStream os, int num, FileFormatOption fileFormat, long seed)
2016-12-01 20:29:25 +00:00
throws IOException {
2015-04-07 18:18:37 +00:00
if (fileFormat.getFileFormat() == FileFormat.ATXT || fileFormat.getFileFormat() == FileFormat.UTXT) {
final UGraphicTxt ugt = new UGraphicTxt();
final UmlCharArea area = ugt.getCharArea();
area.drawStringsLR(getTextStrings(), 0, 0);
area.print(new PrintStream(os));
return new ImageDataSimple(1, 1);
}
final boolean useRed = fileFormat.isUseRedForError();
2016-11-18 21:12:09 +00:00
final TextBlockBackcolored result = GraphicStrings.createForError(getHtmlStrings(useRed), useRed);
2016-12-21 22:10:29 +00:00
2017-03-15 19:13:31 +00:00
TextBlock udrawable;
2015-04-07 18:18:37 +00:00
final ImageBuilder imageBuilder = new ImageBuilder(new ColorMapperIdentity(), 1.0, result.getBackcolor(),
getMetadata(), null, 0, 0, null, false);
2017-03-15 19:13:31 +00:00
if (getSource().getTotalLineCount() < 5) {
udrawable = addWelcome(result);
2016-12-21 22:10:29 +00:00
} else {
udrawable = result;
}
2018-08-26 12:09:50 +00:00
final int min = (int) (System.currentTimeMillis() / 60000L) % 60;
2018-12-22 11:11:40 +00:00
// udrawable = addMessageAdopt(udrawable);
2018-11-26 18:46:22 +00:00
if (min == 1 && LicenseInfo.retrieveNamedOrDistributorQuickIsValid() == false) {
udrawable = addMessagePatreon(udrawable);
} else if (min == 15 && LicenseInfo.retrieveNamedOrDistributorQuickIsValid() == false) {
udrawable = addMessageLiberapay(udrawable);
} else if (min == 30 && LicenseInfo.retrieveNamedOrDistributorQuickIsValid() == false) {
2018-09-23 12:15:14 +00:00
udrawable = addMessageDedication(udrawable);
2018-11-26 18:46:22 +00:00
} else if (getSource().containsIgnoreCase("arecibo")) {
udrawable = addMessageArecibo(udrawable);
2017-06-05 11:27:21 +00:00
}
2016-12-21 22:10:29 +00:00
imageBuilder.setUDrawable(udrawable);
2018-05-01 17:26:04 +00:00
final ImageData imageData = imageBuilder.writeImageTOBEMOVED(fileFormat, seed(), os);
2018-05-21 13:07:09 +00:00
((ImageDataAbstract) imageData).setStatus(FileImageData.ERROR);
2018-05-01 17:26:04 +00:00
return imageData;
2010-11-15 20:35:36 +00:00
}
2017-03-15 19:13:31 +00:00
private TextBlockBackcolored getWelcome() throws IOException {
return new PSystemWelcome(GraphicPosition.BACKGROUND_CORNER_TOP_RIGHT).getGraphicStrings();
}
private TextBlock addWelcome(final TextBlockBackcolored result) throws IOException {
final TextBlockBackcolored welcome = getWelcome();
return TextBlockUtils.mergeTB(welcome, result, HorizontalAlignment.LEFT);
}
2018-11-26 18:46:22 +00:00
private TextBlock addMessageLiberapay(final TextBlock source) throws IOException {
final TextBlock message = getMessageLiberapay();
TextBlock result = TextBlockUtils.mergeTB(message, source, HorizontalAlignment.LEFT);
result = TextBlockUtils.mergeTB(result, message, HorizontalAlignment.LEFT);
return result;
}
private TextBlock addMessagePatreon(final TextBlock source) throws IOException {
final TextBlock message = getMessagePatreon();
2017-03-15 19:13:31 +00:00
TextBlock result = TextBlockUtils.mergeTB(message, source, HorizontalAlignment.LEFT);
result = TextBlockUtils.mergeTB(result, message, HorizontalAlignment.LEFT);
return result;
}
2018-09-23 12:15:14 +00:00
private TextBlock addMessageDedication(final TextBlock source) throws IOException {
final TextBlock message = getMessageDedication();
TextBlock result = TextBlockUtils.mergeTB(message, source, HorizontalAlignment.LEFT);
return result;
}
2018-12-22 11:11:40 +00:00
private TextBlock addMessageAdopt(final TextBlock source) throws IOException {
final TextBlock message = getMessageAdopt();
TextBlock result = TextBlockUtils.mergeTB(message, source, HorizontalAlignment.LEFT);
return result;
}
2018-11-26 18:46:22 +00:00
private TextBlock addMessageArecibo(final TextBlock source) throws IOException {
final UImage message = new UImage(PSystemVersion.getArecibo());
TextBlock result = TextBlockUtils.mergeLR(source, TextBlockUtils.fromUImage(message), VerticalAlignment.TOP);
return result;
}
2018-09-23 12:15:14 +00:00
private TextBlockBackcolored getMessageDedication() {
final FlashCodeUtils utils = FlashCodeFactory.getFlashCodeUtils();
2018-12-22 11:11:40 +00:00
final HtmlColorSimple backColor = (HtmlColorSimple) new HtmlColorSetSimple().getColorIfValid("#eae2c9");
2018-09-23 12:15:14 +00:00
final BufferedImage qrcode = smaller(utils.exportFlashcode("http://plantuml.com/dedication", Color.BLACK,
backColor.getColor999()));
2018-11-26 18:46:22 +00:00
final Display disp = Display.create("<b>Add your own dedication into PlantUML", " ", "For just $5 per month!",
"Details on <i>[[http://plantuml.com/dedication]]");
2018-09-23 12:15:14 +00:00
final UFont font = UFont.sansSerif(14);
final FontConfiguration fc = new FontConfiguration(font, HtmlColorUtils.BLACK, HtmlColorUtils.BLACK, false);
final TextBlock text = TextBlockUtils.withMargin(
disp.create(fc, HorizontalAlignment.LEFT, new SpriteContainerEmpty()), 10, 0);
final TextBlock result;
if (qrcode == null) {
result = text;
} else {
final UImage qr = new UImage(qrcode).scaleNearestNeighbor(3);
result = TextBlockUtils.mergeLR(text, TextBlockUtils.fromUImage(qr), VerticalAlignment.CENTER);
}
return TextBlockUtils.addBackcolor(result, backColor);
2018-12-22 11:11:40 +00:00
}
private TextBlockBackcolored getMessageAdopt() {
final HtmlColorSimple backColor = (HtmlColorSimple) new HtmlColorSetSimple().getColorIfValid("#eff4d2");
final Display disp = Display.create("<b>Adopt-a-Word and put your message here!", " ",
"Details on <i>[[http://plantuml.com/adopt]]", " ");
final UFont font = UFont.sansSerif(14);
final FontConfiguration fc = new FontConfiguration(font, HtmlColorUtils.BLACK, HtmlColorUtils.BLACK, false);
final TextBlock text = TextBlockUtils.withMargin(
disp.create(fc, HorizontalAlignment.LEFT, new SpriteContainerEmpty()), 10, 0);
final TextBlock result;
result = text;
return TextBlockUtils.addBackcolor(result, backColor);
2018-09-23 12:15:14 +00:00
}
2018-11-26 18:46:22 +00:00
private TextBlockBackcolored getMessagePatreon() {
final UImage message = new UImage(PSystemVersion.getTime01());
final Color back = new Color(message.getImage().getRGB(0, 0));
final HtmlColor backColor = new HtmlColorSimple(back, false);
final FlashCodeUtils utils = FlashCodeFactory.getFlashCodeUtils();
final BufferedImage qrcode = smaller(utils.exportFlashcode("http://plantuml.com/patreon", Color.BLACK,
Color.WHITE));
final int scale = 2;
final double imWidth = message.getWidth() + (qrcode == null ? 0 : qrcode.getWidth() * scale + 20);
final double imHeight = qrcode == null ? message.getHeight() : Math.max(message.getHeight(), qrcode.getHeight()
* scale + 10);
return new TextBlockBackcolored() {
public void drawU(UGraphic ug) {
if (qrcode == null) {
ug.apply(new UTranslate(1, 1)).draw(message);
} else {
final UImage qr = new UImage(qrcode).scaleNearestNeighbor(scale);
ug.apply(new UTranslate(1, (imHeight - message.getHeight()) / 2)).draw(message);
ug.apply(new UTranslate(1 + message.getWidth(), (imHeight - qr.getHeight()) / 2)).draw(qr);
}
}
public Rectangle2D getInnerPosition(String member, StringBounder stringBounder, InnerStrategy strategy) {
return null;
}
public Dimension2D calculateDimension(StringBounder stringBounder) {
return new Dimension2DDouble(imWidth + 1, imHeight + 1);
}
public MinMax getMinMax(StringBounder stringBounder) {
return MinMax.fromMax(imWidth + 1, imHeight + 1);
}
public HtmlColor getBackcolor() {
return backColor;
}
};
}
private TextBlockBackcolored getMessageLiberapay() {
final UImage message = new UImage(PSystemVersion.getTime15());
2018-09-23 12:15:14 +00:00
final Color back = new Color(message.getImage().getRGB(0, 0));
final HtmlColor backColor = new HtmlColorSimple(back, false);
final FlashCodeUtils utils = FlashCodeFactory.getFlashCodeUtils();
2018-11-26 18:46:22 +00:00
final BufferedImage qrcode = smaller(utils.exportFlashcode("http://plantuml.com/lp", Color.BLACK, Color.WHITE));
2018-09-23 12:15:14 +00:00
final int scale = 2;
final double imWidth = message.getWidth() + (qrcode == null ? 0 : qrcode.getWidth() * scale + 20);
final double imHeight = qrcode == null ? message.getHeight() : Math.max(message.getHeight(), qrcode.getHeight()
* scale + 10);
2017-03-15 19:13:31 +00:00
return new TextBlockBackcolored() {
public void drawU(UGraphic ug) {
2018-09-23 12:15:14 +00:00
if (qrcode == null) {
ug.apply(new UTranslate(1, 1)).draw(message);
} else {
final UImage qr = new UImage(qrcode).scaleNearestNeighbor(scale);
ug.apply(new UTranslate(1, (imHeight - message.getHeight()) / 2)).draw(message);
ug.apply(new UTranslate(1 + message.getWidth(), (imHeight - qr.getHeight()) / 2)).draw(qr);
}
2017-03-15 19:13:31 +00:00
}
2017-04-05 17:37:42 +00:00
public Rectangle2D getInnerPosition(String member, StringBounder stringBounder, InnerStrategy strategy) {
2017-03-15 19:13:31 +00:00
return null;
}
public Dimension2D calculateDimension(StringBounder stringBounder) {
return new Dimension2DDouble(imWidth + 1, imHeight + 1);
}
2017-11-20 16:10:36 +00:00
public MinMax getMinMax(StringBounder stringBounder) {
return MinMax.fromMax(imWidth + 1, imHeight + 1);
}
2017-03-15 19:13:31 +00:00
public HtmlColor getBackcolor() {
2018-09-23 12:15:14 +00:00
return backColor;
2017-03-15 19:13:31 +00:00
}
};
}
2018-09-23 12:15:14 +00:00
private BufferedImage smaller(BufferedImage im) {
if (im == null) {
return null;
}
final int nb = 1;
return im.getSubimage(nb, nb, im.getWidth() - 2 * nb, im.getHeight() - 2 * nb);
}
2015-04-07 18:18:37 +00:00
private List<String> getTextStrings() {
2015-06-20 10:54:49 +00:00
final List<String> result = new ArrayList<String>(getStack());
if (result.size() > 0) {
result.add(" ");
}
2015-04-07 18:18:37 +00:00
2017-06-05 11:27:21 +00:00
for (String s : getPartialCode()) {
result.add(s);
2015-04-07 18:18:37 +00:00
}
final String errorLine = getSource().getLine(higherErrorPosition);
final String err = StringUtils.hideComparatorCharacters(errorLine);
if (StringUtils.isNotEmpty(err)) {
result.add(err);
2010-11-15 20:35:36 +00:00
}
final StringBuilder underscore = new StringBuilder();
for (int i = 0; i < errorLine.length(); i++) {
underscore.append("^");
}
2015-04-07 18:18:37 +00:00
result.add(underscore.toString());
2011-01-23 19:36:52 +00:00
final Collection<String> textErrors = new LinkedHashSet<String>();
2011-01-13 21:52:37 +00:00
for (ErrorUml er : printedErrors) {
2011-01-23 19:36:52 +00:00
textErrors.add(er.getError());
}
for (String er : textErrors) {
2015-04-07 18:18:37 +00:00
result.add(" " + er);
2011-01-13 21:52:37 +00:00
}
2011-08-08 17:48:29 +00:00
boolean first = true;
for (String s : getSuggest()) {
if (first) {
2015-04-07 18:18:37 +00:00
result.add(" " + s);
2011-08-08 17:48:29 +00:00
} else {
2015-04-07 18:18:37 +00:00
result.add(s);
2011-08-08 17:48:29 +00:00
}
first = false;
}
2015-05-31 18:56:03 +00:00
result.addAll(this.debugLines);
2015-04-07 18:18:37 +00:00
return result;
}
2015-06-20 10:54:49 +00:00
private List<String> getStack() {
LineLocation lineLocation = getLineLocation();
final List<String> result = new ArrayList<String>();
if (lineLocation != null) {
append(result, lineLocation);
while (lineLocation.getParent() != null) {
lineLocation = lineLocation.getParent();
append(result, lineLocation);
}
}
return result;
}
public LineLocation getLineLocation() {
for (ErrorUml err : printedErrors) {
if (err.getLineLocation() != null) {
return err.getLineLocation();
}
}
return null;
}
private void append(List<String> result, LineLocation lineLocation) {
if (lineLocation.getDescription() != null) {
result.add("[From " + lineLocation.getDescription() + " (line " + (lineLocation.getPosition() + 1) + ") ]");
}
}
2017-06-05 11:27:21 +00:00
private List<String> getPartialCode() {
List<String> result = new ArrayList<String>();
2019-03-29 22:14:07 +00:00
for (Iterator<StringLocated> it = getSource().iterator2(); it.hasNext();) {
final StringLocated s = it.next();
final String tmp = s.getString();
result.add(tmp);
final LineLocation location = s.getLocation();
if (location.getDescription().equals(higherErrorPosition.getDescription())
&& location.compareTo(higherErrorPosition) >= 0) {
2018-06-12 20:50:45 +00:00
break;
2017-06-05 11:27:21 +00:00
}
2015-06-20 10:54:49 +00:00
}
2018-06-12 20:50:45 +00:00
final int limit = 5;
2017-06-05 11:27:21 +00:00
if (result.size() > limit) {
final int skip = result.size() - limit + 1;
final String skipMessage;
2015-04-07 18:18:37 +00:00
if (skip == 1) {
2017-06-05 11:27:21 +00:00
skipMessage = "... (skipping 1 line) ...";
2015-04-07 18:18:37 +00:00
} else {
2017-06-05 11:27:21 +00:00
skipMessage = "... (skipping " + skip + " lines) ...";
2015-04-07 18:18:37 +00:00
}
2017-06-05 11:27:21 +00:00
result = new ArrayList<String>(result.subList(skip, result.size()));
result.add(0, skipMessage);
2015-04-07 18:18:37 +00:00
}
2017-06-05 11:27:21 +00:00
return result;
}
private List<String> getHtmlStrings(boolean useRed) {
final List<String> htmlStrings = new ArrayList<String>(getStack());
if (htmlStrings.size() > 0) {
htmlStrings.add("----");
}
2018-06-12 20:50:45 +00:00
final List<String> partialCode = getPartialCode();
for (String s : partialCode) {
2017-06-05 11:27:21 +00:00
htmlStrings.add(StringUtils.hideComparatorCharacters(s));
2015-04-07 18:18:37 +00:00
}
2018-06-12 20:50:45 +00:00
if (partialCode.size() > 0) {
final int idx = htmlStrings.size() - 1;
final String last = htmlStrings.get(idx);
htmlStrings.set(idx, "<w:" + getRed(useRed) + ">" + last + "</w>");
2015-04-07 18:18:37 +00:00
}
2019-03-29 22:14:07 +00:00
2015-04-07 18:18:37 +00:00
final Collection<String> textErrors = new LinkedHashSet<String>();
for (ErrorUml er : printedErrors) {
textErrors.add(er.getError());
}
for (String er : textErrors) {
htmlStrings.add(" <color:" + getRed(useRed) + ">" + er + "</color>");
}
boolean first = true;
for (String s : getSuggest()) {
if (first) {
htmlStrings.add(" <color:" + getSuggestColor(useRed) + "><i>" + s + "</i></color>");
} else {
htmlStrings.add("<color:" + getSuggestColor(useRed) + ">" + StringUtils.hideComparatorCharacters(s)
+ "</color>");
}
first = false;
}
2015-05-31 18:56:03 +00:00
htmlStrings.addAll(this.debugLines);
2015-04-07 18:18:37 +00:00
return htmlStrings;
2011-08-08 17:48:29 +00:00
}
2018-06-12 20:50:45 +00:00
private List<String> getSuggest() {
2011-01-13 21:52:37 +00:00
boolean suggested = false;
for (ErrorUml er : printedErrors) {
if (er.hasSuggest()) {
suggested = true;
}
}
2011-08-08 17:48:29 +00:00
if (suggested == false) {
return Collections.emptyList();
}
final List<String> result = new ArrayList<String>();
result.add("Did you mean:");
for (ErrorUml er : printedErrors) {
if (er.hasSuggest()) {
result.add(er.getSuggest().getSuggestedLine());
2011-01-13 21:52:37 +00:00
}
2010-11-15 20:35:36 +00:00
}
2011-08-08 17:48:29 +00:00
return Collections.unmodifiableList(result);
2010-11-15 20:35:36 +00:00
}
2011-01-13 21:52:37 +00:00
private Collection<ErrorUml> getErrors(ErrorUmlType type, List<ErrorUml> all) {
2010-11-15 20:35:36 +00:00
final Collection<ErrorUml> result = new LinkedHashSet<ErrorUml>();
2011-01-13 21:52:37 +00:00
for (ErrorUml error : all) {
2010-11-15 20:35:36 +00:00
if (error.getType() == type) {
result.add(error);
}
}
return result;
}
2017-06-05 11:27:21 +00:00
private LineLocation getHigherErrorPosition2(ErrorUmlType type, List<ErrorUml> all) {
LineLocation max = null;
2011-01-13 21:52:37 +00:00
for (ErrorUml error : getErrors(type, all)) {
2017-06-05 11:27:21 +00:00
if (max == null || error.getLineLocation().compareTo(max) > 0) {
max = error.getLineLocation();
2010-11-15 20:35:36 +00:00
}
}
return max;
}
2017-06-05 11:27:21 +00:00
private List<ErrorUml> getErrorsAt2(LineLocation position, ErrorUmlType type, List<ErrorUml> all) {
2011-01-13 21:52:37 +00:00
final List<ErrorUml> result = new ArrayList<ErrorUml>();
for (ErrorUml error : getErrors(type, all)) {
2017-06-05 11:27:21 +00:00
if (error.getLineLocation().compareTo(position) == 0 && StringUtils.isNotEmpty(error.getError())) {
2011-01-13 21:52:37 +00:00
result.add(error);
2010-11-15 20:35:36 +00:00
}
}
return result;
}
2013-12-10 19:36:50 +00:00
public DiagramDescription getDescription() {
2017-03-12 17:22:02 +00:00
return new DiagramDescription("(Error)");
2010-11-15 20:35:36 +00:00
}
2017-06-05 11:27:21 +00:00
public final LineLocation getHigherErrorPosition2() {
2010-11-15 20:35:36 +00:00
return higherErrorPosition;
}
2011-01-13 21:52:37 +00:00
public final Collection<ErrorUml> getErrorsUml() {
return Collections.unmodifiableCollection(printedErrors);
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
@Override
public String getWarningOrError() {
final StringBuilder sb = new StringBuilder();
sb.append(getDescription());
2017-06-05 11:27:21 +00:00
sb.append(BackSlash.CHAR_NEWLINE);
2016-01-30 12:20:07 +00:00
for (CharSequence t : getTitle().getDisplay()) {
2013-12-10 19:36:50 +00:00
sb.append(t);
2017-06-05 11:27:21 +00:00
sb.append(BackSlash.CHAR_NEWLINE);
2013-12-10 19:36:50 +00:00
}
2017-06-05 11:27:21 +00:00
sb.append(BackSlash.CHAR_NEWLINE);
2013-12-10 19:36:50 +00:00
for (String s : getSuggest()) {
sb.append(s);
2017-06-05 11:27:21 +00:00
sb.append(BackSlash.CHAR_NEWLINE);
2013-12-10 19:36:50 +00:00
}
return sb.toString();
}
2015-05-31 18:56:03 +00:00
public static PSystemError merge(Collection<PSystemError> ps) {
UmlSource source = null;
final List<ErrorUml> errors = new ArrayList<ErrorUml>();
final List<String> debugs = new ArrayList<String>();
for (PSystemError system : ps) {
2015-06-20 10:54:49 +00:00
if (system == null) {
continue;
}
2015-05-31 18:56:03 +00:00
if (system.getSource() != null && source == null) {
source = system.getSource();
}
errors.addAll(system.getErrorsUml());
debugs.addAll(system.debugLines);
if (system.debugLines.size() > 0) {
debugs.add("-");
}
}
if (source == null) {
throw new IllegalStateException();
}
return new PSystemError(source, errors, debugs);
}
2010-11-15 20:35:36 +00:00
}