Skip to content

Commit

Permalink
✨ feat: extend error message with diagram type
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudroques committed Dec 6, 2024
1 parent d4b7816 commit c6263bd
Show file tree
Hide file tree
Showing 47 changed files with 282 additions and 19 deletions.
22 changes: 12 additions & 10 deletions src/net/sourceforge/plantuml/ErrorUml.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,24 @@

import java.util.Objects;

import net.sourceforge.plantuml.skin.UmlDiagramType;
import net.sourceforge.plantuml.utils.LineLocation;

public class ErrorUml {
// ::remove file when __HAXE__

private final String error;
private final ErrorUmlType type;
private final ErrorUmlType errorType;
private final LineLocation lineLocation;
private final int score;
private final UmlDiagramType diagramType;

public ErrorUml(ErrorUmlType type, String error, int score, LineLocation lineLocation) {
public ErrorUml(ErrorUmlType type, String error, int score, LineLocation lineLocation, UmlDiagramType diagramType) {
this.score = score;
this.error = Objects.requireNonNull(error);
this.type = Objects.requireNonNull(type);
this.errorType = Objects.requireNonNull(type);
this.lineLocation = lineLocation;
this.diagramType = diagramType;
}

public int score() {
Expand All @@ -61,27 +64,26 @@ public int score() {
@Override
public boolean equals(Object obj) {
final ErrorUml this2 = (ErrorUml) obj;
return this.type == this2.type && this.getPosition() == this2.getPosition() && this.error.equals(this2.error);
return this.errorType == this2.errorType && this.getPosition() == this2.getPosition()
&& this.error.equals(this2.error);
}

@Override
public int hashCode() {
return error.hashCode() + type.hashCode() + getPosition();
return error.hashCode() + errorType.hashCode() + getPosition();
}

@Override
public String toString() {
return type.toString() + " " + getPosition() + " " + error;
return errorType.toString() + " " + getPosition() + " " + error;
}

public final String getError() {
if (diagramType != null)
return error + " (Assumed diagram type: " + diagramType.name().toLowerCase() + ")";
return error;
}

public final ErrorUmlType getType() {
return type;
}

public final int getPosition() {
return lineLocation.getPosition();
}
Expand Down
2 changes: 1 addition & 1 deletion src/net/sourceforge/plantuml/PSystemBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ final public Diagram createPSystem(List<StringLocated> source, List<StringLocate
assert false;
Log.error("Preprocessor Error: " + s.getPreprocessorError());
final ErrorUml err = new ErrorUml(ErrorUmlType.SYNTAX_ERROR, s.getPreprocessorError(), 0,
s.getLocation());
s.getLocation(), null);
return PSystemErrorUtils.buildV2(umlSource, err, Collections.<String>emptyList(), source);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import net.sourceforge.plantuml.command.note.CommandFactoryNoteActivity;
import net.sourceforge.plantuml.command.note.CommandFactoryNoteOnLink;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.skin.UmlDiagramType;

public class ActivityDiagramFactory extends PSystemCommandFactory {
// ::remove folder when __HAXE__
Expand Down Expand Up @@ -92,4 +93,9 @@ protected void initCommandsList(List<Command> cmds) {

}

@Override
public UmlDiagramType getUmlDiagramType() {
return UmlDiagramType.ACTIVITY;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import net.sourceforge.plantuml.command.CommonCommands;
import net.sourceforge.plantuml.command.PSystemCommandFactory;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.skin.UmlDiagramType;

public class ActivityDiagramFactory3 extends PSystemCommandFactory {

Expand Down Expand Up @@ -162,4 +163,9 @@ public ActivityDiagram3 createEmptyDiagram(UmlSource source, Map<String, String>
return new ActivityDiagram3(source, skinMap);
}

@Override
public UmlDiagramType getUmlDiagramType() {
return UmlDiagramType.ACTIVITY;
}

}
3 changes: 3 additions & 0 deletions src/net/sourceforge/plantuml/api/PSystemFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@
import net.sourceforge.plantuml.core.Diagram;
import net.sourceforge.plantuml.core.DiagramType;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.skin.UmlDiagramType;

public interface PSystemFactory {

Diagram createSystem(UmlSource source, Map<String, String> skinMap);

DiagramType getDiagramType();

UmlDiagramType getUmlDiagramType();

}
6 changes: 6 additions & 0 deletions src/net/sourceforge/plantuml/board/BoardDiagramFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import net.sourceforge.plantuml.command.PSystemCommandFactory;
import net.sourceforge.plantuml.core.DiagramType;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.skin.UmlDiagramType;

public class BoardDiagramFactory extends PSystemCommandFactory {
// ::remove folder when __CORE__
Expand All @@ -68,4 +69,9 @@ public BoardDiagram createEmptyDiagram(UmlSource source, Map<String, String> ski
return new BoardDiagram(source);
}

@Override
public UmlDiagramType getUmlDiagramType() {
return UmlDiagramType.BOARD;
}

}
7 changes: 7 additions & 0 deletions src/net/sourceforge/plantuml/bpm/BpmDiagramFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import net.sourceforge.plantuml.command.PSystemCommandFactory;
import net.sourceforge.plantuml.core.DiagramType;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.skin.UmlDiagramType;

public class BpmDiagramFactory extends PSystemCommandFactory {

Expand All @@ -65,5 +66,11 @@ protected void initCommandsList(List<Command> result) {
public AbstractPSystem createEmptyDiagram(UmlSource source, Map<String, String> skinMap) {
return new BpmDiagram(source);
}

@Override
public UmlDiagramType getUmlDiagramType() {
return UmlDiagramType.BPM;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import net.sourceforge.plantuml.command.PSystemCommandFactory;
import net.sourceforge.plantuml.core.DiagramType;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.skin.UmlDiagramType;

public class ChenEerDiagramFactory extends PSystemCommandFactory {

Expand All @@ -76,4 +77,9 @@ public AbstractPSystem createEmptyDiagram(UmlSource source, Map<String, String>
return new ChenEerDiagram(source, skinMap);
}

@Override
public UmlDiagramType getUmlDiagramType() {
return UmlDiagramType.CHEN_EER;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import net.sourceforge.plantuml.project.lang.SentenceAndAnd;
import net.sourceforge.plantuml.project.lang.SentenceSimple;
import net.sourceforge.plantuml.project.lang.Subject;
import net.sourceforge.plantuml.skin.UmlDiagramType;

public class ChronologyDiagramFactory extends PSystemCommandFactory {

Expand Down Expand Up @@ -123,4 +124,9 @@ public ChronologyDiagram createEmptyDiagram(UmlSource source, Map<String, String
return new ChronologyDiagram(source);
}

@Override
public UmlDiagramType getUmlDiagramType() {
return UmlDiagramType.CHRONOLOGY;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,10 @@ protected void initCommandsList(List<Command> cmds) {
CommonCommands.addTitleCommands(cmds);
CommonCommands.addCommonCommands2(cmds);
}

@Override
public UmlDiagramType getUmlDiagramType() {
return UmlDiagramType.CLASS;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ protected PSystemAbstractFactory(DiagramType type) {

final protected PSystemError buildEmptyError(UmlSource source, LineLocation lineLocation,
List<StringLocated> trace) {
final ErrorUml err = new ErrorUml(ErrorUmlType.SYNTAX_ERROR, EMPTY_DESCRIPTION, 0, lineLocation);
final ErrorUml err = new ErrorUml(ErrorUmlType.SYNTAX_ERROR, EMPTY_DESCRIPTION, 0, lineLocation, getUmlDiagramType());
final PSystemError result = PSystemErrorUtils.buildV2(source, err, null, trace);
return result;
}

final protected PSystemError buildExecutionError(UmlSource source, String stringError, LineLocation lineLocation,
List<StringLocated> trace) {
final ErrorUml err = new ErrorUml(ErrorUmlType.EXECUTION_ERROR, stringError, 0, lineLocation);
final ErrorUml err = new ErrorUml(ErrorUmlType.EXECUTION_ERROR, stringError, 0, lineLocation, getUmlDiagramType());
final PSystemError result = PSystemErrorUtils.buildV2(source, err, null, trace);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ final public Diagram createSystem(UmlSource source, Map<String, String> skinMap)
}
system = executeLine(source, system, s.getString());
if (system == null) {
final ErrorUml err = new ErrorUml(ErrorUmlType.SYNTAX_ERROR, "Syntax Error?", 0, s.getLocation());
final ErrorUml err = new ErrorUml(ErrorUmlType.SYNTAX_ERROR, "Syntax Error?", 0, s.getLocation(), getUmlDiagramType());
// return PSystemErrorUtils.buildV1(source, err, null);
return PSystemErrorUtils.buildV2(source, err, null, it.getTrace());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private AbstractPSystem executeFewLines(AbstractPSystem sys, UmlSource source, f
ParserPass currentPass) {
final Step step = getCandidate(it);
if (step == null) {
final ErrorUml err = new ErrorUml(ErrorUmlType.SYNTAX_ERROR, "Syntax Error?", 0, it.peek().getLocation());
final ErrorUml err = new ErrorUml(ErrorUmlType.SYNTAX_ERROR, "Syntax Error?", 0, it.peek().getLocation(), getUmlDiagramType());
it.next();
return PSystemErrorUtils.buildV2(source, err, null, it.getTrace());
}
Expand All @@ -142,7 +142,7 @@ private AbstractPSystem executeFewLines(AbstractPSystem sys, UmlSource source, f
if (result.isOk() == false) {
final LineLocation location = ((StringLocated) step.blocLines.getFirst()).getLocation();
final ErrorUml err = new ErrorUml(ErrorUmlType.EXECUTION_ERROR, result.getError(), result.getScore(),
location);
location, getUmlDiagramType());
sys = PSystemErrorUtils.buildV2(source, err, result.getDebugLines(), it.getTrace());
}
if (result.getNewDiagram() != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import net.sourceforge.plantuml.core.DiagramType;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.error.PSystemErrorUtils;
import net.sourceforge.plantuml.skin.UmlDiagramType;
import net.sourceforge.plantuml.text.StringLocated;
import net.sourceforge.plantuml.utils.LineLocation;
import net.sourceforge.plantuml.utils.StartUtils;
Expand Down Expand Up @@ -82,12 +83,18 @@ final public Diagram createSystem(UmlSource source, Map<String, String> skinMap)

final AbstractPSystem sys = executeLine(source, s.getString());
if (sys == null) {
final ErrorUml err = new ErrorUml(ErrorUmlType.SYNTAX_ERROR, "Syntax Error?", 0, s.getLocation());
final ErrorUml err = new ErrorUml(ErrorUmlType.SYNTAX_ERROR, "Syntax Error?", 0, s.getLocation(), getUmlDiagramType());
// return PSystemErrorUtils.buildV1(source, err, null);
return PSystemErrorUtils.buildV2(source, err, null, it.getTrace());
}
return sys;

}

@Override
final public UmlDiagramType getUmlDiagramType() {
return null;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import net.sourceforge.plantuml.compositediagram.command.CommandEndPackageBlock;
import net.sourceforge.plantuml.compositediagram.command.CommandLinkBlock;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.skin.UmlDiagramType;
import net.sourceforge.plantuml.style.ISkinSimple;

public class CompositeDiagramFactory extends PSystemCommandFactory {
Expand All @@ -69,4 +70,10 @@ protected void initCommandsList(List<Command> cmds) {
public CompositeDiagram createEmptyDiagram(UmlSource source, Map<String, String> skinMap) {
return new CompositeDiagram(source, skinMap);
}

@Override
public UmlDiagramType getUmlDiagramType() {
return UmlDiagramType.COMPOSITE;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import net.sourceforge.plantuml.command.PSystemBasicFactory;
import net.sourceforge.plantuml.core.DiagramType;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.skin.UmlDiagramType;

public class PSystemDefinitionFactory extends PSystemBasicFactory<PSystemDefinition> {

Expand All @@ -58,5 +59,11 @@ public PSystemDefinition executeLine(UmlSource source, PSystemDefinition system,
system.doCommandLine(line);
return system;
}

@Override
public UmlDiagramType getUmlDiagramType() {
return null;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import net.sourceforge.plantuml.objectdiagram.command.CommandCreateMap;
import net.sourceforge.plantuml.regex.RegexLeaf;
import net.sourceforge.plantuml.regex.RegexOr;
import net.sourceforge.plantuml.skin.UmlDiagramType;

public class DescriptionDiagramFactory extends PSystemCommandFactory {

Expand Down Expand Up @@ -126,5 +127,11 @@ protected void initCommandsList(List<Command> cmds) {
cmds.add(new CommandArchimateMultilines());
cmds.add(new CommandCreateDomain());
}

@Override
public UmlDiagramType getUmlDiagramType() {
return UmlDiagramType.DESCRIPTION;
}


}
7 changes: 7 additions & 0 deletions src/net/sourceforge/plantuml/directdot/PSystemDotFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import net.sourceforge.plantuml.command.PSystemBasicFactory;
import net.sourceforge.plantuml.core.DiagramType;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.skin.UmlDiagramType;

public class PSystemDotFactory extends PSystemBasicFactory<PSystemDot> {

Expand Down Expand Up @@ -66,4 +67,10 @@ public PSystemDot executeLine(UmlSource source, PSystemDot system, String line)
data.append("\n");
return new PSystemDot(source, data.toString());
}

@Override
public UmlDiagramType getUmlDiagramType() {
return null;
}

}
8 changes: 8 additions & 0 deletions src/net/sourceforge/plantuml/ditaa/PSystemDitaaFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import net.sourceforge.plantuml.command.PSystemBasicFactory;
import net.sourceforge.plantuml.core.DiagramType;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.skin.UmlDiagramType;

public class PSystemDitaaFactory extends PSystemBasicFactory<PSystemDitaa> {
// ::remove folder when __HAXE__
Expand Down Expand Up @@ -170,4 +171,11 @@ private Font extractFont(String line) {

return new Font(fontName, fontVariant, fontSize);
}


@Override
public UmlDiagramType getUmlDiagramType() {
return null;
}

}
7 changes: 7 additions & 0 deletions src/net/sourceforge/plantuml/ebnf/PSystemEbnfFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import net.sourceforge.plantuml.command.PSystemCommandFactory;
import net.sourceforge.plantuml.core.DiagramType;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.skin.UmlDiagramType;

public class PSystemEbnfFactory extends PSystemCommandFactory {

Expand All @@ -65,5 +66,11 @@ protected void initCommandsList(List<Command> cmds) {
public PSystemEbnf createEmptyDiagram(UmlSource source, Map<String, String> skinMap) {
return new PSystemEbnf(source);
}

@Override
public UmlDiagramType getUmlDiagramType() {
return UmlDiagramType.EBNF;
}


}
Loading

0 comments on commit c6263bd

Please sign in to comment.