You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by jt...@apache.org on 2020/12/21 13:12:27 UTC
[netbeans-html4j] 01/02: Applying the NetBeans Convert to Text
Block refactoring
This is an automated email from the ASF dual-hosted git repository.
jtulach pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans-html4j.git
commit 784196d98b3e61fe75a5988597b75cd5119a27c9
Author: Jaroslav Tulach <ja...@oracle.com>
AuthorDate: Fri Nov 13 10:30:00 2020 +0100
Applying the NetBeans Convert to Text Block refactoring
---
.../netbeans/html/boot/fx/AbstractFXPresenter.java | 21 +-
.../java/org/netbeans/html/boot/fx/FXConsole.java | 11 +-
.../html/boot/script/Jsr223JavaScriptTest.java | 28 +-
.../java/html/boot/script/KnockoutEnvJSTest.java | 7 +-
.../org/netbeans/html/boot/impl/JsCallback.java | 15 +-
.../html/boot/impl/JavaScriptProcesorTest.java | 187 +++---
.../netbeans/html/boot/impl/JsCallbackTest.java | 8 +-
.../org/netbeans/html/boot/impl/JsMethods.java | 28 +-
.../java/org/netbeans/html/boot/impl/JsUtils.java | 27 +-
.../presenters/browser/JavaScriptUtilities.java | 11 +-
.../org/netbeans/html/presenters/spi/Generic.java | 211 +++---
.../org/netbeans/html/geo/impl/JsGLProvider.java | 36 +-
.../netbeans/html/geo/impl/GeoProcessorTest.java | 69 +-
json-tck/pom.xml | 8 -
.../main/java/net/java/html/js/tests/Bodies.java | 151 +++--
.../java/net/java/html/js/tests/Factorial.java | 7 +-
.../main/java/net/java/html/js/tests/Receiver.java | 8 +-
.../src/main/java/net/java/html/js/tests/Sum.java | 20 +-
.../net/java/html/json/tests/GCKnockoutTest.java | 36 +-
.../net/java/html/json/tests/KnockoutTest.java | 306 ++++-----
.../java/net/java/html/json/tests/MinesTest.java | 49 +-
.../main/java/net/java/html/json/tests/Utils.java | 79 +--
.../netbeans/html/json/impl/ModelProcessor.java | 68 +-
.../net/java/html/json/ModelProcessorTest.java | 710 +++++++++++----------
.../html/ko/felix/test/KnockoutFelixTCKImpl.java | 11 +-
.../html/ko/osgi/test/KnockoutEquinoxTCKImpl.java | 11 +-
.../java/org/netbeans/html/wstyrus/LoadJSON.java | 11 +-
.../netbeans/html/wstyrus/TyrusKnockoutTest.java | 11 +-
.../main/java/org/netbeans/html/ko4j/Knockout.java | 234 +++----
.../main/java/org/netbeans/html/ko4j/LoadJSON.java | 88 +--
.../main/java/org/netbeans/html/ko4j/LoadWS.java | 59 +-
.../org/netbeans/html/ko4j/KnockoutFXTest.java | 11 +-
pom.xml | 7 +-
.../html/presenters/webkit/GtkKnockoutTest.java | 11 +-
.../java/org/netbeans/html/xhr4j/LoadJSON.java | 24 +-
.../org/netbeans/html/xhr4j/JsonKnockoutTest.java | 11 +-
36 files changed, 1358 insertions(+), 1232 deletions(-)
diff --git a/boot-fx/src/main/java/org/netbeans/html/boot/fx/AbstractFXPresenter.java b/boot-fx/src/main/java/org/netbeans/html/boot/fx/AbstractFXPresenter.java
index 4811a17..aafd3eb 100644
--- a/boot-fx/src/main/java/org/netbeans/html/boot/fx/AbstractFXPresenter.java
+++ b/boot-fx/src/main/java/org/netbeans/html/boot/fx/AbstractFXPresenter.java
@@ -218,16 +218,17 @@ Fn.KeepAlive, Fn.ToJavaScript, Fn.FromJavaScript, Executor, Cloneable, Fn.Ref<Ab
JSObject createPOJOWrapper(int hash, int id) {
if (newPOJOImpl == null) {
try {
- newPOJOImpl = (JSObject) defineJSFn(
- "var k = {};\n" +
- "k.fxBrwsrId = function(hash, id) {\n" +
- " var obj = {};\n" +
- " Object.defineProperty(obj, 'fxBrwsrId', {\n" +
- " value : function(callback) { callback.hashAndId(hash, id) }\n" +
- " });\n" +
- " return obj;\n" +
- "};\n" +
- "return k;\n", new String[] { "callback" }, null
+ newPOJOImpl = (JSObject) defineJSFn("""
+ var k = {};
+ k.fxBrwsrId = function(hash, id) {
+ var obj = {};
+ Object.defineProperty(obj, 'fxBrwsrId', {
+ value : function(callback) { callback.hashAndId(hash, id) }
+ });
+ return obj;
+ };
+ return k;
+ """, new String[] { "callback" }, null
).invokeImpl(null, false);
} catch (Exception ex) {
throw new IllegalStateException(ex);
diff --git a/boot-fx/src/main/java/org/netbeans/html/boot/fx/FXConsole.java b/boot-fx/src/main/java/org/netbeans/html/boot/fx/FXConsole.java
index 8da7481..beb472e 100644
--- a/boot-fx/src/main/java/org/netbeans/html/boot/fx/FXConsole.java
+++ b/boot-fx/src/main/java/org/netbeans/html/boot/fx/FXConsole.java
@@ -52,12 +52,11 @@ public final class FXConsole implements ChangeListener<String> {
}
void register(WebEngine eng) {
- JSObject fn = (JSObject) eng.executeScript(""
- + "(function(attr, l, FXConsole) {\n"
- + " window.console[attr] = function(msg) {\n"
- + " FXConsole.log(l, msg);\n"
- + " };"
- + "})"
+ JSObject fn = (JSObject) eng.executeScript("""
+ (function(attr, l, FXConsole) {
+ window.console[attr] = function(msg) {
+ FXConsole.log(l, msg);
+ };})"""
);
registerImpl(fn, "log", Level.INFO);
registerImpl(fn, "info", Level.INFO);
diff --git a/boot-script/src/test/java/net/java/html/boot/script/Jsr223JavaScriptTest.java b/boot-script/src/test/java/net/java/html/boot/script/Jsr223JavaScriptTest.java
index d21cbbd..e37fdb2 100644
--- a/boot-script/src/test/java/net/java/html/boot/script/Jsr223JavaScriptTest.java
+++ b/boot-script/src/test/java/net/java/html/boot/script/Jsr223JavaScriptTest.java
@@ -92,20 +92,20 @@ public class Jsr223JavaScriptTest {
}
private static void assertNoGlobalSymbolsLeft(ScriptEngine engine) throws ScriptException {
- Object left = engine.eval(
- "(function() {\n" +
- " var names = Object.getOwnPropertyNames(this);\n" +
- " for (var i = 0; i < names.length; i++) {\n" +
- " var n = names[i];\n" +
- " if (n === 'Object') continue;\n" +
- " if (n === 'Number') continue;\n" +
- " if (n === 'Boolean') continue;\n" +
- " if (n === 'Array') continue;\n" +
- " delete this[n];\n" +
- " }\n" +
- " return Object.getOwnPropertyNames(this).toString();\n" +
- "})()\n" +
- ""
+ Object left = engine.eval("""
+ (function() {
+ var names = Object.getOwnPropertyNames(this);
+ for (var i = 0; i < names.length; i++) {
+ var n = names[i];
+ if (n === 'Object') continue;
+ if (n === 'Number') continue;
+ if (n === 'Boolean') continue;
+ if (n === 'Array') continue;
+ delete this[n];
+ }
+ return Object.getOwnPropertyNames(this).toString();
+ })()
+ """
);
assertEquals(left.toString().toLowerCase().indexOf("java"), -1, "No Java symbols " + left);
}
diff --git a/boot-script/src/test/java/net/java/html/boot/script/KnockoutEnvJSTest.java b/boot-script/src/test/java/net/java/html/boot/script/KnockoutEnvJSTest.java
index 6316f10..24b132c 100644
--- a/boot-script/src/test/java/net/java/html/boot/script/KnockoutEnvJSTest.java
+++ b/boot-script/src/test/java/net/java/html/boot/script/KnockoutEnvJSTest.java
@@ -221,9 +221,10 @@ public final class KnockoutEnvJSTest extends KnockoutTCK {
private static native void setProperty(Object json, String key, Object value);
@Override
- @JavaScriptBody(args = { "s", "args" }, body = "\n"
- + "var f = new Function(s);\n"
- + "return f.apply(null, args);\n"
+ @JavaScriptBody(args = { "s", "args" }, body = """
+ var f = new Function(s);
+ return f.apply(null, args);
+ """
)
public native Object executeScript(String script, Object[] arguments);
diff --git a/boot/src/main/java/org/netbeans/html/boot/impl/JsCallback.java b/boot/src/main/java/org/netbeans/html/boot/impl/JsCallback.java
index 237c867..ca5b5dd 100644
--- a/boot/src/main/java/org/netbeans/html/boot/impl/JsCallback.java
+++ b/boot/src/main/java/org/netbeans/html/boot/impl/JsCallback.java
@@ -50,8 +50,9 @@ abstract class JsCallback {
int colon4 = body.indexOf("::", next);
if (sigBeg == -1 || sigEnd == -1 || colon4 == -1) {
throw new IllegalStateException(
- "Wrong format of instance callback. "
- + "Should be: 'inst.@pkg.Class::method(Ljava/lang/Object;)(param)':\n"
+ """
+ Wrong format of instance callback. Should be: 'inst.@pkg.Class::method(Ljava/lang/Object;)(param)':
+ """
+ body
);
}
@@ -62,8 +63,9 @@ abstract class JsCallback {
int paramBeg = body.indexOf('(', sigEnd + 1);
if (paramBeg == -1) {
throw new IllegalStateException(
- "Wrong format of instance callback. "
- + "Should be: 'inst.@pkg.Class::method(Ljava/lang/Object;)(param)':\n"
+ """
+ Wrong format of instance callback. Should be: 'inst.@pkg.Class::method(Ljava/lang/Object;)(param)':
+ """
+ body
);
}
@@ -97,8 +99,9 @@ abstract class JsCallback {
int paramBeg = body.indexOf('(', sigEnd + 1);
if (sigBeg == -1 || sigEnd == -1 || colon4 == -1 || paramBeg == -1) {
throw new IllegalStateException(
- "Wrong format of static callback. "
- + "Should be: '@pkg.Class::staticMethod(Ljava/lang/Object;)(param)':\n"
+ """
+ Wrong format of static callback. Should be: '@pkg.Class::staticMethod(Ljava/lang/Object;)(param)':
+ """
+ body
);
}
diff --git a/boot/src/test/java/org/netbeans/html/boot/impl/JavaScriptProcesorTest.java b/boot/src/test/java/org/netbeans/html/boot/impl/JavaScriptProcesorTest.java
index a05a600..632fcde 100644
--- a/boot/src/test/java/org/netbeans/html/boot/impl/JavaScriptProcesorTest.java
+++ b/boot/src/test/java/org/netbeans/html/boot/impl/JavaScriptProcesorTest.java
@@ -37,14 +37,17 @@ import org.testng.annotations.Test;
public class JavaScriptProcesorTest {
@Test public void detectCallbackToNonExistingClass() throws IOException {
- String code = "package x.y.z;\n"
- + "import net.java.html.js.JavaScriptBody;\n"
- + "class X {\n"
- + " @JavaScriptBody(args={\"r\"}, javacall=true, body =\n"
- + " \"r.@java.lang.Runable::run()();\"\n" // typo
- + " )\n"
- + " private static native void callback(Runnable r);\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.js.JavaScriptBody;
+ class X {
+ @JavaScriptBody(args={"r"}, javacall=true, body =
+ "r.@java.lang.Runable::run()();"
+ )
+ private static native void callback(Runnable r);
+ }
+ """ // typo
+ ;
Compile c = Compile.create("", code);
c.assertErrors();
@@ -52,14 +55,16 @@ public class JavaScriptProcesorTest {
}
@Test public void detectCallbackToNonExistingMethod() throws IOException {
- String code = "package x.y.z;\n"
- + "import net.java.html.js.JavaScriptBody;\n"
- + "class X {\n"
- + " @JavaScriptBody(args={\"r\"}, javacall=true, body =\n"
- + " \"r.@java.lang.Runnable::cancel()();\"\n"
- + " )\n"
- + " private static native void callback(Runnable r);\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.js.JavaScriptBody;
+ class X {
+ @JavaScriptBody(args={"r"}, javacall=true, body =
+ "r.@java.lang.Runnable::cancel()();"
+ )
+ private static native void callback(Runnable r);
+ }
+ """;
Compile c = Compile.create("", code);
c.assertErrors();
@@ -67,14 +72,16 @@ public class JavaScriptProcesorTest {
}
@Test public void detectCallbackToNonExistingParams() throws IOException {
- String code = "package x.y.z;\n"
- + "import net.java.html.js.JavaScriptBody;\n"
- + "class X {\n"
- + " @JavaScriptBody(args={\"r\"}, javacall=true, body =\n"
- + " \"r.@java.lang.Runnable::run(I)(10);\"\n"
- + " )\n"
- + " private static native void callback(Runnable r);\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.js.JavaScriptBody;
+ class X {
+ @JavaScriptBody(args={"r"}, javacall=true, body =
+ "r.@java.lang.Runnable::run(I)(10);"
+ )
+ private static native void callback(Runnable r);
+ }
+ """;
Compile c = Compile.create("", code);
c.assertErrors();
@@ -82,28 +89,32 @@ public class JavaScriptProcesorTest {
}
@Test public void objectTypeParamsAreOK() throws IOException {
- String code = "package x.y.z;\n"
- + "import net.java.html.js.JavaScriptBody;\n"
- + "class X {\n"
- + " @JavaScriptBody(args={\"r\"}, javacall=true, body =\n"
- + " \"r.@java.lang.Object::equals(Ljava/lang/Object;)(null);\"\n"
- + " )\n"
- + " private static native void testEqual(Object r);\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.js.JavaScriptBody;
+ class X {
+ @JavaScriptBody(args={"r"}, javacall=true, body =
+ "r.@java.lang.Object::equals(Ljava/lang/Object;)(null);"
+ )
+ private static native void testEqual(Object r);
+ }
+ """;
Compile c = Compile.create("", code);
c.assertNoErrors();
}
@Test public void primitiveArrayGeneratesAnError() throws IOException {
- String code = "package x.y.z;\n"
- + "import net.java.html.js.JavaScriptBody;\n"
- + "class X {\n"
- + " @JavaScriptBody(args={\"r\"}, body =\n"
- + " \"return [ 1, 2 ];\"\n"
- + " )\n"
- + " private static native double[] returnPrimitive(Object r);\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.js.JavaScriptBody;
+ class X {
+ @JavaScriptBody(args={"r"}, body =
+ "return [ 1, 2 ];"
+ )
+ private static native double[] returnPrimitive(Object r);
+ }
+ """;
Compile c = Compile.create("", code);
c.assertErrors();
@@ -111,14 +122,16 @@ public class JavaScriptProcesorTest {
}
@Test public void nonObjectArrayGeneratesAnError() throws IOException {
- String code = "package x.y.z;\n"
- + "import net.java.html.js.JavaScriptBody;\n"
- + "class X {\n"
- + " @JavaScriptBody(args={\"r\"}, body =\n"
- + " \"return [ 1, 2 ];\"\n"
- + " )\n"
- + " private static native Double[] returnPrimitive(Object r);\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.js.JavaScriptBody;
+ class X {
+ @JavaScriptBody(args={"r"}, body =
+ "return [ 1, 2 ];"
+ )
+ private static native Double[] returnPrimitive(Object r);
+ }
+ """;
Compile c = Compile.create("", code);
c.assertErrors();
@@ -126,17 +139,19 @@ public class JavaScriptProcesorTest {
}
@Test public void primitiveArrayCallbackGeneratesAnError() throws IOException {
- String code = "package x.y.z;\n"
- + "import net.java.html.js.JavaScriptBody;\n"
- + "class X {\n"
- + " @JavaScriptBody(args={\"r\"}, javacall = true, body =\n"
- + " \"return @x.y.z.X::acceptDouble([D)([ 1, 2 ]);\"\n"
- + " )\n"
- + " private static native Object[] returnPrimitive(Object r);\n"
- + " static double[] acceptDouble(double[] arr) {\n"
- + " return arr;\n"
- + " }\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.js.JavaScriptBody;
+ class X {
+ @JavaScriptBody(args={"r"}, javacall = true, body =
+ "return @x.y.z.X::acceptDouble([D)([ 1, 2 ]);"
+ )
+ private static native Object[] returnPrimitive(Object r);
+ static double[] acceptDouble(double[] arr) {
+ return arr;
+ }
+ }
+ """;
Compile c = Compile.create("", code);
c.assertErrors();
@@ -144,17 +159,19 @@ public class JavaScriptProcesorTest {
}
@Test public void nonObjectArrayCallbackGeneratesAnError() throws IOException {
- String code = "package x.y.z;\n"
- + "import net.java.html.js.JavaScriptBody;\n"
- + "class X {\n"
- + " @JavaScriptBody(args={\"r\"}, javacall = true, body =\n"
- + " \"return @x.y.z.X::acceptDouble([Ljava/lang/Double;)([ 1, 2 ]);\"\n"
- + " )\n"
- + " private static native Object[] returnPrimitive(Object r);\n"
- + " static Double[] acceptDouble(Double[] arr) {\n"
- + " return arr;\n"
- + " }\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.js.JavaScriptBody;
+ class X {
+ @JavaScriptBody(args={"r"}, javacall = true, body =
+ "return @x.y.z.X::acceptDouble([Ljava/lang/Double;)([ 1, 2 ]);"
+ )
+ private static native Object[] returnPrimitive(Object r);
+ static Double[] acceptDouble(Double[] arr) {
+ return arr;
+ }
+ }
+ """;
Compile c = Compile.create("", code);
c.assertErrors();
@@ -162,13 +179,15 @@ public class JavaScriptProcesorTest {
}
@Test public void misorderNotified() throws IOException {
- String code = "package x.y.z;\n"
- + "import net.java.html.js.JavaScriptBody;\n"
- + "class X {\n"
- + " @JavaScriptBody(args={\"r\", \"a\", \"b\"}, body =\"\"\n"
- + " )\n"
- + " private static native void testEqual(Object p, String q, int r);\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.js.JavaScriptBody;
+ class X {
+ @JavaScriptBody(args={"r", "a", "b"}, body =""
+ )
+ private static native void testEqual(Object p, String q, int r);
+ }
+ """;
Compile c = Compile.create("", code);
List<Diagnostic<? extends JavaFileObject>> warnings = c.getDiagnostics(Diagnostic.Kind.WARNING);
@@ -182,12 +201,14 @@ public class JavaScriptProcesorTest {
}
@Test public void needJavaScriptBodyToUseResource() throws IOException {
- String code = "package x.y.z;\n"
- + "import net.java.html.js.JavaScriptResource;\n"
- + "@JavaScriptResource(\"x.html\")\n"
- + "class X {\n"
- + " private static native void callback(Runnable r);\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.js.JavaScriptResource;
+ @JavaScriptResource("x.html")
+ class X {
+ private static native void callback(Runnable r);
+ }
+ """;
Compile c = Compile.create("", code);
c.assertErrors();
diff --git a/boot/src/test/java/org/netbeans/html/boot/impl/JsCallbackTest.java b/boot/src/test/java/org/netbeans/html/boot/impl/JsCallbackTest.java
index 5860103..7a30e5a 100644
--- a/boot/src/test/java/org/netbeans/html/boot/impl/JsCallbackTest.java
+++ b/boot/src/test/java/org/netbeans/html/boot/impl/JsCallbackTest.java
@@ -30,9 +30,11 @@ public class JsCallbackTest {
public JsCallbackTest() {
}
@Test public void missingTypeSpecification() {
- String body = "console[attr] = function(msg) {\n"
- + " @org.netbeans.html.charts.Main::log(msg);\n"
- + "};\n";
+ String body = """
+ console[attr] = function(msg) {
+ @org.netbeans.html.charts.Main::log(msg);
+ };
+ """;
JsCallback instance = new JsCallbackImpl();
try {
String result = instance.parse(body);
diff --git a/boot/src/test/java/org/netbeans/html/boot/impl/JsMethods.java b/boot/src/test/java/org/netbeans/html/boot/impl/JsMethods.java
index f5b2fe0..18a5530 100644
--- a/boot/src/test/java/org/netbeans/html/boot/impl/JsMethods.java
+++ b/boot/src/test/java/org/netbeans/html/boot/impl/JsMethods.java
@@ -59,11 +59,12 @@ public class JsMethods {
public static native void callback(Runnable r);
@JavaScriptBody(args = { "at", "arr" }, javacall = true, body =
- "var a = 0;\n"
- + "for (var i = 0; i < arr.length; i++) {\n"
- + " a = at.@org.netbeans.html.boot.impl.Arithm::sumTwo(II)(a, arr[i]);\n"
- + "}\n"
- + "return a;"
+ """
+ var a = 0;
+ for (var i = 0; i < arr.length; i++) {
+ a = at.@org.netbeans.html.boot.impl.Arithm::sumTwo(II)(a, arr[i]);
+ }
+ return a;"""
)
private static native int sumTwo(Arithm at, int... arr);
@@ -72,9 +73,11 @@ public class JsMethods {
}
@JavaScriptBody(args = {"r"}, javacall = true, body =
- "var array = new Array();\n"
- + "array[0]=1; array[1]=2;\n"
- + "return r.@org.netbeans.html.boot.impl.Arithm::sumArr([Ljava/lang/Object;)(array);\n"
+ """
+ var array = new Array();
+ array[0]=1; array[1]=2;
+ return r.@org.netbeans.html.boot.impl.Arithm::sumArr([Ljava/lang/Object;)(array);
+ """
)
private static native int sumArr(Arithm r);
@@ -100,10 +103,11 @@ public class JsMethods {
@JavaScriptBody(args = "arr", body = "return arr;")
public static native java.lang.Object[] arr(java.lang.Object[] arr);
- @JavaScriptBody(args = { "useA", "useB", "a", "b" }, body = "var l = 0;"
- + "if (useA) l += a;\n"
- + "if (useB) l += b;\n"
- + "return l;\n"
+ @JavaScriptBody(args = { "useA", "useB", "a", "b" }, body = """
+ var l = 0;if (useA) l += a;
+ if (useB) l += b;
+ return l;
+ """
)
public static native long chooseLong(boolean useA, boolean useB, long a, long b);
diff --git a/boot/src/test/java/org/netbeans/html/boot/impl/JsUtils.java b/boot/src/test/java/org/netbeans/html/boot/impl/JsUtils.java
index 961ae33..170d407 100644
--- a/boot/src/test/java/org/netbeans/html/boot/impl/JsUtils.java
+++ b/boot/src/test/java/org/netbeans/html/boot/impl/JsUtils.java
@@ -31,19 +31,20 @@ final class JsUtils {
Bindings bindings = eng.getBindings(ScriptContext.ENGINE_SCOPE);
bindings.put("polyglot.js.allowHostAccess", true); // NOI18N
- eng.eval("function checkArray(arr, to) {\n"
- + " if (to === null) {\n"
- + " if (Object.prototype.toString.call(arr) === '[object Array]') return arr.length;\n"
- + " else return -1;\n"
- + " } else {\n"
- + " var l = arr.length;\n"
- + " for (var i = 0; i < l; i++) {\n"
- + " to[i] = arr[i] === undefined ? null : arr[i];\n"
- + " }\n"
- + " return l;\n"
- + " }\n"
- + "}\n"
- );
+ eng.eval("""
+ function checkArray(arr, to) {
+ if (to === null) {
+ if (Object.prototype.toString.call(arr) === '[object Array]') return arr.length;
+ else return -1;
+ } else {
+ var l = arr.length;
+ for (var i = 0; i < l; i++) {
+ to[i] = arr[i] === undefined ? null : arr[i];
+ }
+ return l;
+ }
+ }
+ """);
return eng;
}
diff --git a/browser/src/test/java/org/netbeans/html/presenters/browser/JavaScriptUtilities.java b/browser/src/test/java/org/netbeans/html/presenters/browser/JavaScriptUtilities.java
index 0d8b979..62d7bfe 100644
--- a/browser/src/test/java/org/netbeans/html/presenters/browser/JavaScriptUtilities.java
+++ b/browser/src/test/java/org/netbeans/html/presenters/browser/JavaScriptUtilities.java
@@ -25,12 +25,11 @@ final class JavaScriptUtilities {
}
@JavaScriptBody(args = { }, body =
- "var h;"
- + "if (!!window && !!window.location && !!window.location.href)\n"
- + " h = window.location.href;\n"
- + "else "
- + " h = null;"
- + "return h;\n"
+ """
+ var h;if (!!window && !!window.location && !!window.location.href)
+ h = window.location.href;
+ else h = null;return h;
+ """
)
static native String findBaseURL();
diff --git a/generic/src/main/java/org/netbeans/html/presenters/spi/Generic.java b/generic/src/main/java/org/netbeans/html/presenters/spi/Generic.java
index 8a67799..ea2decc 100644
--- a/generic/src/main/java/org/netbeans/html/presenters/spi/Generic.java
+++ b/generic/src/main/java/org/netbeans/html/presenters/spi/Generic.java
@@ -91,99 +91,100 @@ abstract class Generic implements Fn.Presenter, Fn.KeepAlive, Flushable {
abstract void handleLog(Level level, String msg, Object... args);
@Texts({
- "begin=try {\n"
- + " @1('r', -1, 'OK', 'Connected', null);\n"
- + "} catch (e) {\n"
- + " console.warn(e);\n"
- + "}\n",
-
- "init=(function(global) {"
- + "\n var fncns = new Array();"
- + "\n var js2j = new Array();"
- + "\n function jobject(id,value) {"
- + "\n Object.defineProperty(this, 'id', { value : id });"
- + "\n Object.defineProperty(this, 'v', { value : value });"
- + "\n return this;"
- + "\n };"
- + "\n Object.defineProperty(jobject.prototype, 'native', { value : true });"
- + "\n Object.defineProperty(jobject.prototype, 'valueOf', { value : function() { return this.v ? this.v : '[jobject ' + this.id + ']'; } });"
- + "\n Object.defineProperty(jobject.prototype, 'toString', { value : jobject.prototype.valueOf });"
- + "\n var toVM = global['@2'];"
- + "\n delete global['@2'];"
- + "\n if (typeof toVM !== 'function') {"
- + "\n throw 'toVM should be a function: ' + toVM;"
- + "\n }"
- + "\n function toJava(method, id, r) {"
- + "\n var t = typeof r;"
- + "\n if (t === 'function') t = 'object';"
- + "\n if (t === 'undefined' || r === null) {"
- + "\n t = 'null';"
- + "\n r = null;"
- + "\n } else if (t === 'object') {"
- + "\n if (r['native']) {"
- + "\n t = 'java';"
- + "\n r = r.id;"
- + "\n } else if (Object.prototype.toString.call(r) === '[object Array]') {"
- + "\n t = 'array';"
- + "\n var l = r.length + ':';"
- + "\n for (var i = 0; i < r.length; i++) {"
- + "\n var toObj = toJava(null, id, r[i]);"
- + "\n l += toObj.length + ':' + toObj;"
- + "\n }"
- + "\n r = l;"
- + "\n } else {"
- + "\n var size = js2j.length;"
- + "\n js2j.push(r);"
- + "\n r = size;"
- + "\n }"
- + "\n }"
- + "\n if (method !== null) toVM(method, id, t, r, null);"
- + "\n else return t + ':' + r;"
- + "\n }"
- + "\n var impl = {};"
- + "\n impl.key = @1;"
- + "\n global.ds = function(key) {"
- + "\n if (key != impl.key) {"
- + "\n impl = null;"
- + "\n console.warn('Surprising access to Java with ' + key);"
- + "\n }"
- + "\n return impl;"
- + "\n };"
- + "\n impl.toJava = toJava;"
- + "\n impl.rg = function(id, fn) {"
- + "\n fncns[id] = fn;"
- + "\n };"
- + "\n impl.fn = function(index, n, id, self) {"
- + "\n var args = Array.prototype.slice.call(arguments, 4);"
- + "\n try {"
- + "\n var fn = fncns[index];"
- + "\n if (typeof fn !== 'function') throw 'Cannot find function at index: ' + index + ' in ' + fn + ' apply: ' + (fn ? fn.apply : undefined);"
- + "\n var r = fn.apply(self, args);"
- + "\n if (n) toJava('r', id, r);"
- + "\n } catch (err) {"
- + "\n if (typeof console !== 'undefined') console.warn('Error ' + err + ' at:\\n' + err.stack);"
- + "\n if (n) toVM('r', id, 'error', '' + err + ' at:\\n' + err.stack, null, null);"
- + "\n }"
- + "\n };"
- + "\n impl.o = function(i) {"
- + "\n return js2j[i];"
- + "\n };"
- + "\n impl.j = function(n,v) {"
- + "\n var r = new jobject(n,v);"
- + "\n if (arguments.length > 2) {"
- + "\n for (var i = 2; i < arguments.length; i++) {"
- + "\n r[i - 2] = arguments[i];"
- + "\n }"
- + "\n r.length = arguments.length - 2;"
- + "\n }"
- + "\n return r;"
- + "\n };"
- + "\n impl.v = function(i) {"
- + "\n return fncns[i];"
- + "\n };"
- + "\n impl.toVM = toVM;"
- + "\n impl.toVM('r', -1, 'OK', 'Initialized', null);"
- + "\n})(this);",
+ """
+ begin=try {
+ @1('r', -1, 'OK', 'Connected', null);
+ } catch (e) {
+ console.warn(e);
+ }
+ """, """
+ init=(function(global) {
+ var fncns = new Array();
+ var js2j = new Array();
+ function jobject(id,value) {
+ Object.defineProperty(this, 'id', { value : id });
+ Object.defineProperty(this, 'v', { value : value });
+ return this;
+ };
+ Object.defineProperty(jobject.prototype, 'native', { value : true });
+ Object.defineProperty(jobject.prototype, 'valueOf', { value : function() { return this.v ? this.v : '[jobject ' + this.id + ']'; } });
+ Object.defineProperty(jobject.prototype, 'toString', { value : jobject.prototype.valueOf });
+ var toVM = global['@2'];
+ delete global['@2'];
+ if (typeof toVM !== 'function') {
+ throw 'toVM should be a function: ' + toVM;
+ }
+ function toJava(method, id, r) {
+ var t = typeof r;
+ if (t === 'function') t = 'object';
+ if (t === 'undefined' || r === null) {
+ t = 'null';
+ r = null;
+ } else if (t === 'object') {
+ if (r['native']) {
+ t = 'java';
+ r = r.id;
+ } else if (Object.prototype.toString.call(r) === '[object Array]') {
+ t = 'array';
+ var l = r.length + ':';
+ for (var i = 0; i < r.length; i++) {
+ var toObj = toJava(null, id, r[i]);
+ l += toObj.length + ':' + toObj;
+ }
+ r = l;
+ } else {
+ var size = js2j.length;
+ js2j.push(r);
+ r = size;
+ }
+ }
+ if (method !== null) toVM(method, id, t, r, null);
+ else return t + ':' + r;
+ }
+ var impl = {};
+ impl.key = @1;
+ global.ds = function(key) {
+ if (key != impl.key) {
+ impl = null;
+ console.warn('Surprising access to Java with ' + key);
+ }
+ return impl;
+ };
+ impl.toJava = toJava;
+ impl.rg = function(id, fn) {
+ fncns[id] = fn;
+ };
+ impl.fn = function(index, n, id, self) {
+ var args = Array.prototype.slice.call(arguments, 4);
+ try {
+ var fn = fncns[index];
+ if (typeof fn !== 'function') throw 'Cannot find function at index: ' + index + ' in ' + fn + ' apply: ' + (fn ? fn.apply : undefined);
+ var r = fn.apply(self, args);
+ if (n) toJava('r', id, r);
+ } catch (err) {
+ if (typeof console !== 'undefined') console.warn('Error ' + err + ' at:\\n' + err.stack);
+ if (n) toVM('r', id, 'error', '' + err + ' at:\\n' + err.stack, null, null);
+ }
+ };
+ impl.o = function(i) {
+ return js2j[i];
+ };
+ impl.j = function(n,v) {
+ var r = new jobject(n,v);
+ if (arguments.length > 2) {
+ for (var i = 2; i < arguments.length; i++) {
+ r[i - 2] = arguments[i];
+ }
+ r.length = arguments.length - 2;
+ }
+ return r;
+ };
+ impl.v = function(i) {
+ return fncns[i];
+ };
+ impl.toVM = toVM;
+ impl.toVM('r', -1, 'OK', 'Initialized', null);
+ })(this);""",
"initializationProtocol=--- Initialization protocol ---\n",
"error=Cannot initialize DukeScript: @1",
"version=$version"
@@ -343,18 +344,18 @@ abstract class Generic implements Fn.Presenter, Fn.KeepAlive, Flushable {
"fnParam=p@1",
"fnClose=) {\n",
"fnBegin= var encParams = ds(@1).toJava(null, -1, [",
- "fnPPar=@2 p@1",
- "fnBody=]);\n" +
- " var v = ds(@3).toVM('c', '@1', '@2', thiz ? thiz.id : null, encParams);\n" +
- " while (v !== null && v.indexOf && v.indexOf('javascript:') === 0) {\n" +
- " var script = v.substring(11);\n" +
- " try {\n" +
- " var r = eval.call(null, script);\n" +
- " } catch (e) { console.warn('error: ' + e + ' executing: ' + script + ' at:\\n' + e.stack); }\n" +
- " v = ds(@3).toVM('jr', null, null, null, null);" +
- " }\n" +
- " return @4 ? eval('(' + v + ')') : v;\n" +
- "};\n",
+ "fnPPar=@2 p@1", """
+ fnBody=]);
+ var v = ds(@3).toVM('c', '@1', '@2', thiz ? thiz.id : null, encParams);
+ while (v !== null && v.indexOf && v.indexOf('javascript:') === 0) {
+ var script = v.substring(11);
+ try {
+ var r = eval.call(null, script);
+ } catch (e) { console.warn('error: ' + e + ' executing: ' + script + ' at:\\n' + e.stack); }
+ v = ds(@3).toVM('jr', null, null, null, null); }
+ return @4 ? eval('(' + v + ')') : v;
+ };
+ """,
"fnFoot=ds(@2).rg(@1, jsvm);\n"
})
diff --git a/geo/src/main/java/org/netbeans/html/geo/impl/JsGLProvider.java b/geo/src/main/java/org/netbeans/html/geo/impl/JsGLProvider.java
index 8f7dd76..7503b2a 100644
--- a/geo/src/main/java/org/netbeans/html/geo/impl/JsGLProvider.java
+++ b/geo/src/main/java/org/netbeans/html/geo/impl/JsGLProvider.java
@@ -39,23 +39,25 @@ public final class JsGLProvider extends GLProvider<Object, Long> {
args = { "c", "onlyOnce", "enableHighAccuracy", "timeout", "maximumAge" },
javacall = true,
body =
- "var self = this;\n" +
- "var ok = function (position) {\n" +
- " self.@org.netbeans.html.geo.impl.JsGLProvider::onLocation(Ljava/lang/Object;Ljava/lang/Object;)(c, position);\n" +
- "};\n" +
- "var fail = function (error) {\n" +
- " self.@org.netbeans.html.geo.impl.JsGLProvider::onError(Ljava/lang/Object;Ljava/lang/String;I)(c, error.message, error.code);\n" +
- "};\n" +
- "var options = {};\n" +
- "options.enableHighAccuracy = enableHighAccuracy;\n" +
- "if (timeout >= 0) options.timeout = timeout;\n" +
- "if (maximumAge >= 0) options.maximumAge = maximumAge;\n" +
- "if (onlyOnce) {\n" +
- " navigator.geolocation.getCurrentPosition(ok, fail, options);\n" +
- " return 0;\n" +
- "} else {\n" +
- " return navigator.geolocation.watchPosition(ok, fail, options);\n" +
- "}\n"
+ """
+ var self = this;
+ var ok = function (position) {
+ self.@org.netbeans.html.geo.impl.JsGLProvider::onLocation(Ljava/lang/Object;Ljava/lang/Object;)(c, position);
+ };
+ var fail = function (error) {
+ self.@org.netbeans.html.geo.impl.JsGLProvider::onError(Ljava/lang/Object;Ljava/lang/String;I)(c, error.message, error.code);
+ };
+ var options = {};
+ options.enableHighAccuracy = enableHighAccuracy;
+ if (timeout >= 0) options.timeout = timeout;
+ if (maximumAge >= 0) options.maximumAge = maximumAge;
+ if (onlyOnce) {
+ navigator.geolocation.getCurrentPosition(ok, fail, options);
+ return 0;
+ } else {
+ return navigator.geolocation.watchPosition(ok, fail, options);
+ }
+ """
)
private long doStart(
Query c,
diff --git a/geo/src/test/java/org/netbeans/html/geo/impl/GeoProcessorTest.java b/geo/src/test/java/org/netbeans/html/geo/impl/GeoProcessorTest.java
index 094ef55..0e16c92 100644
--- a/geo/src/test/java/org/netbeans/html/geo/impl/GeoProcessorTest.java
+++ b/geo/src/test/java/org/netbeans/html/geo/impl/GeoProcessorTest.java
@@ -31,58 +31,63 @@ public class GeoProcessorTest {
}
@Test public void onLocationMethodHasToTakePositionParameter() throws IOException {
- Compile res = Compile.create("", "package x;\n"
- + "class UseOnLocation {\n"
- + " @net.java.html.geo.OnLocation\n"
- + " public static void cantCallMe() {}\n"
- + "}\n"
- );
+ Compile res = Compile.create("", """
+ package x;
+ class UseOnLocation {
+ @net.java.html.geo.OnLocation
+ public static void cantCallMe() {}
+ }
+ """);
res.assertErrors();
res.assertError("first argument must be net.java.html.geo.Position");
}
@Test public void onLocationMethodCannotBePrivate() throws IOException {
- Compile res = Compile.create("", "package x;\n"
- + "class UseOnLocation {\n"
- + " @net.java.html.geo.OnLocation\n"
- + " private static void cantCallMe(net.java.html.geo.Position p) {}\n"
- + "}\n"
- );
+ Compile res = Compile.create("", """
+ package x;
+ class UseOnLocation {
+ @net.java.html.geo.OnLocation
+ private static void cantCallMe(net.java.html.geo.Position p) {}
+ }
+ """);
res.assertErrors();
res.assertError("cannot be private");
}
@Test public void onErrorHasToExist() throws IOException {
- Compile res = Compile.create("", "package x;\n"
- + "class UseOnLocation {\n"
- + " @net.java.html.geo.OnLocation(onError=\"doesNotExist\")\n"
- + " static void cantCallMe(net.java.html.geo.Position p) {}\n"
- + "}\n"
- );
+ Compile res = Compile.create("", """
+ package x;
+ class UseOnLocation {
+ @net.java.html.geo.OnLocation(onError="doesNotExist")
+ static void cantCallMe(net.java.html.geo.Position p) {}
+ }
+ """);
res.assertErrors();
res.assertError("not find doesNotExist");
}
@Test public void onErrorWouldHaveToBeStatic() throws IOException {
- Compile res = Compile.create("", "package x;\n"
- + "class UseOnLocation {\n"
- + " @net.java.html.geo.OnLocation(onError=\"notStatic\")\n"
- + " static void cantCallMe(net.java.html.geo.Position p) {}\n"
- + " void notStatic(Exception e) {}\n"
- + "}\n"
- );
+ Compile res = Compile.create("", """
+ package x;
+ class UseOnLocation {
+ @net.java.html.geo.OnLocation(onError="notStatic")
+ static void cantCallMe(net.java.html.geo.Position p) {}
+ void notStatic(Exception e) {}
+ }
+ """);
res.assertErrors();
res.assertError("have to be static");
}
@Test public void onErrorMustAcceptExceptionArgument() throws IOException {
- Compile res = Compile.create("", "package x;\n"
- + "class UseOnLocation {\n"
- + " @net.java.html.geo.OnLocation(onError=\"notStatic\")\n"
- + " static void cantCallMe(net.java.html.geo.Position p) {}\n"
- + " static void notStatic(java.io.IOException e) {}\n"
- + "}\n"
- );
+ Compile res = Compile.create("", """
+ package x;
+ class UseOnLocation {
+ @net.java.html.geo.OnLocation(onError="notStatic")
+ static void cantCallMe(net.java.html.geo.Position p) {}
+ static void notStatic(java.io.IOException e) {}
+ }
+ """);
res.assertErrors();
res.assertError("Error method first argument needs to be Exception");
}
diff --git a/json-tck/pom.xml b/json-tck/pom.xml
index 016c9cd..1c27226 100644
--- a/json-tck/pom.xml
+++ b/json-tck/pom.xml
@@ -55,14 +55,6 @@
<includeDependencySources>true</includeDependencySources>
</configuration>
</plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.8</source>
- <target>1.8</target>
- </configuration>
- </plugin>
</plugins>
</build>
<dependencies>
diff --git a/json-tck/src/main/java/net/java/html/js/tests/Bodies.java b/json-tck/src/main/java/net/java/html/js/tests/Bodies.java
index 2a99e2e..2f5870d 100644
--- a/json-tck/src/main/java/net/java/html/js/tests/Bodies.java
+++ b/json-tck/src/main/java/net/java/html/js/tests/Bodies.java
@@ -64,17 +64,19 @@ final class Bodies {
@JavaScriptBody(args = { "o", "x" }, keepAlive = false, body = "o.x = x;")
public static native Object setX(Object o, Object x);
- @JavaScriptBody(args = { "c", "a", "b" }, keepAlive = false, javacall = true, body =
- "return c.@net.java.html.js.tests.Sum::sum(II)(a, b);"
- )
+ @JavaScriptBody(args = { "c", "a", "b" }, keepAlive = false, javacall = true, body = """
+ return c.@net.java.html.js.tests.Sum::sum(II)(a, b);
+ """)
public static native int sumIndirect(Sum c, int a, int b);
@JavaScriptBody(args = { "c" }, javacall = true, body =
- "return {\n" +
- " 'sum' : function(a,b) {\n" +
- " return c.@net.java.html.js.tests.Sum::sum(II)(a, b);\n" +
- " }\n" +
- "};\n"
+ """
+ return {
+ 'sum' : function(a,b) {
+ return c.@net.java.html.js.tests.Sum::sum(II)(a, b);
+ }
+ };
+ """
)
public static native Object sumDelayed(Sum c);
@@ -128,22 +130,26 @@ final class Bodies {
}
@JavaScriptBody(args = { "arr" }, body =
- "var sum = 0;\n" +
- "for (var i = 0; i < arr.length; i++) {\n" +
- " sum += arr[i];\n" +
- "}\n" +
- "return sum;\n"
+ """
+ var sum = 0;
+ for (var i = 0; i < arr.length; i++) {
+ sum += arr[i];
+ }
+ return sum;
+ """
)
public static native double sumVector(double[] arr);
@JavaScriptBody(args = { "arr" }, body =
- "var sum = 0;\n" +
- "for (var i = 0; i < arr.length; i++) {\n" +
- " for (var j = 0; j < arr[i].length; j++) {\n" +
- " sum += arr[i][j];\n" +
- " }\n" +
- "}\n" +
- "return sum;\n"
+ """
+ var sum = 0;
+ for (var i = 0; i < arr.length; i++) {
+ for (var j = 0; j < arr[i].length; j++) {
+ sum += arr[i][j];
+ }
+ }
+ return sum;
+ """
)
public static native double sumMatrix(double[][] arr);
@@ -159,54 +165,63 @@ final class Bodies {
}
@JavaScriptBody(args = {}, javacall = true, body =
- "var v = { x : 0 };\n" +
- "@net.java.html.js.tests.Bodies::incCounter(ILjava/lang/Object;)(42, v);\n" +
- "return v.x;\n"
+ """
+ var v = { x : 0 };
+ @net.java.html.js.tests.Bodies::incCounter(ILjava/lang/Object;)(42, v);
+ return v.x;
+ """
)
static native int incAsync();
@JavaScriptBody(args = { "obj" }, body =
- "var ret = [];\n" +
- "for (var i in obj) {\n" +
- " ret.push(i);\n" +
- " ret.push(obj[i]);\n" +
- "}\n" +
- "return ret;\n"
+ """
+ var ret = [];
+ for (var i in obj) {
+ ret.push(i);
+ ret.push(obj[i]);
+ }
+ return ret;
+ """
)
static native Object[] forIn(Object obj);
@JavaScriptBody(args = { "max" }, body =
- "var arr = [];\n"
- + "for (var i = 0; i < max; i++) {\n"
- + " arr.push(i);\n"
- + "}\n"
- + "return arr.length;"
+ """
+ var arr = [];
+ for (var i = 0; i < max; i++) {
+ arr.push(i);
+ }
+ return arr.length;"""
)
static native int gc(double max);
- @JavaScriptBody(args = {}, body = ""
- + "var o = {};\n"
- + "return o.x;\n"
+ @JavaScriptBody(args = {}, body = """
+ var o = {};
+ return o.x;
+ """
)
static native Object unknown();
- @JavaScriptBody(args = {}, body = ""
- + "return new Array(2);\n"
+ @JavaScriptBody(args = {}, body = """
+ return new Array(2);
+ """
)
static native Object[] unknownArray();
- @JavaScriptBody(args = { "sum" }, javacall = true, body = ""
- + "var arr = [];\n"
- + "arr[1] = null;\n"
- + "arr[2] = 1;\n"
- + "return sum.@net.java.html.js.tests.Sum::sumNonNull([Ljava/lang/Object;)(arr);\n"
+ @JavaScriptBody(args = { "sum" }, javacall = true, body = """
+ var arr = [];
+ arr[1] = null;
+ arr[2] = 1;
+ return sum.@net.java.html.js.tests.Sum::sumNonNull([Ljava/lang/Object;)(arr);
+ """
)
static native int sumNonNull(Sum sum);
- @JavaScriptBody(args = { "sum", "p" }, javacall = true, body = ""
- + "var obj = {};\n"
- + "obj.x = 1;\n"
- + "return sum.@net.java.html.js.tests.Sum::checkNonNull(Ljava/lang/Object;)(obj[p]);\n"
+ @JavaScriptBody(args = { "sum", "p" }, javacall = true, body = """
+ var obj = {};
+ obj.x = 1;
+ return sum.@net.java.html.js.tests.Sum::checkNonNull(Ljava/lang/Object;)(obj[p]);
+ """
)
static native boolean nonNull(Sum sum, String p);
@@ -220,9 +235,10 @@ final class Bodies {
)
static native String primitiveTypes(Sum sum);
- @JavaScriptBody(args = { "call" }, javacall = true, body = ""
- + "var b = call.@java.util.concurrent.Callable::call()();\n"
- + "return b ? 'yes' : 'no';\n"
+ @JavaScriptBody(args = { "call" }, javacall = true, body = """
+ var b = call.@java.util.concurrent.Callable::call()();
+ return b ? 'yes' : 'no';
+ """
)
static native String yesNo(Callable<Boolean> call);
@@ -236,27 +252,28 @@ final class Bodies {
static native String readGlobal2String();
static String problematicString() {
- return "{\n" +
-" MyViewModel: {\n" +
-"// ViewModel: JavaViewModel,\n" +
-"\n" +
-" } \n" +
-"}";
+ return """
+ {
+ MyViewModel: {
+ // ViewModel: JavaViewModel,
+ }
+ }""";
}
@JavaScriptBody(args = { "o", "n" }, body = "return o[n];")
static native Object get(Object o, String n);
- @JavaScriptBody(args = { "o", "n", "arg" }, body = "\n" +
- "try {\n" +
- " if (arg == null) {\n" +
- " return o[n]();\n" +
- " } else {\n" +
- " return o[n](arg);\n" +
- " }\n" +
- "} catch (e) {\n" +
- " return n;\n" +
- "}\n"
+ @JavaScriptBody(args = { "o", "n", "arg" }, body = """
+ try {
+ if (arg == null) {
+ return o[n]();
+ } else {
+ return o[n](arg);
+ }
+ } catch (e) {
+ return n;
+ }
+ """
)
static native Object invoke(Object o, String n, Object arg);
}
diff --git a/json-tck/src/main/java/net/java/html/js/tests/Factorial.java b/json-tck/src/main/java/net/java/html/js/tests/Factorial.java
index d7d0c89..b279295 100644
--- a/json-tck/src/main/java/net/java/html/js/tests/Factorial.java
+++ b/json-tck/src/main/java/net/java/html/js/tests/Factorial.java
@@ -30,9 +30,10 @@ public final class Factorial {
}
@JavaScriptBody(args = { "i" }, javacall = true,body =
- "if (i <= 1) return 1;\n"
- + "var im1 = this.@net.java.html.js.tests.Factorial::minusOne(I)(i);\n"
- + "return this.@net.java.html.js.tests.Factorial::factorial(I)(im1) * i;"
+ """
+ if (i <= 1) return 1;
+ var im1 = this.@net.java.html.js.tests.Factorial::minusOne(I)(i);
+ return this.@net.java.html.js.tests.Factorial::factorial(I)(im1) * i;"""
)
native int factorial(int n);
}
diff --git a/json-tck/src/main/java/net/java/html/js/tests/Receiver.java b/json-tck/src/main/java/net/java/html/js/tests/Receiver.java
index 3db2103..548a2e9 100644
--- a/json-tck/src/main/java/net/java/html/js/tests/Receiver.java
+++ b/json-tck/src/main/java/net/java/html/js/tests/Receiver.java
@@ -44,9 +44,11 @@ public final class Receiver {
}
@JavaScriptBody(args = { "v" }, keepAlive = false, javacall = true,
- body = "return function(rec) {\n"
- + " rec.@net.java.html.js.tests.Receiver::set(Ljava/lang/Object;)(v);\n"
- + "};\n")
+ body = """
+ return function(rec) {
+ rec.@net.java.html.js.tests.Receiver::set(Ljava/lang/Object;)(v);
+ };
+ """)
private static native Object initFn(Object v);
@JavaScriptBody(args = { "fn", "thiz" }, body =
diff --git a/json-tck/src/main/java/net/java/html/js/tests/Sum.java b/json-tck/src/main/java/net/java/html/js/tests/Sum.java
index 215df29..1cecdcf 100644
--- a/json-tck/src/main/java/net/java/html/js/tests/Sum.java
+++ b/json-tck/src/main/java/net/java/html/js/tests/Sum.java
@@ -30,18 +30,22 @@ public final class Sum {
}
@JavaScriptBody(args = { "a", "b" }, javacall = true, keepAlive = false, body =
- "return {\n"
- + " 'x' : this.@net.java.html.js.tests.Sum::sum(II)(a, b),\n"
- + " 'y' : this\n"
- + "}\n"
+ """
+ return {
+ 'x' : this.@net.java.html.js.tests.Sum::sum(II)(a, b),
+ 'y' : this
+ }
+ """
)
public native Object jsSum(int a, int b);
@JavaScriptBody(args = { "thiz", "a", "b" }, javacall = true, keepAlive = false, body =
- "return {\n"
- + " 'x' : thiz.@net.java.html.js.tests.Sum::sum(II)(a, b),\n"
- + " 'y' : thiz\n"
- + "}\n"
+ """
+ return {
+ 'x' : thiz.@net.java.html.js.tests.Sum::sum(II)(a, b),
+ 'y' : thiz
+ }
+ """
)
public static native Object jsStaticSum(Sum thiz, int a, int b);
diff --git a/json-tck/src/main/java/net/java/html/json/tests/GCKnockoutTest.java b/json-tck/src/main/java/net/java/html/json/tests/GCKnockoutTest.java
index ea45046..4024c57 100644
--- a/json-tck/src/main/java/net/java/html/json/tests/GCKnockoutTest.java
+++ b/json-tck/src/main/java/net/java/html/json/tests/GCKnockoutTest.java
@@ -40,11 +40,11 @@ public class GCKnockoutTest {
@KOTest public void noLongerNeededArrayElementsCanDisappear() throws Exception {
BrwsrCtx ctx = Utils.newContext(GCKnockoutTest.class);
- Object exp = Utils.exposeHTML(GCKnockoutTest.class,
- "<ul id='ul' data-bind='foreach: all'>\n"
- + " <li data-bind='text: firstName'/>\n"
- + "</ul>\n"
- );
+ Object exp = Utils.exposeHTML(GCKnockoutTest.class, """
+ <ul id='ul' data-bind='foreach: all'>
+ <li data-bind='text: firstName'/>
+ </ul>
+ """);
try {
GC m = Models.bind(new GC(), ctx);
m.getAll().add(Models.bind(new Fullname("Jarda", "Tulach"), ctx));
@@ -81,12 +81,13 @@ public class GCKnockoutTest {
if (ref.get() == null) {
return;
}
- String gc = "var max = arguments[0];\n"
- + "var arr = [];\n"
- + "for (var i = 0; i < max; i++) {\n"
- + " arr.push(i);\n"
- + "}\n"
- + "return arr.length;";
+ String gc = """
+ var max = arguments[0];
+ var arr = [];
+ for (var i = 0; i < max; i++) {
+ arr.push(i);
+ }
+ return arr.length;""";
Object cnt = Utils.executeScript(GCKnockoutTest.class, gc, Math.pow(2.0, i));
System.gc();
System.runFinalization();
@@ -99,12 +100,13 @@ public class GCKnockoutTest {
if (ref.get() == null) {
throw new IllegalStateException(msg);
}
- String gc = "var max = arguments[0];\n"
- + "var arr = [];\n"
- + "for (var i = 0; i < max; i++) {\n"
- + " arr.push(i);\n"
- + "}\n"
- + "return arr.length;";
+ String gc = """
+ var max = arguments[0];
+ var arr = [];
+ for (var i = 0; i < max; i++) {
+ arr.push(i);
+ }
+ return arr.length;""";
Object cnt = Utils.executeScript(GCKnockoutTest.class, gc, Math.pow(2.0, i));
System.gc();
System.runFinalization();
diff --git a/json-tck/src/main/java/net/java/html/json/tests/KnockoutTest.java b/json-tck/src/main/java/net/java/html/json/tests/KnockoutTest.java
index 7e07b35..c25567c 100644
--- a/json-tck/src/main/java/net/java/html/json/tests/KnockoutTest.java
+++ b/json-tck/src/main/java/net/java/html/json/tests/KnockoutTest.java
@@ -88,10 +88,10 @@ public final class KnockoutTest {
@KOTest public void modifyRadioValueOnEnum() throws Throwable {
- Object exp = Utils.exposeHTML(KnockoutTest.class,
- "<input id='i1' type=\"radio\" name=\"choice\" value=\"A\" data-bind=\"checked: choice\"></input>Right\n" +
- "<input id='input' type=\"radio\" name=\"choice\" value=\"B\" data-bind=\"checked: choice\"></input>Never\n" +
- "\n"
+ Object exp = Utils.exposeHTML(KnockoutTest.class, """
+ <input id='i1' type="radio" name="choice" value="A" data-bind="checked: choice"></input>Right
+ <input id='input' type="radio" name="choice" value="B" data-bind="checked: choice"></input>Never
+ """
);
try {
@@ -184,10 +184,11 @@ public final class KnockoutTest {
}
@KOTest public void modifyComputedProperty() throws Throwable {
- Object exp = Utils.exposeHTML(KnockoutTest.class,
- "Full name: <div data-bind='with:firstPerson'>\n"
- + "<input id='input' data-bind=\"value: fullName\"></input>\n"
- + "</div>\n"
+ Object exp = Utils.exposeHTML(KnockoutTest.class, """
+ Full name: <div data-bind='with:firstPerson'>
+ <input id='input' data-bind="value: fullName"></input>
+ </div>
+ """
);
try {
KnockoutModel m = new KnockoutModel();
@@ -238,10 +239,11 @@ public final class KnockoutTest {
}
@KOTest public void modifyValueAssertChangeInModel() throws Exception {
- Object exp = Utils.exposeHTML(KnockoutTest.class,
- "<h1 data-bind=\"text: helloMessage\">Loading Bck2Brwsr's Hello World...</h1>\n" +
- "Your name: <input id='input' data-bind=\"value: name\"></input>\n" +
- "<button id=\"hello\">Say Hello!</button>\n"
+ Object exp = Utils.exposeHTML(KnockoutTest.class, """
+ <h1 data-bind="text: helloMessage">Loading Bck2Brwsr's Hello World...</h1>
+ Your name: <input id='input' data-bind="value: name"></input>
+ <button id="hello">Say Hello!</button>
+ """
);
try {
@@ -262,14 +264,16 @@ public final class KnockoutTest {
}
private static String getSetSelected(int index, Object value) throws Exception {
- String s = "var index = arguments[0];\n"
- + "var n = window.document.getElementById('input'); \n "
- + "if (index >= 0) {\n"
- + " n.options.selectedIndex = index; \n"
- + " ko.utils.triggerEvent(n, 'change'); \n"
- + "} \n "
- + "var op = n.options[n.selectedIndex]; \n"
- + "return op ? op.text : n.selectedIndex;\n";
+ String s = """
+ var index = arguments[0];
+ var n = window.document.getElementById('input');
+ if (index >= 0) {
+ n.options.selectedIndex = index;
+ ko.utils.triggerEvent(n, 'change');
+ }
+ var op = n.options[n.selectedIndex];
+ return op ? op.text : n.selectedIndex;
+ """;
Object ret = Utils.executeScript(
KnockoutTest.class,
s, index, value
@@ -290,13 +294,12 @@ public final class KnockoutTest {
@KOTest public void selectWorksOnModels() throws Exception {
if (js == null) {
- Utils.exposeHTML(KnockoutTest.class,
- "<select id='input' data-bind=\"options: archetypes,\n" +
-" optionsText: 'name',\n" +
-" value: archetype\">\n" +
-" </select>\n" +
-""
- );
+ Utils.exposeHTML(KnockoutTest.class, """
+ <select id='input' data-bind="options: archetypes,
+ optionsText: 'name',
+ value: archetype">
+ </select>
+ """);
{
KnockoutModel km = new KnockoutModel();
@@ -330,11 +333,11 @@ public final class KnockoutTest {
nestedObjectEqualsChange(false);
}
private void nestedObjectEqualsChange(boolean preApply) throws Exception {
- Utils.exposeHTML(KnockoutTest.class,
-" <div data-bind='with: archetype'>\n" +
-" <input id='input' data-bind='value: groupId'></input>\n" +
-" </div>\n"
- );
+ Utils.exposeHTML(KnockoutTest.class, """
+ <div data-bind='with: archetype'>
+ <input id='input' data-bind='value: groupId'></input>
+ </div>
+ """);
js = Models.bind(new KnockoutModel(), newContext());
if (preApply) {
@@ -351,11 +354,11 @@ public final class KnockoutTest {
@KOTest public void modifyValueAssertAsyncChangeInModel() throws Exception {
if (js == null) {
- Utils.exposeHTML(KnockoutTest.class,
- "<h1 data-bind=\"text: helloMessage\">Loading Bck2Brwsr's Hello World...</h1>\n" +
- "Your name: <input id='input' data-bind=\"value: name\"></input>\n" +
- "<button id=\"hello\">Say Hello!</button>\n"
- );
+ Utils.exposeHTML(KnockoutTest.class, """
+ <h1 data-bind="text: helloMessage">Loading Bck2Brwsr's Hello World...</h1>
+ Your name: <input id='input' data-bind="value: name"></input>
+ <button id="hello">Say Hello!</button>
+ """);
js = Models.bind(new KnockoutModel(), newContext());
js.setName("Kukuc");
@@ -454,10 +457,11 @@ public final class KnockoutTest {
}
private static String getSetInput(String id, String value) throws Exception {
- String s = "var value = arguments[0];\n"
- + "var n = window.document.getElementById(arguments[1]); \n "
- + "if (value != null) n['value'] = value; \n "
- + "return n['value'];";
+ String s = """
+ var value = arguments[0];
+ var n = window.document.getElementById(arguments[1]);
+ if (value != null) n['value'] = value;
+ return n['value'];""";
Object ret = Utils.executeScript(
KnockoutTest.class,
s, value, id
@@ -466,9 +470,9 @@ public final class KnockoutTest {
}
private static boolean isChecked(String id) throws Exception {
- String s = ""
- + "var n = window.document.getElementById(arguments[0]); \n "
- + "return n['checked'];";
+ String s = """
+ var n = window.document.getElementById(arguments[0]);
+ return n['checked'];""";
Object ret = Utils.executeScript(
KnockoutTest.class,
s, id
@@ -485,11 +489,11 @@ public final class KnockoutTest {
}
@KOTest public void displayContentOfArray() throws Exception {
- Object exp = Utils.exposeHTML(KnockoutTest.class,
- "<ul id='ul' data-bind='foreach: results'>\n"
- + " <li data-bind='text: $data, click: $root.call'/>\n"
- + "</ul>\n"
- );
+ Object exp = Utils.exposeHTML(KnockoutTest.class, """
+ <ul id='ul' data-bind='foreach: results'>
+ <li data-bind='text: $data, click: $root.call'/>
+ </ul>
+ """);
try {
KnockoutModel m = Models.bind(new KnockoutModel(), newContext());
m.getResults().add("Ahoj");
@@ -514,11 +518,11 @@ public final class KnockoutTest {
@KOTest public void displayContentOfAsyncArray() throws Exception {
if (js == null) {
- Utils.exposeHTML(KnockoutTest.class,
- "<ul id='ul' data-bind='foreach: results'>\n"
- + " <li data-bind='text: $data, click: $root.call'/>\n"
- + "</ul>\n"
- );
+ Utils.exposeHTML(KnockoutTest.class, """
+ <ul id='ul' data-bind='foreach: results'>
+ <li data-bind='text: $data, click: $root.call'/>
+ </ul>
+ """);
js = Models.bind(new KnockoutModel(), newContext());
js.getResults().add("Ahoj");
js.applyBindings();
@@ -551,11 +555,11 @@ public final class KnockoutTest {
}
@KOTest public void displayContentOfComputedArray() throws Exception {
- Object exp = Utils.exposeHTML(KnockoutTest.class,
- "<ul id='ul' data-bind='foreach: bothNames'>\n"
- + " <li data-bind='text: $data, click: $root.assignFirstName'/>\n"
- + "</ul>\n"
- );
+ Object exp = Utils.exposeHTML(KnockoutTest.class, """
+ <ul id='ul' data-bind='foreach: bothNames'>
+ <li data-bind='text: $data, click: $root.assignFirstName'/>
+ </ul>
+ """);
try {
Pair m = Models.bind(new Pair("First", "Last", null), newContext());
m.applyBindings();
@@ -582,13 +586,12 @@ public final class KnockoutTest {
}
@KOTest public void displayContentOfComputedArrayOnASubpair() throws Exception {
- Object exp = Utils.exposeHTML(KnockoutTest.class,
- "<div data-bind='with: next'>\n"
- + "<ul id='ul' data-bind='foreach: bothNames'>\n"
- + " <li data-bind='text: $data, click: $root.assignFirstName'/>\n"
- + "</ul>"
- + "</div>\n"
- );
+ Object exp = Utils.exposeHTML(KnockoutTest.class, """
+ <div data-bind='with: next'>
+ <ul id='ul' data-bind='foreach: bothNames'>
+ <li data-bind='text: $data, click: $root.assignFirstName'/>
+ </ul></div>
+ """);
try {
final BrwsrCtx ctx = newContext();
Pair m = Models.bind(new Pair(null, null, new Pair("First", "Last", null)), ctx);
@@ -608,13 +611,12 @@ public final class KnockoutTest {
}
@KOTest public void displayContentOfComputedArrayOnComputedASubpair() throws Exception {
- Object exp = Utils.exposeHTML(KnockoutTest.class,
- "<div data-bind='with: nextOne'>\n"
- + "<ul id='ul' data-bind='foreach: bothNames'>\n"
- + " <li data-bind='text: $data, click: $root.assignFirstName'/>\n"
- + "</ul>"
- + "</div>\n"
- );
+ Object exp = Utils.exposeHTML(KnockoutTest.class, """
+ <div data-bind='with: nextOne'>
+ <ul id='ul' data-bind='foreach: bothNames'>
+ <li data-bind='text: $data, click: $root.assignFirstName'/>
+ </ul></div>
+ """);
try {
Pair m = Models.bind(new Pair(null, null, new Pair("First", "Last", null)), newContext());
m.applyBindings();
@@ -651,11 +653,11 @@ public final class KnockoutTest {
@KOTest public void displayContentOfDerivedArray() throws Exception {
- Object exp = Utils.exposeHTML(KnockoutTest.class,
- "<ul id='ul' data-bind='foreach: cmpResults'>\n"
- + " <li><b data-bind='text: $data'></b></li>\n"
- + "</ul>\n"
- );
+ Object exp = Utils.exposeHTML(KnockoutTest.class, """
+ <ul id='ul' data-bind='foreach: cmpResults'>
+ <li><b data-bind='text: $data'></b></li>
+ </ul>
+ """);
try {
KnockoutModel m = Models.bind(new KnockoutModel(), newContext());
m.getResults().add("Ahoj");
@@ -674,11 +676,11 @@ public final class KnockoutTest {
}
@KOTest public void displayContentOfArrayOfPeople() throws Exception {
- Object exp = Utils.exposeHTML(KnockoutTest.class,
- "<ul id='ul' data-bind='foreach: people'>\n"
- + " <li data-bind='text: $data.firstName, click: $root.removePerson'></li>\n"
- + "</ul>\n"
- );
+ Object exp = Utils.exposeHTML(KnockoutTest.class, """
+ <ul id='ul' data-bind='foreach: people'>
+ <li data-bind='text: $data.firstName, click: $root.removePerson'></li>
+ </ul>
+ """);
try {
final BrwsrCtx c = newContext();
KnockoutModel m = Models.bind(new KnockoutModel(), c);
@@ -724,10 +726,11 @@ public final class KnockoutTest {
}
@KOTest public void accessFirstPersonWithOnFunction() throws Exception {
- Object exp = Utils.exposeHTML(KnockoutTest.class,
- "<p id='ul' data-bind='with: firstPerson'>\n"
- + " <span data-bind='text: firstName, click: changeSex'></span>\n"
- + "</p>\n"
+ Object exp = Utils.exposeHTML(KnockoutTest.class, """
+ <p id='ul' data-bind='with: firstPerson'>
+ <span data-bind='text: firstName, click: changeSex'></span>
+ </p>
+ """
);
try {
trasfertToFemale();
@@ -737,10 +740,11 @@ public final class KnockoutTest {
}
@KOTest public void onPersonFunction() throws Exception {
- Object exp = Utils.exposeHTML(KnockoutTest.class,
- "<ul id='ul' data-bind='foreach: people'>\n"
- + " <li data-bind='text: $data.firstName, click: changeSex'></li>\n"
- + "</ul>\n"
+ Object exp = Utils.exposeHTML(KnockoutTest.class, """
+ <ul id='ul' data-bind='foreach: people'>
+ <li data-bind='text: $data.firstName, click: changeSex'></li>
+ </ul>
+ """
);
try {
trasfertToFemale();
@@ -770,13 +774,13 @@ public final class KnockoutTest {
}
@KOTest public void stringArrayModificationVisible() throws Exception {
- Object exp = Utils.exposeHTML(KnockoutTest.class,
- "<div>\n"
- + "<ul id='ul' data-bind='foreach: results'>\n"
- + " <li data-bind='text: $data'></li>\n"
- + "</ul>\n"
- + "</div>\n"
- );
+ Object exp = Utils.exposeHTML(KnockoutTest.class, """
+ <div>
+ <ul id='ul' data-bind='foreach: results'>
+ <li data-bind='text: $data'></li>
+ </ul>
+ </div>
+ """);
try {
KnockoutModel m = Models.bind(new KnockoutModel(), newContext());
m.getResults().add("Ahoj");
@@ -802,13 +806,13 @@ public final class KnockoutTest {
}
@KOTest public void intArrayModificationVisible() throws Exception {
- Object exp = Utils.exposeHTML(KnockoutTest.class,
- "<div>\n"
- + "<ul id='ul' data-bind='foreach: numbers'>\n"
- + " <li data-bind='text: $data'></li>\n"
- + "</ul>\n"
- + "</div>\n"
- );
+ Object exp = Utils.exposeHTML(KnockoutTest.class, """
+ <div>
+ <ul id='ul' data-bind='foreach: numbers'>
+ <li data-bind='text: $data'></li>
+ </ul>
+ </div>
+ """);
try {
KnockoutModel m = Models.bind(new KnockoutModel(), newContext());
m.getNumbers().add(1);
@@ -835,13 +839,13 @@ public final class KnockoutTest {
}
@KOTest public void derivedIntArrayModificationVisible() throws Exception {
- Object exp = Utils.exposeHTML(KnockoutTest.class,
- "<div>\n"
- + "<ul id='ul' data-bind='foreach: resultLengths'>\n"
- + " <li data-bind='text: $data'></li>\n"
- + "</ul>\n"
- + "</div>\n"
- );
+ Object exp = Utils.exposeHTML(KnockoutTest.class, """
+ <div>
+ <ul id='ul' data-bind='foreach: resultLengths'>
+ <li data-bind='text: $data'></li>
+ </ul>
+ </div>
+ """);
try {
KnockoutModel m = Models.bind(new KnockoutModel(), newContext());
m.getResults().add("Ahoj");
@@ -868,13 +872,13 @@ public final class KnockoutTest {
}
@KOTest public void archetypeArrayModificationVisible() throws Exception {
- Object exp = Utils.exposeHTML(KnockoutTest.class,
- "<div>\n"
- + "<ul id='ul' data-bind='foreach: archetypes'>\n"
- + " <li data-bind='text: artifactId'></li>\n"
- + "</ul>\n"
- + "</div>\n"
- );
+ Object exp = Utils.exposeHTML(KnockoutTest.class, """
+ <div>
+ <ul id='ul' data-bind='foreach: archetypes'>
+ <li data-bind='text: artifactId'></li>
+ </ul>
+ </div>
+ """);
try {
KnockoutModel m = Models.bind(new KnockoutModel(), newContext());
m.applyBindings();
@@ -923,33 +927,36 @@ public final class KnockoutTest {
}
private static void triggerClick(String id) throws Exception {
- String s = "var id = arguments[0];"
- + "var e = window.document.getElementById(id);\n "
- + "if (e.checked) throw 'It should not be checked yet: ' + e;\n "
- + "var ev = window.document.createEvent('MouseEvents');\n "
- + "ev.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);\n "
- + "e.dispatchEvent(ev);\n "
- + "if (!e.checked) {\n"
- + " e.checked = true;\n "
- + " e.dispatchEvent(ev);\n "
- + "}\n";
+ String s = """
+ var id = arguments[0];var e = window.document.getElementById(id);
+ if (e.checked) throw 'It should not be checked yet: ' + e;
+ var ev = window.document.createEvent('MouseEvents');
+ ev.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
+ e.dispatchEvent(ev);
+ if (!e.checked) {
+ e.checked = true;
+ e.dispatchEvent(ev);
+ }
+ """;
Utils.executeScript(
KnockoutTest.class,
s, id);
}
private static void triggerChildClick(String id, int pos) throws Exception {
String s =
- "var id = arguments[0]; var pos = arguments[1];\n" +
- "var e = window.document.getElementById(id);\n " +
- "var ev = window.document.createEvent('MouseEvents');\n " +
- "ev.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);\n " +
- "var list = e.childNodes;\n" +
- "var cnt = -1;\n" +
- "for (var i = 0; i < list.length; i++) {\n" +
- " if (list[i].nodeType == 1) cnt++;\n" +
- " if (cnt == pos) return list[i].dispatchEvent(ev);\n" +
- "}\n" +
- "return null;\n";
+ """
+ var id = arguments[0]; var pos = arguments[1];
+ var e = window.document.getElementById(id);
+ var ev = window.document.createEvent('MouseEvents');
+ ev.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
+ var list = e.childNodes;
+ var cnt = -1;
+ for (var i = 0; i < list.length; i++) {
+ if (list[i].nodeType == 1) cnt++;
+ if (cnt == pos) return list[i].dispatchEvent(ev);
+ }
+ return null;
+ """;
Utils.executeScript(
KnockoutTest.class,
s, id, pos);
@@ -957,15 +964,16 @@ public final class KnockoutTest {
private static String childText(String id, int pos) throws Exception {
String s =
- "var id = arguments[0]; var pos = arguments[1];" +
- "var e = window.document.getElementById(id);\n" +
- "var list = e.childNodes;\n" +
- "var cnt = -1;\n" +
- "for (var i = 0; i < list.length; i++) {\n" +
- " if (list[i].nodeType == 1) cnt++;\n" +
- " if (cnt == pos) return list[i].innerHTML;\n" +
- "}\n" +
- "return null;\n";
+ """
+ var id = arguments[0]; var pos = arguments[1];var e = window.document.getElementById(id);
+ var list = e.childNodes;
+ var cnt = -1;
+ for (var i = 0; i < list.length; i++) {
+ if (list[i].nodeType == 1) cnt++;
+ if (cnt == pos) return list[i].innerHTML;
+ }
+ return null;
+ """;
return (String)Utils.executeScript(
KnockoutTest.class,
s, id, pos);
diff --git a/json-tck/src/main/java/net/java/html/json/tests/MinesTest.java b/json-tck/src/main/java/net/java/html/json/tests/MinesTest.java
index 55c5ce3..f33e557 100644
--- a/json-tck/src/main/java/net/java/html/json/tests/MinesTest.java
+++ b/json-tck/src/main/java/net/java/html/json/tests/MinesTest.java
@@ -40,23 +40,22 @@ public final class MinesTest {
@KOTest public void paintTheGridOnClick() throws Throwable {
if (m == null) {
BrwsrCtx ctx = Utils.newContext(MinesTest.class);
- Object exp = Utils.exposeHTML(MinesTest.class,
- " <button id='init' data-bind='click: normalSize'></button>\n" +
- " <table>\n" +
- " <tbody id='table'>\n" +
- " <!-- ko foreach: rows -->\n" +
- " <tr>\n" +
- " <!-- ko foreach: columns -->\n" +
- " <td data-bind='css: style' >\n" +
- " <div data-bind='text: html'></div>\n" +
- " </td>\n" +
- " <!-- /ko -->\n" +
- " </tr>\n" +
- " <!-- /ko -->\n" +
- " </tbody>\n" +
- " </table>\n" +
- ""
- );
+ Object exp = Utils.exposeHTML(MinesTest.class, """
+ <button id='init' data-bind='click: normalSize'></button>
+ <table>
+ <tbody id='table'>
+ <!-- ko foreach: rows -->
+ <tr>
+ <!-- ko foreach: columns -->
+ <td data-bind='css: style' >
+ <div data-bind='text: html'></div>
+ </td>
+ <!-- /ko -->
+ </tr>
+ <!-- /ko -->
+ </tbody>
+ </table>
+ """);
m = Models.bind(new Mines(), ctx);
m.applyBindings();
int cnt = Utils.countChildren(MinesTest.class, "table");
@@ -86,14 +85,14 @@ public final class MinesTest {
}
private static void scheduleClick(String id, int delay) throws Exception {
- String s = "var id = arguments[0]; var delay = arguments[1];"
- + "var e = window.document.getElementById(id);\n "
- + "var f = function() {;\n "
- + " var ev = window.document.createEvent('MouseEvents');\n "
- + " ev.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);\n "
- + " e.dispatchEvent(ev);\n"
- + "};\n"
- + "window.setTimeout(f, delay);";
+ String s = """
+ var id = arguments[0]; var delay = arguments[1];var e = window.document.getElementById(id);
+ var f = function() {;
+ var ev = window.document.createEvent('MouseEvents');
+ ev.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
+ e.dispatchEvent(ev);
+ };
+ window.setTimeout(f, delay);""";
Utils.executeScript(
MinesTest.class,
s, id, delay);
diff --git a/json-tck/src/main/java/net/java/html/json/tests/Utils.java b/json-tck/src/main/java/net/java/html/json/tests/Utils.java
index faa346c..7eb8ffd 100644
--- a/json-tck/src/main/java/net/java/html/json/tests/Utils.java
+++ b/json-tck/src/main/java/net/java/html/json/tests/Utils.java
@@ -106,57 +106,58 @@ public final class Utils {
}
static void exposeTypeOf(Class<?> clazz) throws Exception {
- String s =
- "var global = 0 || eval('this');\n" +
- "if (!global['getTypeof']) {\n" +
- " global['getTypeof'] = function (o) {\n" +
- " return typeof o;\n" +
- " };\n" +
- "}\n" +
- "\n";
+ String s = """
+ var global = 0 || eval('this');
+ if (!global['getTypeof']) {
+ global['getTypeof'] = function (o) {
+ return typeof o;
+ };
+ }
+ """;
executeScript(clazz, s);
}
static Object exposeHTML(Class<?> clazz, String html) throws Exception {
- String s =
- "var n = window.document.getElementById('ko.test.div'); \n "
- + "if (!n) { \n"
- + " n = window.document.createElement('div'); \n "
- + " n.id = 'ko.test.div'; \n "
- + " var body = window.document.getElementsByTagName('body')[0];\n"
- + " body.appendChild(n);\n"
- + "}\n"
- + "n.innerHTML = arguments[0]; \n ";
+ String s = """
+ var n = window.document.getElementById('ko.test.div');
+ if (!n) {
+ n = window.document.createElement('div');
+ n.id = 'ko.test.div';
+ var body = window.document.getElementsByTagName('body')[0];
+ body.appendChild(n);
+ }
+ n.innerHTML = arguments[0];
+ """;
return executeScript(clazz, s, html);
}
static int countChildren(Class<?> caller, String id) throws Exception {
- return ((Number) executeScript(caller,
- "var e = window.document.getElementById(arguments[0]);\n" +
- "if (typeof e === 'undefined') return -2;\n " +
- "var list = e.childNodes;\n" +
- "var cnt = 0;\n" +
- "for (var i = 0; i < list.length; i++) {\n" +
- " if (list[i].nodeType == 1) cnt++;\n" +
- "}\n" +
- "return cnt;\n"
- , id
+ return ((Number) executeScript(caller, """
+ var e = window.document.getElementById(arguments[0]);
+ if (typeof e === 'undefined') return -2;
+ var list = e.childNodes;
+ var cnt = 0;
+ for (var i = 0; i < list.length; i++) {
+ if (list[i].nodeType == 1) cnt++;
+ }
+ return cnt;
+ """, id
)).intValue();
}
static Object addChildren(Class<?> caller, String id, String field, Object value) throws Exception {
- return executeScript(caller,
- "var e = window.document.getElementById(arguments[0]);\n" +
- "var f = arguments[1];\n" +
- "var v = arguments[2];\n" +
- "if (typeof e === 'undefined') return -2;\n " +
- "var c = ko.contextFor(e);\n" +
- "var fn = c.$rawData[f];\n" +
- "var arr = c.$rawData[f]();\n" +
- "arr.push(v);\n" +
- "fn(arr);\n" +
- "return arr;\n"
- , id, field, value
+ return executeScript(caller, """
+ var e = window.document.getElementById(arguments[0]);
+ var f = arguments[1];
+ var v = arguments[2];
+ if (typeof e === 'undefined') return -2;
+ var c = ko.contextFor(e);
+ var fn = c.$rawData[f];
+ var arr = c.$rawData[f]();
+ arr.push(v);
+ fn(arr);
+ return arr;
+ """, id, field, value
);
}
diff --git a/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java b/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java
index 7e342d3..889485f 100644
--- a/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java
+++ b/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java
@@ -543,19 +543,20 @@ public final class ModelProcessor extends AbstractProcessor {
writeClone(className, props, w);
String targetId = findTargetId(e);
if (targetId != null) {
- w.write(" /** Activates this model instance in the current {@link \n"
- + "net.java.html.json.Models#bind(java.lang.Object, net.java.html.BrwsrCtx) browser context}. \n"
- + "In case of using Knockout technology, this means to \n"
- + "bind JSON like data in this model instance with Knockout tags in \n"
- + "the surrounding HTML page.\n"
- );
+ w.write("""
+ /** Activates this model instance in the current {@link
+ net.java.html.json.Models#bind(java.lang.Object, net.java.html.BrwsrCtx) browser context}.
+ In case of using Knockout technology, this means to
+ bind JSON like data in this model instance with Knockout tags in
+ the surrounding HTML page.
+ """);
if (targetId != null) {
w.write("This method binds to element '" + targetId + "' on the page\n");
}
- w.write(""
- + "@return <code>this</code> object\n"
- + "*/\n"
- );
+ w.write("""
+ @return <code>this</code> object
+ */
+ """);
w.write(" public " + className + " applyBindings() {\n");
w.write(" proto.applyBindings();\n");
// w.write(" proto.applyBindings(id);\n");
@@ -1454,11 +1455,11 @@ public final class ModelProcessor extends AbstractProcessor {
}
body.append(");\n");
}
- body.append(
- " return;\n" +
- " } else if (type == 1) {\n" +
- " Object[] ev = (Object[])data;\n"
- );
+ body.append("""
+ return;
+ } else if (type == 1) {
+ Object[] ev = (Object[])data;
+ """);
if (expectsList) {
body.append(
" " + modelClass + "[] arr = new " + modelClass + "[ev.length];\n"
@@ -1481,11 +1482,11 @@ public final class ModelProcessor extends AbstractProcessor {
}
body.append(");\n");
}
- body.append(
- " return;\n" +
- " }\n" +
- " }\n"
- );
+ body.append("""
+ return;
+ }
+ }
+ """);
method.append(" proto.loadJSONWithHeaders(" + index + ",\n ");
method.append(headers.length() == 0 ? "null" : headers).append(",\n ");
method.append(urlBefore).append(", ");
@@ -1529,11 +1530,11 @@ public final class ModelProcessor extends AbstractProcessor {
}
}
body.append(");\n");
- body.append(
- " return;\n" +
- " } else if (type == 2) { /* on error */\n" +
- " Exception value = (Exception)data;\n"
- );
+ body.append("""
+ return;
+ } else if (type == 2) { /* on error */
+ Exception value = (Exception)data;
+ """);
if (onR.onError().isEmpty()) {
body.append(
" value.printStackTrace();\n"
@@ -1556,11 +1557,11 @@ public final class ModelProcessor extends AbstractProcessor {
}
body.append(");\n");
}
- body.append(
- " return;\n" +
- " } else if (type == 1) {\n" +
- " Object[] ev = (Object[])data;\n"
- );
+ body.append("""
+ return;
+ } else if (type == 1) {
+ Object[] ev = (Object[])data;
+ """);
if (expectsList) {
body.append(
" " + modelClass + "[] arr = new " + modelClass + "[ev.length];\n"
@@ -1583,10 +1584,9 @@ public final class ModelProcessor extends AbstractProcessor {
}
body.append(");\n");
}
- body.append(
- " return;\n" +
- " }"
- );
+ body.append("""
+ return;
+ }""");
if (!onR.onError().isEmpty()) {
body.append(" else if (type == 3) { /* on close */\n");
body.append(" ").append(inPckName(clazz, true)).append(".").append(onR.onError()).append("(");
diff --git a/json/src/test/java/net/java/html/json/ModelProcessorTest.java b/json/src/test/java/net/java/html/json/ModelProcessorTest.java
index 5c39641..a440627 100644
--- a/json/src/test/java/net/java/html/json/ModelProcessorTest.java
+++ b/json/src/test/java/net/java/html/json/ModelProcessorTest.java
@@ -34,14 +34,16 @@ public class ModelProcessorTest {
@Test public void verifyWrongType() throws IOException {
String html = "<html><body>"
+ "</body></html>";
- String code = "package x.y.z;\n"
- + "import net.java.html.json.Model;\n"
- + "import net.java.html.json.Property;\n"
- + "@Model(className=\"XModel\", properties={\n"
- + " @Property(name=\"prop\", type=Runnable.class)\n"
- + "})\n"
- + "class X {\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.json.Model;
+ import net.java.html.json.Property;
+ @Model(className="XModel", properties={
+ @Property(name="prop", type=Runnable.class)
+ })
+ class X {
+ }
+ """;
Compile c = Compile.create(html, code);
assertFalse(c.getErrors().isEmpty(), "One error: " + c.getErrors());
@@ -62,16 +64,18 @@ public class ModelProcessorTest {
@Test public void verifyWrongTypeInInnerClass() throws IOException {
String html = "<html><body>"
+ "</body></html>";
- String code = "package x.y.z;\n"
- + "import net.java.html.json.Model;\n"
- + "import net.java.html.json.Property;\n"
- + "class X {\n"
- + " @Model(className=\"XModel\", properties={\n"
- + " @Property(name=\"prop\", type=Runnable.class)\n"
- + " })\n"
- + " static class Inner {\n"
- + " }\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.json.Model;
+ import net.java.html.json.Property;
+ class X {
+ @Model(className="XModel", properties={
+ @Property(name="prop", type=Runnable.class)
+ })
+ static class Inner {
+ }
+ }
+ """;
Compile c = Compile.create(html, code);
assertFalse(c.getErrors().isEmpty(), "One error: " + c.getErrors());
@@ -92,18 +96,20 @@ public class ModelProcessorTest {
@Test public void warnOnNonStatic() throws IOException {
String html = "<html><body>"
+ "</body></html>";
- String code = "package x.y.z;\n"
- + "import net.java.html.json.Model;\n"
- + "import net.java.html.json.Property;\n"
- + "import net.java.html.json.ComputedProperty;\n"
- + "@Model(className=\"XModel\", properties={\n"
- + " @Property(name=\"prop\", type=int.class)\n"
- + "})\n"
- + "class X {\n"
- + " @ComputedProperty int y(int prop) {\n"
- + " return prop;\n"
- + " }\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.json.Model;
+ import net.java.html.json.Property;
+ import net.java.html.json.ComputedProperty;
+ @Model(className="XModel", properties={
+ @Property(name="prop", type=int.class)
+ })
+ class X {
+ @ComputedProperty int y(int prop) {
+ return prop;
+ }
+ }
+ """;
Compile c = Compile.create(html, code);
assertFalse(c.getErrors().isEmpty(), "One error: " + c.getErrors());
@@ -124,22 +130,24 @@ public class ModelProcessorTest {
@Test public void warnOnDuplicated() throws IOException {
String html = "<html><body>"
+ "</body></html>";
- String code = "package x.y.z;\n"
- + "import net.java.html.json.Model;\n"
- + "import net.java.html.json.Property;\n"
- + "import net.java.html.json.ComputedProperty;\n"
- + "@Model(className=\"XModel\", properties={\n"
- + " @Property(name=\"prop1\", type=int.class),\n"
- + " @Property(name=\"prop2\", type=int.class)\n"
- + "})\n"
- + "class X {\n"
- + " @ComputedProperty static int y(int prop1) {\n"
- + " return prop1;\n"
- + " }\n"
- + " @ComputedProperty static int y(int prop1, int prop2) {\n"
- + " return prop2;\n"
- + " }\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.json.Model;
+ import net.java.html.json.Property;
+ import net.java.html.json.ComputedProperty;
+ @Model(className="XModel", properties={
+ @Property(name="prop1", type=int.class),
+ @Property(name="prop2", type=int.class)
+ })
+ class X {
+ @ComputedProperty static int y(int prop1) {
+ return prop1;
+ }
+ @ComputedProperty static int y(int prop1, int prop2) {
+ return prop2;
+ }
+ }
+ """;
Compile c = Compile.create(html, code);
assertFalse(c.getErrors().isEmpty(), "One error: " + c.getErrors());
@@ -160,19 +168,21 @@ public class ModelProcessorTest {
@Test public void warnOnDuplicatedWithNormalProp() throws IOException {
String html = "<html><body>"
+ "</body></html>";
- String code = "package x.y.z;\n"
- + "import net.java.html.json.Model;\n"
- + "import net.java.html.json.Property;\n"
- + "import net.java.html.json.ComputedProperty;\n"
- + "@Model(className=\"XModel\", properties={\n"
- + " @Property(name=\"prop1\", type=int.class),\n"
- + " @Property(name=\"prop2\", type=int.class)\n"
- + "})\n"
- + "class X {\n"
- + " @ComputedProperty static int prop2(int prop1) {\n"
- + " return prop1;\n"
- + " }\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.json.Model;
+ import net.java.html.json.Property;
+ import net.java.html.json.ComputedProperty;
+ @Model(className="XModel", properties={
+ @Property(name="prop1", type=int.class),
+ @Property(name="prop2", type=int.class)
+ })
+ class X {
+ @ComputedProperty static int prop2(int prop1) {
+ return prop1;
+ }
+ }
+ """;
Compile c = Compile.create(html, code);
assertFalse(c.getErrors().isEmpty(), "One error: " + c.getErrors());
@@ -216,11 +226,12 @@ public class ModelProcessorTest {
String html = "<html><body>"
+ "</body></html>";
StringBuilder code = new StringBuilder();
- code.append("package x.y.z;\n"
- + "import net.java.html.json.Model;\n"
- + "import net.java.html.json.Property;\n"
- + "@Model(className=\"XModel\", properties={\n"
- );
+ code.append("""
+ package x.y.z;
+ import net.java.html.json.Model;
+ import net.java.html.json.Property;
+ @Model(className="XModel", properties={
+ """);
for (int i = 1; i <= cnt; i++) {
code.append(" @Property(name=\"prop").append(i).append("\", ");
code.append("type=int.class),\n");
@@ -230,23 +241,23 @@ public class ModelProcessorTest {
code.append("array=true, ");
code.append("type=int.class),\n");
}
- code.append(""
- + "})\n"
- + "class X {\n"
- + " static {\n"
- + " new XModel();\n"
- + " new XModel("
- );
+ code.append("""
+ })
+ class X {
+ static {
+ new XModel();
+ new XModel(""");
if (constructorWithParams) {
code.append("0");
for (int i = 1; i < cnt; i++) {
code.append(",\n").append(i);
}
}
- code.append(");\n"
- + " }\n"
- + "}\n"
- );
+ code.append("""
+ );
+ }
+ }
+ """);
Compile c = Compile.create(html, code.toString());
assertTrue(c.getErrors().isEmpty(), "Compiles OK: " + c.getErrors());
@@ -255,18 +266,20 @@ public class ModelProcessorTest {
@Test public void writeableComputedPropertyMissingWrite() throws IOException {
String html = "<html><body>"
+ "</body></html>";
- String code = "package x.y.z;\n"
- + "import net.java.html.json.Model;\n"
- + "import net.java.html.json.Property;\n"
- + "import net.java.html.json.ComputedProperty;\n"
- + "@Model(className=\"XModel\", properties={\n"
- + " @Property(name=\"prop\", type=int.class)\n"
- + "})\n"
- + "class X {\n"
- + " static @ComputedProperty(write=\"setY\") int y(int prop) {\n"
- + " return prop;\n"
- + " }\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.json.Model;
+ import net.java.html.json.Property;
+ import net.java.html.json.ComputedProperty;
+ @Model(className="XModel", properties={
+ @Property(name="prop", type=int.class)
+ })
+ class X {
+ static @ComputedProperty(write="setY") int y(int prop) {
+ return prop;
+ }
+ }
+ """;
Compile c = Compile.create(html, code);
assertFalse(c.getErrors().isEmpty(), "One error: " + c.getErrors());
@@ -287,20 +300,22 @@ public class ModelProcessorTest {
@Test public void writeableComputedPropertyWrongWriteType() throws IOException {
String html = "<html><body>"
+ "</body></html>";
- String code = "package x.y.z;\n"
- + "import net.java.html.json.Model;\n"
- + "import net.java.html.json.Property;\n"
- + "import net.java.html.json.ComputedProperty;\n"
- + "@Model(className=\"XModel\", properties={\n"
- + " @Property(name=\"prop\", type=int.class)\n"
- + "})\n"
- + "class X {\n"
- + " static @ComputedProperty(write=\"setY\") int y(int prop) {\n"
- + " return prop;\n"
- + " }\n"
- + " static void setY(XModel model, String prop) {\n"
- + " }\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.json.Model;
+ import net.java.html.json.Property;
+ import net.java.html.json.ComputedProperty;
+ @Model(className="XModel", properties={
+ @Property(name="prop", type=int.class)
+ })
+ class X {
+ static @ComputedProperty(write="setY") int y(int prop) {
+ return prop;
+ }
+ static void setY(XModel model, String prop) {
+ }
+ }
+ """;
Compile c = Compile.create(html, code);
assertFalse(c.getErrors().isEmpty(), "One error: " + c.getErrors());
@@ -321,20 +336,22 @@ public class ModelProcessorTest {
@Test public void writeableComputedPropertyReturnsVoid() throws IOException {
String html = "<html><body>"
+ "</body></html>";
- String code = "package x.y.z;\n"
- + "import net.java.html.json.Model;\n"
- + "import net.java.html.json.Property;\n"
- + "import net.java.html.json.ComputedProperty;\n"
- + "@Model(className=\"XModel\", properties={\n"
- + " @Property(name=\"prop\", type=int.class)\n"
- + "})\n"
- + "class X {\n"
- + " static @ComputedProperty(write=\"setY\") int y(int prop) {\n"
- + " return prop;\n"
- + " }\n"
- + " static Number setY(XModel model, int prop) {\n"
- + " }\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.json.Model;
+ import net.java.html.json.Property;
+ import net.java.html.json.ComputedProperty;
+ @Model(className="XModel", properties={
+ @Property(name="prop", type=int.class)
+ })
+ class X {
+ static @ComputedProperty(write="setY") int y(int prop) {
+ return prop;
+ }
+ static Number setY(XModel model, int prop) {
+ }
+ }
+ """;
Compile c = Compile.create(html, code);
assertFalse(c.getErrors().isEmpty(), "One error: " + c.getErrors());
@@ -355,17 +372,19 @@ public class ModelProcessorTest {
@Test public void computedCantReturnVoid() throws IOException {
String html = "<html><body>"
+ "</body></html>";
- String code = "package x.y.z;\n"
- + "import net.java.html.json.Model;\n"
- + "import net.java.html.json.Property;\n"
- + "import net.java.html.json.ComputedProperty;\n"
- + "@Model(className=\"XModel\", properties={\n"
- + " @Property(name=\"prop\", type=int.class)\n"
- + "})\n"
- + "class X {\n"
- + " @ComputedProperty static void y(int prop) {\n"
- + " }\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.json.Model;
+ import net.java.html.json.Property;
+ import net.java.html.json.ComputedProperty;
+ @Model(className="XModel", properties={
+ @Property(name="prop", type=int.class)
+ })
+ class X {
+ @ComputedProperty static void y(int prop) {
+ }
+ }
+ """;
Compile c = Compile.create(html, code);
assertFalse(c.getErrors().isEmpty(), "One error: " + c.getErrors());
@@ -386,18 +405,20 @@ public class ModelProcessorTest {
@Test public void computedCantReturnRunnable() throws IOException {
String html = "<html><body>"
+ "</body></html>";
- String code = "package x.y.z;\n"
- + "import net.java.html.json.Model;\n"
- + "import net.java.html.json.Property;\n"
- + "import net.java.html.json.ComputedProperty;\n"
- + "@Model(className=\"XModel\", properties={\n"
- + " @Property(name=\"prop\", type=int.class)\n"
- + "})\n"
- + "class X {\n"
- + " @ComputedProperty static Runnable y(int prop) {\n"
- + " return null;\n"
- + " }\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.json.Model;
+ import net.java.html.json.Property;
+ import net.java.html.json.ComputedProperty;
+ @Model(className="XModel", properties={
+ @Property(name="prop", type=int.class)
+ })
+ class X {
+ @ComputedProperty static Runnable y(int prop) {
+ return null;
+ }
+ }
+ """;
Compile c = Compile.create(html, code);
assertFalse(c.getErrors().isEmpty(), "One error: " + c.getErrors());
@@ -425,16 +446,17 @@ public class ModelProcessorTest {
String html = "<html><body>"
+ "</body></html>";
- String code = "package x.y.z;\n"
- + "import net.java.html.json.Model;\n"
- + "import net.java.html.json.Property;\n"
- + "import net.java.html.json.ComputedProperty;\n"
- + "@Model(className=\"XModel\", properties={\n"
- + " @Property(name=\"prop\", type=long.class)\n"
- + "})\n"
- + "class X {\n"
- + " @ComputedProperty static double derived(long prop) { return prop; }"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.json.Model;
+ import net.java.html.json.Property;
+ import net.java.html.json.ComputedProperty;
+ @Model(className="XModel", properties={
+ @Property(name="prop", type=long.class)
+ })
+ class X {
+ @ComputedProperty static double derived(long prop) { return prop; }}
+ """;
Compile c = Compile.create(html, code, "1.5");
assertTrue(c.getErrors().isEmpty(), "No errors: " + c.getErrors());
@@ -443,16 +465,18 @@ public class ModelProcessorTest {
@Test public void instanceNeedsDefaultConstructor() throws IOException {
String html = "<html><body>"
+ "</body></html>";
- String code = "package x.y.z;\n"
- + "import net.java.html.json.Model;\n"
- + "import net.java.html.json.Property;\n"
- + "import net.java.html.json.ComputedProperty;\n"
- + "@Model(className=\"XModel\", instance=true, properties={\n"
- + " @Property(name=\"prop\", type=long.class)\n"
- + "})\n"
- + "class X {\n"
- + " X(int x) {}\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.json.Model;
+ import net.java.html.json.Property;
+ import net.java.html.json.ComputedProperty;
+ @Model(className="XModel", instance=true, properties={
+ @Property(name="prop", type=long.class)
+ })
+ class X {
+ X(int x) {}
+ }
+ """;
Compile c = Compile.create(html, code);
c.assertError("Needs non-private default constructor when instance=true");
@@ -461,16 +485,18 @@ public class ModelProcessorTest {
@Test public void instanceNeedsNonPrivateConstructor() throws IOException {
String html = "<html><body>"
+ "</body></html>";
- String code = "package x.y.z;\n"
- + "import net.java.html.json.Model;\n"
- + "import net.java.html.json.Property;\n"
- + "import net.java.html.json.ComputedProperty;\n"
- + "@Model(className=\"XModel\", instance=true, properties={\n"
- + " @Property(name=\"prop\", type=long.class)\n"
- + "})\n"
- + "class X {\n"
- + " private X() {}\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.json.Model;
+ import net.java.html.json.Property;
+ import net.java.html.json.ComputedProperty;
+ @Model(className="XModel", instance=true, properties={
+ @Property(name="prop", type=long.class)
+ })
+ class X {
+ private X() {}
+ }
+ """;
Compile c = Compile.create(html, code);
c.assertError("Needs non-private default constructor when instance=true");
@@ -479,15 +505,17 @@ public class ModelProcessorTest {
@Test public void instanceNoConstructorIsOK() throws IOException {
String html = "<html><body>"
+ "</body></html>";
- String code = "package x.y.z;\n"
- + "import net.java.html.json.Model;\n"
- + "import net.java.html.json.Property;\n"
- + "import net.java.html.json.ComputedProperty;\n"
- + "@Model(className=\"XModel\", instance=true, properties={\n"
- + " @Property(name=\"prop\", type=long.class)\n"
- + "})\n"
- + "class X {\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.json.Model;
+ import net.java.html.json.Property;
+ import net.java.html.json.ComputedProperty;
+ @Model(className="XModel", instance=true, properties={
+ @Property(name="prop", type=long.class)
+ })
+ class X {
+ }
+ """;
Compile c = Compile.create(html, code);
c.assertNoErrors();
@@ -535,20 +563,22 @@ public class ModelProcessorTest {
@Test public void jsonNeedsToUseGet () throws Exception {
String html = "<html><body>"
+ "</body></html>";
- String code = "package x.y.z;\n"
- + "import net.java.html.json.Model;\n"
- + "import net.java.html.json.Property;\n"
- + "import net.java.html.json.OnReceive;\n"
- + "@Model(className=\"XModel\", properties={\n"
- + " @Property(name=\"prop\", type=long.class)\n"
- + "})\n"
- + "class X {\n"
- + " @Model(className=\"PQ\", properties={})\n"
- + " class PImpl {\n"
- + " }\n"
- + " @OnReceive(method=\"POST\", jsonp=\"callback\", url=\"whereever\")\n"
- + " static void obtained(XModel m, PQ p) { }\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.json.Model;
+ import net.java.html.json.Property;
+ import net.java.html.json.OnReceive;
+ @Model(className="XModel", properties={
+ @Property(name="prop", type=long.class)
+ })
+ class X {
+ @Model(className="PQ", properties={})
+ class PImpl {
+ }
+ @OnReceive(method="POST", jsonp="callback", url="whereever")
+ static void obtained(XModel m, PQ p) { }
+ }
+ """;
Compile c = Compile.create(html, code);
assertFalse(c.getErrors().isEmpty(), "One error: " + c.getErrors());
@@ -565,20 +595,22 @@ public class ModelProcessorTest {
@Test public void noHeadersForWebSockets() throws Exception {
String html = "<html><body>"
+ "</body></html>";
- String code = "package x.y.z;\n"
- + "import net.java.html.json.Model;\n"
- + "import net.java.html.json.Property;\n"
- + "import net.java.html.json.OnReceive;\n"
- + "@Model(className=\"XModel\", properties={\n"
- + " @Property(name=\"prop\", type=long.class)\n"
- + "})\n"
- + "class X {\n"
- + " @Model(className=\"PQ\", properties={})\n"
- + " class PImpl {\n"
- + " }\n"
- + " @OnReceive(method=\"WebSocket\", data = PQ.class, headers=\"SomeHeader: {some}\", url=\"whereever\")\n"
- + " static void obtained(XModel m, PQ p) { }\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.json.Model;
+ import net.java.html.json.Property;
+ import net.java.html.json.OnReceive;
+ @Model(className="XModel", properties={
+ @Property(name="prop", type=long.class)
+ })
+ class X {
+ @Model(className="PQ", properties={})
+ class PImpl {
+ }
+ @OnReceive(method="WebSocket", data = PQ.class, headers="SomeHeader: {some}", url="whereever")
+ static void obtained(XModel m, PQ p) { }
+ }
+ """;
Compile c = Compile.create(html, code);
assertFalse(c.getErrors().isEmpty(), "One error: " + c.getErrors());
@@ -595,20 +627,22 @@ public class ModelProcessorTest {
@Test public void webSocketsWithoutDataIsError() throws Exception {
String html = "<html><body>"
+ "</body></html>";
- String code = "package x.y.z;\n"
- + "import net.java.html.json.Model;\n"
- + "import net.java.html.json.Property;\n"
- + "import net.java.html.json.OnReceive;\n"
- + "@Model(className=\"XModel\", properties={\n"
- + " @Property(name=\"prop\", type=long.class)\n"
- + "})\n"
- + "class X {\n"
- + " @Model(className=\"PQ\", properties={})\n"
- + " class PImpl {\n"
- + " }\n"
- + " @OnReceive(method=\"WebSocket\", url=\"whereever\")\n"
- + " static void obtained(XModel m, PQ p) { }\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.json.Model;
+ import net.java.html.json.Property;
+ import net.java.html.json.OnReceive;
+ @Model(className="XModel", properties={
+ @Property(name="prop", type=long.class)
+ })
+ class X {
+ @Model(className="PQ", properties={})
+ class PImpl {
+ }
+ @OnReceive(method="WebSocket", url="whereever")
+ static void obtained(XModel m, PQ p) { }
+ }
+ """;
Compile c = Compile.create(html, code);
assertFalse(c.getErrors().isEmpty(), "One error: " + c.getErrors());
@@ -624,20 +658,22 @@ public class ModelProcessorTest {
@Test public void noNewLinesInHeaderLines() throws Exception {
String html = "<html><body>"
+ "</body></html>";
- String code = "package x.y.z;\n"
- + "import net.java.html.json.Model;\n"
- + "import net.java.html.json.Property;\n"
- + "import net.java.html.json.OnReceive;\n"
- + "@Model(className=\"XModel\", properties={\n"
- + " @Property(name=\"prop\", type=long.class)\n"
- + "})\n"
- + "class X {\n"
- + " @Model(className=\"PQ\", properties={})\n"
- + " class PImpl {\n"
- + " }\n"
- + " @OnReceive(headers=\"SomeHeader\\n: {some}\", url=\"whereever\")\n"
- + " static void obtained(XModel m, PQ p) { }\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.json.Model;
+ import net.java.html.json.Property;
+ import net.java.html.json.OnReceive;
+ @Model(className="XModel", properties={
+ @Property(name="prop", type=long.class)
+ })
+ class X {
+ @Model(className="PQ", properties={})
+ class PImpl {
+ }
+ @OnReceive(headers="SomeHeader\\n: {some}", url="whereever")
+ static void obtained(XModel m, PQ p) { }
+ }
+ """;
Compile c = Compile.create(html, code);
assertFalse(c.getErrors().isEmpty(), "One error: " + c.getErrors());
@@ -654,20 +690,22 @@ public class ModelProcessorTest {
@Test public void noReturnInHeaderLines() throws Exception {
String html = "<html><body>"
+ "</body></html>";
- String code = "package x.y.z;\n"
- + "import net.java.html.json.Model;\n"
- + "import net.java.html.json.Property;\n"
- + "import net.java.html.json.OnReceive;\n"
- + "@Model(className=\"XModel\", properties={\n"
- + " @Property(name=\"prop\", type=long.class)\n"
- + "})\n"
- + "class X {\n"
- + " @Model(className=\"PQ\", properties={})\n"
- + " class PImpl {\n"
- + " }\n"
- + " @OnReceive(headers=\"Some\\rHeader: {some}\", url=\"whereever\")\n"
- + " static void obtained(XModel m, PQ p) { }\n"
- + "}\n";
+ String code = """
+ package x.y.z;
+ import net.java.html.json.Model;
+ import net.java.html.json.Property;
+ import net.java.html.json.OnReceive;
+ @Model(className="XModel", properties={
+ @Property(name="prop", type=long.class)
+ })
+ class X {
+ @Model(className="PQ", properties={})
+ class PImpl {
+ }
+ @OnReceive(headers="Some\\rHeader: {some}", url="whereever")
+ static void obtained(XModel m, PQ p) { }
+ }
+ """;
Compile c = Compile.create(html, code);
assertFalse(c.getErrors().isEmpty(), "One error: " + c.getErrors());
@@ -682,125 +720,133 @@ public class ModelProcessorTest {
}
@Test public void onErrorHasToExist() throws IOException {
- Compile res = Compile.create("", "package x;\n"
- + "@net.java.html.json.Model(className=\"MyModel\", properties= {\n"
- + " @net.java.html.json.Property(name=\"x\", type=String.class)\n"
- + "})\n"
- + "class UseOnReceive {\n"
- + " @net.java.html.json.OnReceive(url=\"http://nowhere.com\", onError=\"doesNotExist\")\n"
- + " static void onMessage(MyModel model, String value) {\n"
- + " }\n"
- + "}\n"
- );
+ Compile res = Compile.create("", """
+ package x;
+ @net.java.html.json.Model(className="MyModel", properties= {
+ @net.java.html.json.Property(name="x", type=String.class)
+ })
+ class UseOnReceive {
+ @net.java.html.json.OnReceive(url="http://nowhere.com", onError="doesNotExist")
+ static void onMessage(MyModel model, String value) {
+ }
+ }
+ """);
res.assertErrors();
res.assertError("not find doesNotExist");
}
@Test public void usingListIsOK() throws IOException {
- Compile res = Compile.create("", "package x;\n"
- + "@net.java.html.json.Model(className=\"MyModel\", properties= {\n"
- + " @net.java.html.json.Property(name=\"x\", type=String.class)\n"
- + "})\n"
- + "class UseOnReceive {\n"
- + " @net.java.html.json.OnReceive(url=\"http://nowhere.com\")\n"
- + " static void onMessage(MyModel model, java.util.List<MyData> value) {\n"
- + " }\n"
- + "\n"
- + " @net.java.html.json.Model(className=\"MyData\", properties={\n"
- + " })\n"
- + " static class MyDataModel {\n"
- + " }\n"
- + "}\n"
- );
+ Compile res = Compile.create("", """
+ package x;
+ @net.java.html.json.Model(className="MyModel", properties= {
+ @net.java.html.json.Property(name="x", type=String.class)
+ })
+ class UseOnReceive {
+ @net.java.html.json.OnReceive(url="http://nowhere.com")
+ static void onMessage(MyModel model, java.util.List<MyData> value) {
+ }
+
+ @net.java.html.json.Model(className="MyData", properties={
+ })
+ static class MyDataModel {
+ }
+ }
+ """);
res.assertNoErrors();
}
@Test public void functionAndPropertyCollide() throws IOException {
- Compile res = Compile.create("", "package x;\n"
- + "@net.java.html.json.Model(className=\"MyModel\", properties= {\n"
- + " @net.java.html.json.Property(name=\"x\", type=String.class)\n"
- + "})\n"
- + "class Collision {\n"
- + " @net.java.html.json.Function\n"
- + " static void x(MyModel model, String value) {\n"
- + " }\n"
- + "}\n"
- );
+ Compile res = Compile.create("", """
+ package x;
+ @net.java.html.json.Model(className="MyModel", properties= {
+ @net.java.html.json.Property(name="x", type=String.class)
+ })
+ class Collision {
+ @net.java.html.json.Function
+ static void x(MyModel model, String value) {
+ }
+ }
+ """);
res.assertErrors();
res.assertError("cannot have the name");
}
@Test public void twoPropertiesCollide() throws IOException {
- Compile res = Compile.create("", "package x;\n"
- + "@net.java.html.json.Model(className=\"MyModel\", properties= {\n"
- + " @net.java.html.json.Property(name=\"x\", type=String.class),\n"
- + " @net.java.html.json.Property(name=\"x\", type=int.class)\n"
- + "})\n"
- + "class Collision {\n"
- + "}\n"
- );
+ Compile res = Compile.create("", """
+ package x;
+ @net.java.html.json.Model(className="MyModel", properties= {
+ @net.java.html.json.Property(name="x", type=String.class),
+ @net.java.html.json.Property(name="x", type=int.class)
+ })
+ class Collision {
+ }
+ """);
res.assertErrors();
res.assertError("Cannot have the property");
}
@Test public void propertyAndComputedOneCollide() throws IOException {
- Compile res = Compile.create("", "package x;\n"
- + "@net.java.html.json.Model(className=\"MyModel\", properties= {\n"
- + " @net.java.html.json.Property(name=\"x\", type=String.class),\n"
- + "})\n"
- + "class Collision {\n"
- + " @net.java.html.json.ComputedProperty static int x(String x) {\n"
- + " return x.length();\n"
- + " }\n"
- + "}\n"
- );
+ Compile res = Compile.create("", """
+ package x;
+ @net.java.html.json.Model(className="MyModel", properties= {
+ @net.java.html.json.Property(name="x", type=String.class),
+ })
+ class Collision {
+ @net.java.html.json.ComputedProperty static int x(String x) {
+ return x.length();
+ }
+ }
+ """);
res.assertErrors();
res.assertError("Cannot have the property");
}
@Test public void onWebSocketJustTwoArgs() throws IOException {
- Compile res = Compile.create("", "package x;\n"
- + "@net.java.html.json.Model(className=\"MyModel\", properties= {\n"
- + " @net.java.html.json.Property(name=\"x\", type=String.class)\n"
- + "})\n"
- + "class UseOnReceive {\n"
- + " @net.java.html.json.OnReceive(url=\"http://nowhere.com\", method=\"WebSocket\", data=String.class)\n"
- + " static void onMessage(MyModel model, String value, int arg) {\n"
- + " }\n"
- + "}\n"
- );
+ Compile res = Compile.create("", """
+ package x;
+ @net.java.html.json.Model(className="MyModel", properties= {
+ @net.java.html.json.Property(name="x", type=String.class)
+ })
+ class UseOnReceive {
+ @net.java.html.json.OnReceive(url="http://nowhere.com", method="WebSocket", data=String.class)
+ static void onMessage(MyModel model, String value, int arg) {
+ }
+ }
+ """);
res.assertErrors();
res.assertError("only have two arg");
}
@Test public void onErrorWouldHaveToBeStatic() throws IOException {
- Compile res = Compile.create("", "package x;\n"
- + "@net.java.html.json.Model(className=\"MyModel\", properties= {\n"
- + " @net.java.html.json.Property(name=\"x\", type=String.class)\n"
- + "})\n"
- + "class UseOnReceive {\n"
- + " @net.java.html.json.OnReceive(url=\"http://nowhere.com\", onError=\"notStatic\")\n"
- + " static void onMessage(MyModel model, String value) {\n"
- + " }\n"
- + " void notStatic(Exception e) {}\n"
- + "}\n"
- );
+ Compile res = Compile.create("", """
+ package x;
+ @net.java.html.json.Model(className="MyModel", properties= {
+ @net.java.html.json.Property(name="x", type=String.class)
+ })
+ class UseOnReceive {
+ @net.java.html.json.OnReceive(url="http://nowhere.com", onError="notStatic")
+ static void onMessage(MyModel model, String value) {
+ }
+ void notStatic(Exception e) {}
+ }
+ """);
res.assertErrors();
res.assertError("have to be static");
}
@Test public void onErrorMustAcceptExceptionArgument() throws IOException {
- Compile res = Compile.create("", "package x;\n"
- + "@net.java.html.json.Model(className=\"MyModel\", properties= {\n"
- + " @net.java.html.json.Property(name=\"x\", type=String.class)\n"
- + "})\n"
- + "class UseOnReceive {\n"
- + " @net.java.html.json.OnReceive(url=\"http://nowhere.com\", onError=\"subclass\")\n"
- + " static void onMessage(MyModel model, String value) {\n"
- + " }\n"
- + " static void subclass(java.io.IOException e) {}\n"
- + "}\n"
- );
+ Compile res = Compile.create("", """
+ package x;
+ @net.java.html.json.Model(className="MyModel", properties= {
+ @net.java.html.json.Property(name="x", type=String.class)
+ })
+ class UseOnReceive {
+ @net.java.html.json.OnReceive(url="http://nowhere.com", onError="subclass")
+ static void onMessage(MyModel model, String value) {
+ }
+ static void subclass(java.io.IOException e) {}
+ }
+ """);
res.assertErrors();
res.assertError("Error method first argument needs to be MyModel and second Exception");
}
diff --git a/ko-felix-test/src/main/java/org/netbeans/html/ko/felix/test/KnockoutFelixTCKImpl.java b/ko-felix-test/src/main/java/org/netbeans/html/ko/felix/test/KnockoutFelixTCKImpl.java
index d7ee68a..e786df0 100644
--- a/ko-felix-test/src/main/java/org/netbeans/html/ko/felix/test/KnockoutFelixTCKImpl.java
+++ b/ko-felix-test/src/main/java/org/netbeans/html/ko/felix/test/KnockoutFelixTCKImpl.java
@@ -161,12 +161,11 @@ public class KnockoutFelixTCKImpl extends KnockoutTCK implements Callable<Class[
public native Object executeScript(String script, Object[] arguments);
@JavaScriptBody(args = { }, body =
- "var h;"
- + "if (!!window && !!window.location && !!window.location.href)\n"
- + " h = window.location.href;\n"
- + "else "
- + " h = null;"
- + "return h;\n"
+ """
+ var h;if (!!window && !!window.location && !!window.location.href)
+ h = window.location.href;
+ else h = null;return h;
+ """
)
private static native String findBaseURL();
diff --git a/ko-osgi-test/src/main/java/org/netbeans/html/ko/osgi/test/KnockoutEquinoxTCKImpl.java b/ko-osgi-test/src/main/java/org/netbeans/html/ko/osgi/test/KnockoutEquinoxTCKImpl.java
index fe060d4..77bd5d0 100644
--- a/ko-osgi-test/src/main/java/org/netbeans/html/ko/osgi/test/KnockoutEquinoxTCKImpl.java
+++ b/ko-osgi-test/src/main/java/org/netbeans/html/ko/osgi/test/KnockoutEquinoxTCKImpl.java
@@ -156,12 +156,11 @@ public class KnockoutEquinoxTCKImpl extends KnockoutTCK implements Callable<Clas
public native Object executeScript(String script, Object[] arguments);
@JavaScriptBody(args = { }, body =
- "var h;"
- + "if (!!window && !!window.location && !!window.location.href)\n"
- + " h = window.location.href;\n"
- + "else "
- + " h = null;"
- + "return h;\n"
+ """
+ var h;if (!!window && !!window.location && !!window.location.href)
+ h = window.location.href;
+ else h = null;return h;
+ """
)
private static native String findBaseURL();
diff --git a/ko-ws-tyrus/src/main/java/org/netbeans/html/wstyrus/LoadJSON.java b/ko-ws-tyrus/src/main/java/org/netbeans/html/wstyrus/LoadJSON.java
index 403b169..8cfcf24 100644
--- a/ko-ws-tyrus/src/main/java/org/netbeans/html/wstyrus/LoadJSON.java
+++ b/ko-ws-tyrus/src/main/java/org/netbeans/html/wstyrus/LoadJSON.java
@@ -248,11 +248,12 @@ final class LoadJSON implements Runnable {
}
@JavaScriptBody(args = {"object", "property"}, body =
- "var ret;\n" +
- "if (property === null) ret = object;\n" +
- "else if (object === null) ret = null;\n" +
- "else ret = object[property];\n" +
- "return ret ? (typeof ko === 'undefined' ? ret : ko.utils.unwrapObservable(ret)) : null;"
+ """
+ var ret;
+ if (property === null) ret = object;
+ else if (object === null) ret = null;
+ else ret = object[property];
+ return ret ? (typeof ko === 'undefined' ? ret : ko.utils.unwrapObservable(ret)) : null;"""
)
private static Object getProperty(Object object, String property) {
return null;
diff --git a/ko-ws-tyrus/src/test/java/org/netbeans/html/wstyrus/TyrusKnockoutTest.java b/ko-ws-tyrus/src/test/java/org/netbeans/html/wstyrus/TyrusKnockoutTest.java
index c651346..95b24dc 100644
--- a/ko-ws-tyrus/src/test/java/org/netbeans/html/wstyrus/TyrusKnockoutTest.java
+++ b/ko-ws-tyrus/src/test/java/org/netbeans/html/wstyrus/TyrusKnockoutTest.java
@@ -159,12 +159,11 @@ public final class TyrusKnockoutTest extends KnockoutTCK {
public native Object executeScript(String script, Object[] arguments);
@JavaScriptBody(args = { }, body =
- "var h;"
- + "if (!!window && !!window.location && !!window.location.href)\n"
- + " h = window.location.href;\n"
- + "else "
- + " h = null;"
- + "return h;\n"
+ """
+ var h;if (!!window && !!window.location && !!window.location.href)
+ h = window.location.href;
+ else h = null;return h;
+ """
)
private static native String findBaseURL();
diff --git a/ko4j/src/main/java/org/netbeans/html/ko4j/Knockout.java b/ko4j/src/main/java/org/netbeans/html/ko4j/Knockout.java
index 871c55b..47bdf7c 100644
--- a/ko4j/src/main/java/org/netbeans/html/ko4j/Knockout.java
+++ b/ko4j/src/main/java/org/netbeans/html/ko4j/Knockout.java
@@ -41,17 +41,19 @@ import org.netbeans.html.json.spi.PropertyBinding;
final class Knockout {
@JavaScriptBody(args = {"object", "property"}, body =
- "var ret;\n" +
- "if (property === null) ret = object;\n" +
- "else if (object === null) ret = null;\n" +
- "else ret = object[property];\n" +
- "if (typeof ret !== 'undefined' && ret !== null) {\n" +
- " if (typeof ko !== 'undefined' && ko['utils'] && ko['utils']['unwrapObservable']) {\n" +
- " return ko['utils']['unwrapObservable'](ret);\n" +
- " }\n" +
- " return ret;\n" +
- "}\n" +
- "return null;\n"
+ """
+ var ret;
+ if (property === null) ret = object;
+ else if (object === null) ret = null;
+ else ret = object[property];
+ if (typeof ret !== 'undefined' && ret !== null) {
+ if (typeof ko !== 'undefined' && ko['utils'] && ko['utils']['unwrapObservable']) {
+ return ko['utils']['unwrapObservable'](ret);
+ }
+ return ret;
+ }
+ return null;
+ """
)
static Object getProperty(Object object, String property) {
return null;
@@ -192,19 +194,21 @@ final class Knockout {
@JavaScriptBody(args = { "model", "prop", "oldValue", "newValue" },
wait4js = false,
body =
- "if (model) {\n"
- + " var koProp = model[prop];\n"
- + " if (koProp) {\n"
- + " var koFire = koProp['valueHasMutated'];\n"
- + " if (koFire) {\n"
- + " if (oldValue !== null || newValue !== null) {\n"
- + " koFire(newValue);\n"
- + " } else {\n"
- + " koFire();\n"
- + " }\n"
- + " }\n"
- + " }\n"
- + "}\n"
+ """
+ if (model) {
+ var koProp = model[prop];
+ if (koProp) {
+ var koFire = koProp['valueHasMutated'];
+ if (koFire) {
+ if (oldValue !== null || newValue !== null) {
+ koFire(newValue);
+ } else {
+ koFire();
+ }
+ }
+ }
+ }
+ """
)
private native static void valueHasMutated(
Object model, String prop, Object oldValue, Object newValue
@@ -215,18 +219,22 @@ final class Knockout {
}
@JavaScriptBody(args = { "id", "bindings" }, body =
- "var d = window['document'];\n" +
- "var e = id ? d['getElementById'](id) : d['body'];\n" +
- "ko['cleanNode'](e);\n" +
- "ko['applyBindings'](bindings, e);\n" +
- "return bindings['ko4j'];\n"
+ """
+ var d = window['document'];
+ var e = id ? d['getElementById'](id) : d['body'];
+ ko['cleanNode'](e);
+ ko['applyBindings'](bindings, e);
+ return bindings['ko4j'];
+ """
)
private native static Object applyBindings(String id, Object bindings);
@JavaScriptBody(args = { "cnt" }, body =
- "var arr = new Array(cnt);\n" +
- "for (var i = 0; i < cnt; i++) arr[i] = new Object();\n" +
- "return arr;\n"
+ """
+ var arr = new Array(cnt);
+ for (var i = 0; i < cnt; i++) arr[i] = new Object();
+ return arr;
+ """
)
native static Object[] allocJS(int cnt);
@@ -236,80 +244,82 @@ final class Knockout {
wait4js = false,
args = { "thiz", "ret", "copyFrom", "propNames", "propInfo", "propValues", "funcNames" },
body =
- "Object.defineProperty(ret, 'ko4j', { value : thiz });\n"
- + "function normalValue(r) {\n"
- + " if (r) try { var br = r.valueOf(); } catch (err) {}\n"
- + " return br === undefined ? r: br;\n"
- + "}\n"
- + "function koComputed(index, name, readOnly, value) {\n"
- + " var orig = copyFrom ? copyFrom[name] : null;\n"
- + " if (!ko['isObservable'](orig)) {\n"
- + " orig = null;\n"
- + " var trigger = ko['observable']()['extend']({'notify':'always'});\n"
- + " } else {\n"
- + " var trigger = orig;\n"
- + " }\n"
- + " function realGetter() {\n"
- + " var self = ret['ko4j'];\n"
- + " try {\n"
- + " var v = self ? self.@org.netbeans.html.ko4j.Knockout::getValue(I)(index) : null;\n"
- + " return v;\n"
- + " } catch (e) {\n"
- + " alert(\"Cannot call getValue on \" + self + \" prop: \" + name + \" error: \" + e);\n"
- + " }\n"
- + " }\n"
- + " var activeGetter = orig ? orig : function() { return value; };\n"
- + " var bnd = {\n"
- + " 'read': function() {\n"
- + " trigger();\n"
- + " if (orig) {\n"
- + " var r = orig();\n"
- + " } else {\n"
- + " var r = activeGetter();\n"
- + " activeGetter = realGetter;\n"
- + " }\n"
- + " return normalValue(r);;\n"
- + " },\n"
- + " 'owner': ret\n"
- + " };\n"
- + " if (!readOnly) {\n"
- + " function write(val) {\n"
- + " if (orig) orig(val);\n"
- + " var self = ret['ko4j'];\n"
- + " if (!self) return;\n"
- + " var model = val ? val['ko4j'] : null;\n"
- + " self.@org.netbeans.html.ko4j.Knockout::setValue(ILjava/lang/Object;)(index, model ? model : val);\n"
- + " };\n"
- + " bnd['write'] = write;\n"
- + " if (orig) {\n"
- + " write(orig());\n"
- + " orig.subscribe(write);\n"
- + " }\n"
- + " };\n"
- + " var cmpt = ko['computed'](bnd);\n"
- + " cmpt['valueHasMutated'] = function(val) {\n"
- + " if (arguments.length === 1) activeGetter = function() { return val; };\n"
- + " trigger(val);\n"
- + " };\n"
- + " ret[name] = cmpt;\n"
- + "}\n"
- + "for (var i = 0; i < propNames.length; i++) {\n"
- + " if ((propInfo[i] & 2) !== 0) {\n"
- + " ret[propNames[i]] = normalValue(propValues[i]);\n"
- + " } else {\n"
- + " koComputed(i, propNames[i], (propInfo[i] & 1) !== 0, propValues[i]);\n"
- + " }\n"
- + "}\n"
- + "function koExpose(index, name) {\n"
- + " ret[name] = function(data, ev) {\n"
- + " var self = ret['ko4j'];\n"
- + " if (!self) return;\n"
- + " self.@org.netbeans.html.ko4j.Knockout::call(ILjava/lang/Object;Ljava/lang/Object;)(index, data, ev);\n"
- + " };\n"
- + "}\n"
- + "for (var i = 0; i < funcNames.length; i++) {\n"
- + " koExpose(i, funcNames[i]);\n"
- + "}\n"
+ """
+ Object.defineProperty(ret, 'ko4j', { value : thiz });
+ function normalValue(r) {
+ if (r) try { var br = r.valueOf(); } catch (err) {}
+ return br === undefined ? r: br;
+ }
+ function koComputed(index, name, readOnly, value) {
+ var orig = copyFrom ? copyFrom[name] : null;
+ if (!ko['isObservable'](orig)) {
+ orig = null;
+ var trigger = ko['observable']()['extend']({'notify':'always'});
+ } else {
+ var trigger = orig;
+ }
+ function realGetter() {
+ var self = ret['ko4j'];
+ try {
+ var v = self ? self.@org.netbeans.html.ko4j.Knockout::getValue(I)(index) : null;
+ return v;
+ } catch (e) {
+ alert("Cannot call getValue on " + self + " prop: " + name + " error: " + e);
+ }
+ }
+ var activeGetter = orig ? orig : function() { return value; };
+ var bnd = {
+ 'read': function() {
+ trigger();
+ if (orig) {
+ var r = orig();
+ } else {
+ var r = activeGetter();
+ activeGetter = realGetter;
+ }
+ return normalValue(r);;
+ },
+ 'owner': ret
+ };
+ if (!readOnly) {
+ function write(val) {
+ if (orig) orig(val);
+ var self = ret['ko4j'];
+ if (!self) return;
+ var model = val ? val['ko4j'] : null;
+ self.@org.netbeans.html.ko4j.Knockout::setValue(ILjava/lang/Object;)(index, model ? model : val);
+ };
+ bnd['write'] = write;
+ if (orig) {
+ write(orig());
+ orig.subscribe(write);
+ }
+ };
+ var cmpt = ko['computed'](bnd);
+ cmpt['valueHasMutated'] = function(val) {
+ if (arguments.length === 1) activeGetter = function() { return val; };
+ trigger(val);
+ };
+ ret[name] = cmpt;
+ }
+ for (var i = 0; i < propNames.length; i++) {
+ if ((propInfo[i] & 2) !== 0) {
+ ret[propNames[i]] = normalValue(propValues[i]);
+ } else {
+ koComputed(i, propNames[i], (propInfo[i] & 1) !== 0, propValues[i]);
+ }
+ }
+ function koExpose(index, name) {
+ ret[name] = function(data, ev) {
+ var self = ret['ko4j'];
+ if (!self) return;
+ self.@org.netbeans.html.ko4j.Knockout::call(ILjava/lang/Object;Ljava/lang/Object;)(index, data, ev);
+ };
+ }
+ for (var i = 0; i < funcNames.length; i++) {
+ koExpose(i, funcNames[i]);
+ }
+ """
)
private static native void wrapModel(
Knockout thiz,
@@ -320,11 +330,13 @@ final class Knockout {
);
@JavaScriptBody(args = { "js" }, wait4js = false, body =
- "delete js['ko4j'];\n" +
- "for (var p in js) {\n" +
- " delete js[p];\n" +
- "};\n" +
- "\n"
+ """
+ delete js['ko4j'];
+ for (var p in js) {
+ delete js[p];
+ };
+
+ """
)
private static native void clean(Object js);
diff --git a/ko4j/src/main/java/org/netbeans/html/ko4j/LoadJSON.java b/ko4j/src/main/java/org/netbeans/html/ko4j/LoadJSON.java
index 67c9123..78d3bb2 100644
--- a/ko4j/src/main/java/org/netbeans/html/ko4j/LoadJSON.java
+++ b/ko4j/src/main/java/org/netbeans/html/ko4j/LoadJSON.java
@@ -41,14 +41,16 @@ final class LoadJSON {
}
@JavaScriptBody(args = {"name", "done"}, javacall = true, body
- = "if (window[name]) return false;\n "
- + "window[name] = function(data) {\n "
- + " delete window[name];\n"
- + " var el = window.document.getElementById(name);\n"
- + " el.parentNode.removeChild(el);\n"
- + " done.@org.netbeans.html.json.spi.JSONCall::notifySuccess(Ljava/lang/Object;)(data);\n"
- + "};\n"
- + "return true;\n"
+ = """
+ if (window[name]) return false;
+ window[name] = function(data) {
+ delete window[name];
+ var el = window.document.getElementById(name);
+ el.parentNode.removeChild(el);
+ done.@org.netbeans.html.json.spi.JSONCall::notifySuccess(Ljava/lang/Object;)(data);
+ };
+ return true;
+ """
)
private static boolean defineIfUnused(String name, JSONCall done) {
return true;
@@ -59,47 +61,47 @@ final class LoadJSON {
return s;
}
- @JavaScriptBody(args = {"url", "done", "method", "data", "hp"}, javacall = true, body = ""
- + "var request = new XMLHttpRequest();\n"
- + "if (!method) method = 'GET';\n"
- + "request.open(method, url, true);\n"
- + "request.setRequestHeader('Content-Type', 'application/json; charset=utf-8');\n"
- + "for (var i = 0; i < hp.length; i += 2) {\n"
- + " var h = hp[i];\n"
- + " var v = hp[i + 1];\n"
- + " request.setRequestHeader(h, v);\n"
- + "}\n"
- + "request.onreadystatechange = function() {\n"
- + " if (request.readyState !== 4) return;\n"
- + " var r = request.response || request.responseText;\n"
- + " try {\n"
- + " var str = r;\n"
- + " if (request.status !== 0)\n"
- + " if (request.status < 100 || request.status >= 400) throw request.status + ': ' + request.statusText;"
- + " try { r = eval('(' + r + ')'); } catch (ignore) { }"
- + " @org.netbeans.html.ko4j.KOTransfer::notifySuccess(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)(done, str, r);\n"
- + " } catch (error) {;\n"
- + " @org.netbeans.html.ko4j.KOTransfer::notifyError(Ljava/lang/Object;Ljava/lang/Object;)(done, error);\n"
- + " }\n"
- + "};\n"
- + "request.onerror = function (e) {\n"
- + " @org.netbeans.html.ko4j.KOTransfer::notifyError(Ljava/lang/Object;Ljava/lang/Object;)(done, e.type + ' status ' + request.status);\n"
- + "};\n"
- + "if (data) request.send(data);\n"
- + "else request.send();\n"
+ @JavaScriptBody(args = {"url", "done", "method", "data", "hp"}, javacall = true, body = """
+ var request = new XMLHttpRequest();
+ if (!method) method = 'GET';
+ request.open(method, url, true);
+ request.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
+ for (var i = 0; i < hp.length; i += 2) {
+ var h = hp[i];
+ var v = hp[i + 1];
+ request.setRequestHeader(h, v);
+ }
+ request.onreadystatechange = function() {
+ if (request.readyState !== 4) return;
+ var r = request.response || request.responseText;
+ try {
+ var str = r;
+ if (request.status !== 0)
+ if (request.status < 100 || request.status >= 400) throw request.status + ': ' + request.statusText; try { r = eval('(' + r + ')'); } catch (ignore) { } @org.netbeans.html.ko4j.KOTransfer::notifySuccess(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)(done, str, r);
+ } catch (error) {;
+ @org.netbeans.html.ko4j.KOTransfer::notifyError(Ljava/lang/Object;Ljava/lang/Object;)(done, error);
+ }
+ };
+ request.onerror = function (e) {
+ @org.netbeans.html.ko4j.KOTransfer::notifyError(Ljava/lang/Object;Ljava/lang/Object;)(done, e.type + ' status ' + request.status);
+ };
+ if (data) request.send(data);
+ else request.send();
+ """
)
static void loadJSON(
String url, JSONCall done, String method, String data, Object[] headerPairs
) {
}
- @JavaScriptBody(args = {"url", "jsonp"}, body
- = "var scrpt = window.document.createElement('script');\n "
- + "scrpt.setAttribute('src', url);\n "
- + "scrpt.setAttribute('id', jsonp);\n "
- + "scrpt.setAttribute('type', 'text/javascript');\n "
- + "var body = document.getElementsByTagName('body')[0];\n "
- + "body.appendChild(scrpt);\n"
+ @JavaScriptBody(args = {"url", "jsonp"}, body = """
+ var scrpt = window.document.createElement('script');
+ scrpt.setAttribute('src', url);
+ scrpt.setAttribute('id', jsonp);
+ scrpt.setAttribute('type', 'text/javascript');
+ var body = document.getElementsByTagName('body')[0];
+ body.appendChild(scrpt);
+ """
)
static void loadJSONP(String url, String jsonp) {
diff --git a/ko4j/src/main/java/org/netbeans/html/ko4j/LoadWS.java b/ko4j/src/main/java/org/netbeans/html/ko4j/LoadWS.java
index 49f07dc..e9b146e 100644
--- a/ko4j/src/main/java/org/netbeans/html/ko4j/LoadWS.java
+++ b/ko4j/src/main/java/org/netbeans/html/ko4j/LoadWS.java
@@ -51,11 +51,13 @@ final class LoadWS {
}
- @JavaScriptBody(args = { "data" }, body = "try {\n"
- + " return eval('(' + data + ')');\n"
- + " } catch (error) {;\n"
- + " return data;\n"
- + " }\n"
+ @JavaScriptBody(args = { "data" }, body = """
+ try {
+ return eval('(' + data + ')');
+ } catch (error) {;
+ return data;
+ }
+ """
)
private static native Object toJSON(String data);
@@ -72,29 +74,30 @@ final class LoadWS {
call.notifyError(null);
}
- @JavaScriptBody(args = { "back", "url" }, javacall = true, body = ""
- + "if (window.WebSocket) {\n"
- + " try {\n"
- + " var ws = new window.WebSocket(url);\n"
- + " ws.onopen = function(ev) {\n"
- + " back.@org.netbeans.html.ko4j.LoadWS::onOpen(Ljava/lang/Object;)(ev);\n"
- + " };\n"
- + " ws.onmessage = function(ev) {\n"
- + " back.@org.netbeans.html.ko4j.LoadWS::onMessage(Ljava/lang/Object;Ljava/lang/String;)(ev, ev.data);\n"
- + " };\n"
- + " ws.onerror = function(ev) {\n"
- + " back.@org.netbeans.html.ko4j.LoadWS::onError(Ljava/lang/Object;)(ev);\n"
- + " };\n"
- + " ws.onclose = function(ev) {\n"
- + " back.@org.netbeans.html.ko4j.LoadWS::onClose(ZILjava/lang/String;)(ev.wasClean, ev.code, ev.reason);\n"
- + " };\n"
- + " return ws;\n"
- + " } catch (ex) {\n"
- + " return null;\n"
- + " }\n"
- + "} else {\n"
- + " return null;\n"
- + "}\n"
+ @JavaScriptBody(args = { "back", "url" }, javacall = true, body = """
+ if (window.WebSocket) {
+ try {
+ var ws = new window.WebSocket(url);
+ ws.onopen = function(ev) {
+ back.@org.netbeans.html.ko4j.LoadWS::onOpen(Ljava/lang/Object;)(ev);
+ };
+ ws.onmessage = function(ev) {
+ back.@org.netbeans.html.ko4j.LoadWS::onMessage(Ljava/lang/Object;Ljava/lang/String;)(ev, ev.data);
+ };
+ ws.onerror = function(ev) {
+ back.@org.netbeans.html.ko4j.LoadWS::onError(Ljava/lang/Object;)(ev);
+ };
+ ws.onclose = function(ev) {
+ back.@org.netbeans.html.ko4j.LoadWS::onClose(ZILjava/lang/String;)(ev.wasClean, ev.code, ev.reason);
+ };
+ return ws;
+ } catch (ex) {
+ return null;
+ }
+ } else {
+ return null;
+ }
+ """
)
private static Object initWebSocket(Object back, String url) {
return null;
diff --git a/ko4j/src/test/java/org/netbeans/html/ko4j/KnockoutFXTest.java b/ko4j/src/test/java/org/netbeans/html/ko4j/KnockoutFXTest.java
index 42dac5b..412ec91 100644
--- a/ko4j/src/test/java/org/netbeans/html/ko4j/KnockoutFXTest.java
+++ b/ko4j/src/test/java/org/netbeans/html/ko4j/KnockoutFXTest.java
@@ -186,12 +186,11 @@ public final class KnockoutFXTest extends KnockoutTCK {
public native Object executeScript(String script, Object[] arguments);
@JavaScriptBody(args = { }, body =
- "var h;"
- + "if (!!window && !!window.location && !!window.location.href)\n"
- + " h = window.location.href;\n"
- + "else "
- + " h = null;"
- + "return h;\n"
+ """
+ var h;if (!!window && !!window.location && !!window.location.href)
+ h = window.location.href;
+ else h = null;return h;
+ """
)
private static native String findBaseURL();
diff --git a/pom.xml b/pom.xml
index ed859f3..ea32f22 100644
--- a/pom.xml
+++ b/pom.xml
@@ -43,6 +43,7 @@
<sigtestPackages>${publicPackages}</sigtestPackages>
<publicMetaInf>META-INF.services.*</publicMetaInf>
<skipJavaFXTests>true</skipJavaFXTests>
+ <maven.compiler.source>15</maven.compiler.source>
</properties>
<modules>
<module>json</module>
@@ -280,14 +281,14 @@ org.netbeans.html.boot.impl:org.netbeans.html.boot.fx:org.netbeans.html.context.
<dependency>
<artifactId>compiler-maven-plugin</artifactId>
<groupId>org.frgaal</groupId>
- <version>14.0.1</version>
+ <version>15.0.0</version>
</dependency>
</dependencies>
<configuration>
<compilerId>frgaal</compilerId>
- <source>1.8</source>
+ <source>15</source>
<target>1.8</target>
- <testSource>1.8</testSource>
+ <testSource>15</testSource>
<testTarget>1.8</testTarget>
</configuration>
</plugin>
diff --git a/webkit/src/test/java/org/netbeans/html/presenters/webkit/GtkKnockoutTest.java b/webkit/src/test/java/org/netbeans/html/presenters/webkit/GtkKnockoutTest.java
index 8cb518f..860c72e 100644
--- a/webkit/src/test/java/org/netbeans/html/presenters/webkit/GtkKnockoutTest.java
+++ b/webkit/src/test/java/org/netbeans/html/presenters/webkit/GtkKnockoutTest.java
@@ -180,12 +180,11 @@ public final class GtkKnockoutTest extends KnockoutTCK {
public native Object executeScript(String script, Object[] arguments);
@JavaScriptBody(args = { }, body =
- "var h;"
- + "if (!!window && !!window.location && !!window.location.href)\n"
- + " h = window.location.href;\n"
- + "else "
- + " h = null;"
- + "return h;\n"
+ """
+ var h;if (!!window && !!window.location && !!window.location.href)
+ h = window.location.href;
+ else h = null;return h;
+ """
)
private static native String findBaseURL();
diff --git a/xhr4j/src/main/java/org/netbeans/html/xhr4j/LoadJSON.java b/xhr4j/src/main/java/org/netbeans/html/xhr4j/LoadJSON.java
index 9f1ac6e..e5bd745 100644
--- a/xhr4j/src/main/java/org/netbeans/html/xhr4j/LoadJSON.java
+++ b/xhr4j/src/main/java/org/netbeans/html/xhr4j/LoadJSON.java
@@ -223,17 +223,19 @@ final class LoadJSON implements Runnable {
}
@JavaScriptBody(args = {"object", "property"}, body =
- "var ret;\n" +
- "if (property === null) ret = object;\n" +
- "else if (object === null) ret = null;\n" +
- "else ret = object[property];\n" +
- "if (typeof ret !== 'undefined' && ret !== null) {\n" +
- " if (typeof ko !== 'undefined' && ko['utils'] && ko['utils']['unwrapObservable']) {\n" +
- " return ko['utils']['unwrapObservable'](ret);\n" +
- " }\n" +
- " return ret;\n" +
- "}\n" +
- "return null;\n"
+ """
+ var ret;
+ if (property === null) ret = object;
+ else if (object === null) ret = null;
+ else ret = object[property];
+ if (typeof ret !== 'undefined' && ret !== null) {
+ if (typeof ko !== 'undefined' && ko['utils'] && ko['utils']['unwrapObservable']) {
+ return ko['utils']['unwrapObservable'](ret);
+ }
+ return ret;
+ }
+ return null;
+ """
)
private static Object getProperty(Object object, String property) {
return null;
diff --git a/xhr4j/src/test/java/org/netbeans/html/xhr4j/JsonKnockoutTest.java b/xhr4j/src/test/java/org/netbeans/html/xhr4j/JsonKnockoutTest.java
index 168de1d..e5ef259 100644
--- a/xhr4j/src/test/java/org/netbeans/html/xhr4j/JsonKnockoutTest.java
+++ b/xhr4j/src/test/java/org/netbeans/html/xhr4j/JsonKnockoutTest.java
@@ -158,12 +158,11 @@ public final class JsonKnockoutTest extends KnockoutTCK {
public native Object executeScript(String script, Object[] arguments);
@JavaScriptBody(args = { }, body =
- "var h;"
- + "if (!!window && !!window.location && !!window.location.href)\n"
- + " h = window.location.href;\n"
- + "else "
- + " h = null;"
- + "return h;\n"
+ """
+ var h;if (!!window && !!window.location && !!window.location.href)
+ h = window.location.href;
+ else h = null;return h;
+ """
)
private static native String findBaseURL();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists