From 33d96429f417f563fbbcb3e73d6ea2a7695fd713 Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Sat, 26 Aug 2023 11:56:14 +0300 Subject: [PATCH] remove formatted --- .../topchetoeu/jscript/engine/values/Values.java | 2 +- .../jscript/exceptions/SyntaxException.java | 2 +- src/me/topchetoeu/jscript/json/JSONMap.java | 10 +++++----- src/me/topchetoeu/jscript/parsing/Parsing.java | 14 +++++++------- .../jscript/polyfills/PolyfillEngine.java | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/me/topchetoeu/jscript/engine/values/Values.java b/src/me/topchetoeu/jscript/engine/values/Values.java index fd5bcf3..4f4b967 100644 --- a/src/me/topchetoeu/jscript/engine/values/Values.java +++ b/src/me/topchetoeu/jscript/engine/values/Values.java @@ -426,7 +426,7 @@ public class Values { if (clazz == Void.class) return null; if (clazz == null || clazz == Object.class) return (T)obj; - var err = new IllegalArgumentException("Cannot convert '%s' to '%s'.".formatted(type(obj), clazz.getName())); + var err = new IllegalArgumentException(String.format("Cannot convert '%s' to '%s'.", type(obj), clazz.getName())); if (obj instanceof NativeWrapper) { var res = ((NativeWrapper)obj).wrapped; diff --git a/src/me/topchetoeu/jscript/exceptions/SyntaxException.java b/src/me/topchetoeu/jscript/exceptions/SyntaxException.java index 0fef28b..98d8d0b 100644 --- a/src/me/topchetoeu/jscript/exceptions/SyntaxException.java +++ b/src/me/topchetoeu/jscript/exceptions/SyntaxException.java @@ -7,7 +7,7 @@ public class SyntaxException extends RuntimeException { public final String msg; public SyntaxException(Location loc, String msg) { - super("Syntax error (at %s): %s".formatted(loc, msg)); + super(String.format("Syntax error (at %s): %s", loc, msg)); this.loc = loc; this.msg = msg; } diff --git a/src/me/topchetoeu/jscript/json/JSONMap.java b/src/me/topchetoeu/jscript/json/JSONMap.java index 9f805c5..203adaf 100644 --- a/src/me/topchetoeu/jscript/json/JSONMap.java +++ b/src/me/topchetoeu/jscript/json/JSONMap.java @@ -51,7 +51,7 @@ public class JSONMap implements Map { public JSONMap map(String path) { var el = get(path); - if (el == null) throw new IllegalStateException("'%s' doesn't exist.".formatted(path)); + if (el == null) throw new IllegalStateException(String.format("'%s' doesn't exist.", path)); return el.map(); } public JSONMap map(String path, JSONMap defaultVal) { @@ -63,7 +63,7 @@ public class JSONMap implements Map { public JSONList list(String path) { var el = get(path); - if (el == null) throw new IllegalStateException("'%s' doesn't exist.".formatted(path)); + if (el == null) throw new IllegalStateException(String.format("'%s' doesn't exist.", path)); return el.list(); } public JSONList list(String path, JSONList defaultVal) { @@ -75,7 +75,7 @@ public class JSONMap implements Map { public String string(String path) { var el = get(path); - if (el == null) throw new IllegalStateException("'%s' doesn't exist.".formatted(path)); + if (el == null) throw new IllegalStateException(String.format("'%s' doesn't exist.", path)); return el.string(); } public String string(String path, String defaultVal) { @@ -87,7 +87,7 @@ public class JSONMap implements Map { public double number(String path) { var el = get(path); - if (el == null) throw new IllegalStateException("'%s' doesn't exist.".formatted(path)); + if (el == null) throw new IllegalStateException(String.format("'%s' doesn't exist.", path)); return el.number(); } public double number(String path, double defaultVal) { @@ -99,7 +99,7 @@ public class JSONMap implements Map { public boolean bool(String path) { var el = get(path); - if (el == null) throw new IllegalStateException("'%s' doesn't exist.".formatted(path)); + if (el == null) throw new IllegalStateException(String.format("'%s' doesn't exist.", path)); return el.bool(); } public boolean bool(String path, boolean defaultVal) { diff --git a/src/me/topchetoeu/jscript/parsing/Parsing.java b/src/me/topchetoeu/jscript/parsing/Parsing.java index 2c2b0ca..2a22195 100644 --- a/src/me/topchetoeu/jscript/parsing/Parsing.java +++ b/src/me/topchetoeu/jscript/parsing/Parsing.java @@ -374,7 +374,7 @@ public class Parsing { currStage = CURR_STRING; continue; } - else throw new SyntaxException(new Location(line, start, filename), "Unrecognized character %s.".formatted(c)); + else throw new SyntaxException(new Location(line, start, filename), String.format("Unrecognized character %s.", c)); } // if we got here, we know that we have encountered the end of a token @@ -542,7 +542,7 @@ public class Parsing { else res.add(Token.number(el.line, el.start, Double.parseDouble(el.value))); break; case OPERATOR: Operator op = Operator.parse(el.value); - if (op == null) throw new SyntaxException(loc, "Unrecognized operator '%s'.".formatted(el.value)); + if (op == null) throw new SyntaxException(loc, String.format("Unrecognized operator '%s'.", el.value)); res.add(Token.operator(el.line, el.start, op)); break; case STRING: @@ -959,7 +959,7 @@ public class Parsing { var res = parseValue(filename, tokens, n + i, 14); if (res.isSuccess()) return ParseRes.res(new OperationStatement(loc, operation, res.result), n + res.n); - else return ParseRes.error(loc, "Expected a value after the unary operator '%s'.".formatted(op.value), res); + else return ParseRes.error(loc, String.format("Expected a value after the unary operator '%s'.", op.value), res); } public static ParseRes parsePrefixChange(String filename, List tokens, int i) { var loc = getLoc(filename, tokens, i); @@ -1029,7 +1029,7 @@ public class Parsing { if (literal.result.equals("async")) return ParseRes.error(loc, "'async' is not supported."); if (literal.result.equals("const")) return ParseRes.error(loc, "'const' declarations are not supported."); if (literal.result.equals("let")) return ParseRes.error(loc, "'let' declarations are not supported."); - return ParseRes.error(loc, "Unexpected identifier '%s'.".formatted(literal.result)); + return ParseRes.error(loc, String.format("Unexpected identifier '%s'.", literal.result)); } return ParseRes.res(new VariableStatement(loc, literal.result), 1); @@ -1106,7 +1106,7 @@ public class Parsing { if (!(prev instanceof AssignableStatement)) return ParseRes.error(loc, "Invalid expression on left hand side of assign operator."); var res = parseValue(filename, tokens, i + n, 2); - if (!res.isSuccess()) return ParseRes.error(loc, "Expected value after assignment operator '%s'.".formatted(op.value), res); + if (!res.isSuccess()) return ParseRes.error(loc, String.format("Expected value after assignment operator '%s'.", op.value), res); n += res.n; Operation operation = null; @@ -1245,7 +1245,7 @@ public class Parsing { if (op.isAssign()) return parseAssign(filename, tokens, i + n - 1, prev, precedence); var res = parseValue(filename, tokens, i + n, op.precedence + (op.reverse ? 0 : 1)); - if (!res.isSuccess()) return ParseRes.error(loc, "Expected a value after the '%s' operator.".formatted(op.value), res); + if (!res.isSuccess()) return ParseRes.error(loc, String.format("Expected a value after the '%s' operator.", op.value), res); n += res.n; if (op == Operator.LAZY_AND) { @@ -1337,7 +1337,7 @@ public class Parsing { if (!nameRes.isSuccess()) return ParseRes.error(loc, "Expected a variable name."); if (!checkVarName(nameRes.result)) { - return ParseRes.error(loc, "Unexpected identifier '%s'.".formatted(nameRes.result)); + return ParseRes.error(loc, String.format("Unexpected identifier '%s'.", nameRes.result)); } Statement val = null; diff --git a/src/me/topchetoeu/jscript/polyfills/PolyfillEngine.java b/src/me/topchetoeu/jscript/polyfills/PolyfillEngine.java index 19cde7e..07fa886 100644 --- a/src/me/topchetoeu/jscript/polyfills/PolyfillEngine.java +++ b/src/me/topchetoeu/jscript/polyfills/PolyfillEngine.java @@ -73,7 +73,7 @@ public class PolyfillEngine extends Engine { return Values.call(ctx, values[0], ctx); } finally { - System.out.println("Function took %s ms".formatted((System.nanoTime() - start) / 1000000.)); + System.out.println(String.format("Function took %s ms", (System.nanoTime() - start) / 1000000.)); } })); global().define(true, new NativeFunction("isNaN", (ctx, thisArg, args) -> {