diff --git a/gradle.properties b/gradle.properties index 6f86d3d815a..ddbe9ba1daf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ # Warning, "version" should be the same in gradle.properties and Version.java # Any idea anyone how to magically synchronize those :-) ? -version = 1.2024.4beta1 +version = 1.2024.4beta5 org.gradle.workers.max = 3 \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/BlockUml.java b/src/net/sourceforge/plantuml/BlockUml.java index 9a4229bad55..b5c6b76c724 100644 --- a/src/net/sourceforge/plantuml/BlockUml.java +++ b/src/net/sourceforge/plantuml/BlockUml.java @@ -143,7 +143,7 @@ public BlockUml(List strings, Defines defines, ISkinSimple skinPa this.data = new ArrayList<>(strings); } else { final TimLoader timLoader = new TimLoader(mode.getImportedFiles(), defines, charset, - (DefinitionsContainer) mode); + (DefinitionsContainer) mode, strings.get(0)); this.included.addAll(timLoader.load(strings)); this.data = timLoader.getResultList(); this.debug = timLoader.getDebug(); diff --git a/src/net/sourceforge/plantuml/preproc/Defines.java b/src/net/sourceforge/plantuml/preproc/Defines.java index ed1478741a3..14ec49a0ee6 100644 --- a/src/net/sourceforge/plantuml/preproc/Defines.java +++ b/src/net/sourceforge/plantuml/preproc/Defines.java @@ -55,6 +55,7 @@ import net.sourceforge.plantuml.security.SFile; import net.sourceforge.plantuml.security.SecurityProfile; import net.sourceforge.plantuml.security.SecurityUtils; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.TVariableScope; @@ -81,11 +82,11 @@ public static Defines createEmpty() { return new Defines(); } - public void copyTo(TMemory memory) throws EaterException { + public void copyTo(TMemory memory, StringLocated location) throws EaterException { for (Entry ent : values.entrySet()) { final String name = ent.getKey(); final Define def = ent.getValue(); - memory.putVariable(name, def.asTVariable(), TVariableScope.GLOBAL); + memory.putVariable(name, def.asTVariable(), TVariableScope.GLOBAL, location); } } @@ -114,10 +115,10 @@ public static Defines createWithFileName(SFile file) { final Defines result = createEmpty(); result.overrideFilename(file.getName()); result.environment.put("filedate", new Date(file.lastModified()).toString()); - if (SecurityUtils.getSecurityProfile() == SecurityProfile.UNSECURE) { + if (SecurityUtils.getSecurityProfile() == SecurityProfile.UNSECURE) result.environment.put("dirpath", file.getAbsoluteFile().getParentFile().getAbsolutePath().replace('\\', '/')); - } + return result; } @@ -126,10 +127,10 @@ public static Defines createWithFileName(java.io.File file) { final Defines result = createEmpty(); result.overrideFilename(file.getName()); result.environment.put("filedate", new Date(file.lastModified()).toString()); - if (SecurityUtils.getSecurityProfile() == SecurityProfile.UNSECURE) { + if (SecurityUtils.getSecurityProfile() == SecurityProfile.UNSECURE) result.environment.put("dirpath", file.getAbsoluteFile().getParentFile().getAbsolutePath().replace('\\', '/')); - } + return result; } @@ -147,9 +148,9 @@ public String getEnvironmentValue(String key) { private static String nameNoExtension(String name) { final int x = name.lastIndexOf('.'); - if (x == -1) { + if (x == -1) return name; - } + return name.substring(0, x); } @@ -169,11 +170,10 @@ public boolean isDefine(String expression) { } public boolean isTrue(String name) { - for (String key : values.keySet()) { - if (key.equals(name) || key.startsWith(name + "(")) { + for (String key : values.keySet()) + if (key.equals(name) || key.startsWith(name + "(")) return true; - } - } + return false; } @@ -192,9 +192,9 @@ public List applyDefines(String line) { } private String method1(String line) { - for (Define def : values.values()) { + for (Define def : values.values()) line = def.apply(line); - } + return line; } @@ -215,18 +215,17 @@ private Map> getAll() { private String method2(String line) { final Set words = words(line); - if (magic == null) { + if (magic == null) magic = getAll(); - } for (String w : words) { Collection tmp = magic.get(w); - if (tmp == null) { + if (tmp == null) continue; - } - for (Define def : tmp) { + + for (Define def : tmp) line = def.apply(line); - } + } return line; } @@ -236,9 +235,9 @@ private Set words(String line) { Pattern p = Pattern.compile(ID); Matcher m = p.matcher(line); final Set words = new HashSet<>(); - while (m.find()) { + while (m.find()) words.add(m.group(0)); - } + return words; } diff --git a/src/net/sourceforge/plantuml/preproc/Stdlib.java b/src/net/sourceforge/plantuml/preproc/Stdlib.java index 3072500d00b..805b9f1c84f 100644 --- a/src/net/sourceforge/plantuml/preproc/Stdlib.java +++ b/src/net/sourceforge/plantuml/preproc/Stdlib.java @@ -335,7 +335,7 @@ public static void extractStdLib() throws IOException { } } - private static Collection getAll() throws IOException { + public static Collection getAll() throws IOException { final Set result = new TreeSet<>(); final InputStream home = getInternalInputStream("home", ".repx"); if (home == null) @@ -451,11 +451,11 @@ public static void addInfoVersion(List strings, boolean details) { } } - private String getVersion() { + public String getVersion() { return info.get("VERSION"); } - private String getSource() { + public String getSource() { return info.get("SOURCE"); } diff --git a/src/net/sourceforge/plantuml/preproc/Sub.java b/src/net/sourceforge/plantuml/preproc/Sub.java index 00b7bddcddc..b39e8d4d0d1 100644 --- a/src/net/sourceforge/plantuml/preproc/Sub.java +++ b/src/net/sourceforge/plantuml/preproc/Sub.java @@ -48,7 +48,7 @@ import net.sourceforge.plantuml.tim.TMemory; public class Sub { - // ::remove folder when __HAXE__ + // ::remove folder when __HAXE__ private final String name; private final List lines = new ArrayList<>(); diff --git a/src/net/sourceforge/plantuml/preproc/Truth.java b/src/net/sourceforge/plantuml/preproc/Truth.java index 7a33da793ca..1ec283d02e6 100644 --- a/src/net/sourceforge/plantuml/preproc/Truth.java +++ b/src/net/sourceforge/plantuml/preproc/Truth.java @@ -36,6 +36,7 @@ package net.sourceforge.plantuml.preproc; public interface Truth { + public boolean isTrue(String name); } diff --git a/src/net/sourceforge/plantuml/preproc2/PreprocessorUtils.java b/src/net/sourceforge/plantuml/preproc2/PreprocessorUtils.java index ee238c99c85..8132faab8fc 100644 --- a/src/net/sourceforge/plantuml/preproc2/PreprocessorUtils.java +++ b/src/net/sourceforge/plantuml/preproc2/PreprocessorUtils.java @@ -54,7 +54,6 @@ import net.sourceforge.plantuml.security.SURL; import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.utils.LineLocation; import net.sourceforge.plantuml.utils.Log; public class PreprocessorUtils { @@ -139,21 +138,21 @@ public static ReadLine getReaderIncludeUrl(final SURL url, StringLocated s, Stri if (StartDiagramExtractReader.containsStartDiagram(url, s, charset)) return StartDiagramExtractReader.build(url, s, suf, charset); - return getReaderInclude(url, s.getLocation(), charset); + return getReaderInclude(url, s, charset); } catch (IOException e) { Logme.error(e); - throw EaterException.located("Cannot open URL " + e.getMessage()); + throw new EaterException("Cannot open URL " + e.getMessage(), s); } } - public static ReadLine getReaderInclude(SURL url, LineLocation lineLocation, Charset charset) + public static ReadLine getReaderInclude(SURL url, StringLocated s, Charset charset) throws EaterException, UnsupportedEncodingException { final InputStream is = url.openStream(); if (is == null) - throw EaterException.located("Cannot open URL"); + throw new EaterException("Cannot open URL", s); - return ReadLineReader.create(new InputStreamReader(is, charset), url.toString(), lineLocation); + return ReadLineReader.create(new InputStreamReader(is, charset), url.toString(), s.getLocation()); } } diff --git a/src/net/sourceforge/plantuml/text/StringLocated.java b/src/net/sourceforge/plantuml/text/StringLocated.java index ed15e2f118d..bc99b864a5c 100644 --- a/src/net/sourceforge/plantuml/text/StringLocated.java +++ b/src/net/sourceforge/plantuml/text/StringLocated.java @@ -158,4 +158,8 @@ public int length() { return s.length(); } + public char charAt(int i) { + return s.charAt(i); + } + } diff --git a/src/net/sourceforge/plantuml/tim/Eater.java b/src/net/sourceforge/plantuml/tim/Eater.java index c23fbf085af..2f528755536 100644 --- a/src/net/sourceforge/plantuml/tim/Eater.java +++ b/src/net/sourceforge/plantuml/tim/Eater.java @@ -50,35 +50,33 @@ public abstract class Eater { private int i = 0; - private final String s; - private final LineLocation lineLocation; + private final StringLocated stringLocated; - public Eater(StringLocated sl) { - this(sl.getString(), sl.getLocation()); + public Eater(StringLocated stringLocated) { + this.stringLocated = stringLocated; } - protected Eater(String s, LineLocation lineLocation) { - this.s = s; - this.lineLocation = lineLocation; + public final LineLocation getLineLocation() { + return stringLocated.getLocation(); } - public final LineLocation getLineLocation() { - return lineLocation; + public final StringLocated getStringLocated() { + return stringLocated; } - public abstract void analyze(TContext context, TMemory memory) throws EaterException, EaterExceptionLocated; + public abstract void analyze(TContext context, TMemory memory) throws EaterException; public int getCurrentPosition() { return i; } final protected String eatAllToEnd() throws EaterException { - final String result = s.substring(i); - i = s.length(); + final String result = stringLocated.getString().substring(i); + i = stringLocated.length(); return result; } - final public TValue eatExpression(TContext context, TMemory memory) throws EaterException, EaterExceptionLocated { + final public TValue eatExpression(TContext context, TMemory memory) throws EaterException { final char ch = peekChar(); if (ch == '{' || ch == '[') { final String data = eatAllToEnd(); @@ -88,23 +86,22 @@ final public TValue eatExpression(TContext context, TMemory memory) throws Eater return TValue.fromJson(json); } final TokenStack tokenStack = eatTokenStack(); - return tokenStack.getResult(getLineLocation(), context, memory); + return tokenStack.getResult(getStringLocated(), context, memory); } final protected TokenStack eatTokenStack() throws EaterException { final TokenStack tokenStack = new TokenStack(); addIntoTokenStack(tokenStack, false); if (tokenStack.size() == 0) - throw EaterException.located("Missing expression"); + throw new EaterException("Missing expression", stringLocated); return tokenStack; } - final protected TValue eatExpressionStopAtColon(TContext context, TMemory memory) - throws EaterException, EaterExceptionLocated { + final protected TValue eatExpressionStopAtColon(TContext context, TMemory memory) throws EaterException { final TokenStack tokenStack = new TokenStack(); addIntoTokenStack(tokenStack, true); - return tokenStack.getResult(getLineLocation(), context, memory); + return tokenStack.getResult(getStringLocated(), context, memory); } final protected void addIntoTokenStack(TokenStack tokenStack, boolean stopAtColon) throws EaterException { @@ -123,7 +120,7 @@ final protected void addIntoTokenStack(TokenStack tokenStack, boolean stopAtColo final public String eatAndGetQuotedString() throws EaterException { final char separator = peekChar(); if (TLineType.isQuote(separator) == false) - throw EaterException.located("quote10"); + throw new EaterException("quote10", stringLocated); checkAndEatChar(separator); final StringBuilder value = new StringBuilder(); @@ -144,7 +141,7 @@ final protected String eatAndGetOptionalQuotedString() throws EaterException { while (true) { char ch = peekChar(); if (ch == 0) - throw EaterException.located("until001"); + throw new EaterException("until001", stringLocated); if (level == 0 && (ch == ',' || ch == ')')) return value.toString().trim(); @@ -192,7 +189,7 @@ final public String eatAndGetSpaces() throws EaterException { final protected String eatAndGetVarname() throws EaterException { final StringBuilder varname = new StringBuilder("" + eatOneChar()); if (TLineType.isLetterOrUnderscoreOrDollar(varname.charAt(0)) == false) - throw EaterException.located("a002"); + throw new EaterException("a002", stringLocated); addUpToLastLetterOrUnderscoreOrDigit(varname); return varname.toString(); @@ -201,63 +198,63 @@ final protected String eatAndGetVarname() throws EaterException { final protected String eatAndGetFunctionName() throws EaterException { final StringBuilder varname = new StringBuilder("" + eatOneChar()); if (TLineType.isLetterOrUnderscoreOrDollar(varname.charAt(0)) == false) - throw EaterException.located("a003"); + throw new EaterException("a003", stringLocated); addUpToLastLetterOrUnderscoreOrDigit(varname); return varname.toString(); } final public void skipSpaces() { - while (i < s.length() && Character.isWhitespace(s.charAt(i))) + while (i < stringLocated.length() && Character.isWhitespace(stringLocated.charAt(i))) i++; } final protected void skipUntilChar(char ch) { - while (i < s.length() && s.charAt(i) != ch) + while (i < stringLocated.length() && stringLocated.charAt(i) != ch) i++; } final public char peekChar() { - if (i >= s.length()) + if (i >= stringLocated.length()) return 0; - return s.charAt(i); + return stringLocated.charAt(i); } final public boolean matchAffectation() { - final String tmp = s.substring(i); + final String tmp = stringLocated.getString().substring(i); final boolean result = tmp.matches("^\\$?[_\\p{L}][_\\p{L}0-9]*\\s*=.*"); return result; } final public char peekCharN2() { - if (i + 1 >= s.length()) + if (i + 1 >= stringLocated.length()) return 0; - return s.charAt(i + 1); + return stringLocated.charAt(i + 1); } final protected boolean hasNextChar() { - return i < s.length(); + return i < stringLocated.length(); } final public char eatOneChar() { - final char ch = s.charAt(i); + final char ch = stringLocated.charAt(i); i++; return ch; } final protected void checkAndEatChar(char ch) throws EaterException { - if (i >= s.length() || s.charAt(i) != ch) - throw EaterException.located("a001"); + if (i >= stringLocated.length() || stringLocated.charAt(i) != ch) + throw new EaterException("a001", stringLocated); i++; } final protected boolean safeCheckAndEatChar(char ch) throws EaterException { - if (i >= s.length() || s.charAt(i) != ch) + if (i >= stringLocated.length() || stringLocated.charAt(i) != ch) return false; i++; @@ -265,10 +262,10 @@ final protected boolean safeCheckAndEatChar(char ch) throws EaterException { } final protected void optionallyEatChar(char ch) throws EaterException { - if (i >= s.length() || s.charAt(i) != ch) + if (i >= stringLocated.length() || stringLocated.charAt(i) != ch) return; - assert s.charAt(i) == ch; + assert stringLocated.charAt(i) == ch; i++; } @@ -279,8 +276,8 @@ final protected void checkAndEatChar(String s) throws EaterException { } final protected void addUpToLastLetterOrUnderscoreOrDigit(StringBuilder sb) { - while (i < s.length()) { - final char ch = s.charAt(i); + while (i < stringLocated.length()) { + final char ch = stringLocated.charAt(i); if (TLineType.isLetterOrUnderscoreOrDigit(ch) == false) return; @@ -290,7 +287,7 @@ final protected void addUpToLastLetterOrUnderscoreOrDigit(StringBuilder sb) { } final protected void addUpTo(char separator, StringBuilder sb) { - while (i < s.length()) { + while (i < stringLocated.length()) { final char ch = peekChar(); if (ch == separator) return; @@ -301,8 +298,7 @@ final protected void addUpTo(char separator, StringBuilder sb) { } final protected TFunctionImpl eatDeclareFunction(TContext context, TMemory memory, boolean unquoted, - LineLocation location, boolean allowNoParenthesis, TFunctionType type) - throws EaterException, EaterExceptionLocated { + StringLocated location, boolean allowNoParenthesis, TFunctionType type) throws EaterException { final List args = new ArrayList<>(); final String functionName = eatAndGetFunctionName(); skipSpaces(); @@ -310,7 +306,7 @@ final protected TFunctionImpl eatDeclareFunction(TContext context, TMemory memor if (allowNoParenthesis) return new TFunctionImpl(functionName, args, unquoted, type); - throw EaterException.located("Missing opening parenthesis"); + throw new EaterException("Missing opening parenthesis", stringLocated); } while (true) { skipSpaces(); @@ -322,8 +318,8 @@ final protected TFunctionImpl eatDeclareFunction(TContext context, TMemory memor if (peekChar() == '=') { eatOneChar(); final TokenStack def = TokenStack.eatUntilCloseParenthesisOrComma(this); - def.guessFunctions(); - defValue = def.getResult(getLineLocation(), context, memory); + def.guessFunctions(location); + defValue = def.getResult(getStringLocated(), context, memory); // System.err.println("result=" + defValue); } else { defValue = null; @@ -335,7 +331,7 @@ final protected TFunctionImpl eatDeclareFunction(TContext context, TMemory memor checkAndEatChar(")"); break; } else { - throw EaterException.located("Error in function definition"); + throw new EaterException("Error in function definition", stringLocated); } } skipSpaces(); @@ -343,25 +339,25 @@ final protected TFunctionImpl eatDeclareFunction(TContext context, TMemory memor } final protected TFunctionImpl eatDeclareReturnFunctionWithOptionalReturn(TContext context, TMemory memory, - boolean unquoted, LineLocation location) throws EaterException, EaterExceptionLocated { + boolean unquoted, StringLocated location) throws EaterException { final TFunctionImpl result = eatDeclareFunction(context, memory, unquoted, location, false, TFunctionType.RETURN_FUNCTION); if (peekChar() == 'r') { checkAndEatChar("return"); skipSpaces(); final String line = "!return " + eatAllToEnd(); - result.addBody(new StringLocated(line, location)); + result.addBody(new StringLocated(line, location.getLocation())); } else if (peekChar() == '!') { checkAndEatChar("!return"); skipSpaces(); final String line = "!return " + eatAllToEnd(); - result.addBody(new StringLocated(line, location)); + result.addBody(new StringLocated(line, location.getLocation())); } return result; } final protected TFunctionImpl eatDeclareProcedure(TContext context, TMemory memory, boolean unquoted, - LineLocation location) throws EaterException, EaterExceptionLocated { + StringLocated location) throws EaterException { final TFunctionImpl result = eatDeclareFunction(context, memory, unquoted, location, false, TFunctionType.PROCEDURE); return result; diff --git a/src/net/sourceforge/plantuml/tim/EaterAffectation.java b/src/net/sourceforge/plantuml/tim/EaterAffectation.java index 1c729758087..cad5ded5e89 100644 --- a/src/net/sourceforge/plantuml/tim/EaterAffectation.java +++ b/src/net/sourceforge/plantuml/tim/EaterAffectation.java @@ -44,7 +44,7 @@ public EaterAffectation(StringLocated sl) { } @Override - public void analyze(TContext context, TMemory memory) throws EaterException, EaterExceptionLocated { + public void analyze(TContext context, TMemory memory) throws EaterException { skipSpaces(); checkAndEatChar("!"); skipSpaces(); @@ -53,7 +53,8 @@ public void analyze(TContext context, TMemory memory) throws EaterException, Eat if (scope != null) { skipSpaces(); if (peekChar() == '?' || peekChar() == '=') { - // The variable itself is "local" or "glocal", which is not a good idea by the way + // The variable itself is "local" or "global", which is not a good idea by the + // way scope = null; } else varname = eatAndGetVarname(); @@ -71,7 +72,7 @@ public void analyze(TContext context, TMemory memory) throws EaterException, Eat skipSpaces(); final TValue value = eatExpression(context, memory); - memory.putVariable(varname, value, scope); + memory.putVariable(varname, value, scope, getStringLocated()); } } diff --git a/src/net/sourceforge/plantuml/tim/EaterAffectationDefine.java b/src/net/sourceforge/plantuml/tim/EaterAffectationDefine.java index d5a4fb95067..3db77f96c7a 100644 --- a/src/net/sourceforge/plantuml/tim/EaterAffectationDefine.java +++ b/src/net/sourceforge/plantuml/tim/EaterAffectationDefine.java @@ -44,19 +44,19 @@ public EaterAffectationDefine(StringLocated s) { } @Override - public void analyze(TContext context, TMemory memory) throws EaterException, EaterExceptionLocated { + public void analyze(TContext context, TMemory memory) throws EaterException { skipSpaces(); checkAndEatChar("!define"); skipSpaces(); final String varname = eatAndGetVarname(); skipSpaces(); final String tmp = eatAllToEnd(); - final String tmp2 = context.applyFunctionsAndVariables(memory, getLineLocation(), tmp); + final String tmp2 = context.applyFunctionsAndVariables(memory, new StringLocated(tmp, getLineLocation())); final TValue value = TValue.fromString(tmp2); // if (memory instanceof TMemoryLocal) { // memory = ((TMemoryLocal) memory).getGlobalForInternalUseOnly(); // } - memory.putVariable(varname, value, TVariableScope.GLOBAL); + memory.putVariable(varname, value, TVariableScope.GLOBAL, getStringLocated()); } } diff --git a/src/net/sourceforge/plantuml/tim/EaterAssert.java b/src/net/sourceforge/plantuml/tim/EaterAssert.java index 1858579eeab..00603e675ab 100644 --- a/src/net/sourceforge/plantuml/tim/EaterAssert.java +++ b/src/net/sourceforge/plantuml/tim/EaterAssert.java @@ -44,7 +44,7 @@ public EaterAssert(StringLocated s) { } @Override - public void analyze(TContext context, TMemory memory) throws EaterException, EaterExceptionLocated { + public void analyze(TContext context, TMemory memory) throws EaterException { skipSpaces(); checkAndEatChar("!assert"); skipSpaces(); @@ -55,9 +55,9 @@ public void analyze(TContext context, TMemory memory) throws EaterException, Eat if (ch == ':') { checkAndEatChar(':'); final TValue message = eatExpression(context, memory); - throw EaterException.located("Assertion error : " + message.toString()); + throw new EaterException("Assertion error : " + message.toString(), getStringLocated()); } - throw EaterException.located("Assertion error"); + throw new EaterException("Assertion error", getStringLocated()); } } diff --git a/src/net/sourceforge/plantuml/tim/EaterDeclareProcedure.java b/src/net/sourceforge/plantuml/tim/EaterDeclareProcedure.java index 43dc732c38b..b26b2b4253f 100644 --- a/src/net/sourceforge/plantuml/tim/EaterDeclareProcedure.java +++ b/src/net/sourceforge/plantuml/tim/EaterDeclareProcedure.java @@ -35,21 +35,20 @@ package net.sourceforge.plantuml.tim; import net.sourceforge.plantuml.text.StringLocated; -import net.sourceforge.plantuml.utils.LineLocation; public class EaterDeclareProcedure extends Eater { private TFunctionImpl function; - private final LineLocation location; + private final StringLocated location; private boolean finalFlag; public EaterDeclareProcedure(StringLocated s) { super(s.getTrimmed()); - this.location = s.getLocation(); + this.location = s; } @Override - public void analyze(TContext context, TMemory memory) throws EaterException, EaterExceptionLocated { + public void analyze(TContext context, TMemory memory) throws EaterException { skipSpaces(); checkAndEatChar("!"); boolean unquoted = false; diff --git a/src/net/sourceforge/plantuml/tim/EaterDeclareReturnFunction.java b/src/net/sourceforge/plantuml/tim/EaterDeclareReturnFunction.java index e02ad1e3062..139130ed64e 100644 --- a/src/net/sourceforge/plantuml/tim/EaterDeclareReturnFunction.java +++ b/src/net/sourceforge/plantuml/tim/EaterDeclareReturnFunction.java @@ -35,21 +35,20 @@ package net.sourceforge.plantuml.tim; import net.sourceforge.plantuml.text.StringLocated; -import net.sourceforge.plantuml.utils.LineLocation; public class EaterDeclareReturnFunction extends Eater { private TFunctionImpl function; - private final LineLocation location; + private final StringLocated location; private boolean finalFlag; public EaterDeclareReturnFunction(StringLocated s) { super(s.getTrimmed()); - this.location = s.getLocation(); + this.location = s; } @Override - public void analyze(TContext context, TMemory memory) throws EaterException, EaterExceptionLocated { + public void analyze(TContext context, TMemory memory) throws EaterException { skipSpaces(); checkAndEatChar("!"); boolean unquoted = false; diff --git a/src/net/sourceforge/plantuml/tim/EaterElseIf.java b/src/net/sourceforge/plantuml/tim/EaterElseIf.java index 8ddc5e35a4f..85f8a1ae8c7 100644 --- a/src/net/sourceforge/plantuml/tim/EaterElseIf.java +++ b/src/net/sourceforge/plantuml/tim/EaterElseIf.java @@ -46,7 +46,7 @@ public EaterElseIf(StringLocated s) { } @Override - public void analyze(TContext context, TMemory memory) throws EaterException, EaterExceptionLocated { + public void analyze(TContext context, TMemory memory) throws EaterException { skipSpaces(); checkAndEatChar("!elseif"); skipSpaces(); diff --git a/src/net/sourceforge/plantuml/tim/EaterException.java b/src/net/sourceforge/plantuml/tim/EaterException.java index 94cf2a60465..4de83e32bd4 100644 --- a/src/net/sourceforge/plantuml/tim/EaterException.java +++ b/src/net/sourceforge/plantuml/tim/EaterException.java @@ -34,30 +34,26 @@ */ package net.sourceforge.plantuml.tim; +import java.util.Objects; + import net.sourceforge.plantuml.text.StringLocated; public class EaterException extends Exception { private final String message; + private final StringLocated location; - private EaterException(String message) { - this.message = message; - } - - public static EaterException unlocated(String message) { - return new EaterException(message); - } - - public static EaterException located(String message) { - return unlocated(message); + public EaterException(String message, StringLocated location) { + this.message = Objects.requireNonNull(message); + this.location = Objects.requireNonNull(location); } public final String getMessage() { return message; } - public EaterExceptionLocated withLocation(StringLocated sl) { - return EaterExceptionLocated.located(message, sl); + public final StringLocated getLocation() { + return location; } } diff --git a/src/net/sourceforge/plantuml/tim/EaterExceptionLocated.java b/src/net/sourceforge/plantuml/tim/EaterExceptionLocated.java deleted file mode 100644 index 36ee621873e..00000000000 --- a/src/net/sourceforge/plantuml/tim/EaterExceptionLocated.java +++ /dev/null @@ -1,63 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009-2024, Arnaud Roques - * - * Project Info: https://plantuml.com - * - * If you like this project or if you find it useful, you can support us at: - * - * https://plantuml.com/patreon (only 1$ per month!) - * https://plantuml.com/paypal - * - * 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.tim; - -import java.util.Objects; - -import net.sourceforge.plantuml.text.StringLocated; - -public class EaterExceptionLocated extends Exception { - - private final String message; - private final StringLocated location; - - private EaterExceptionLocated(String message, StringLocated location) { - this.message = message; - this.location = location; - } - - public static EaterExceptionLocated located(String message, StringLocated location) { - return new EaterExceptionLocated(message, Objects.requireNonNull(location)); - } - - public final String getMessage() { - return message; - } - - public final StringLocated getLocation() { - return location; - } - -} diff --git a/src/net/sourceforge/plantuml/tim/EaterForeach.java b/src/net/sourceforge/plantuml/tim/EaterForeach.java index b7be391dad5..37be05afccc 100644 --- a/src/net/sourceforge/plantuml/tim/EaterForeach.java +++ b/src/net/sourceforge/plantuml/tim/EaterForeach.java @@ -48,7 +48,7 @@ public EaterForeach(StringLocated s) { } @Override - public void analyze(TContext context, TMemory memory) throws EaterException, EaterExceptionLocated { + public void analyze(TContext context, TMemory memory) throws EaterException { skipSpaces(); checkAndEatChar("!foreach"); skipSpaces(); diff --git a/src/net/sourceforge/plantuml/tim/EaterFunctionCall.java b/src/net/sourceforge/plantuml/tim/EaterFunctionCall.java index 22c2338680b..b5cc4204bfb 100644 --- a/src/net/sourceforge/plantuml/tim/EaterFunctionCall.java +++ b/src/net/sourceforge/plantuml/tim/EaterFunctionCall.java @@ -58,7 +58,7 @@ public EaterFunctionCall(StringLocated s, boolean isLegacyDefine, boolean unquot } @Override - public void analyze(TContext context, TMemory memory) throws EaterException, EaterExceptionLocated { + public void analyze(TContext context, TMemory memory) throws EaterException { skipUntilChar('('); checkAndEatChar('('); skipSpaces(); @@ -70,7 +70,8 @@ public void analyze(TContext context, TMemory memory) throws EaterException, Eat skipSpaces(); if (isLegacyDefine) { final String read = eatAndGetOptionalQuotedString(); - final String value = context.applyFunctionsAndVariables(memory, getLineLocation(), read); + final String value = context.applyFunctionsAndVariables(memory, + new StringLocated(read, getLineLocation())); final TValue result = TValue.fromString(value); values.add(result); } else if (unquoted) { @@ -80,12 +81,14 @@ public void analyze(TContext context, TMemory memory) throws EaterException, Eat checkAndEatChar('='); skipSpaces(); final String read = eatAndGetOptionalQuotedString(); - final String value = context.applyFunctionsAndVariables(memory, getLineLocation(), read); + final String value = context.applyFunctionsAndVariables(memory, + new StringLocated(read, getLineLocation())); final TValue result = TValue.fromString(value); namedArguments.put(varname, result); } else { final String read = eatAndGetOptionalQuotedString(); - final String value = context.applyFunctionsAndVariables(memory, getLineLocation(), read); + final String value = context.applyFunctionsAndVariables(memory, + new StringLocated(read, getLineLocation())); final TValue result = TValue.fromString(value); values.add(result); } @@ -97,13 +100,13 @@ public void analyze(TContext context, TMemory memory) throws EaterException, Eat checkAndEatChar('='); skipSpaces(); final TokenStack tokens = TokenStack.eatUntilCloseParenthesisOrComma(this).withoutSpace(); - tokens.guessFunctions(); - final TValue result = tokens.getResult(getLineLocation(), context, memory); + tokens.guessFunctions(getStringLocated()); + final TValue result = tokens.getResult(getStringLocated(), context, memory); namedArguments.put(varname, result); } else { final TokenStack tokens = TokenStack.eatUntilCloseParenthesisOrComma(this).withoutSpace(); - tokens.guessFunctions(); - final TValue result = tokens.getResult(getLineLocation(), context, memory); + tokens.guessFunctions(getStringLocated()); + final TValue result = tokens.getResult(getStringLocated(), context, memory); values.add(result); } } @@ -116,9 +119,9 @@ public void analyze(TContext context, TMemory memory) throws EaterException, Eat break; } if (unquoted) { - throw EaterException.located("unquoted function/procedure cannot use expression."); + throw new EaterException("unquoted function/procedure cannot use expression.", getStringLocated()); } - throw EaterException.located("call001"); + throw new EaterException("call001", getStringLocated()); } } diff --git a/src/net/sourceforge/plantuml/tim/EaterIf.java b/src/net/sourceforge/plantuml/tim/EaterIf.java index 50ad453da7f..f44772c48ed 100644 --- a/src/net/sourceforge/plantuml/tim/EaterIf.java +++ b/src/net/sourceforge/plantuml/tim/EaterIf.java @@ -46,7 +46,7 @@ public EaterIf(StringLocated s) { } @Override - public void analyze(TContext context, TMemory memory) throws EaterException, EaterExceptionLocated { + public void analyze(TContext context, TMemory memory) throws EaterException { skipSpaces(); checkAndEatChar("!if"); skipSpaces(); diff --git a/src/net/sourceforge/plantuml/tim/EaterImport.java b/src/net/sourceforge/plantuml/tim/EaterImport.java index b17727d1757..3f1296de671 100644 --- a/src/net/sourceforge/plantuml/tim/EaterImport.java +++ b/src/net/sourceforge/plantuml/tim/EaterImport.java @@ -38,23 +38,24 @@ public class EaterImport extends Eater { - private String location; + private String what; public EaterImport(StringLocated s) { super(s); } @Override - public void analyze(TContext context, TMemory memory) throws EaterException, EaterExceptionLocated { + public void analyze(TContext context, TMemory memory) throws EaterException { skipSpaces(); checkAndEatChar("!import"); skipSpaces(); - this.location = context.applyFunctionsAndVariables(memory, getLineLocation(), this.eatAllToEnd()); + this.what = context.applyFunctionsAndVariables(memory, + new StringLocated(this.eatAllToEnd(), getLineLocation())); } - public final String getLocation() { - return location; + public final String getWhat() { + return what; } } diff --git a/src/net/sourceforge/plantuml/tim/EaterInclude.java b/src/net/sourceforge/plantuml/tim/EaterInclude.java index c41bd9f88cd..cf6eb397546 100644 --- a/src/net/sourceforge/plantuml/tim/EaterInclude.java +++ b/src/net/sourceforge/plantuml/tim/EaterInclude.java @@ -39,7 +39,7 @@ public class EaterInclude extends Eater { - private String location; + private String what; private PreprocessorIncludeStrategy strategy = PreprocessorIncludeStrategy.DEFAULT; public EaterInclude(StringLocated s) { @@ -47,7 +47,7 @@ public EaterInclude(StringLocated s) { } @Override - public void analyze(TContext context, TMemory memory) throws EaterException, EaterExceptionLocated { + public void analyze(TContext context, TMemory memory) throws EaterException { skipSpaces(); checkAndEatChar("!include"); final char peekChar = peekChar(); @@ -65,14 +65,15 @@ public void analyze(TContext context, TMemory memory) throws EaterException, Eat } } skipSpaces(); - this.location = context.applyFunctionsAndVariables(memory, getLineLocation(), this.eatAllToEnd()); + this.what = context.applyFunctionsAndVariables(memory, + new StringLocated(this.eatAllToEnd(), getLineLocation())); // final TValue value = eatExpression(context, memory); // this.location = value.toString(); } - public final String getLocation() { - return location; + public final String getWhat() { + return what; } public final PreprocessorIncludeStrategy getPreprocessorIncludeStrategy() { diff --git a/src/net/sourceforge/plantuml/tim/EaterIncludeDef.java b/src/net/sourceforge/plantuml/tim/EaterIncludeDef.java index 1cb81336372..6e3ce76c592 100644 --- a/src/net/sourceforge/plantuml/tim/EaterIncludeDef.java +++ b/src/net/sourceforge/plantuml/tim/EaterIncludeDef.java @@ -45,11 +45,12 @@ public EaterIncludeDef(StringLocated s) { } @Override - public void analyze(TContext context, TMemory memory) throws EaterException, EaterExceptionLocated { + public void analyze(TContext context, TMemory memory) throws EaterException { skipSpaces(); checkAndEatChar("!includedef"); skipSpaces(); - this.location = context.applyFunctionsAndVariables(memory, getLineLocation(), this.eatAllToEnd()); + this.location = context.applyFunctionsAndVariables(memory, + new StringLocated(this.eatAllToEnd(), getLineLocation())); } diff --git a/src/net/sourceforge/plantuml/tim/EaterIncludesub.java b/src/net/sourceforge/plantuml/tim/EaterIncludesub.java index 355b1160582..5cdb7f5c612 100644 --- a/src/net/sourceforge/plantuml/tim/EaterIncludesub.java +++ b/src/net/sourceforge/plantuml/tim/EaterIncludesub.java @@ -38,23 +38,24 @@ public class EaterIncludesub extends Eater { - private String location; + private String what; public EaterIncludesub(StringLocated s) { super(s); } @Override - public void analyze(TContext context, TMemory memory) throws EaterException, EaterExceptionLocated { + public void analyze(TContext context, TMemory memory) throws EaterException { skipSpaces(); checkAndEatChar("!includesub"); skipSpaces(); - this.location = context.applyFunctionsAndVariables(memory, getLineLocation(), this.eatAllToEnd()); + this.what = context.applyFunctionsAndVariables(memory, + new StringLocated(this.eatAllToEnd(), getLineLocation())); } - public final String getLocation() { - return location; + public final String getWhat() { + return what; } } diff --git a/src/net/sourceforge/plantuml/tim/EaterLegacyDefine.java b/src/net/sourceforge/plantuml/tim/EaterLegacyDefine.java index bd82decbeee..6035a7ed639 100644 --- a/src/net/sourceforge/plantuml/tim/EaterLegacyDefine.java +++ b/src/net/sourceforge/plantuml/tim/EaterLegacyDefine.java @@ -45,11 +45,11 @@ public EaterLegacyDefine(StringLocated s) { } @Override - public void analyze(TContext context, TMemory memory) throws EaterException, EaterExceptionLocated { + public void analyze(TContext context, TMemory memory) throws EaterException { skipSpaces(); checkAndEatChar("!define"); skipSpaces(); - function = eatDeclareFunction(context, memory, true, getLineLocation(), false, TFunctionType.LEGACY_DEFINE); + function = eatDeclareFunction(context, memory, true, getStringLocated(), false, TFunctionType.LEGACY_DEFINE); final String def = this.eatAllToEnd(); // function.setFunctionType(TFunctionType.LEGACY_DEFINE); function.setLegacyDefinition(def); diff --git a/src/net/sourceforge/plantuml/tim/EaterLegacyDefineLong.java b/src/net/sourceforge/plantuml/tim/EaterLegacyDefineLong.java index 56a10e488ac..3fccd619c67 100644 --- a/src/net/sourceforge/plantuml/tim/EaterLegacyDefineLong.java +++ b/src/net/sourceforge/plantuml/tim/EaterLegacyDefineLong.java @@ -45,11 +45,11 @@ public EaterLegacyDefineLong(StringLocated s) { } @Override - public void analyze(TContext context, TMemory memory) throws EaterException, EaterExceptionLocated { + public void analyze(TContext context, TMemory memory) throws EaterException { skipSpaces(); checkAndEatChar("!definelong"); skipSpaces(); - function = eatDeclareFunction(context, memory, true, getLineLocation(), true, TFunctionType.LEGACY_DEFINELONG); + function = eatDeclareFunction(context, memory, true, getStringLocated(), true, TFunctionType.LEGACY_DEFINELONG); // function.setFunctionType(TFunctionType.LEGACY_DEFINELONG); } diff --git a/src/net/sourceforge/plantuml/tim/EaterLog.java b/src/net/sourceforge/plantuml/tim/EaterLog.java index 4a0bc62df58..3e31b00f7b9 100644 --- a/src/net/sourceforge/plantuml/tim/EaterLog.java +++ b/src/net/sourceforge/plantuml/tim/EaterLog.java @@ -44,11 +44,12 @@ public EaterLog(StringLocated s) { } @Override - public void analyze(TContext context, TMemory memory) throws EaterException, EaterExceptionLocated { + public void analyze(TContext context, TMemory memory) throws EaterException { skipSpaces(); checkAndEatChar("!log"); skipSpaces(); - final String logData = context.applyFunctionsAndVariables(memory, getLineLocation(), this.eatAllToEnd()); + final String logData = context.applyFunctionsAndVariables(memory, + new StringLocated(this.eatAllToEnd(), getLineLocation())); Log.error("[Log] " + logData); } diff --git a/src/net/sourceforge/plantuml/tim/EaterReturn.java b/src/net/sourceforge/plantuml/tim/EaterReturn.java index 99ed3dd21da..32794020734 100644 --- a/src/net/sourceforge/plantuml/tim/EaterReturn.java +++ b/src/net/sourceforge/plantuml/tim/EaterReturn.java @@ -46,7 +46,7 @@ public EaterReturn(StringLocated s) { } @Override - public void analyze(TContext context, TMemory memory) throws EaterException, EaterExceptionLocated { + public void analyze(TContext context, TMemory memory) throws EaterException { skipSpaces(); checkAndEatChar("!return"); skipSpaces(); diff --git a/src/net/sourceforge/plantuml/tim/EaterStartsub.java b/src/net/sourceforge/plantuml/tim/EaterStartsub.java index 44a1ba17533..5cd8207b281 100644 --- a/src/net/sourceforge/plantuml/tim/EaterStartsub.java +++ b/src/net/sourceforge/plantuml/tim/EaterStartsub.java @@ -50,9 +50,9 @@ public void analyze(TContext context, TMemory memory) throws EaterException { checkAndEatChar("!startsub"); skipSpaces(); this.subname = eatAllToEnd(); - if (this.subname.matches("\\w+") == false) { - throw EaterException.located("Bad sub name"); - } + if (this.subname.matches("\\w+") == false) + throw new EaterException("Bad sub name", getStringLocated()); + } public final String getSubname() { diff --git a/src/net/sourceforge/plantuml/tim/EaterTheme.java b/src/net/sourceforge/plantuml/tim/EaterTheme.java index 35dfc4938bd..7203c5521a1 100644 --- a/src/net/sourceforge/plantuml/tim/EaterTheme.java +++ b/src/net/sourceforge/plantuml/tim/EaterTheme.java @@ -67,7 +67,7 @@ public EaterTheme(StringLocated s, ImportedFiles importedFiles) { } @Override - public void analyze(TContext context, TMemory memory) throws EaterException, EaterExceptionLocated { + public void analyze(TContext context, TMemory memory) throws EaterException { skipSpaces(); checkAndEatChar("!theme"); skipSpaces(); @@ -76,12 +76,12 @@ public void analyze(TContext context, TMemory memory) throws EaterException, Eat final int x = this.name.toLowerCase().indexOf(" from "); if (x != -1) { final String fromTmp = this.name.substring(x + " from ".length()).trim(); - this.from = context.applyFunctionsAndVariables(memory, getLineLocation(), fromTmp); + this.from = context.applyFunctionsAndVariables(memory, new StringLocated(fromTmp, getLineLocation())); this.name = this.name.substring(0, x).trim(); this.context = context; } - this.realName = context.applyFunctionsAndVariables(memory, getLineLocation(), this.name); + this.realName = context.applyFunctionsAndVariables(memory, new StringLocated(this.name, getLineLocation())); } @@ -101,24 +101,24 @@ public final ReadLine getTheme() throws EaterException { } catch (IOException e) { Logme.error(e); } - throw EaterException.located("Cannot load " + realName); + throw new EaterException("Cannot load " + realName, getStringLocated()); } if (from.startsWith("<") && from.endsWith(">")) { final ReadLine reader = ThemeUtils.getReaderTheme(realName, from); if (reader == null) - throw EaterException.located("No such theme " + realName + " in " + from); + throw new EaterException("No such theme " + realName + " in " + from, getStringLocated()); return reader; } else if (from.startsWith("http://") || from.startsWith("https://")) { final SURL url = SURL.create(ThemeUtils.getFullPath(from, realName)); if (url == null) - throw EaterException.located("Cannot open URL"); + throw new EaterException("Cannot open URL", getStringLocated()); try { - return PreprocessorUtils.getReaderInclude(url, getLineLocation(), UTF_8); + return PreprocessorUtils.getReaderInclude(url, getStringLocated(), UTF_8); } catch (UnsupportedEncodingException e) { Logme.error(e); - throw EaterException.located("Cannot decode charset"); + throw new EaterException("Cannot decode charset", getStringLocated()); } } @@ -126,12 +126,12 @@ public final ReadLine getTheme() throws EaterException { final FileWithSuffix file = context.getFileWithSuffix(from, realName); final Reader tmp = file.getReader(UTF_8); if (tmp == null) - throw EaterException.located("No such theme " + realName); + throw new EaterException("No such theme " + realName, getStringLocated()); return ReadLineReader.create(tmp, "theme " + realName); } catch (IOException e) { Logme.error(e); - throw EaterException.located("Cannot load " + realName); + throw new EaterException("Cannot load " + realName, getStringLocated()); } } diff --git a/src/net/sourceforge/plantuml/tim/ExecutionContextWhile.java b/src/net/sourceforge/plantuml/tim/ExecutionContextWhile.java index 424a3d84591..9e406e18572 100644 --- a/src/net/sourceforge/plantuml/tim/ExecutionContextWhile.java +++ b/src/net/sourceforge/plantuml/tim/ExecutionContextWhile.java @@ -34,6 +34,7 @@ */ package net.sourceforge.plantuml.tim; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.expression.TValue; import net.sourceforge.plantuml.tim.expression.TokenStack; import net.sourceforge.plantuml.tim.iterator.CodePosition; @@ -59,8 +60,8 @@ public static ExecutionContextWhile fromValue(TokenStack whileExpression, CodePo return new ExecutionContextWhile(whileExpression, codePosition); } - public TValue conditionValue(LineLocation location, TContext context, TMemory memory) - throws EaterException, EaterExceptionLocated { + public TValue conditionValue(StringLocated location, TContext context, TMemory memory) + throws EaterException { return whileExpression.getResult(location, context, memory); } diff --git a/src/net/sourceforge/plantuml/tim/ExecutionContexts.java b/src/net/sourceforge/plantuml/tim/ExecutionContexts.java index 8a3cb85184c..f42116e1ab7 100644 --- a/src/net/sourceforge/plantuml/tim/ExecutionContexts.java +++ b/src/net/sourceforge/plantuml/tim/ExecutionContexts.java @@ -80,11 +80,11 @@ public ExecutionContextForeach pollForeach() { } public boolean areAllIfOk(TContext context, TMemory memory) throws EaterException { - for (ExecutionContextIf conditionalContext : allIfs) { - if (conditionalContext.conditionIsOkHere() == false) { + for (ExecutionContextIf conditionalContext : allIfs) + if (conditionalContext.conditionIsOkHere() == false) return false; - } - } + + return true; } diff --git a/src/net/sourceforge/plantuml/tim/FunctionsSet.java b/src/net/sourceforge/plantuml/tim/FunctionsSet.java index ee9d2101994..683d0d7fa86 100644 --- a/src/net/sourceforge/plantuml/tim/FunctionsSet.java +++ b/src/net/sourceforge/plantuml/tim/FunctionsSet.java @@ -51,16 +51,16 @@ public class FunctionsSet { public TFunction getFunctionSmart(TFunctionSignature searched) { final TFunction func = this.functions.get(searched); - if (func != null) { + if (func != null) return func; - } + for (TFunction candidate : this.functions.values()) { - if (candidate.getSignature().sameFunctionNameAs(searched) == false) { + if (candidate.getSignature().sameFunctionNameAs(searched) == false) continue; - } - if (candidate.canCover(searched.getNbArg(), searched.getNamedArguments())) { + + if (candidate.canCover(searched.getNbArg(), searched.getNamedArguments())) return candidate; - } + } return null; } @@ -82,9 +82,9 @@ public TFunctionImpl pendingFunction() { } public void addFunction(TFunction func) { - if (func.getFunctionType() == TFunctionType.LEGACY_DEFINELONG) { + if (func.getFunctionType() == TFunctionType.LEGACY_DEFINELONG) ((TFunctionImpl) func).finalizeEnddefinelong(); - } + this.functions.put(func.getSignature(), func); this.functions3.add(func.getSignature().getFunctionName() + "("); } @@ -95,10 +95,10 @@ public void executeEndfunction() { } public void executeLegacyDefine(TContext context, TMemory memory, StringLocated s) - throws EaterException, EaterExceptionLocated { - if (this.pendingFunction != null) { - throw EaterException.located("already0048"); - } + throws EaterException { + if (this.pendingFunction != null) + throw new EaterException("already0048", s); + final EaterLegacyDefine legacyDefine = new EaterLegacyDefine(s); legacyDefine.analyze(context, memory); final TFunction function = legacyDefine.getFunction(); @@ -107,59 +107,59 @@ public void executeLegacyDefine(TContext context, TMemory memory, StringLocated } public void executeLegacyDefineLong(TContext context, TMemory memory, StringLocated s) - throws EaterException, EaterExceptionLocated { - if (this.pendingFunction != null) { - throw EaterException.located("already0068"); - } + throws EaterException { + if (this.pendingFunction != null) + throw new EaterException("already0068", s); + final EaterLegacyDefineLong legacyDefineLong = new EaterLegacyDefineLong(s); legacyDefineLong.analyze(context, memory); this.pendingFunction = legacyDefineLong.getFunction(); } public void executeDeclareReturnFunction(TContext context, TMemory memory, StringLocated s) - throws EaterException, EaterExceptionLocated { - if (this.pendingFunction != null) { - throw EaterException.located("already0068"); - } + throws EaterException { + if (this.pendingFunction != null) + throw new EaterException("already0068", s); + final EaterDeclareReturnFunction declareFunction = new EaterDeclareReturnFunction(s); declareFunction.analyze(context, memory); final boolean finalFlag = declareFunction.getFinalFlag(); final TFunctionSignature declaredSignature = declareFunction.getFunction().getSignature(); final TFunction previous = this.functions.get(declaredSignature); - if (previous != null && (finalFlag || this.functionsFinal.contains(declaredSignature))) { - throw EaterException.located("This function is already defined"); - } - if (finalFlag) { + if (previous != null && (finalFlag || this.functionsFinal.contains(declaredSignature))) + throw new EaterException("This function is already defined", s); + + if (finalFlag) this.functionsFinal.add(declaredSignature); - } - if (declareFunction.getFunction().hasBody()) { + + if (declareFunction.getFunction().hasBody()) this.addFunction(declareFunction.getFunction()); - } else { + else this.pendingFunction = declareFunction.getFunction(); - } + } public void executeDeclareProcedure(TContext context, TMemory memory, StringLocated s) - throws EaterException, EaterExceptionLocated { - if (this.pendingFunction != null) { - throw EaterException.located("already0068"); - } + throws EaterException { + if (this.pendingFunction != null) + throw new EaterException("already0068", s); + final EaterDeclareProcedure declareFunction = new EaterDeclareProcedure(s); declareFunction.analyze(context, memory); final boolean finalFlag = declareFunction.getFinalFlag(); final TFunctionSignature declaredSignature = declareFunction.getFunction().getSignature(); final TFunction previous = this.functions.get(declaredSignature); - if (previous != null && (finalFlag || this.functionsFinal.contains(declaredSignature))) { - throw EaterException.located("This function is already defined"); - } - if (finalFlag) { + if (previous != null && (finalFlag || this.functionsFinal.contains(declaredSignature))) + throw new EaterException("This function is already defined", s); + + if (finalFlag) this.functionsFinal.add(declaredSignature); - } - if (declareFunction.getFunction().hasBody()) { + + if (declareFunction.getFunction().hasBody()) this.addFunction(declareFunction.getFunction()); - } else { + else this.pendingFunction = declareFunction.getFunction(); - } + } } diff --git a/src/net/sourceforge/plantuml/tim/StringEater.java b/src/net/sourceforge/plantuml/tim/StringEater.java index 6e6a1489a6c..818a7856d09 100644 --- a/src/net/sourceforge/plantuml/tim/StringEater.java +++ b/src/net/sourceforge/plantuml/tim/StringEater.java @@ -34,14 +34,16 @@ */ package net.sourceforge.plantuml.tim; +import net.sourceforge.plantuml.text.StringLocated; + public class StringEater extends Eater { public StringEater(String s) { - super(s, null); + super(new StringLocated(s, null)); } @Override - public void analyze(TContext context, TMemory memory) throws EaterException, EaterExceptionLocated { + public void analyze(TContext context, TMemory memory) throws EaterException { throw new UnsupportedOperationException(); } diff --git a/src/net/sourceforge/plantuml/tim/TContext.java b/src/net/sourceforge/plantuml/tim/TContext.java index 30f2f0b9ff6..79188e5ca1b 100644 --- a/src/net/sourceforge/plantuml/tim/TContext.java +++ b/src/net/sourceforge/plantuml/tim/TContext.java @@ -97,6 +97,7 @@ import net.sourceforge.plantuml.tim.stdlib.FileExists; import net.sourceforge.plantuml.tim.stdlib.Filename; import net.sourceforge.plantuml.tim.stdlib.FunctionExists; +import net.sourceforge.plantuml.tim.stdlib.GetAllStdlib; import net.sourceforge.plantuml.tim.stdlib.GetAllTheme; import net.sourceforge.plantuml.tim.stdlib.GetJsonKey; import net.sourceforge.plantuml.tim.stdlib.GetJsonType; @@ -212,6 +213,7 @@ private void addStandardFunctions(Defines defines) { functionsSet.addFunction(new Ord()); functionsSet.addFunction(new RandomFunction()); functionsSet.addFunction(new GetAllTheme()); + functionsSet.addFunction(new GetAllStdlib()); // %standard_exists_function // %str_replace // !exit @@ -234,7 +236,7 @@ public TContext(ImportedFiles importedFiles, Defines defines, Charset charset, public Knowledge asKnowledge(final TMemory memory, final LineLocation location) { return new Knowledge() { - public TValue getVariable(String name) throws EaterException, EaterExceptionLocated { + public TValue getVariable(String name) throws EaterException { if (name.contains(".") || name.contains("[")) { final TValue result = fromJson(memory, name, location); return result; @@ -248,9 +250,8 @@ public TFunction getFunction(TFunctionSignature name) { }; } - private TValue fromJson(TMemory memory, String name, LineLocation location) - throws EaterException, EaterExceptionLocated { - final String result = applyFunctionsAndVariables(memory, location, name); + private TValue fromJson(TMemory memory, String name, LineLocation location) throws EaterException { + final String result = applyFunctionsAndVariables(memory, new StringLocated(name, location)); try { final JsonValue json = Json.parse(result); return TValue.fromJson(json); @@ -278,27 +279,23 @@ private CodeIterator buildCodeIterator(TMemory memory, List body) } public TValue executeLines(TMemory memory, List body, TFunctionType ftype, boolean modeSpecial) - throws EaterExceptionLocated { + throws EaterException { final CodeIterator it = buildCodeIterator(memory, body); StringLocated s = null; - try { - while ((s = it.peek()) != null) { - final TValue result = executeOneLineSafe(memory, s, ftype, modeSpecial); - if (result != null) - return result; + while ((s = it.peek()) != null) { + final TValue result = executeOneLineSafe(memory, s, ftype, modeSpecial); + if (result != null) + return result; - it.next(); - } - return null; - } catch (EaterException e) { - throw e.withLocation(s); + it.next(); } + return null; } private void executeLinesInternal(TMemory memory, List body, TFunctionType ftype) - throws EaterExceptionLocated, EaterException { + throws EaterException { final CodeIterator it = buildCodeIterator(memory, body); StringLocated s = null; @@ -310,22 +307,20 @@ private void executeLinesInternal(TMemory memory, List body, TFun } private TValue executeOneLineSafe(TMemory memory, StringLocated s, TFunctionType ftype, boolean modeSpecial) - throws EaterException, EaterExceptionLocated { + throws EaterException { try { this.debug.add(s); return executeOneLineNotSafe(memory, s, ftype, modeSpecial); } catch (Exception e) { if (e instanceof EaterException) throw (EaterException) e; - if (e instanceof EaterExceptionLocated) - throw (EaterExceptionLocated) e; Logme.error(e); - throw EaterException.located("Fatal parsing error"); + throw new EaterException("Fatal parsing error", s); } } private TValue executeOneLineNotSafe(TMemory memory, StringLocated s, TFunctionType ftype, boolean modeSpecial) - throws EaterException, EaterExceptionLocated { + throws EaterException { final TLineType type = s.getType(); if (type == TLineType.INCLUDESUB) { @@ -380,11 +375,11 @@ private TValue executeOneLineNotSafe(TMemory memory, StringLocated s, TFunctionT } else if (s.getString().matches("^\\s+$")) { return null; } else { - throw EaterException.located("Compile Error " + ftype + " " + type); + throw new EaterException("Compile Error " + ftype + " " + type, s); } } - private void addPlain(TMemory memory, StringLocated s) throws EaterException, EaterExceptionLocated { + private void addPlain(TMemory memory, StringLocated s) throws EaterException { final StringLocated tmp[] = applyFunctionsAndVariablesInternal(memory, s); if (tmp != null) { if (pendingAdd != null) { @@ -397,12 +392,11 @@ private void addPlain(TMemory memory, StringLocated s) throws EaterException, Ea } } - private void simulatePlain(TMemory memory, StringLocated s) throws EaterException, EaterExceptionLocated { + private void simulatePlain(TMemory memory, StringLocated s) throws EaterException { final StringLocated ignored[] = applyFunctionsAndVariablesInternal(memory, s); } - private void executeAffectationDefine(TMemory memory, StringLocated s) - throws EaterException, EaterExceptionLocated { + private void executeAffectationDefine(TMemory memory, StringLocated s) throws EaterException { new EaterAffectationDefine(s).analyze(this, memory); } @@ -411,7 +405,7 @@ private void executeDumpMemory(TMemory memory, StringLocated s) throws EaterExce condition.analyze(this, memory); } - private void executeAssert(TMemory memory, StringLocated s) throws EaterException, EaterExceptionLocated { + private void executeAssert(TMemory memory, StringLocated s) throws EaterException { final EaterAssert condition = new EaterAssert(s); condition.analyze(this, memory); } @@ -422,11 +416,11 @@ private void executeUndef(TMemory memory, StringLocated s) throws EaterException } private StringLocated[] applyFunctionsAndVariablesInternal(TMemory memory, StringLocated located) - throws EaterException, EaterExceptionLocated { + throws EaterException { if (memory.isEmpty() && functionsSet.size() == 0) return new StringLocated[] { located }; - final String result = applyFunctionsAndVariables(memory, located.getLocation(), located.getString()); + final String result = applyFunctionsAndVariables(memory, located); if (result == null) return null; @@ -440,54 +434,53 @@ private StringLocated[] applyFunctionsAndVariablesInternal(TMemory memory, Strin private String pendingAdd = null; - public String applyFunctionsAndVariables(TMemory memory, LineLocation location, final String str) - throws EaterException, EaterExceptionLocated { + public String applyFunctionsAndVariables(TMemory memory, final StringLocated str) throws EaterException { // https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore%E2%80%93Horspool_algorithm // https://stackoverflow.com/questions/1326682/java-replacing-multiple-different-substring-in-a-string-at-once-or-in-the-most // https://en.wikipedia.org/wiki/String-searching_algorithm // https://www.quora.com/What-is-the-most-efficient-algorithm-to-replace-all-occurrences-of-a-pattern-P-in-a-string-with-a-pattern-P // https://en.wikipedia.org/wiki/Trie if (memory.isEmpty() && functionsSet.size() == 0) - return str; + return str.getString(); final StringBuilder result = new StringBuilder(); for (int i = 0; i < str.length(); i++) { final char c = str.charAt(i); - final String presentFunction = getFunctionNameAt(str, i); + final String presentFunction = getFunctionNameAt(str.getString(), i); if (presentFunction != null) { - final String sub = str.substring(i); - final EaterFunctionCall call = new EaterFunctionCall(new StringLocated(sub, location), + final String sub = str.getString().substring(i); + final EaterFunctionCall call = new EaterFunctionCall(new StringLocated(sub, str.getLocation()), isLegacyDefine(presentFunction), isUnquoted(presentFunction)); call.analyze(this, memory); final TFunctionSignature signature = new TFunctionSignature(presentFunction, call.getValues().size(), call.getNamedArguments().keySet()); final TFunction function = functionsSet.getFunctionSmart(signature); if (function == null) - throw EaterException.located("Function not found " + presentFunction); + throw new EaterException("Function not found " + presentFunction, str); if (function.getFunctionType() == TFunctionType.PROCEDURE) { this.pendingAdd = result.toString(); - executeVoid3(location, memory, sub, function, call); + executeVoid3(str, memory, function, call); i += call.getCurrentPosition(); - final String remaining = str.substring(i); + final String remaining = str.getString().substring(i); if (remaining.length() > 0) appendToLastResult(remaining); return null; } if (function.getFunctionType() == TFunctionType.LEGACY_DEFINELONG) { - this.pendingAdd = str.substring(0, i); - executeVoid3(location, memory, sub, function, call); + this.pendingAdd = str.getString().substring(0, i); + executeVoid3(str, memory, function, call); return null; } assert function.getFunctionType() == TFunctionType.RETURN_FUNCTION || function.getFunctionType() == TFunctionType.LEGACY_DEFINE; - final TValue functionReturn = function.executeReturnFunction(this, memory, location, call.getValues(), + final TValue functionReturn = function.executeReturnFunction(this, memory, str, call.getValues(), call.getNamedArguments()); result.append(functionReturn.toString()); i += call.getCurrentPosition() - 1; - } else if (new VariableManager(this, memory, location).getVarnameAt(str, i) != null) { - i = new VariableManager(this, memory, location).replaceVariables(str, i, result); + } else if (new VariableManager(this, memory, str).getVarnameAt(str.getString(), i) != null) { + i = new VariableManager(this, memory, str).replaceVariables(str.getString(), i, result); } else { result.append(c); } @@ -500,33 +493,31 @@ private void appendToLastResult(String remaining) { this.resultList.set(this.resultList.size() - 1, last.append(remaining)); } - private void executeVoid3(LineLocation location, TMemory memory, String s, TFunction function, - EaterFunctionCall call) throws EaterException, EaterExceptionLocated { - function.executeProcedureInternal(this, memory, call.getValues(), call.getNamedArguments()); - // function.executeProcedure(this, memory, location, s, call.getValues(), - // call.getNamedArguments()); + private void executeVoid3(StringLocated location, TMemory memory, TFunction function, EaterFunctionCall call) + throws EaterException { + function.executeProcedureInternal(this, memory, location, call.getValues(), call.getNamedArguments()); } - private void executeImport(TMemory memory, StringLocated s) throws EaterException, EaterExceptionLocated { + private void executeImport(TMemory memory, StringLocated s) throws EaterException { final EaterImport _import = new EaterImport(s.getTrimmed()); _import.analyze(this, memory); try { final SFile file = FileSystem.getInstance() - .getFile(applyFunctionsAndVariables(memory, s.getLocation(), _import.getLocation())); + .getFile(applyFunctionsAndVariables(memory, new StringLocated(_import.getWhat(), s.getLocation()))); if (file.exists() && file.isDirectory() == false) { importedFiles.add(file); return; } } catch (IOException e) { Logme.error(e); - throw EaterException.located("Cannot import " + e.getMessage()); + throw new EaterException("Cannot import " + e.getMessage(), s); } - throw EaterException.located("Cannot import"); + throw new EaterException("Cannot import", s); } - private void executeLog(TMemory memory, StringLocated s) throws EaterException, EaterExceptionLocated { + private void executeLog(TMemory memory, StringLocated s) throws EaterException { final EaterLog log = new EaterLog(s.getTrimmed()); log.analyze(this, memory); } @@ -538,17 +529,17 @@ public FileWithSuffix getFileWithSuffix(String from, String realName) throws IOE } - private void executeIncludesub(TMemory memory, StringLocated s) throws EaterException, EaterExceptionLocated { + private void executeIncludesub(TMemory memory, StringLocated s) throws EaterException { ImportedFiles saveImportedFiles = null; try { final EaterIncludesub include = new EaterIncludesub(s.getTrimmed()); include.analyze(this, memory); - final String location = include.getLocation(); - final int idx = location.indexOf('!'); + final String what = include.getWhat(); + final int idx = what.indexOf('!'); Sub sub = null; if (idx != -1) { - final String filename = location.substring(0, idx); - final String blocname = location.substring(idx + 1); + final String filename = what.substring(0, idx); + final String blocname = what.substring(idx + 1); try { final FileWithSuffix f2 = importedFiles.getFile(filename, null); if (f2.fileOk()) { @@ -556,10 +547,10 @@ private void executeIncludesub(TMemory memory, StringLocated s) throws EaterExce this.importedFiles = this.importedFiles.withCurrentDir(f2.getParentFile()); final Reader reader = f2.getReader(charset); if (reader == null) - throw EaterException.located("cannot include " + location); + throw new EaterException("cannot include " + what, s); try { - ReadLine readerline = ReadLineReader.create(reader, location, s.getLocation()); + ReadLine readerline = ReadLineReader.create(reader, what, s.getLocation()); readerline = new UncommentReadLine(readerline); sub = Sub.fromFile(readerline, blocname, this, memory); } finally { @@ -568,14 +559,14 @@ private void executeIncludesub(TMemory memory, StringLocated s) throws EaterExce } } catch (IOException e) { Logme.error(e); - throw EaterException.located("cannot include " + location); + throw new EaterException("cannot include " + what, s); } } if (sub == null) - sub = subs.get(location); + sub = subs.get(what); if (sub == null) - throw EaterException.located("cannot include " + location); + throw new EaterException("cannot include " + what, s); executeLinesInternal(memory, sub.lines(), null); } finally { @@ -585,7 +576,7 @@ private void executeIncludesub(TMemory memory, StringLocated s) throws EaterExce } } - private void executeIncludeDef(TMemory memory, StringLocated s) throws EaterException, EaterExceptionLocated { + private void executeIncludeDef(TMemory memory, StringLocated s) throws EaterException { final EaterIncludeDef include = new EaterIncludeDef(s.getTrimmed()); include.analyze(this, memory); final String definitionName = include.getLocation(); @@ -604,7 +595,7 @@ private void executeIncludeDef(TMemory memory, StringLocated s) throws EaterExce } while (true); } catch (IOException e) { Logme.error(e); - throw EaterException.located("" + e); + throw new EaterException("" + e, s); } finally { try { reader2.close(); @@ -614,12 +605,12 @@ private void executeIncludeDef(TMemory memory, StringLocated s) throws EaterExce } } - private void executeTheme(TMemory memory, StringLocated s) throws EaterException, EaterExceptionLocated { + private void executeTheme(TMemory memory, StringLocated s) throws EaterException { final EaterTheme eater = new EaterTheme(s.getTrimmed(), importedFiles); eater.analyze(this, memory); final ReadLine reader = eater.getTheme(); if (reader == null) - throw EaterException.located("No such theme " + eater.getName()); + throw new EaterException("No such theme " + eater.getName(), s); try { final List body = new ArrayList<>(); @@ -633,7 +624,7 @@ private void executeTheme(TMemory memory, StringLocated s) throws EaterException } while (true); } catch (IOException e) { Logme.error(e); - throw EaterException.located("Error reading theme " + e); + throw new EaterException("Error reading theme " + e, s); } finally { try { reader.close(); @@ -643,10 +634,10 @@ private void executeTheme(TMemory memory, StringLocated s) throws EaterException } } - private void executeInclude(TMemory memory, StringLocated s) throws EaterException, EaterExceptionLocated { + private void executeInclude(TMemory memory, StringLocated s) throws EaterException { final EaterInclude include = new EaterInclude(s.getTrimmed()); include.analyze(this, memory); - String location = include.getLocation(); + String location = include.getWhat(); final PreprocessorIncludeStrategy strategy = include.getPreprocessorIncludeStrategy(); final int idx = location.lastIndexOf('!'); String suf = null; @@ -661,7 +652,7 @@ private void executeInclude(TMemory memory, StringLocated s) throws EaterExcepti if (location.startsWith("http://") || location.startsWith("https://")) { final SURL url = SURL.create(location); if (url == null) - throw EaterException.located("Cannot open URL"); + throw new EaterException("Cannot open URL", s); reader = PreprocessorUtils.getReaderIncludeUrl(url, s, suf, charset); } else if (location.startsWith("<") && location.endsWith(">")) { @@ -677,14 +668,14 @@ private void executeInclude(TMemory memory, StringLocated s) throws EaterExcepti return; if (strategy == PreprocessorIncludeStrategy.ONCE && filesUsedCurrent.contains(f2)) - throw EaterException.located("This file has already been included"); + throw new EaterException("This file has already been included", s); if (StartDiagramExtractReader.containsStartDiagram(f2, s, charset)) { reader = StartDiagramExtractReader.build(f2, s, charset); } else { final Reader tmp = f2.getReader(charset); if (tmp == null) - throw EaterException.located("Cannot include file"); + throw new EaterException("Cannot include file", s); reader = ReadLineReader.create(tmp, location, s.getLocation()); } @@ -713,7 +704,7 @@ private void executeInclude(TMemory memory, StringLocated s) throws EaterExcepti } } catch (IOException e) { Logme.error(e); - throw EaterException.located("cannot include " + e); + throw new EaterException("cannot include " + e, s); } finally { if (reader != null) { try { @@ -724,7 +715,7 @@ private void executeInclude(TMemory memory, StringLocated s) throws EaterExcepti } } - throw EaterException.located("cannot include " + location); + throw new EaterException("cannot include " + location, s); } public boolean isLegacyDefine(String functionName) { diff --git a/src/net/sourceforge/plantuml/tim/TFunction.java b/src/net/sourceforge/plantuml/tim/TFunction.java index b608b400697..3570bfbea20 100644 --- a/src/net/sourceforge/plantuml/tim/TFunction.java +++ b/src/net/sourceforge/plantuml/tim/TFunction.java @@ -38,8 +38,8 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public interface TFunction { @@ -49,11 +49,11 @@ public interface TFunction { public TFunctionType getFunctionType(); - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List args, - Map named) throws EaterException, EaterExceptionLocated; + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List args, + Map named) throws EaterException; - public void executeProcedureInternal(TContext context, TMemory memory, List args, Map named) - throws EaterException, EaterExceptionLocated; + public void executeProcedureInternal(TContext context, TMemory memory, StringLocated location, List args, + Map named) throws EaterException; public boolean isUnquoted(); diff --git a/src/net/sourceforge/plantuml/tim/TFunctionImpl.java b/src/net/sourceforge/plantuml/tim/TFunctionImpl.java index 54183810b74..bf51f7064da 100644 --- a/src/net/sourceforge/plantuml/tim/TFunctionImpl.java +++ b/src/net/sourceforge/plantuml/tim/TFunctionImpl.java @@ -121,19 +121,18 @@ public String toString() { return "FUNCTION " + signature + " " + args; } - public void addBody(StringLocated s) throws EaterExceptionLocated { + public void addBody(StringLocated s) throws EaterException { body.add(s); if (s.getType() == TLineType.RETURN) { this.containsReturn = true; if (functionType == TFunctionType.PROCEDURE) - throw EaterExceptionLocated - .located("A procedure cannot have !return directive. Declare it as a function instead ?", s); + throw new EaterException("A procedure cannot have !return directive. Declare it as a function instead ?", s); } } @Override - public void executeProcedureInternal(TContext context, TMemory memory, List args, Map named) - throws EaterException, EaterExceptionLocated { + public void executeProcedureInternal(TContext context, TMemory memory, StringLocated location, List args, + Map named) throws EaterException { if (functionType != TFunctionType.PROCEDURE && functionType != TFunctionType.LEGACY_DEFINELONG) throw new IllegalStateException(); @@ -142,29 +141,29 @@ public void executeProcedureInternal(TContext context, TMemory memory, List args, Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List args, + Map named) throws EaterException { if (functionType == TFunctionType.LEGACY_DEFINE) - return executeReturnLegacyDefine(location, context, memory, args); + return executeReturnLegacyDefine(location.getLocation(), context, memory, args); if (functionType != TFunctionType.RETURN_FUNCTION) - throw EaterException.unlocated("Illegal call here. Is there a return directive in your function?"); + throw new EaterException("Illegal call here. Is there a return directive in your function?", location); final TMemory copy = getNewMemory(memory, args, named); final TValue result = context.executeLines(copy, body, TFunctionType.RETURN_FUNCTION, true); if (result == null) - throw EaterException.unlocated("No return directive found in your function"); + throw new EaterException("No return directive found in your function", location); return result; } private TValue executeReturnLegacyDefine(LineLocation location, TContext context, TMemory memory, List args) - throws EaterException, EaterExceptionLocated { + throws EaterException { if (legacyDefinition == null) throw new IllegalStateException(); final TMemory copy = getNewMemory(memory, args, Collections.emptyMap()); - final String tmp = context.applyFunctionsAndVariables(copy, location, legacyDefinition); + final String tmp = context.applyFunctionsAndVariables(copy, new StringLocated(legacyDefinition, location)); if (tmp == null) return TValue.fromString(""); diff --git a/src/net/sourceforge/plantuml/tim/TMemory.java b/src/net/sourceforge/plantuml/tim/TMemory.java index a1f830e7967..466b5951bdd 100644 --- a/src/net/sourceforge/plantuml/tim/TMemory.java +++ b/src/net/sourceforge/plantuml/tim/TMemory.java @@ -37,13 +37,15 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.expression.TValue; public interface TMemory { public TValue getVariable(String varname); - public void putVariable(String varname, TValue value, TVariableScope scope) throws EaterException; + public void putVariable(String varname, TValue value, TVariableScope scope, StringLocated location) + throws EaterException; public void removeVariable(String varname); diff --git a/src/net/sourceforge/plantuml/tim/TMemoryGlobal.java b/src/net/sourceforge/plantuml/tim/TMemoryGlobal.java index 9b10805a480..86629e9106d 100644 --- a/src/net/sourceforge/plantuml/tim/TMemoryGlobal.java +++ b/src/net/sourceforge/plantuml/tim/TMemoryGlobal.java @@ -41,6 +41,7 @@ import java.util.Set; import java.util.TreeMap; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.expression.TValue; import net.sourceforge.plantuml.utils.Log; @@ -49,10 +50,12 @@ public class TMemoryGlobal extends ExecutionContexts implements TMemory { private final Map globalVariables = new HashMap(); private final TrieImpl variables = new TrieImpl(); + @Override public TValue getVariable(String varname) { return this.globalVariables.get(varname); } + @Override public void dumpDebug(String message) { Log.error("[MemGlobal] Start of memory_dump " + message); dumpMemoryInternal(); @@ -68,32 +71,39 @@ void dumpMemoryInternal() { } } - public void putVariable(String varname, TValue value, TVariableScope scope) throws EaterException { + @Override + public void putVariable(String varname, TValue value, TVariableScope scope, StringLocated location) + throws EaterException { Log.info("[MemGlobal] Setting " + varname); - if (scope == TVariableScope.LOCAL) { - throw EaterException.unlocated("Cannot use local variable here"); - } + if (scope == TVariableScope.LOCAL) + throw new EaterException("Cannot use local variable here", location); + this.globalVariables.put(varname, value); this.variables.add(varname); } + @Override public void removeVariable(String varname) { this.globalVariables.remove(varname); this.variables.remove(varname); } + @Override public boolean isEmpty() { return globalVariables.isEmpty(); } + @Override public Set variablesNames() { return Collections.unmodifiableSet(globalVariables.keySet()); } + @Override public Trie variablesNames3() { return variables; } + @Override public TMemory forkFromGlobal(Map input) { return new TMemoryLocal(this, input); } diff --git a/src/net/sourceforge/plantuml/tim/TMemoryLocal.java b/src/net/sourceforge/plantuml/tim/TMemoryLocal.java index 4d9b7da33bb..2603e1d0da0 100644 --- a/src/net/sourceforge/plantuml/tim/TMemoryLocal.java +++ b/src/net/sourceforge/plantuml/tim/TMemoryLocal.java @@ -40,6 +40,7 @@ import java.util.Set; import java.util.TreeMap; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.expression.TValue; import net.sourceforge.plantuml.utils.Log; @@ -76,19 +77,21 @@ public void dumpDebug(String message) { Log.error("[MemGlobal] End of memory_dump"); } - public void putVariable(String varname, TValue value, TVariableScope scope) throws EaterException { + @Override + public void putVariable(String varname, TValue value, TVariableScope scope, StringLocated location) + throws EaterException { if (scope == TVariableScope.GLOBAL) { - memoryGlobal.putVariable(varname, value, scope); + memoryGlobal.putVariable(varname, value, scope, location); return; } if (scope == TVariableScope.LOCAL || overridenVariables01.containsKey(varname)) { this.overridenVariables01.put(varname, value); - if (this.overridenVariables00 != null) { + if (this.overridenVariables00 != null) this.overridenVariables00.add(varname); - } + Log.info("[MemLocal/overrriden] Setting " + varname); } else if (memoryGlobal.getVariable(varname) != null) { - memoryGlobal.putVariable(varname, value, scope); + memoryGlobal.putVariable(varname, value, scope, location); } else { this.localVariables01.put(varname, value); this.localVariables00.add(varname); @@ -96,12 +99,13 @@ public void putVariable(String varname, TValue value, TVariableScope scope) thro } } + @Override public void removeVariable(String varname) { if (overridenVariables01.containsKey(varname)) { this.overridenVariables01.remove(varname); - if (this.overridenVariables00 != null) { + if (this.overridenVariables00 != null) this.overridenVariables00.remove(varname); - } + } else if (memoryGlobal.getVariable(varname) != null) { memoryGlobal.removeVariable(varname); } else { @@ -110,25 +114,27 @@ public void removeVariable(String varname) { } } + @Override public TValue getVariable(String varname) { TValue result = overridenVariables01.get(varname); - if (result != null) { + if (result != null) return result; - } + result = memoryGlobal.getVariable(varname); - if (result != null) { + if (result != null) return result; - } + result = localVariables01.get(varname); return result; } + @Override public Trie variablesNames3() { if (overridenVariables00 == null) { overridenVariables00 = new TrieImpl(); - for (String name : overridenVariables01.keySet()) { + for (String name : overridenVariables01.keySet()) overridenVariables00.add(name); - } + } return new Trie() { public void add(String s) { @@ -140,12 +146,12 @@ public String getLonguestMatchStartingIn(String s) { final String s2 = overridenVariables00.getLonguestMatchStartingIn(s); final String s3 = localVariables00.getLonguestMatchStartingIn(s); - if (s1.length() >= s2.length() && s1.length() >= s3.length()) { + if (s1.length() >= s2.length() && s1.length() >= s3.length()) return s1; - } - if (s2.length() >= s3.length() && s2.length() >= s1.length()) { + + if (s2.length() >= s3.length() && s2.length() >= s1.length()) return s2; - } + return s3; } }; @@ -162,14 +168,17 @@ public String getLonguestMatchStartingIn(String s) { // return result; } + @Override public boolean isEmpty() { return memoryGlobal.isEmpty() && localVariables01.isEmpty() && overridenVariables01.isEmpty(); } + @Override public Set variablesNames() { throw new UnsupportedOperationException(); } + @Override public TMemory forkFromGlobal(Map input) { return new TMemoryLocal(memoryGlobal, input); } diff --git a/src/net/sourceforge/plantuml/tim/TimLoader.java b/src/net/sourceforge/plantuml/tim/TimLoader.java index de15c55f9cb..1dcdd96705a 100644 --- a/src/net/sourceforge/plantuml/tim/TimLoader.java +++ b/src/net/sourceforge/plantuml/tim/TimLoader.java @@ -53,10 +53,10 @@ public class TimLoader { private List resultList; public TimLoader(ImportedFiles importedFiles, Defines defines, Charset charset, - DefinitionsContainer definitionsContainer) { + DefinitionsContainer definitionsContainer, StringLocated location) { this.context = new TContext(importedFiles, defines, charset, definitionsContainer); try { - defines.copyTo(global); + defines.copyTo(global, location); } catch (EaterException e) { Logme.error(e); } @@ -66,7 +66,7 @@ public Set load(List list) { // CodeIteratorImpl.indentNow(list); try { context.executeLines(global, list, null, false); - } catch (EaterExceptionLocated e) { + } catch (EaterException e) { context.getResultList().add(e.getLocation().withErrorPreprocessor(e.getMessage())); changeLastLine(context.getDebug(), e.getMessage()); this.preprocessorError = true; diff --git a/src/net/sourceforge/plantuml/tim/VariableManager.java b/src/net/sourceforge/plantuml/tim/VariableManager.java index 8f3a7bd0098..c2a7aed7cc9 100644 --- a/src/net/sourceforge/plantuml/tim/VariableManager.java +++ b/src/net/sourceforge/plantuml/tim/VariableManager.java @@ -37,27 +37,27 @@ import net.sourceforge.plantuml.json.JsonArray; import net.sourceforge.plantuml.json.JsonObject; import net.sourceforge.plantuml.json.JsonValue; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.text.TLineType; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class VariableManager { private final TMemory memory; private final TContext context; - private final LineLocation location; + private final StringLocated location; - public VariableManager(TContext context, TMemory memory, LineLocation location) { + public VariableManager(TContext context, TMemory memory, StringLocated location) { this.memory = memory; this.context = context; this.location = location; } - public int replaceVariables(String str, int i, StringBuilder result) throws EaterException, EaterExceptionLocated { + public int replaceVariables(String str, int i, StringBuilder result) throws EaterException { final String presentVariable = getVarnameAt(str, i); - if (result.toString().endsWith("##")) { + if (result.toString().endsWith("##")) result.setLength(result.length() - 2); - } + final TValue value = memory.getVariable(presentVariable); i += presentVariable.length() - 1; if (value.isJson()) { @@ -67,30 +67,29 @@ public int replaceVariables(String str, int i, StringBuilder result) throws Eate result.append(value.toJson().toString()); } else { JsonValue jsonValue = (value.toJson().isArray()) ? (JsonArray) value.toJson() - : (JsonObject) value.toJson(); + : (JsonObject) value.toJson(); i++; i = replaceJson(jsonValue, str, i, result) - 1; } } else { result.append(value.toString()); } - if (i + 2 < str.length() && str.charAt(i + 1) == '#' && str.charAt(i + 2) == '#') { + if (i + 2 < str.length() && str.charAt(i + 1) == '#' && str.charAt(i + 2) == '#') i += 2; - } + return i; } - private int replaceJson(JsonValue jsonValue, String str, int i, StringBuilder result) - throws EaterException, EaterExceptionLocated { + private int replaceJson(JsonValue jsonValue, String str, int i, StringBuilder result) throws EaterException { while (i < str.length()) { final char n = str.charAt(i); if (n == '.') { i++; final StringBuilder fieldName = new StringBuilder(); while (i < str.length()) { - if (Character.isJavaIdentifierPart(str.charAt(i)) == false) { + if (Character.isJavaIdentifierPart(str.charAt(i)) == false) break; - } + fieldName.append(str.charAt(i)); i++; } @@ -100,9 +99,9 @@ private int replaceJson(JsonValue jsonValue, String str, int i, StringBuilder re final StringBuilder inBracket = new StringBuilder(); int level = 0; while (true) { - if (str.charAt(i) == '[') { + if (str.charAt(i) == '[') level++; - } + if (str.charAt(i) == ']') { if (level == 0) break; @@ -111,29 +110,30 @@ private int replaceJson(JsonValue jsonValue, String str, int i, StringBuilder re inBracket.append(str.charAt(i)); i++; } - final String nbString = context.applyFunctionsAndVariables(memory, location, inBracket.toString()); + final String nbString = context.applyFunctionsAndVariables(memory, + new StringLocated(inBracket.toString(), location.getLocation())); if (jsonValue instanceof JsonArray) { final int nb = Integer.parseInt(nbString); jsonValue = ((JsonArray) jsonValue).get(nb); } else if (jsonValue instanceof JsonObject) { jsonValue = ((JsonObject) jsonValue).get(nbString); } else { - throw EaterException.unlocated("Major parsing error"); - } - if (jsonValue == null) { - throw EaterException.unlocated("Data parsing error"); + throw new EaterException("Major parsing error", location); } + + if (jsonValue == null) + throw new EaterException("Data parsing error", location); + i++; } else { break; } } if (jsonValue != null) { - if (jsonValue.isString()) { + if (jsonValue.isString()) result.append(jsonValue.asString()); - } else { + else result.append(jsonValue.toString()); - } } return i; } @@ -144,13 +144,13 @@ && justAfterBackslashN(s, pos) == false) { return null; } final String varname = memory.variablesNames3().getLonguestMatchStartingIn(s.substring(pos)); - if (varname.length() == 0) { + if (varname.length() == 0) return null; - } + if (pos + varname.length() == s.length() - || TLineType.isLetterOrUnderscoreOrDigit(s.charAt(pos + varname.length())) == false) { + || TLineType.isLetterOrUnderscoreOrDigit(s.charAt(pos + varname.length())) == false) return varname; - } + return null; } diff --git a/src/net/sourceforge/plantuml/tim/expression/Knowledge.java b/src/net/sourceforge/plantuml/tim/expression/Knowledge.java index 60723a615a2..1ca3fba7b31 100644 --- a/src/net/sourceforge/plantuml/tim/expression/Knowledge.java +++ b/src/net/sourceforge/plantuml/tim/expression/Knowledge.java @@ -35,13 +35,12 @@ package net.sourceforge.plantuml.tim.expression; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TFunction; import net.sourceforge.plantuml.tim.TFunctionSignature; public interface Knowledge { - public TValue getVariable(String name) throws EaterException, EaterExceptionLocated; + public TValue getVariable(String name) throws EaterException; public TFunction getFunction(TFunctionSignature signature); diff --git a/src/net/sourceforge/plantuml/tim/expression/ReversePolishInterpretor.java b/src/net/sourceforge/plantuml/tim/expression/ReversePolishInterpretor.java index c5b4be10925..7d4aff50f47 100644 --- a/src/net/sourceforge/plantuml/tim/expression/ReversePolishInterpretor.java +++ b/src/net/sourceforge/plantuml/tim/expression/ReversePolishInterpretor.java @@ -40,26 +40,20 @@ import java.util.Deque; import java.util.List; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunction; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; -import net.sourceforge.plantuml.utils.LineLocation; public class ReversePolishInterpretor { private final TValue result; private final boolean trace = false; - public ReversePolishInterpretor(TokenStack queue, Knowledge knowledge, TMemory memory, TContext context) - throws EaterException, EaterExceptionLocated { - this(null, queue, knowledge, memory, context); - } - - public ReversePolishInterpretor(LineLocation location, TokenStack queue, Knowledge knowledge, TMemory memory, - TContext context) throws EaterException, EaterExceptionLocated { + public ReversePolishInterpretor(StringLocated location, TokenStack queue, Knowledge knowledge, TMemory memory, + TContext context) throws EaterException { final Deque stack = new ArrayDeque<>(); if (trace) @@ -78,45 +72,44 @@ public ReversePolishInterpretor(LineLocation location, TokenStack queue, Knowled final TValue v2 = stack.removeFirst(); final TValue v1 = stack.removeFirst(); final TokenOperator op = token.getTokenOperator(); - if (op == null) { - throw EaterException.unlocated("bad op"); - } + if (op == null) + throw new EaterException("bad op", location); + final TValue tmp = op.operate(v1, v2); stack.addFirst(tmp); } else if (token.getTokenType() == TokenType.OPEN_PAREN_FUNC) { final int nb = Integer.parseInt(token.getSurface()); final Token token2 = it.nextToken(); - if (token2.getTokenType() != TokenType.FUNCTION_NAME) { - throw EaterException.unlocated("rpn43"); - } + if (token2.getTokenType() != TokenType.FUNCTION_NAME) + throw new EaterException("rpn43", location); + if (trace) System.err.println("token2=" + token2); final TFunction function = knowledge.getFunction(new TFunctionSignature(token2.getSurface(), nb)); if (trace) System.err.println("function=" + function); - if (function == null) { - throw EaterException.unlocated("Unknown built-in function " + token2.getSurface()); - } - if (function.canCover(nb, Collections.emptySet()) == false) { - throw EaterException - .unlocated("Bad number of arguments for " + function.getSignature().getFunctionName()); - } + if (function == null) + throw new EaterException("Unknown built-in function " + token2.getSurface(), location); + + if (function.canCover(nb, Collections.emptySet()) == false) + throw new EaterException("Bad number of arguments for " + function.getSignature().getFunctionName(), location); + final List args = new ArrayList<>(); - for (int i = 0; i < nb; i++) { + for (int i = 0; i < nb; i++) args.add(0, stack.removeFirst()); - } + if (trace) System.err.println("args=" + args); - if (location == null) { - throw EaterException.unlocated("rpn44"); - } + if (location == null) + throw new EaterException("rpn44", location); + final TValue r = function.executeReturnFunction(context, memory, location, args, Collections.emptyMap()); if (trace) System.err.println("r=" + r); stack.addFirst(r); } else { - throw EaterException.unlocated("rpn41"); + throw new EaterException("rpn41", location); } } result = stack.removeFirst(); diff --git a/src/net/sourceforge/plantuml/tim/expression/ShuntingYard.java b/src/net/sourceforge/plantuml/tim/expression/ShuntingYard.java index c6366f6bd24..fb75931c541 100644 --- a/src/net/sourceforge/plantuml/tim/expression/ShuntingYard.java +++ b/src/net/sourceforge/plantuml/tim/expression/ShuntingYard.java @@ -37,8 +37,8 @@ import java.util.ArrayDeque; import java.util.Deque; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; // https://en.wikipedia.org/wiki/Shunting-yard_algorithm // https://en.cppreference.com/w/c/language/operator_precedence @@ -58,7 +58,7 @@ private void traceMe() { System.err.println(""); } - public ShuntingYard(TokenIterator it, Knowledge knowledge) throws EaterException, EaterExceptionLocated { + public ShuntingYard(TokenIterator it, Knowledge knowledge, StringLocated location) throws EaterException { while (it.hasMoreTokens()) { final Token token = it.nextToken(); @@ -74,7 +74,7 @@ public ShuntingYard(TokenIterator it, Knowledge knowledge) throws EaterException final TValue variable = knowledge.getVariable(name); if (variable == null) { if (isVariableName(name) == false) - throw EaterException.unlocated("Parsing syntax error about " + name); + throw new EaterException("Parsing syntax error about " + name, location); ouputQueue.add(new Token(name, TokenType.QUOTED_STRING, null)); } else { diff --git a/src/net/sourceforge/plantuml/tim/expression/TokenStack.java b/src/net/sourceforge/plantuml/tim/expression/TokenStack.java index 3bd091e4bac..e94574dab51 100644 --- a/src/net/sourceforge/plantuml/tim/expression/TokenStack.java +++ b/src/net/sourceforge/plantuml/tim/expression/TokenStack.java @@ -42,12 +42,11 @@ import java.util.List; import java.util.Map; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.Eater; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TMemory; -import net.sourceforge.plantuml.utils.LineLocation; public class TokenStack { @@ -95,7 +94,7 @@ static public TokenStack eatUntilCloseParenthesisOrComma(Eater eater) throws Eat eater.skipSpaces(); final char ch = eater.peekChar(); if (ch == 0) - throw EaterException.unlocated("until001"); + throw new EaterException("until001", eater.getStringLocated()); if (level == 0 && (ch == ',' || ch == ')')) return result; @@ -113,12 +112,13 @@ else if (type == TokenType.CLOSE_PAREN_MATH) } } - static public void eatUntilCloseParenthesisOrComma(TokenIterator it) throws EaterException { + static public void eatUntilCloseParenthesisOrComma(TokenIterator it, StringLocated location) + throws EaterException { int level = 0; while (true) { final Token ch = it.peekToken(); if (ch == null) - throw EaterException.unlocated("until002"); + throw new EaterException("until002", location); final TokenType typech = ch.getTokenType(); if (level == 0 && (typech == TokenType.COMMA || typech == TokenType.CLOSE_PAREN_MATH) @@ -135,7 +135,7 @@ else if (type == TokenType.CLOSE_PAREN_MATH || type == TokenType.CLOSE_PAREN_FUN } } - private int countFunctionArg(TokenIterator it) throws EaterException { + private int countFunctionArg(TokenIterator it, StringLocated location) throws EaterException { // return 42; final TokenType type1 = it.peekToken().getTokenType(); if (type1 == TokenType.CLOSE_PAREN_MATH || type1 == TokenType.CLOSE_PAREN_FUNC) @@ -143,7 +143,7 @@ private int countFunctionArg(TokenIterator it) throws EaterException { int result = 1; while (it.hasMoreTokens()) { - eatUntilCloseParenthesisOrComma(it); + eatUntilCloseParenthesisOrComma(it, location); final Token token = it.nextToken(); final TokenType type = token.getTokenType(); if (type == TokenType.CLOSE_PAREN_MATH || type == TokenType.CLOSE_PAREN_FUNC) @@ -151,13 +151,13 @@ private int countFunctionArg(TokenIterator it) throws EaterException { else if (type == TokenType.COMMA) result++; else - throw EaterException.unlocated("count13"); + throw new EaterException("count13", location); } - throw EaterException.unlocated("count12"); + throw new EaterException("count12", location); } - public void guessFunctions() throws EaterException { + public void guessFunctions(StringLocated location) throws EaterException { final Deque open = new ArrayDeque<>(); final Map parens = new HashMap(); for (int i = 0; i < tokens.size(); i++) { @@ -177,7 +177,7 @@ else if (token.getTokenType().equals(TokenType.CLOSE_PAREN_MATH)) assert tokens.get(iclose).getTokenType() == TokenType.CLOSE_PAREN_MATH; if (iopen > 0 && tokens.get(iopen - 1).getTokenType() == TokenType.PLAIN_TEXT) { tokens.set(iopen - 1, new Token(tokens.get(iopen - 1).getSurface(), TokenType.FUNCTION_NAME, null)); - final int nbArg = countFunctionArg(subTokenStack(iopen + 1).tokenIterator()); + final int nbArg = countFunctionArg(subTokenStack(iopen + 1).tokenIterator(), location); tokens.set(iopen, new Token("" + nbArg, TokenType.OPEN_PAREN_FUNC, null)); tokens.set(iclose, new Token(")", TokenType.CLOSE_PAREN_FUNC, null)); } @@ -210,13 +210,12 @@ public TokenIterator tokenIterator() { return new InternalIterator(); } - public TValue getResult(LineLocation location, TContext context, TMemory memory) - throws EaterException, EaterExceptionLocated { - final Knowledge knowledge = context.asKnowledge(memory, location); + public TValue getResult(StringLocated location, TContext context, TMemory memory) throws EaterException { + final Knowledge knowledge = context.asKnowledge(memory, location.getLocation()); final TokenStack tmp = withoutSpace(); - tmp.guessFunctions(); + tmp.guessFunctions(location); final TokenIterator it = tmp.tokenIterator(); - final ShuntingYard shuntingYard = new ShuntingYard(it, knowledge); + final ShuntingYard shuntingYard = new ShuntingYard(it, knowledge, location); final ReversePolishInterpretor rpn = new ReversePolishInterpretor(location, shuntingYard.getQueue(), knowledge, memory, context); return rpn.getResult(); diff --git a/src/net/sourceforge/plantuml/tim/expression/TokenType.java b/src/net/sourceforge/plantuml/tim/expression/TokenType.java index a72a65bef4e..41c0fc7ef88 100644 --- a/src/net/sourceforge/plantuml/tim/expression/TokenType.java +++ b/src/net/sourceforge/plantuml/tim/expression/TokenType.java @@ -39,7 +39,7 @@ import net.sourceforge.plantuml.tim.EaterException; public enum TokenType { - // ::remove folder when __HAXE__ + // ::remove folder when __HAXE__ QUOTED_STRING, JSON_DATA, OPERATOR, OPEN_PAREN_MATH, COMMA, CLOSE_PAREN_MATH, NUMBER, PLAIN_TEXT, SPACES, FUNCTION_NAME, OPEN_PAREN_FUNC, CLOSE_PAREN_FUNC; @@ -77,7 +77,8 @@ else if (TLineType.isSpaceChar(ch)) return result; } - final static public Token eatOneToken(Token lastToken, Eater eater, boolean manageColon) throws EaterException { + final static public Token eatOneToken(Token lastToken, Eater eater, boolean manageColon) + throws EaterException { char ch = eater.peekChar(); if (ch == 0) return null; diff --git a/src/net/sourceforge/plantuml/tim/iterator/AbstractCodeIterator.java b/src/net/sourceforge/plantuml/tim/iterator/AbstractCodeIterator.java index 83165b8ee7a..51fbdfad514 100644 --- a/src/net/sourceforge/plantuml/tim/iterator/AbstractCodeIterator.java +++ b/src/net/sourceforge/plantuml/tim/iterator/AbstractCodeIterator.java @@ -34,8 +34,8 @@ */ package net.sourceforge.plantuml.tim.iterator; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; public abstract class AbstractCodeIterator implements CodeIterator { @@ -45,16 +45,20 @@ public AbstractCodeIterator(CodeIterator source) { this.source = source; } - public void next() throws EaterException, EaterExceptionLocated { + @Override + public void next() throws EaterException { source.next(); } + @Override final public CodePosition getCodePosition() { return source.getCodePosition(); } - final public void jumpToCodePosition(CodePosition newPosition) throws EaterException { - source.jumpToCodePosition(newPosition); + @Override + final public void jumpToCodePosition(CodePosition newPosition, StringLocated location) + throws EaterException { + source.jumpToCodePosition(newPosition, location); } } diff --git a/src/net/sourceforge/plantuml/tim/iterator/CodeIterator.java b/src/net/sourceforge/plantuml/tim/iterator/CodeIterator.java index c0b59f04d5e..4011028932d 100644 --- a/src/net/sourceforge/plantuml/tim/iterator/CodeIterator.java +++ b/src/net/sourceforge/plantuml/tim/iterator/CodeIterator.java @@ -36,17 +36,16 @@ import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; public interface CodeIterator { - // ::remove folder when __HAXE__ + // ::remove folder when __HAXE__ - public StringLocated peek() throws EaterException, EaterExceptionLocated; + public StringLocated peek() throws EaterException; - public void next() throws EaterException, EaterExceptionLocated; + public void next() throws EaterException; public CodePosition getCodePosition(); - public void jumpToCodePosition(CodePosition newPosition) throws EaterException; + public void jumpToCodePosition(CodePosition newPosition, StringLocated location) throws EaterException; } diff --git a/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorAffectation.java b/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorAffectation.java index e2a5fc5e93f..8bd3a2b4f67 100644 --- a/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorAffectation.java +++ b/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorAffectation.java @@ -41,7 +41,6 @@ import net.sourceforge.plantuml.text.TLineType; import net.sourceforge.plantuml.tim.EaterAffectation; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TMemory; @@ -58,7 +57,8 @@ public CodeIteratorAffectation(CodeIterator source, TContext context, TMemory me this.logs = log; } - public StringLocated peek() throws EaterException, EaterExceptionLocated { + @Override + public StringLocated peek() throws EaterException { while (true) { final StringLocated result = source.peek(); if (result == null) { @@ -74,16 +74,16 @@ public StringLocated peek() throws EaterException, EaterExceptionLocated { } } - private void doAffectation(StringLocated result) throws EaterException, EaterExceptionLocated { + private void doAffectation(StringLocated result) throws EaterException { int lastLocation = -1; for (int i = 0; i < 9999; i++) try { this.executeAffectation(context, memory, result); return; } catch (ParseException e) { - if (e.getColumn() <= lastLocation) { - throw EaterException.located("Error in JSON format"); - } + if (e.getColumn() <= lastLocation) + throw new EaterException("Error in JSON format", result); + lastLocation = e.getColumn(); next(); final StringLocated forward = source.peek(); @@ -92,7 +92,7 @@ private void doAffectation(StringLocated result) throws EaterException, EaterExc } private void executeAffectation(TContext context, TMemory memory, StringLocated s) - throws EaterException, EaterExceptionLocated { + throws EaterException { new EaterAffectation(s).analyze(context, memory); } diff --git a/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorForeach.java b/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorForeach.java index 540b1e1beab..2ea2ef99094 100644 --- a/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorForeach.java +++ b/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorForeach.java @@ -40,7 +40,6 @@ import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.text.TLineType; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.EaterForeach; import net.sourceforge.plantuml.tim.ExecutionContextForeach; import net.sourceforge.plantuml.tim.TContext; @@ -61,13 +60,12 @@ public CodeIteratorForeach(CodeIterator source, TContext context, TMemory memory this.logs = logs; } - public StringLocated peek() throws EaterException, EaterExceptionLocated { + public StringLocated peek() throws EaterException { int level = 0; while (true) { final StringLocated result = source.peek(); - if (result == null) { + if (result == null) return null; - } final ExecutionContextForeach foreach = memory.peekForeach(); if (foreach != null && foreach.isSkipMe()) { @@ -91,15 +89,15 @@ public StringLocated peek() throws EaterException, EaterExceptionLocated { continue; } else if (result.getType() == TLineType.ENDFOREACH) { logs.add(result); - if (foreach == null) { - throw EaterException.located("No foreach related to this endforeach"); - } + if (foreach == null) + throw new EaterException("No foreach related to this endforeach", result); + foreach.inc(); if (foreach.isSkipMe()) { memory.pollForeach(); } else { setLoopVariable(memory, foreach, result); - source.jumpToCodePosition(foreach.getStartForeach()); + source.jumpToCodePosition(foreach.getStartForeach(), result); } next(); continue; @@ -109,23 +107,23 @@ public StringLocated peek() throws EaterException, EaterExceptionLocated { } } - private void executeForeach(TMemory memory, StringLocated s) throws EaterException, EaterExceptionLocated { + private void executeForeach(TMemory memory, StringLocated s) throws EaterException { final EaterForeach condition = new EaterForeach(s); condition.analyze(context, memory); final ExecutionContextForeach foreach = ExecutionContextForeach.fromValue(condition.getVarname(), condition.getJsonArray(), source.getCodePosition()); - if (condition.isSkip()) { + if (condition.isSkip()) foreach.skipMeNow(); - } else { + else setLoopVariable(memory, foreach, s); - } + memory.addForeach(foreach); } private void setLoopVariable(TMemory memory, ExecutionContextForeach foreach, StringLocated position) throws EaterException { final JsonValue first = foreach.getJsonArray().get(foreach.currentIndex()); - memory.putVariable(foreach.getVarname(), TValue.fromJson(first), TVariableScope.GLOBAL); + memory.putVariable(foreach.getVarname(), TValue.fromJson(first), TVariableScope.GLOBAL, position); } } diff --git a/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorIf.java b/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorIf.java index 8ee1d08a101..831726ecc5e 100644 --- a/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorIf.java +++ b/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorIf.java @@ -40,7 +40,6 @@ import net.sourceforge.plantuml.text.TLineType; import net.sourceforge.plantuml.tim.EaterElseIf; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.EaterIf; import net.sourceforge.plantuml.tim.EaterIfdef; import net.sourceforge.plantuml.tim.EaterIfndef; @@ -61,7 +60,7 @@ public CodeIteratorIf(CodeIterator source, TContext context, TMemory memory, Lis this.logs = logs; } - public StringLocated peek() throws EaterException, EaterExceptionLocated { + public StringLocated peek() throws EaterException { while (true) { final StringLocated result = source.peek(); if (result == null) { @@ -107,29 +106,26 @@ public StringLocated peek() throws EaterException, EaterExceptionLocated { } } - private void executeIf(TContext context, TMemory memory, StringLocated s) - throws EaterException, EaterExceptionLocated { + private void executeIf(TContext context, TMemory memory, StringLocated s) throws EaterException { final EaterIf condition = new EaterIf(s); condition.analyze(context, memory); final boolean isTrue = condition.isTrue(); memory.addIf(ExecutionContextIf.fromValue(isTrue)); } - private void executeElseIf(TContext context, TMemory memory, StringLocated s) - throws EaterException, EaterExceptionLocated { + private void executeElseIf(TContext context, TMemory memory, StringLocated s) throws EaterException { final ExecutionContextIf poll = (ExecutionContextIf) memory.peekIf(); - if (poll == null) { - throw EaterException.located("No if related to this else"); - } + if (poll == null) + throw new EaterException("No if related to this else", s); poll.enteringElseIf(); if (poll.hasBeenBurn() == false) { final EaterElseIf condition = new EaterElseIf(s); condition.analyze(context, memory); final boolean isTrue = condition.isTrue(); - if (isTrue) { + if (isTrue) poll.nowInSomeElseIf(); - } + } } @@ -149,17 +145,17 @@ private void executeIfndef(TContext context, TMemory memory, StringLocated s) th private void executeElse(TContext context, TMemory memory, StringLocated s) throws EaterException { final ExecutionContextIf poll = (ExecutionContextIf) memory.peekIf(); - if (poll == null) { - throw EaterException.located("No if related to this else"); - } + if (poll == null) + throw new EaterException("No if related to this else", s); + poll.nowInElse(); } private void executeEndif(TContext context, TMemory memory, StringLocated s) throws EaterException { final ExecutionContextIf poll = (ExecutionContextIf) memory.pollIf(); - if (poll == null) { - throw EaterException.located("No if related to this endif"); - } + if (poll == null) + throw new EaterException("No if related to this endif", s); + } } diff --git a/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorImpl.java b/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorImpl.java index e0098681063..07dead5aafd 100644 --- a/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorImpl.java +++ b/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorImpl.java @@ -62,34 +62,38 @@ public CodeIteratorImpl(List list) { this.list = list; } + @Override public StringLocated peek() { - if (current == list.size()) { + if (current == list.size()) return null; - } - if (current > list.size()) { + + if (current > list.size()) throw new IllegalStateException(); - } + return list.get(current); } + @Override public void next() { - if (current >= list.size()) { + if (current >= list.size()) throw new IllegalStateException(); - } + assert current < list.size(); current++; assert current <= list.size(); } + @Override public CodePosition getCodePosition() { return new Position(current); } - public void jumpToCodePosition(CodePosition newPosition) throws EaterException { + @Override + public void jumpToCodePosition(CodePosition newPosition, StringLocated location) throws EaterException { this.countJump++; - if (this.countJump > 999) { - throw EaterException.unlocated("Infinite loop?"); - } + if (this.countJump > 999) + throw new EaterException("Infinite loop?", location); + final Position pos = (Position) newPosition; this.current = pos.pos; diff --git a/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorInnerComment.java b/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorInnerComment.java index f7baab3e83a..501bd9b4ec6 100644 --- a/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorInnerComment.java +++ b/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorInnerComment.java @@ -36,7 +36,6 @@ import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; public class CodeIteratorInnerComment extends AbstractCodeIterator { @@ -44,7 +43,7 @@ public CodeIteratorInnerComment(CodeIterator source) { super(source); } - public StringLocated peek() throws EaterException, EaterExceptionLocated { + public StringLocated peek() throws EaterException { final StringLocated result = source.peek(); if (result == null) { return null; diff --git a/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorLegacyDefine.java b/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorLegacyDefine.java index 51670f20e05..fb4a99f751b 100644 --- a/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorLegacyDefine.java +++ b/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorLegacyDefine.java @@ -39,7 +39,6 @@ import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.text.TLineType; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.FunctionsSet; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TMemory; @@ -61,7 +60,7 @@ public CodeIteratorLegacyDefine(CodeIterator source, TContext context, TMemory m this.memory = memory; } - public StringLocated peek() throws EaterException, EaterExceptionLocated { + public StringLocated peek() throws EaterException { while (true) { final StringLocated result = source.peek(); if (result == null) { diff --git a/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorLongComment.java b/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorLongComment.java index 3f2cc2e0b78..656cf882da8 100644 --- a/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorLongComment.java +++ b/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorLongComment.java @@ -39,7 +39,6 @@ import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.text.TLineType; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; public class CodeIteratorLongComment extends AbstractCodeIterator { @@ -50,7 +49,7 @@ public CodeIteratorLongComment(CodeIterator source, List logs) { this.logs = logs; } - public StringLocated peek() throws EaterException, EaterExceptionLocated { + public StringLocated peek() throws EaterException { while (true) { if (source.peek() == null) { return null; diff --git a/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorProcedure.java b/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorProcedure.java index d03dfcc00f8..ba88da272de 100644 --- a/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorProcedure.java +++ b/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorProcedure.java @@ -39,7 +39,6 @@ import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.text.TLineType; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.FunctionsSet; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionType; @@ -62,7 +61,7 @@ public CodeIteratorProcedure(CodeIterator source, TContext context, TMemory memo this.memory = memory; } - public StringLocated peek() throws EaterException, EaterExceptionLocated { + public StringLocated peek() throws EaterException { while (true) { final StringLocated result = source.peek(); if (result == null) { diff --git a/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorReturnFunction.java b/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorReturnFunction.java index 8ff1feea557..b3c628fa115 100644 --- a/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorReturnFunction.java +++ b/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorReturnFunction.java @@ -39,7 +39,6 @@ import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.text.TLineType; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.FunctionsSet; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionType; @@ -62,7 +61,7 @@ public CodeIteratorReturnFunction(CodeIterator source, TContext context, TMemory this.memory = memory; } - public StringLocated peek() throws EaterException, EaterExceptionLocated { + public StringLocated peek() throws EaterException { while (true) { final StringLocated result = source.peek(); if (result == null) { @@ -74,9 +73,7 @@ public StringLocated peek() throws EaterException, EaterExceptionLocated { logs.add(result); if (result.getType() == TLineType.END_FUNCTION) { if (functionsSet.pendingFunction().doesContainReturn() == false) { - throw EaterExceptionLocated.located( - "This function does not have any !return directive. Declare it as a procedure instead ?", - result); + throw new EaterException("This function does not have any !return directive. Declare it as a procedure instead ?", result); } functionsSet.executeEndfunction(); } else { diff --git a/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorShortComment.java b/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorShortComment.java index b70c45584f6..0b36e237437 100644 --- a/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorShortComment.java +++ b/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorShortComment.java @@ -39,7 +39,6 @@ import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.text.TLineType; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; public class CodeIteratorShortComment extends AbstractCodeIterator { @@ -50,7 +49,7 @@ public CodeIteratorShortComment(CodeIterator source, List logs) { this.logs = logs; } - public StringLocated peek() throws EaterException, EaterExceptionLocated { + public StringLocated peek() throws EaterException { while (true) { final StringLocated result = source.peek(); if (result == null) { diff --git a/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorSub.java b/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorSub.java index 6a7aaa876c0..248f200f8e4 100644 --- a/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorSub.java +++ b/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorSub.java @@ -41,7 +41,6 @@ import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.text.TLineType; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.EaterStartsub; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TMemory; @@ -66,14 +65,14 @@ public Map getSubs() { return Collections.unmodifiableMap(subs); } - public StringLocated peek() throws EaterException, EaterExceptionLocated { - if (readingInProgress != null) { + public StringLocated peek() throws EaterException { + if (readingInProgress != null) return readingInProgress.peek(); - } + StringLocated result = source.peek(); - if (result == null) { + if (result == null) return null; - } + if (result.getType() == TLineType.STARTSUB) { final EaterStartsub eater = new EaterStartsub(result.getTrimmed()); eater.analyze(context, memory); @@ -83,7 +82,7 @@ public StringLocated peek() throws EaterException, EaterExceptionLocated { StringLocated s = null; while ((s = source.peek()) != null) { if (s.getType() == TLineType.STARTSUB) { - throw EaterException.located("Cannot nest sub"); + throw new EaterException("Cannot nest sub", result); } else if (s.getType() == TLineType.ENDSUB) { source.next(); readingInProgress = new CodeIteratorImpl(created.lines()); @@ -94,22 +93,22 @@ public StringLocated peek() throws EaterException, EaterExceptionLocated { } } } - if (readingInProgress != null) { + if (readingInProgress != null) return readingInProgress.peek(); - } + return result; } @Override - public void next() throws EaterException, EaterExceptionLocated { + public void next() throws EaterException { if (readingInProgress == null) { source.next(); return; } readingInProgress.next(); - if (readingInProgress.peek() == null) { + if (readingInProgress.peek() == null) readingInProgress = null; - } + } } diff --git a/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorWhile.java b/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorWhile.java index 037c33200d8..68679b1d3ca 100644 --- a/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorWhile.java +++ b/src/net/sourceforge/plantuml/tim/iterator/CodeIteratorWhile.java @@ -39,7 +39,6 @@ import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.text.TLineType; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.EaterWhile; import net.sourceforge.plantuml.tim.ExecutionContextWhile; import net.sourceforge.plantuml.tim.TContext; @@ -60,13 +59,12 @@ public CodeIteratorWhile(CodeIterator source, TContext context, TMemory memory, this.logs = logs; } - public StringLocated peek() throws EaterException, EaterExceptionLocated { + public StringLocated peek() throws EaterException { int level = 0; while (true) { final StringLocated result = source.peek(); - if (result == null) { + if (result == null) return null; - } final ExecutionContextWhile currentWhile = memory.peekWhile(); if (currentWhile != null && currentWhile.isSkipMe()) { @@ -90,15 +88,15 @@ public StringLocated peek() throws EaterException, EaterExceptionLocated { continue; } else if (result.getType() == TLineType.ENDWHILE) { logs.add(result); - if (currentWhile == null) { - throw EaterException.located("No while related to this endwhile"); - } - final TValue value = currentWhile.conditionValue(result.getLocation(), context, memory); - if (value.toBoolean()) { - source.jumpToCodePosition(currentWhile.getStartWhile()); - } else { + if (currentWhile == null) + throw new EaterException("No while related to this endwhile", result); + + final TValue value = currentWhile.conditionValue(result, context, memory); + if (value.toBoolean()) + source.jumpToCodePosition(currentWhile.getStartWhile(), result); + else memory.pollWhile(); - } + next(); continue; } @@ -107,16 +105,16 @@ public StringLocated peek() throws EaterException, EaterExceptionLocated { } } - private void executeWhile(TMemory memory, StringLocated s) throws EaterException, EaterExceptionLocated { + private void executeWhile(TMemory memory, StringLocated s) throws EaterException { final EaterWhile condition = new EaterWhile(s); condition.analyze(context, memory); final TokenStack whileExpression = condition.getWhileExpression(); final ExecutionContextWhile theWhile = ExecutionContextWhile.fromValue(whileExpression, source.getCodePosition()); - final TValue value = theWhile.conditionValue(s.getLocation(), context, memory); - if (value.toBoolean() == false) { + final TValue value = theWhile.conditionValue(s, context, memory); + if (value.toBoolean() == false) theWhile.skipMe(); - } + memory.addWhile(theWhile); } diff --git a/src/net/sourceforge/plantuml/tim/package-info.java b/src/net/sourceforge/plantuml/tim/package-info.java index d185cc4bd9e..7aa0e198b5d 100644 --- a/src/net/sourceforge/plantuml/tim/package-info.java +++ b/src/net/sourceforge/plantuml/tim/package-info.java @@ -1,7 +1,7 @@ /** - * Provides classes used to manage - * - * Preprocessing of PlantUML input. + * Provides classes used to manage + * Preprocessing + * of PlantUML input. * * @see net.sourceforge.plantuml.text.TLineType * @see net.sourceforge.plantuml.preproc diff --git a/src/net/sourceforge/plantuml/tim/stdlib/AlwaysFalse.java b/src/net/sourceforge/plantuml/tim/stdlib/AlwaysFalse.java index 0c73b754a6c..29b116da73a 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/AlwaysFalse.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/AlwaysFalse.java @@ -38,13 +38,12 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class AlwaysFalse extends SimpleReturnFunction { @@ -56,10 +55,10 @@ public TFunctionSignature getSignature() { public boolean canCover(int nbArg, Set namedArgument) { return nbArg == 0; } - + @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { return TValue.fromBoolean(false); } } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/AlwaysTrue.java b/src/net/sourceforge/plantuml/tim/stdlib/AlwaysTrue.java index 66ec893af2c..e59c5e0f657 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/AlwaysTrue.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/AlwaysTrue.java @@ -38,13 +38,12 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class AlwaysTrue extends SimpleReturnFunction { @@ -58,8 +57,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { return TValue.fromBoolean(true); } } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/CallUserFunction.java b/src/net/sourceforge/plantuml/tim/stdlib/CallUserFunction.java index 5d9107a92c8..36bbdf7c102 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/CallUserFunction.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/CallUserFunction.java @@ -38,14 +38,13 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunction; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class CallUserFunction extends SimpleReturnFunction { @@ -59,15 +58,15 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final String fname = values.get(0).toString(); final List args = values.subList(1, values.size()); final TFunctionSignature signature = new TFunctionSignature(fname, args.size()); final TFunction func = context.getFunctionSmart(signature); - if (func == null) { - throw EaterException.unlocated("Cannot find void function " + fname); - } + if (func == null) + throw new EaterException("Cannot find void function " + fname, location); + return func.executeReturnFunction(context, memory, location, args, named); } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/Chr.java b/src/net/sourceforge/plantuml/tim/stdlib/Chr.java index cdd7e139add..fb55e335ad1 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/Chr.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/Chr.java @@ -38,13 +38,12 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class Chr extends SimpleReturnFunction { @@ -58,8 +57,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { try { final String value = String.valueOf(Character.toChars(values.get(0).toInt())); return TValue.fromString(value); diff --git a/src/net/sourceforge/plantuml/tim/stdlib/Darken.java b/src/net/sourceforge/plantuml/tim/stdlib/Darken.java index e053ac6c75c..924f24be1c6 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/Darken.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/Darken.java @@ -41,13 +41,12 @@ import net.sourceforge.plantuml.klimt.color.HColor; import net.sourceforge.plantuml.klimt.color.HColorSet; import net.sourceforge.plantuml.klimt.color.NoSuchColorException; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class Darken extends SimpleReturnFunction { @@ -62,8 +61,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final String colorString = values.get(0).toString(); final int ratio = values.get(1).toInt(); try { @@ -71,7 +70,7 @@ public TValue executeReturnFunction(TContext context, TMemory memory, LineLocati color = color.darken(ratio); return TValue.fromString(color.asString()); } catch (NoSuchColorException e) { - throw EaterException.located("No such color"); + throw new EaterException("No such color", location); } } } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/DateFunction.java b/src/net/sourceforge/plantuml/tim/stdlib/DateFunction.java index 1c18155d9b3..6f8efa2eac6 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/DateFunction.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/DateFunction.java @@ -40,13 +40,12 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class DateFunction extends SimpleReturnFunction { @@ -60,8 +59,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { if (values.size() == 0) return TValue.fromString(new Date().toString()); @@ -71,10 +70,11 @@ public TValue executeReturnFunction(TContext context, TMemory memory, LineLocati now = 1000L * values.get(1).toInt(); else now = System.currentTimeMillis(); + try { return TValue.fromString(new SimpleDateFormat(format).format(now)); } catch (Exception e) { - throw EaterException.unlocated("Bad date pattern"); + throw new EaterException("Bad date pattern", location); } } } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/Dec2hex.java b/src/net/sourceforge/plantuml/tim/stdlib/Dec2hex.java index 3dc6f7b634a..9bbc29e4cc8 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/Dec2hex.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/Dec2hex.java @@ -38,13 +38,12 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class Dec2hex extends SimpleReturnFunction { @@ -58,8 +57,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { try { return TValue.fromString("" + Integer.toHexString(values.get(0).toInt())); } catch (Throwable t) { diff --git a/src/net/sourceforge/plantuml/tim/stdlib/Dirpath.java b/src/net/sourceforge/plantuml/tim/stdlib/Dirpath.java index 1c918c4e8a1..ef08879cc89 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/Dirpath.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/Dirpath.java @@ -39,13 +39,12 @@ import java.util.Set; import net.sourceforge.plantuml.preproc.Defines; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class Dirpath extends SimpleReturnFunction { @@ -65,11 +64,11 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { - if (value == null) { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { + if (value == null) return TValue.fromString(""); - } + return TValue.fromString(value); } } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/Eval.java b/src/net/sourceforge/plantuml/tim/stdlib/Eval.java index ee7ad6e4618..311404c1720 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/Eval.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/Eval.java @@ -38,14 +38,13 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.StringEater; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class Eval extends SimpleReturnFunction { @@ -59,8 +58,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final String exp = values.get(0).toString(); final StringEater eater = new StringEater(exp); final TValue value = eater.eatExpression(context, memory); diff --git a/src/net/sourceforge/plantuml/tim/stdlib/Feature.java b/src/net/sourceforge/plantuml/tim/stdlib/Feature.java index f79b4ed4dda..0f789f30c68 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/Feature.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/Feature.java @@ -38,13 +38,12 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class Feature extends SimpleReturnFunction { @@ -58,15 +57,15 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final String arg = values.get(0).toString(); - if ("style".equalsIgnoreCase(arg)) { + if ("style".equalsIgnoreCase(arg)) return TValue.fromInt(1); - } - if ("theme".equalsIgnoreCase(arg)) { + + if ("theme".equalsIgnoreCase(arg)) return TValue.fromInt(1); - } + return TValue.fromInt(0); } } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/FileExists.java b/src/net/sourceforge/plantuml/tim/stdlib/FileExists.java index d7b68e42309..cee70de583a 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/FileExists.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/FileExists.java @@ -39,13 +39,12 @@ import java.util.Set; import net.sourceforge.plantuml.security.SFile; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class FileExists extends SimpleReturnFunction { @@ -59,8 +58,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { // ::comment when __CORE__ final String path = values.get(0).toString(); return TValue.fromBoolean(new SFile(path).exists()); diff --git a/src/net/sourceforge/plantuml/tim/stdlib/Filename.java b/src/net/sourceforge/plantuml/tim/stdlib/Filename.java index 49fd6b6c848..9a4223d45a9 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/Filename.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/Filename.java @@ -39,13 +39,12 @@ import java.util.Set; import net.sourceforge.plantuml.preproc.Defines; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class Filename extends SimpleReturnFunction { @@ -65,8 +64,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { if (value == null) { return TValue.fromString(""); } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/FunctionExists.java b/src/net/sourceforge/plantuml/tim/stdlib/FunctionExists.java index 43442f82ec5..d2bd9d1b2a2 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/FunctionExists.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/FunctionExists.java @@ -38,16 +38,15 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class FunctionExists extends SimpleReturnFunction { - // ::remove folder when __HAXE__ + // ::remove folder when __HAXE__ public TFunctionSignature getSignature() { return new TFunctionSignature("%function_exists", 1); @@ -59,8 +58,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final String name = values.get(0).toString(); return TValue.fromBoolean(context.doesFunctionExist(name)); } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/GetAllStdlib.java b/src/net/sourceforge/plantuml/tim/stdlib/GetAllStdlib.java new file mode 100644 index 00000000000..d1b0bff9dd8 --- /dev/null +++ b/src/net/sourceforge/plantuml/tim/stdlib/GetAllStdlib.java @@ -0,0 +1,105 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2024, Arnaud Roques + * + * Project Info: https://plantuml.com + * + * If you like this project or if you find it useful, you can support us at: + * + * https://plantuml.com/patreon (only 1$ per month!) + * https://plantuml.com/paypal + * + * 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.tim.stdlib; + +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import net.sourceforge.plantuml.json.Json; +import net.sourceforge.plantuml.json.JsonArray; +import net.sourceforge.plantuml.json.JsonObject; +import net.sourceforge.plantuml.log.Logme; +import net.sourceforge.plantuml.preproc.Stdlib; +import net.sourceforge.plantuml.text.StringLocated; +import net.sourceforge.plantuml.tim.EaterException; +import net.sourceforge.plantuml.tim.TContext; +import net.sourceforge.plantuml.tim.TFunctionSignature; +import net.sourceforge.plantuml.tim.TMemory; +import net.sourceforge.plantuml.tim.expression.TValue; + +public class GetAllStdlib extends SimpleReturnFunction { + + public TFunctionSignature getSignature() { + return new TFunctionSignature("%get_all_stdlib", 1); + } + + @Override + public boolean canCover(int nbArg, Set namedArgument) { + return nbArg == 0 || nbArg == 1; + } + + @Override + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { + + switch (values.size()) { + case 0: + final JsonArray result = new JsonArray(); + try { + for (String name : Stdlib.getAll()) { + result.add(name); + } + return TValue.fromJson(result); + } catch (IOException e) { + Logme.error(e); + return TValue.fromJson(result); + } + + case 1: + final JsonObject res = new JsonObject(); + try { + // Inspired by Stdlib.addInfoVersion + for (String name : Stdlib.getAll()) { + final Stdlib folder = Stdlib.retrieve(name); + final JsonObject object = Json.object() // + .add("name", name) // + .add("version", folder.getVersion()) // + .add("source", folder.getSource()); + res.add(name, object); + } + return TValue.fromJson(res); + } catch (IOException e) { + Logme.error(e); + return TValue.fromJson(res); + } + + default: + assert false; // Should not append because of canCover() + throw new EaterException("Error on get_all_stdlib: Too many arguments", location); + } + } +} diff --git a/src/net/sourceforge/plantuml/tim/stdlib/GetAllTheme.java b/src/net/sourceforge/plantuml/tim/stdlib/GetAllTheme.java index e0b2d0281a7..2512d26f1b8 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/GetAllTheme.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/GetAllTheme.java @@ -39,16 +39,15 @@ import java.util.Map; import java.util.Set; -import net.sourceforge.plantuml.log.Logme; import net.sourceforge.plantuml.json.JsonArray; +import net.sourceforge.plantuml.log.Logme; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.theme.ThemeUtils; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class GetAllTheme extends SimpleReturnFunction { @@ -62,8 +61,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final JsonArray result = new JsonArray(); try { for (String theme : ThemeUtils.getAllThemeNames()) { diff --git a/src/net/sourceforge/plantuml/tim/stdlib/GetJsonKey.java b/src/net/sourceforge/plantuml/tim/stdlib/GetJsonKey.java index 244824ee322..6e7df046c25 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/GetJsonKey.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/GetJsonKey.java @@ -41,13 +41,12 @@ import net.sourceforge.plantuml.json.JsonArray; import net.sourceforge.plantuml.json.JsonObject; import net.sourceforge.plantuml.json.JsonValue; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class GetJsonKey extends SimpleReturnFunction { @@ -61,11 +60,12 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final TValue data = values.get(0); if (data.isJson() == false) - throw EaterException.unlocated("Not JSON data"); + throw new EaterException("Not JSON data", location); + final JsonValue json = data.toJson(); if (json.isObject()) { final JsonObject object = (JsonObject) json; @@ -87,7 +87,7 @@ public TValue executeReturnFunction(TContext context, TMemory memory, LineLocati return TValue.fromJson(result); } - throw EaterException.unlocated("Bad JSON type"); + throw new EaterException("Bad JSON type", location); } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/GetJsonType.java b/src/net/sourceforge/plantuml/tim/stdlib/GetJsonType.java index 33d3b5b6489..0c09b9e847d 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/GetJsonType.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/GetJsonType.java @@ -39,13 +39,12 @@ import java.util.Set; import net.sourceforge.plantuml.json.JsonValue; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class GetJsonType extends SimpleReturnFunction { @@ -59,8 +58,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final TValue data = values.get(0); if (data.isString()) return TValue.fromString("string"); diff --git a/src/net/sourceforge/plantuml/tim/stdlib/GetVariableValue.java b/src/net/sourceforge/plantuml/tim/stdlib/GetVariableValue.java index 082921acbe2..b99e3478add 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/GetVariableValue.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/GetVariableValue.java @@ -38,13 +38,12 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class GetVariableValue extends SimpleReturnFunction { @@ -58,13 +57,13 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final String name = values.get(0).toString(); final TValue variable = memory.getVariable(name); - if (variable == null) { + if (variable == null) return TValue.fromString(""); - } + return variable; } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/GetVersion.java b/src/net/sourceforge/plantuml/tim/stdlib/GetVersion.java index c206538cbf9..df0218cea3e 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/GetVersion.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/GetVersion.java @@ -38,13 +38,12 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; import net.sourceforge.plantuml.version.Version; public class GetVersion extends SimpleReturnFunction { @@ -59,8 +58,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { return TValue.fromString(Version.versionString()); } } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/Getenv.java b/src/net/sourceforge/plantuml/tim/stdlib/Getenv.java index 88fd8a6382c..4c93f23f5c4 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/Getenv.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/Getenv.java @@ -39,13 +39,12 @@ import java.util.Set; import net.sourceforge.plantuml.security.SecurityUtils; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class Getenv extends SimpleReturnFunction { @@ -59,8 +58,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { // ::comment when __CORE__ final String value = getenv(values.get(0).toString()); if (value == null) @@ -82,7 +81,7 @@ private String getenv(String name) { // also stop here in other deployments. if (SecurityUtils.getSecurityProfile().canWeReadThisEnvironmentVariable(name) == false) return null; - + final String env = System.getProperty(name); if (env != null) return env; diff --git a/src/net/sourceforge/plantuml/tim/stdlib/Hex2dec.java b/src/net/sourceforge/plantuml/tim/stdlib/Hex2dec.java index 27f5102486a..964a6cfb048 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/Hex2dec.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/Hex2dec.java @@ -38,13 +38,12 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class Hex2dec extends SimpleReturnFunction { @@ -58,8 +57,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { try { return TValue.fromInt(Integer.parseInt(values.get(0).toString(), 16)); } catch (Throwable t) { diff --git a/src/net/sourceforge/plantuml/tim/stdlib/HslColor.java b/src/net/sourceforge/plantuml/tim/stdlib/HslColor.java index cc1173882c3..2113908d21a 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/HslColor.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/HslColor.java @@ -41,13 +41,12 @@ import net.sourceforge.plantuml.klimt.color.HColors; import net.sourceforge.plantuml.klimt.color.HSLColor; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class HslColor extends SimpleReturnFunction { @@ -61,8 +60,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final int h = values.get(0).toInt(); final int s = values.get(1).toInt(); final int l = values.get(2).toInt(); diff --git a/src/net/sourceforge/plantuml/tim/stdlib/IntVal.java b/src/net/sourceforge/plantuml/tim/stdlib/IntVal.java index 27e19db7ab4..bda216b4c62 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/IntVal.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/IntVal.java @@ -38,13 +38,12 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; import net.sourceforge.plantuml.utils.Log; public class IntVal extends SimpleReturnFunction { @@ -59,8 +58,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final String s = values.get(0).toString(); try { return TValue.fromInt(Integer.parseInt(s)); diff --git a/src/net/sourceforge/plantuml/tim/stdlib/InvokeProcedure.java b/src/net/sourceforge/plantuml/tim/stdlib/InvokeProcedure.java index 5331f7b2e19..4eab28dde9c 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/InvokeProcedure.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/InvokeProcedure.java @@ -38,15 +38,14 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunction; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TFunctionType; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class InvokeProcedure implements TFunction { @@ -64,20 +63,20 @@ public TFunctionType getFunctionType() { } @Override - public void executeProcedureInternal(TContext context, TMemory memory, List args, Map named) - throws EaterException, EaterExceptionLocated { + public void executeProcedureInternal(TContext context, TMemory memory, StringLocated location, List args, + Map named) throws EaterException { final String fname = args.get(0).toString(); final List sublist = args.subList(1, args.size()); final TFunctionSignature signature = new TFunctionSignature(fname, sublist.size()); final TFunction func = context.getFunctionSmart(signature); - if (func == null) { - throw EaterException.located("Cannot find void function " + fname); - } - func.executeProcedureInternal(context, memory, sublist, named); + if (func == null) + throw new EaterException("Cannot find void function " + fname, location); + + func.executeProcedureInternal(context, memory, location, sublist, named); } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, Map named) { throw new UnsupportedOperationException(); } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/IsDark.java b/src/net/sourceforge/plantuml/tim/stdlib/IsDark.java index efc4299da9b..cf94491222f 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/IsDark.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/IsDark.java @@ -41,13 +41,12 @@ import net.sourceforge.plantuml.klimt.color.HColor; import net.sourceforge.plantuml.klimt.color.HColorSet; import net.sourceforge.plantuml.klimt.color.NoSuchColorException; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class IsDark extends SimpleReturnFunction { @@ -62,14 +61,14 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final String colorString = values.get(0).toString(); try { final HColor color = HColorSet.instance().getColorLEGACY(colorString); return TValue.fromBoolean(color.isDark()); } catch (NoSuchColorException e) { - throw EaterException.located("No such color"); + throw new EaterException("No such color", location); } } } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/IsLight.java b/src/net/sourceforge/plantuml/tim/stdlib/IsLight.java index deff7b24d9a..b717e419a13 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/IsLight.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/IsLight.java @@ -41,13 +41,12 @@ import net.sourceforge.plantuml.klimt.color.HColor; import net.sourceforge.plantuml.klimt.color.HColorSet; import net.sourceforge.plantuml.klimt.color.NoSuchColorException; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class IsLight extends SimpleReturnFunction { @@ -62,14 +61,14 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final String colorString = values.get(0).toString(); try { final HColor color = HColorSet.instance().getColorLEGACY(colorString); return TValue.fromBoolean(!color.isDark()); } catch (NoSuchColorException e) { - throw EaterException.located("No such color"); + throw new EaterException("No such color", location); } } } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/JsonKeyExists.java b/src/net/sourceforge/plantuml/tim/stdlib/JsonKeyExists.java index 85eafc5400f..35238cc5b0d 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/JsonKeyExists.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/JsonKeyExists.java @@ -40,13 +40,12 @@ import net.sourceforge.plantuml.json.JsonObject; import net.sourceforge.plantuml.json.JsonValue; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class JsonKeyExists extends SimpleReturnFunction { @@ -60,8 +59,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final TValue arg0 = values.get(0); if (arg0.isJson() == false) return TValue.fromBoolean(false); diff --git a/src/net/sourceforge/plantuml/tim/stdlib/Lighten.java b/src/net/sourceforge/plantuml/tim/stdlib/Lighten.java index e4de200feef..e309859b33c 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/Lighten.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/Lighten.java @@ -41,13 +41,12 @@ import net.sourceforge.plantuml.klimt.color.HColor; import net.sourceforge.plantuml.klimt.color.HColorSet; import net.sourceforge.plantuml.klimt.color.NoSuchColorException; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class Lighten extends SimpleReturnFunction { @@ -62,8 +61,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final String colorString = values.get(0).toString(); final int ratio = values.get(1).toInt(); try { @@ -71,7 +70,7 @@ public TValue executeReturnFunction(TContext context, TMemory memory, LineLocati color = color.lighten(ratio); return TValue.fromString(color.asString()); } catch (NoSuchColorException e) { - throw EaterException.located("No such color"); + throw new EaterException("No such color", location); } } } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/LoadJson.java b/src/net/sourceforge/plantuml/tim/stdlib/LoadJson.java index a5021562ce6..5f8e30b004a 100755 --- a/src/net/sourceforge/plantuml/tim/stdlib/LoadJson.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/LoadJson.java @@ -49,13 +49,12 @@ import net.sourceforge.plantuml.log.Logme; import net.sourceforge.plantuml.security.SFile; import net.sourceforge.plantuml.security.SURL; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; /** * Loads JSON data from file or URL source. @@ -108,8 +107,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final String path = values.get(0).toString(); try { String data = loadStringData(path, getCharset(values)); @@ -120,10 +119,10 @@ public TValue executeReturnFunction(TContext context, TMemory memory, LineLocati return TValue.fromJson(jsonValue); } catch (ParseException pe) { Logme.error(pe); - throw EaterException.unlocated("JSON parse issue in source " + path + " on location " + pe.getLocation()); + throw new EaterException("JSON parse issue in source " + path + " on location " + pe.getLocation(), location); } catch (UnsupportedEncodingException e) { Logme.error(e); - throw EaterException.unlocated("JSON encoding issue in source " + path + ": " + e.getMessage()); + throw new EaterException("JSON encoding issue in source " + path + ": " + e.getMessage(), location); } } @@ -162,7 +161,8 @@ private String getCharset(List values) { * @return the decoded String from the data source * @throws EaterException if something went wrong on reading data */ - private String loadStringData(String path, String charset) throws EaterException, UnsupportedEncodingException { + private String loadStringData(String path, String charset) + throws EaterException, UnsupportedEncodingException { byte[] byteData = null; if (path.startsWith("http://") || path.startsWith("https://")) { diff --git a/src/net/sourceforge/plantuml/tim/stdlib/LogicalAnd.java b/src/net/sourceforge/plantuml/tim/stdlib/LogicalAnd.java index 4fe2d2a143d..ede165c2217 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/LogicalAnd.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/LogicalAnd.java @@ -38,13 +38,12 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class LogicalAnd extends SimpleReturnFunction { @@ -58,8 +57,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { for (TValue v : values) if (v.toBoolean() == false) return TValue.fromBoolean(false); diff --git a/src/net/sourceforge/plantuml/tim/stdlib/LogicalNand.java b/src/net/sourceforge/plantuml/tim/stdlib/LogicalNand.java index 9b018d3c072..0740118e54f 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/LogicalNand.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/LogicalNand.java @@ -38,13 +38,12 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class LogicalNand extends SimpleReturnFunction { @@ -58,8 +57,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { for (TValue v : values) if (v.toBoolean() == false) return TValue.fromBoolean(!false); diff --git a/src/net/sourceforge/plantuml/tim/stdlib/LogicalNor.java b/src/net/sourceforge/plantuml/tim/stdlib/LogicalNor.java index 95c4e3c6ddd..d0fcb1e146a 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/LogicalNor.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/LogicalNor.java @@ -38,13 +38,12 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class LogicalNor extends SimpleReturnFunction { @@ -58,8 +57,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { for (TValue v : values) if (v.toBoolean() == true) return TValue.fromBoolean(!true); diff --git a/src/net/sourceforge/plantuml/tim/stdlib/LogicalNot.java b/src/net/sourceforge/plantuml/tim/stdlib/LogicalNot.java index ca6d5ab3a56..071620862ba 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/LogicalNot.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/LogicalNot.java @@ -38,13 +38,12 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class LogicalNot extends SimpleReturnFunction { @@ -58,8 +57,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final boolean arg = values.get(0).toBoolean(); return TValue.fromBoolean(!arg); } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/LogicalNxor.java b/src/net/sourceforge/plantuml/tim/stdlib/LogicalNxor.java index e83c05b1eef..8403263c7c8 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/LogicalNxor.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/LogicalNxor.java @@ -38,13 +38,12 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class LogicalNxor extends SimpleReturnFunction { @@ -58,8 +57,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { int cpt = 0; for (TValue v : values) if (v.toBoolean() == true) diff --git a/src/net/sourceforge/plantuml/tim/stdlib/LogicalOr.java b/src/net/sourceforge/plantuml/tim/stdlib/LogicalOr.java index 41026ac89d6..de58b384a2a 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/LogicalOr.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/LogicalOr.java @@ -38,13 +38,12 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class LogicalOr extends SimpleReturnFunction { @@ -58,8 +57,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { for (TValue v : values) if (v.toBoolean() == true) return TValue.fromBoolean(true); diff --git a/src/net/sourceforge/plantuml/tim/stdlib/LogicalXor.java b/src/net/sourceforge/plantuml/tim/stdlib/LogicalXor.java index 14ad07a5e5d..3a5e24eabeb 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/LogicalXor.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/LogicalXor.java @@ -38,13 +38,12 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class LogicalXor extends SimpleReturnFunction { @@ -58,8 +57,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { int cpt = 0; for (TValue v : values) if (v.toBoolean() == true) diff --git a/src/net/sourceforge/plantuml/tim/stdlib/Lower.java b/src/net/sourceforge/plantuml/tim/stdlib/Lower.java index d0dbcb7315a..721a521b8ef 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/Lower.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/Lower.java @@ -38,11 +38,11 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class Lower extends SimpleReturnFunction { @@ -56,7 +56,7 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, Map named) { return TValue.fromString(values.get(0).toString().toLowerCase()); } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/Newline.java b/src/net/sourceforge/plantuml/tim/stdlib/Newline.java index 2f5c7abb71a..d3b4b87685d 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/Newline.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/Newline.java @@ -38,11 +38,11 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class Newline extends SimpleReturnFunction { @@ -56,7 +56,7 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, Map named) { return TValue.fromString("\n"); } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/Now.java b/src/net/sourceforge/plantuml/tim/stdlib/Now.java index c90eb25d104..de2c7bb71bb 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/Now.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/Now.java @@ -38,13 +38,12 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class Now extends SimpleReturnFunction { @@ -58,8 +57,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final long now = System.currentTimeMillis() / 1000L; return TValue.fromInt((int) now); } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/Ord.java b/src/net/sourceforge/plantuml/tim/stdlib/Ord.java index bf0f7d767f3..9b1c87d5d4e 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/Ord.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/Ord.java @@ -38,13 +38,12 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class Ord extends SimpleReturnFunction { @@ -58,8 +57,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { try { final int codePoint = values.get(0).toString().codePointAt(0); return TValue.fromInt(codePoint); diff --git a/src/net/sourceforge/plantuml/tim/stdlib/RandomFunction.java b/src/net/sourceforge/plantuml/tim/stdlib/RandomFunction.java index a165f00a400..1b4de5ac9bd 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/RandomFunction.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/RandomFunction.java @@ -39,13 +39,12 @@ import java.util.Random; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class RandomFunction extends SimpleReturnFunction { @@ -59,25 +58,26 @@ public boolean canCover(int nbArg, Set namedArgument) { } private final Random random = new Random(); - + @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { switch (values.size()) { - case 0: - return TValue.fromInt(random.nextInt(2)); + case 0: + return TValue.fromInt(random.nextInt(2)); - case 1: - final Integer mx = values.get(0).toInt(); - return TValue.fromInt(random.nextInt(mx)); + case 1: + final Integer mx = values.get(0).toInt(); + return TValue.fromInt(random.nextInt(mx)); - case 2: - final Integer min = values.get(0).toInt(); - final Integer max = values.get(1).toInt(); - return TValue.fromInt(random.nextInt(max - min) + min); + case 2: + final Integer min = values.get(0).toInt(); + final Integer max = values.get(1).toInt(); + return TValue.fromInt(random.nextInt(max - min) + min); - default: - throw EaterException.located("Error on Random: Too many argument"); + default: + assert false; // Should not append because of canCover() + throw new EaterException("Error on Random: Too many argument", location); } } } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/RetrieveProcedure.java b/src/net/sourceforge/plantuml/tim/stdlib/RetrieveProcedure.java index fa75ab9466b..a9b51e5f35f 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/RetrieveProcedure.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/RetrieveProcedure.java @@ -39,14 +39,13 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunction; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class RetrieveProcedure extends SimpleReturnFunction { @@ -60,14 +59,14 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final String fname = values.get(0).toString(); final List args = values.subList(1, values.size()); final TFunctionSignature signature = new TFunctionSignature(fname, args.size()); final TFunction func = context.getFunctionSmart(signature); final int n1 = context.getResultList().size(); - func.executeProcedureInternal(context, memory, args, Collections.emptyMap()); + func.executeProcedureInternal(context, memory, location, args, Collections.emptyMap()); final String extracted = context.extractFromResultList(n1); return TValue.fromString(extracted); } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/ReverseColor.java b/src/net/sourceforge/plantuml/tim/stdlib/ReverseColor.java index 6084e16d1cf..a46c9695f43 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/ReverseColor.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/ReverseColor.java @@ -41,13 +41,12 @@ import net.sourceforge.plantuml.klimt.color.HColor; import net.sourceforge.plantuml.klimt.color.HColorSet; import net.sourceforge.plantuml.klimt.color.NoSuchColorException; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class ReverseColor extends SimpleReturnFunction { @@ -61,15 +60,15 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final String colorString = values.get(0).toString(); try { HColor color = HColorSet.instance().getColorLEGACY(colorString); color = color.reverse(); return TValue.fromString(color.asString()); } catch (NoSuchColorException e) { - throw EaterException.located("No such color"); + throw new EaterException("No such color", location); } } } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/ReverseHsluvColor.java b/src/net/sourceforge/plantuml/tim/stdlib/ReverseHsluvColor.java index 6a42843f74f..8fd8422e3ab 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/ReverseHsluvColor.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/ReverseHsluvColor.java @@ -41,13 +41,12 @@ import net.sourceforge.plantuml.klimt.color.HColor; import net.sourceforge.plantuml.klimt.color.HColorSet; import net.sourceforge.plantuml.klimt.color.NoSuchColorException; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class ReverseHsluvColor extends SimpleReturnFunction { @@ -61,15 +60,15 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final String colorString = values.get(0).toString(); try { HColor color = HColorSet.instance().getColorLEGACY(colorString); color = color.reverseHsluv(); return TValue.fromString(color.asString()); } catch (NoSuchColorException e) { - throw EaterException.located("No such color"); + throw new EaterException("No such color", location); } } } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/SetVariableValue.java b/src/net/sourceforge/plantuml/tim/stdlib/SetVariableValue.java index a35ec7786e7..631037c45eb 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/SetVariableValue.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/SetVariableValue.java @@ -38,14 +38,13 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.TVariableScope; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class SetVariableValue extends SimpleReturnFunction { @@ -59,14 +58,14 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { // if (memory instanceof TMemoryLocal) { // memory = ((TMemoryLocal) memory).getGlobalForInternalUseOnly(); // } final String name = values.get(0).toString(); final TValue value = values.get(1); - memory.putVariable(name, value, TVariableScope.GLOBAL); + memory.putVariable(name, value, TVariableScope.GLOBAL, location); return TValue.fromString(""); } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/SimpleReturnFunction.java b/src/net/sourceforge/plantuml/tim/stdlib/SimpleReturnFunction.java index f276bcbdd26..c649a86a4a1 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/SimpleReturnFunction.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/SimpleReturnFunction.java @@ -37,13 +37,13 @@ import java.util.List; import java.util.Map; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunction; import net.sourceforge.plantuml.tim.TFunctionType; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public abstract class SimpleReturnFunction implements TFunction { @@ -52,8 +52,8 @@ final public TFunctionType getFunctionType() { } @Override - final public void executeProcedureInternal(TContext context, TMemory memory, List args, - Map named) throws EaterException { + final public void executeProcedureInternal(TContext context, TMemory memory, StringLocated location, + List args, Map named) throws EaterException { throw new UnsupportedOperationException(); } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/Size.java b/src/net/sourceforge/plantuml/tim/stdlib/Size.java index 0794bca42bd..b2e17650426 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/Size.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/Size.java @@ -41,13 +41,12 @@ import net.sourceforge.plantuml.json.JsonArray; import net.sourceforge.plantuml.json.JsonObject; import net.sourceforge.plantuml.json.JsonValue; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class Size extends SimpleReturnFunction { @@ -61,8 +60,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final TValue value = values.get(0); if (value.isNumber()) return TValue.fromInt(0); diff --git a/src/net/sourceforge/plantuml/tim/stdlib/SplitStr.java b/src/net/sourceforge/plantuml/tim/stdlib/SplitStr.java index d9aa2fdedfc..536ee9ba059 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/SplitStr.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/SplitStr.java @@ -40,13 +40,12 @@ import java.util.StringTokenizer; import net.sourceforge.plantuml.json.JsonArray; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class SplitStr extends SimpleReturnFunction { @@ -60,8 +59,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final JsonArray result = new JsonArray(); final String str = values.get(0).toString(); diff --git a/src/net/sourceforge/plantuml/tim/stdlib/StringFunction.java b/src/net/sourceforge/plantuml/tim/stdlib/StringFunction.java index f2b972a8058..de63add20d9 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/StringFunction.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/StringFunction.java @@ -38,11 +38,11 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class StringFunction extends SimpleReturnFunction { @@ -56,7 +56,7 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, Map named) { return TValue.fromString(values.get(0).toString()); } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/Strlen.java b/src/net/sourceforge/plantuml/tim/stdlib/Strlen.java index 3e1578fba23..2a91bd05dcc 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/Strlen.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/Strlen.java @@ -38,13 +38,12 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class Strlen extends SimpleReturnFunction { @@ -58,8 +57,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { return TValue.fromInt(values.get(0).toString().length()); } } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/Strpos.java b/src/net/sourceforge/plantuml/tim/stdlib/Strpos.java index 09a5c43a995..2f7c32c7c51 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/Strpos.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/Strpos.java @@ -38,13 +38,12 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class Strpos extends SimpleReturnFunction { @@ -58,8 +57,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final String full = values.get(0).toString(); final String searched = values.get(1).toString(); return TValue.fromInt(full.indexOf(searched)); diff --git a/src/net/sourceforge/plantuml/tim/stdlib/Substr.java b/src/net/sourceforge/plantuml/tim/stdlib/Substr.java index ba0c0e8ce64..76e7751f9d5 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/Substr.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/Substr.java @@ -38,13 +38,12 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class Substr extends SimpleReturnFunction { @@ -58,8 +57,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final String full = values.get(0).toString(); final int pos = values.get(1).toInt(); if (pos >= full.length()) diff --git a/src/net/sourceforge/plantuml/tim/stdlib/Upper.java b/src/net/sourceforge/plantuml/tim/stdlib/Upper.java index 98caf89ffe4..71ebe587ea2 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/Upper.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/Upper.java @@ -38,11 +38,11 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class Upper extends SimpleReturnFunction { @@ -56,7 +56,7 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, Map named) { return TValue.fromString(values.get(0).toString().toUpperCase()); } diff --git a/src/net/sourceforge/plantuml/tim/stdlib/VariableExists.java b/src/net/sourceforge/plantuml/tim/stdlib/VariableExists.java index a63730447f5..db3c39f1b27 100644 --- a/src/net/sourceforge/plantuml/tim/stdlib/VariableExists.java +++ b/src/net/sourceforge/plantuml/tim/stdlib/VariableExists.java @@ -38,13 +38,12 @@ import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.text.StringLocated; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TContext; import net.sourceforge.plantuml.tim.TFunctionSignature; import net.sourceforge.plantuml.tim.TMemory; import net.sourceforge.plantuml.tim.expression.TValue; -import net.sourceforge.plantuml.utils.LineLocation; public class VariableExists extends SimpleReturnFunction { @@ -58,8 +57,8 @@ public boolean canCover(int nbArg, Set namedArgument) { } @Override - public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List values, - Map named) throws EaterException, EaterExceptionLocated { + public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List values, + Map named) throws EaterException { final String name = values.get(0).toString(); return TValue.fromBoolean(memory.getVariable(name) != null); } diff --git a/src/net/sourceforge/plantuml/version/Version.java b/src/net/sourceforge/plantuml/version/Version.java index 50dd4b24ed0..61bcf79714f 100644 --- a/src/net/sourceforge/plantuml/version/Version.java +++ b/src/net/sourceforge/plantuml/version/Version.java @@ -46,7 +46,7 @@ public class Version { // Warning, "version" should be the same in gradle.properties and Version.java // Any idea anyone how to magically synchronize those :-) ? - private static final String version = "1.2024.4beta1"; + private static final String version = "1.2024.4beta5"; public static String versionString() { return version; diff --git a/test/net/sourceforge/plantuml/tim/TimTestUtils.java b/test/net/sourceforge/plantuml/tim/TimTestUtils.java index 81993d3a22b..c71b7d8a3ac 100644 --- a/test/net/sourceforge/plantuml/tim/TimTestUtils.java +++ b/test/net/sourceforge/plantuml/tim/TimTestUtils.java @@ -14,27 +14,27 @@ public class TimTestUtils { // Tfunc: () -> (String) - public static void assertTimExpectedOutput(TFunction func, String expected) throws EaterException, EaterExceptionLocated { + public static void assertTimExpectedOutput(TFunction func, String expected) throws EaterException { TValue tValue = func.executeReturnFunction(null, null, null, null, null); assertEquals(expected, tValue.toString()); } // Tfunc: (Integer) -> (String) - public static void assertTimExpectedOutputFromInput(TFunction func, Integer input, String expected) throws EaterException, EaterExceptionLocated { + public static void assertTimExpectedOutputFromInput(TFunction func, Integer input, String expected) throws EaterException { List values = Collections.singletonList(TValue.fromInt(input)); TValue tValue = func.executeReturnFunction(null, null, null, values, null); assertEquals(expected, tValue.toString()); } // Tfunc: (String) -> (String) - public static void assertTimExpectedOutputFromInput(TFunction func, String input, String expected) throws EaterException, EaterExceptionLocated { + public static void assertTimExpectedOutputFromInput(TFunction func, String input, String expected) throws EaterException { List values = Collections.singletonList(TValue.fromString(input)); TValue tValue = func.executeReturnFunction(null, null, null, values, null); assertEquals(expected, tValue.toString()); } // Tfunc: (JsonValue) -> (String) - public static void assertTimExpectedOutputFromInput(TFunction func, JsonValue input, String expected) throws EaterException, EaterExceptionLocated { + public static void assertTimExpectedOutputFromInput(TFunction func, JsonValue input, String expected) throws EaterException { List values = Collections.singletonList(TValue.fromJson(input)); TValue tValue = func.executeReturnFunction(null, null, null, values, null); assertEquals(expected, tValue.toString()); diff --git a/test/net/sourceforge/plantuml/tim/stdlib/AlwaysFalseTest.java b/test/net/sourceforge/plantuml/tim/stdlib/AlwaysFalseTest.java index addb2050c68..1ff9e68ff88 100644 --- a/test/net/sourceforge/plantuml/tim/stdlib/AlwaysFalseTest.java +++ b/test/net/sourceforge/plantuml/tim/stdlib/AlwaysFalseTest.java @@ -6,12 +6,10 @@ import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; import org.junit.jupiter.api.IndicativeSentencesGeneration; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.converter.ConvertWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TFunction; /** @@ -24,7 +22,7 @@ class AlwaysFalseTest { final String cutName = "AlwaysFalse"; @Test - void Test_without_Param() throws EaterException, EaterExceptionLocated { + void Test_without_Param() throws EaterException { assertTimExpectedOutput(cut, "0"); } @@ -34,7 +32,7 @@ void Test_without_Param() throws EaterException, EaterExceptionLocated { " 1 , 0 ", " 'a' , 0 ", }) - void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_String(String input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } @@ -44,7 +42,7 @@ void Test_with_String(String input, String expected) throws EaterException, Eate " 1 , 0 ", " 123 , 0 ", }) - void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_Integer(Integer input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } } diff --git a/test/net/sourceforge/plantuml/tim/stdlib/AlwaysTrueTest.java b/test/net/sourceforge/plantuml/tim/stdlib/AlwaysTrueTest.java index 439bde93d54..d1e910b844b 100644 --- a/test/net/sourceforge/plantuml/tim/stdlib/AlwaysTrueTest.java +++ b/test/net/sourceforge/plantuml/tim/stdlib/AlwaysTrueTest.java @@ -6,12 +6,10 @@ import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; import org.junit.jupiter.api.IndicativeSentencesGeneration; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.converter.ConvertWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TFunction; /** @@ -24,7 +22,7 @@ class AlwaysTrueTest { final String cutName = "AlwaysTrue"; @Test - void Test_without_Param() throws EaterException, EaterExceptionLocated { + void Test_without_Param() throws EaterException { assertTimExpectedOutput(cut, "1"); } @@ -34,7 +32,7 @@ void Test_without_Param() throws EaterException, EaterExceptionLocated { " 1 , 1 ", " 'a' , 1 ", }) - void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_String(String input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } @@ -44,7 +42,7 @@ void Test_with_String(String input, String expected) throws EaterException, Eate " 1 , 1 ", " 123 , 1 ", }) - void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_Integer(Integer input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } } diff --git a/test/net/sourceforge/plantuml/tim/stdlib/ChrTest.java b/test/net/sourceforge/plantuml/tim/stdlib/ChrTest.java index 6659ecd950f..58cba9f0483 100644 --- a/test/net/sourceforge/plantuml/tim/stdlib/ChrTest.java +++ b/test/net/sourceforge/plantuml/tim/stdlib/ChrTest.java @@ -8,7 +8,6 @@ import org.junit.jupiter.params.provider.CsvSource; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TFunction; /** @@ -23,7 +22,6 @@ class ChrTest { * Tests chr according to a list of input / expected output * * @throws EaterException should not - * @throws EaterExceptionLocated should not */ @ParameterizedTest(name = "[{index}] " + cutName + "({0}) = ''{1}''") @CsvSource(nullValues = "null", value = { @@ -38,7 +36,7 @@ class ChrTest { " 128512 , 😀 ", " 128512 , \uD83D\uDE00 ", }) - void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_Integer(Integer input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } } \ No newline at end of file diff --git a/test/net/sourceforge/plantuml/tim/stdlib/Dec2hexTest.java b/test/net/sourceforge/plantuml/tim/stdlib/Dec2hexTest.java index 1134c293d62..ff05ebff70c 100644 --- a/test/net/sourceforge/plantuml/tim/stdlib/Dec2hexTest.java +++ b/test/net/sourceforge/plantuml/tim/stdlib/Dec2hexTest.java @@ -6,12 +6,10 @@ import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; import org.junit.jupiter.api.IndicativeSentencesGeneration; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.converter.ConvertWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TFunction; /** @@ -24,7 +22,7 @@ class Dec2hexTest { final String cutName = "Dec2hex"; @Test - void Test_without_Param() throws EaterException, EaterExceptionLocated { + void Test_without_Param() throws EaterException { assertTimExpectedOutput(cut, ""); } @@ -38,7 +36,7 @@ void Test_without_Param() throws EaterException, EaterExceptionLocated { " 255 , 0 ", " 65535 , 0 ", }) - void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_String(String input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } @@ -52,7 +50,7 @@ void Test_with_String(String input, String expected) throws EaterException, Eate " 255 , ff ", " 65535 , ffff ", }) - void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_Integer(Integer input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } } diff --git a/test/net/sourceforge/plantuml/tim/stdlib/FeatureTest.java b/test/net/sourceforge/plantuml/tim/stdlib/FeatureTest.java index 52507fb51ba..d5ea79e3fb5 100644 --- a/test/net/sourceforge/plantuml/tim/stdlib/FeatureTest.java +++ b/test/net/sourceforge/plantuml/tim/stdlib/FeatureTest.java @@ -2,20 +2,19 @@ import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput; import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput; -import static test.utils.JunitUtils.StringJsonConverter; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; import org.junit.jupiter.api.IndicativeSentencesGeneration; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.converter.ConvertWith; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.converter.ConvertWith; import org.junit.jupiter.params.provider.CsvSource; import net.sourceforge.plantuml.json.JsonValue; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TFunction; +import test.utils.JunitUtils.StringJsonConverter; /** * Tests the builtin function. @@ -28,7 +27,7 @@ class FeatureTest { @Disabled @Test - void Test_without_Param() throws EaterException, EaterExceptionLocated { + void Test_without_Param() throws EaterException { assertTimExpectedOutput(cut, "0"); } @@ -43,7 +42,7 @@ void Test_without_Param() throws EaterException, EaterExceptionLocated { " abc , 0", }) - void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_String(String input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } @@ -52,7 +51,7 @@ void Test_with_String(String input, String expected) throws EaterException, Eate " 0, 0", " 10, 0", }) - void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_Integer(Integer input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } @@ -62,7 +61,7 @@ void Test_with_Integer(Integer input, String expected) throws EaterException, Ea " \"theme\", 1", " 0, 0", }) - void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } } diff --git a/test/net/sourceforge/plantuml/tim/stdlib/GetAllStdlibTest.java b/test/net/sourceforge/plantuml/tim/stdlib/GetAllStdlibTest.java new file mode 100644 index 00000000000..e22ebbc20cf --- /dev/null +++ b/test/net/sourceforge/plantuml/tim/stdlib/GetAllStdlibTest.java @@ -0,0 +1,38 @@ +package net.sourceforge.plantuml.tim.stdlib; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; +import org.junit.jupiter.api.IndicativeSentencesGeneration; +import org.junit.jupiter.api.Test; + +import net.sourceforge.plantuml.tim.EaterException; +import net.sourceforge.plantuml.tim.TFunction; +import net.sourceforge.plantuml.tim.expression.TValue; + +/** + * Tests the builtin function. + */ +@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class) + +class GetAllStdlibTest { + TFunction cut = new GetAllStdlib(); + final String cutName = "GetAllStdlib"; + + @Test + void Test_without_Param() throws EaterException { + final List empty = new ArrayList<>(); + final TValue tValue = cut.executeReturnFunction(null, null, null, empty, null); + assertThat(tValue.toString()).contains("archimate", "aws", "tupadr3"); + } + + @Test + void Test_with_one_argument() throws EaterException { + final TValue tValue = cut.executeReturnFunction(null, null, null, Arrays.asList(TValue.fromInt(0)), null); + assertThat(tValue.toString()).contains("archimate", "https://github.com/plantuml-stdlib/Archimate-PlantUML"); + } +} diff --git a/test/net/sourceforge/plantuml/tim/stdlib/GetAllThemeTest.java b/test/net/sourceforge/plantuml/tim/stdlib/GetAllThemeTest.java index c17bc33d22f..0c6d65ae851 100644 --- a/test/net/sourceforge/plantuml/tim/stdlib/GetAllThemeTest.java +++ b/test/net/sourceforge/plantuml/tim/stdlib/GetAllThemeTest.java @@ -2,14 +2,14 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.util.Collections; +import java.util.ArrayList; +import java.util.List; import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; import org.junit.jupiter.api.IndicativeSentencesGeneration; import org.junit.jupiter.api.Test; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TFunction; import net.sourceforge.plantuml.tim.expression.TValue; @@ -23,8 +23,9 @@ class GetAllThemeTest { final String cutName = "GetAllTheme"; @Test - void Test_without_Param() throws EaterException, EaterExceptionLocated { - final TValue tValue = cut.executeReturnFunction(null, null, null, Collections.emptyList(), null); + void Test_without_Param() throws EaterException { + final List empty = new ArrayList<>(); + final TValue tValue = cut.executeReturnFunction(null, null, null, empty, null); assertThat(tValue.toString()).contains("_none_", "amiga", "vibrant"); } } diff --git a/test/net/sourceforge/plantuml/tim/stdlib/GetJsonKeyTest.java b/test/net/sourceforge/plantuml/tim/stdlib/GetJsonKeyTest.java index 80635e4569d..269a3aaf3b3 100644 --- a/test/net/sourceforge/plantuml/tim/stdlib/GetJsonKeyTest.java +++ b/test/net/sourceforge/plantuml/tim/stdlib/GetJsonKeyTest.java @@ -2,20 +2,19 @@ import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput; import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput; -import static test.utils.JunitUtils.StringJsonConverter; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; import org.junit.jupiter.api.IndicativeSentencesGeneration; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.converter.ConvertWith; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.converter.ConvertWith; import org.junit.jupiter.params.provider.CsvSource; import net.sourceforge.plantuml.json.JsonValue; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TFunction; +import test.utils.JunitUtils.StringJsonConverter; /** * Tests the builtin function. @@ -28,7 +27,7 @@ class GetJsonKeyTest { @Disabled @Test - void Test_without_Param() throws EaterException, EaterExceptionLocated { + void Test_without_Param() throws EaterException { assertTimExpectedOutput(cut, "0"); } @@ -39,7 +38,7 @@ void Test_without_Param() throws EaterException, EaterExceptionLocated { " a, Not JSON data", " -1, Not JSON data", }) - void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_String(String input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } @@ -49,7 +48,7 @@ void Test_with_String(String input, String expected) throws EaterException, Eate " 0, Not JSON data", " -1, Not JSON data", }) - void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_Integer(Integer input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } @@ -67,7 +66,7 @@ void Test_with_Integer(Integer input, String expected) throws EaterException, Ea // - https://json-schema.org/understanding-json-schema/reference/array.html " '[3, \"different\", { \"types\" : \"of values\" }]', [\"types\"]", }) - void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } } diff --git a/test/net/sourceforge/plantuml/tim/stdlib/GetJsonTypeTest.java b/test/net/sourceforge/plantuml/tim/stdlib/GetJsonTypeTest.java index 0fe35543c05..6422fd8de1b 100644 --- a/test/net/sourceforge/plantuml/tim/stdlib/GetJsonTypeTest.java +++ b/test/net/sourceforge/plantuml/tim/stdlib/GetJsonTypeTest.java @@ -2,20 +2,19 @@ import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput; import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput; -import static test.utils.JunitUtils.StringJsonConverter; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; import org.junit.jupiter.api.IndicativeSentencesGeneration; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.converter.ConvertWith; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.converter.ConvertWith; import org.junit.jupiter.params.provider.CsvSource; import net.sourceforge.plantuml.json.JsonValue; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TFunction; +import test.utils.JunitUtils.StringJsonConverter; /** * Tests the builtin function. @@ -28,7 +27,7 @@ class GetJsonTypeTest { @Disabled @Test - void Test_without_Param() throws EaterException, EaterExceptionLocated { + void Test_without_Param() throws EaterException { assertTimExpectedOutput(cut, "0"); } @@ -38,7 +37,7 @@ void Test_without_Param() throws EaterException, EaterExceptionLocated { " a, string", " -1, string", }) - void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_String(String input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } @@ -47,7 +46,7 @@ void Test_with_String(String input, String expected) throws EaterException, Eate " 0, number", " -1, number", }) - void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_Integer(Integer input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } @@ -67,7 +66,7 @@ void Test_with_Integer(Integer input, String expected) throws EaterException, Ea " null , json ", " '{\"a\":[1, 2], \"b\":\"abc\", \"b\":true}' , object", }) - void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } } diff --git a/test/net/sourceforge/plantuml/tim/stdlib/GetenvTest.java b/test/net/sourceforge/plantuml/tim/stdlib/GetenvTest.java index aea38a7453f..883fa0090f5 100644 --- a/test/net/sourceforge/plantuml/tim/stdlib/GetenvTest.java +++ b/test/net/sourceforge/plantuml/tim/stdlib/GetenvTest.java @@ -9,7 +9,6 @@ import org.junit.jupiter.params.provider.ValueSource; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.expression.TValue; /** @@ -21,7 +20,6 @@ class GetenvTest { * Tests getenv should not publish plantuml.security.* environment variables. * * @throws EaterException should not - * @throws EaterExceptionLocated should not */ @ParameterizedTest @ValueSource(strings = { @@ -29,7 +27,7 @@ class GetenvTest { "plantuml.SECURITY.blabla", "plantuml.security.credentials.path", }) - void executeReturnFunctionSecurityTest(String name) throws EaterException, EaterExceptionLocated { + void executeReturnFunctionSecurityTest(String name) throws EaterException { System.setProperty("plantuml.security.blabla", "example"); Getenv cut = new Getenv(); @@ -42,14 +40,13 @@ void executeReturnFunctionSecurityTest(String name) throws EaterException, Eater * Tests getenv still returns 'good' variables. * * @throws EaterException should not - * @throws EaterExceptionLocated should not */ @ParameterizedTest @ValueSource(strings = { "path.separator", "line.separator", }) - void executeReturnFunctionTest(String name) throws EaterException, EaterExceptionLocated { + void executeReturnFunctionTest(String name) throws EaterException { Getenv cut = new Getenv(); List values = Collections.singletonList(TValue.fromString(name)); diff --git a/test/net/sourceforge/plantuml/tim/stdlib/Hex2decTest.java b/test/net/sourceforge/plantuml/tim/stdlib/Hex2decTest.java index 329347b79bd..08a33c4c7f0 100644 --- a/test/net/sourceforge/plantuml/tim/stdlib/Hex2decTest.java +++ b/test/net/sourceforge/plantuml/tim/stdlib/Hex2decTest.java @@ -6,12 +6,10 @@ import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; import org.junit.jupiter.api.IndicativeSentencesGeneration; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.converter.ConvertWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TFunction; /** @@ -24,7 +22,7 @@ class Hex2decTest { final String cutName = "Hex2dec"; @Test - void Test_without_Param() throws EaterException, EaterExceptionLocated { + void Test_without_Param() throws EaterException { assertTimExpectedOutput(cut, "0"); } @@ -44,7 +42,7 @@ void Test_without_Param() throws EaterException, EaterExceptionLocated { " -1 , -1 ", " -a , -10 ", }) - void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_String(String input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } @@ -55,7 +53,7 @@ void Test_with_String(String input, String expected) throws EaterException, Eate " 10 , 16 ", " -1 , -1 ", }) - void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_Integer(Integer input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } } diff --git a/test/net/sourceforge/plantuml/tim/stdlib/LowerTest.java b/test/net/sourceforge/plantuml/tim/stdlib/LowerTest.java index 3b50a2d3000..1488eb6417e 100644 --- a/test/net/sourceforge/plantuml/tim/stdlib/LowerTest.java +++ b/test/net/sourceforge/plantuml/tim/stdlib/LowerTest.java @@ -2,20 +2,19 @@ import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput; import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput; -import static test.utils.JunitUtils.StringJsonConverter; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; import org.junit.jupiter.api.IndicativeSentencesGeneration; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.converter.ConvertWith; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.converter.ConvertWith; import org.junit.jupiter.params.provider.CsvSource; import net.sourceforge.plantuml.json.JsonValue; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TFunction; +import test.utils.JunitUtils.StringJsonConverter; /** * Tests the builtin function. @@ -29,7 +28,7 @@ class LowerTest { // TODO: Manage Lower function without param. (today: we observe `Function not found %lower`) @Disabled @Test - void Test_without_Param() throws EaterException, EaterExceptionLocated { + void Test_without_Param() throws EaterException { assertTimExpectedOutput(cut, ""); } @@ -44,7 +43,7 @@ void Test_without_Param() throws EaterException, EaterExceptionLocated { " É , é ", " 😀 , 😀 ", }) - void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_String(String input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } @@ -55,7 +54,7 @@ void Test_with_String(String input, String expected) throws EaterException, Eate " 10 , 10 ", " -1 , -1 ", }) - void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_Integer(Integer input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } @@ -70,7 +69,7 @@ void Test_with_Integer(Integer input, String expected) throws EaterException, Ea // TODO: See JSON management of TRUE/FALSE //" TRUE , true ", }) - void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } } diff --git a/test/net/sourceforge/plantuml/tim/stdlib/OrdTest.java b/test/net/sourceforge/plantuml/tim/stdlib/OrdTest.java index 4fd0411abc2..ae2cfcd14c0 100644 --- a/test/net/sourceforge/plantuml/tim/stdlib/OrdTest.java +++ b/test/net/sourceforge/plantuml/tim/stdlib/OrdTest.java @@ -8,7 +8,6 @@ import org.junit.jupiter.params.provider.CsvSource; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TFunction; /** @@ -23,7 +22,6 @@ class OrdTest { * Tests ord according to a list of input / expected output * * @throws EaterException should not - * @throws EaterExceptionLocated should not */ @ParameterizedTest(name = "[{index}] " + cutName + "(''{0}'') = {1}") @CsvSource(nullValues = "null", value = { @@ -41,7 +39,7 @@ class OrdTest { " 😀 , 128512 ", " \uD83D\uDE00 , 128512 ", }) - void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_String(String input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } } \ No newline at end of file diff --git a/test/net/sourceforge/plantuml/tim/stdlib/RandomFuntionTest.java b/test/net/sourceforge/plantuml/tim/stdlib/RandomFuntionTest.java index c8505449ea7..f7b61cfdffc 100644 --- a/test/net/sourceforge/plantuml/tim/stdlib/RandomFuntionTest.java +++ b/test/net/sourceforge/plantuml/tim/stdlib/RandomFuntionTest.java @@ -2,15 +2,15 @@ import static org.assertj.core.api.Assertions.assertThat; +import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; +import java.util.List; import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; import org.junit.jupiter.api.IndicativeSentencesGeneration; import org.junit.jupiter.api.RepeatedTest; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TFunction; import net.sourceforge.plantuml.tim.expression.TValue; @@ -25,26 +25,29 @@ class RandomFunctionTest { final String repetitionLabel = "[{currentRepetition}/{totalRepetitions}] "; @RepeatedTest(value = 10, name = repetitionLabel + cutName + "()") - void test_with_no_argument() throws EaterException, EaterExceptionLocated { - final TValue tValue = cut.executeReturnFunction(null, null, null, Collections.emptyList(), null); + void test_with_no_argument() throws EaterException { + final List empty = new ArrayList<>(); + final TValue tValue = cut.executeReturnFunction(null, null, null, empty, null); assertThat(tValue.toInt()).isIn(0, 1); } @RepeatedTest(value = 10, name = repetitionLabel + cutName + "(7)") - void test_with_one_argument() throws EaterException, EaterExceptionLocated { + void test_with_one_argument() throws EaterException { final TValue tValue = cut.executeReturnFunction(null, null, null, Arrays.asList(TValue.fromInt(7)), null); - assertThat(tValue.toInt()).isBetween(0, 7-1); + assertThat(tValue.toInt()).isBetween(0, 7 - 1); } @RepeatedTest(value = 10, name = repetitionLabel + cutName + "(0, 7)") - void test_with_two_argument_first_zero() throws EaterException, EaterExceptionLocated { - final TValue tValue = cut.executeReturnFunction(null, null, null, Arrays.asList(TValue.fromInt(0), TValue.fromInt(7)), null); - assertThat(tValue.toInt()).isBetween(0, 7-1); + void test_with_two_argument_first_zero() throws EaterException { + final TValue tValue = cut.executeReturnFunction(null, null, null, + Arrays.asList(TValue.fromInt(0), TValue.fromInt(7)), null); + assertThat(tValue.toInt()).isBetween(0, 7 - 1); } @RepeatedTest(value = 10, name = repetitionLabel + cutName + "(3, 7)") - void test_with_two_argument() throws EaterException, EaterExceptionLocated { - final TValue tValue = cut.executeReturnFunction(null, null, null, Arrays.asList(TValue.fromInt(3), TValue.fromInt(7)), null); - assertThat(tValue.toInt()).isBetween(3, 7-1); + void test_with_two_argument() throws EaterException { + final TValue tValue = cut.executeReturnFunction(null, null, null, + Arrays.asList(TValue.fromInt(3), TValue.fromInt(7)), null); + assertThat(tValue.toInt()).isBetween(3, 7 - 1); } } \ No newline at end of file diff --git a/test/net/sourceforge/plantuml/tim/stdlib/SizeTest.java b/test/net/sourceforge/plantuml/tim/stdlib/SizeTest.java index 6bcfd105e10..1763537baa8 100644 --- a/test/net/sourceforge/plantuml/tim/stdlib/SizeTest.java +++ b/test/net/sourceforge/plantuml/tim/stdlib/SizeTest.java @@ -2,20 +2,19 @@ import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput; import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput; -import static test.utils.JunitUtils.StringJsonConverter; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; import org.junit.jupiter.api.IndicativeSentencesGeneration; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.converter.ConvertWith; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.converter.ConvertWith; import org.junit.jupiter.params.provider.CsvSource; import net.sourceforge.plantuml.json.JsonValue; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TFunction; +import test.utils.JunitUtils.StringJsonConverter; /** * Tests the builtin function. @@ -29,7 +28,7 @@ class SizeTest { // TODO: Manage `Size` function without param. (today: we observe `Function not found`) @Disabled @Test - void Test_without_Param() throws EaterException, EaterExceptionLocated { + void Test_without_Param() throws EaterException { assertTimExpectedOutput(cut, "0"); } @@ -48,7 +47,7 @@ void Test_without_Param() throws EaterException, EaterExceptionLocated { // " 😀 , 1 ", // " \uD83D\uDE00 , 1", }) - void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_String(String input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } @@ -58,7 +57,7 @@ void Test_with_String(String input, String expected) throws EaterException, Eate " 1 , 0 ", " 10 , 0 ", }) - void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_Integer(Integer input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } @@ -75,7 +74,7 @@ void Test_with_Integer(Integer input, String expected) throws EaterException, Ea " 1, 0 ", " null, 0 ", }) - void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } } diff --git a/test/net/sourceforge/plantuml/tim/stdlib/UpperTest.java b/test/net/sourceforge/plantuml/tim/stdlib/UpperTest.java index 35c1e2e8738..5db56f0e975 100644 --- a/test/net/sourceforge/plantuml/tim/stdlib/UpperTest.java +++ b/test/net/sourceforge/plantuml/tim/stdlib/UpperTest.java @@ -2,20 +2,19 @@ import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput; import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput; -import static test.utils.JunitUtils.StringJsonConverter; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; import org.junit.jupiter.api.IndicativeSentencesGeneration; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.converter.ConvertWith; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.converter.ConvertWith; import org.junit.jupiter.params.provider.CsvSource; import net.sourceforge.plantuml.json.JsonValue; import net.sourceforge.plantuml.tim.EaterException; -import net.sourceforge.plantuml.tim.EaterExceptionLocated; import net.sourceforge.plantuml.tim.TFunction; +import test.utils.JunitUtils.StringJsonConverter; /** * Tests the builtin function. @@ -29,7 +28,7 @@ class UpperTest { // TODO: Manage Upper function without param. (today: we observe `Function not found %upper`) @Disabled @Test - void Test_without_Param() throws EaterException, EaterExceptionLocated { + void Test_without_Param() throws EaterException { assertTimExpectedOutput(cut, ""); } @@ -44,7 +43,7 @@ void Test_without_Param() throws EaterException, EaterExceptionLocated { " é , É ", " 😀 , 😀 ", }) - void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_String(String input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } @@ -55,7 +54,7 @@ void Test_with_String(String input, String expected) throws EaterException, Eate " 10 , 10 ", " -1 , -1 ", }) - void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_Integer(Integer input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } @@ -66,7 +65,7 @@ void Test_with_Integer(Integer input, String expected) throws EaterException, Ea " '{\"a\":[1, 2], \"b\":\"abc\", \"b\":true}' , '{\"A\":[1,2],\"B\":\"ABC\",\"B\":TRUE}'", " true , TRUE ", }) - void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException, EaterExceptionLocated { + void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException { assertTimExpectedOutputFromInput(cut, input, expected); } }