From a24652a57652e098d669243ef6d7974355483433 Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Sun, 19 Oct 2014 16:13:43 +0400 Subject: [PATCH] Support of html4j version 1.0. Better support of JavaScriptBody callbacks. --- pom.xml | 2 +- .../html4j/JavaScriptBodyDependency.java | 2 +- .../teavm/html4j/JavaScriptBodyGenerator.java | 14 +++++-- .../teavm/html4j/JavaScriptConvGenerator.java | 38 ++++++++----------- .../java/org/teavm/html4j/JsCallback.java | 2 +- .../teavm/html4j/testing/KOTestAdapter.java | 2 +- .../org/teavm/html4j/test/KnockoutFXTest.java | 12 +++--- ...=> org.netbeans.html.json.tck.KnockoutTCK} | 0 8 files changed, 37 insertions(+), 35 deletions(-) rename teavm-html4j/src/test/resources/META-INF/services/{org.apidesign.html.json.tck.KnockoutTCK => org.netbeans.html.json.tck.KnockoutTCK} (100%) diff --git a/pom.xml b/pom.xml index 6c660cffd..5fe03e8cd 100644 --- a/pom.xml +++ b/pom.xml @@ -66,7 +66,7 @@ UTF-8 https://oss.sonatype.org/content/repositories/snapshots/ - 0.9 + 1.0 9.2.1.v20140609 1.7.7 diff --git a/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyDependency.java b/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyDependency.java index a4939ea46..d8787da89 100644 --- a/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyDependency.java +++ b/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyDependency.java @@ -138,7 +138,7 @@ public class JavaScriptBodyDependency implements DependencyListener { if (!methodDep.isMissing()) { if (reader.hasModifier(ElementModifier.STATIC) || reader.hasModifier(ElementModifier.FINAL)) { methodDep.use(); - for (int i = 0; i <= methodDep.getParameterCount(); ++i) { + for (int i = 0; i < methodDep.getParameterCount(); ++i) { allClassesNode.connect(methodDep.getVariable(i)); } } else { diff --git a/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyGenerator.java b/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyGenerator.java index 917acaafc..50fb1e828 100644 --- a/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyGenerator.java +++ b/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptBodyGenerator.java @@ -85,9 +85,15 @@ public class JavaScriptBodyGenerator implements Generator { MethodDescriptor desc = MethodDescriptor.parse(method + params + "V"); MethodReader reader = findMethod(fqn, desc); StringBuilder sb = new StringBuilder(); - sb.append("(function($this"); + sb.append("(function("); + if (ident != null) { + sb.append("$this"); + } for (int i = 0; i < reader.parameterCount(); ++i) { - sb.append(", ").append("p").append(i); + if (ident != null || i > 0) { + sb.append(", "); + } + sb.append("p").append(i); } sb.append(") { return ").append(naming.getFullNameFor(JavaScriptConvGenerator.toJsMethod)).append("("); if (ident == null) { @@ -105,7 +111,9 @@ public class JavaScriptBodyGenerator implements Generator { .append(Renderer.typeToClsString(naming, reader.parameterType(i))).append(")"); } sb.append(")); })("); - sb.append(ident == null ? "null" : ident); + if (ident != null) { + sb.append(ident); + } return sb.toString(); } private MethodReader findMethod(String clsName, MethodDescriptor desc) { diff --git a/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptConvGenerator.java b/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptConvGenerator.java index e68d243ed..5a9743509 100644 --- a/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptConvGenerator.java +++ b/teavm-html4j/src/main/java/org/teavm/html4j/JavaScriptConvGenerator.java @@ -26,28 +26,22 @@ import org.teavm.model.*; * @author Alexey Andreev */ public class JavaScriptConvGenerator implements Generator { - private static final String convCls = JavaScriptConv.class.getName(); - static final MethodReference intValueMethod = new MethodReference("java.lang.Integer", - new MethodDescriptor("intValue", ValueType.INTEGER)); - static final MethodReference booleanValueMethod = new MethodReference("java.lang.Boolean", - new MethodDescriptor("booleanValue", ValueType.BOOLEAN)); - static final MethodReference doubleValueMethod = new MethodReference("java.lang.Double", - new MethodDescriptor("doubleValue", ValueType.DOUBLE)); - static final MethodReference charValueMethod = new MethodReference("java.lang.Character", - new MethodDescriptor("charValue", ValueType.CHARACTER)); - static final MethodReference valueOfIntMethod = new MethodReference("java.lang.Integer", - new MethodDescriptor("valueOf", ValueType.INTEGER, ValueType.object("java.lang.Integer"))); - static final MethodReference valueOfBooleanMethod = new MethodReference("java.lang.Boolean", - new MethodDescriptor("valueOf", ValueType.BOOLEAN, ValueType.object("java.lang.Boolean"))); - static final MethodReference valueOfDoubleMethod = new MethodReference("java.lang.Double", - new MethodDescriptor("valueOf", ValueType.DOUBLE, ValueType.object("java.lang.Double"))); - static final MethodReference valueOfCharMethod = new MethodReference("java.lang.Character", - new MethodDescriptor("valueOf", ValueType.CHARACTER, ValueType.object("java.lang.Character"))); - private static final ValueType objType = ValueType.object("java.lang.Object"); - static final MethodReference toJsMethod = new MethodReference(convCls, new MethodDescriptor( - "toJavaScript", objType, objType)); - static final MethodReference fromJsMethod = new MethodReference(convCls, new MethodDescriptor( - "fromJavaScript", objType, objType, objType)); + static final MethodReference intValueMethod = new MethodReference(Integer.class, "intValue", int.class); + static final MethodReference booleanValueMethod = new MethodReference(Boolean.class, "booleanValue", boolean.class); + static final MethodReference doubleValueMethod = new MethodReference(Double.class, "doubleValue", double.class); + static final MethodReference charValueMethod = new MethodReference(Character.class, "charValue", char.class); + static final MethodReference valueOfIntMethod = new MethodReference(Integer.class, "valueOf", + int.class, Integer.class); + static final MethodReference valueOfBooleanMethod = new MethodReference(Boolean.class, "valueOf", + boolean.class, Boolean.class); + static final MethodReference valueOfDoubleMethod = new MethodReference(Double.class, "valueOf", + double.class, Double.class); + static final MethodReference valueOfCharMethod = new MethodReference(Character.class, "valueOf", + char.class, Character.class); + static final MethodReference toJsMethod = new MethodReference(JavaScriptConv.class, "toJavaScript", + Object.class, Object.class); + static final MethodReference fromJsMethod = new MethodReference(JavaScriptConv.class, "fromJavaScript", + Object.class, Object.class, Object.class); @Override public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef) throws IOException { diff --git a/teavm-html4j/src/main/java/org/teavm/html4j/JsCallback.java b/teavm-html4j/src/main/java/org/teavm/html4j/JsCallback.java index 2ca89f7cf..45ff283bc 100644 --- a/teavm-html4j/src/main/java/org/teavm/html4j/JsCallback.java +++ b/teavm-html4j/src/main/java/org/teavm/html4j/JsCallback.java @@ -107,7 +107,7 @@ abstract class JsCallback { } sb.append(callMethod(refId, fqn, method, params)); - if (body.charAt(paramBeg + 1) != (')')) { + if (body.charAt(paramBeg + 1) != ')') { sb.append(","); } pos = paramBeg + 1; diff --git a/teavm-html4j/src/main/java/org/teavm/html4j/testing/KOTestAdapter.java b/teavm-html4j/src/main/java/org/teavm/html4j/testing/KOTestAdapter.java index d684ec611..60f874e97 100644 --- a/teavm-html4j/src/main/java/org/teavm/html4j/testing/KOTestAdapter.java +++ b/teavm-html4j/src/main/java/org/teavm/html4j/testing/KOTestAdapter.java @@ -18,7 +18,7 @@ package org.teavm.html4j.testing; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.Collections; -import org.apidesign.html.json.tck.KOTest; +import org.netbeans.html.json.tck.KOTest; import org.teavm.model.MethodReader; import org.teavm.testing.TestAdapter; diff --git a/teavm-html4j/src/test/java/org/teavm/html4j/test/KnockoutFXTest.java b/teavm-html4j/src/test/java/org/teavm/html4j/test/KnockoutFXTest.java index 11b29035e..f2d2d1547 100644 --- a/teavm-html4j/src/test/java/org/teavm/html4j/test/KnockoutFXTest.java +++ b/teavm-html4j/src/test/java/org/teavm/html4j/test/KnockoutFXTest.java @@ -51,12 +51,12 @@ import java.util.HashMap; import java.util.Map; import net.java.html.BrwsrCtx; import net.java.html.js.JavaScriptBody; -import org.apidesign.html.boot.spi.Fn; -import org.apidesign.html.context.spi.Contexts; -import org.apidesign.html.json.spi.JSONCall; -import org.apidesign.html.json.spi.Technology; -import org.apidesign.html.json.spi.Transfer; -import org.apidesign.html.json.tck.KnockoutTCK; +import org.netbeans.html.boot.spi.Fn; +import org.netbeans.html.context.spi.Contexts; +import org.netbeans.html.json.spi.JSONCall; +import org.netbeans.html.json.spi.Technology; +import org.netbeans.html.json.spi.Transfer; +import org.netbeans.html.json.tck.KnockoutTCK; import org.netbeans.html.ko4j.KO4J; import org.testng.Assert; diff --git a/teavm-html4j/src/test/resources/META-INF/services/org.apidesign.html.json.tck.KnockoutTCK b/teavm-html4j/src/test/resources/META-INF/services/org.netbeans.html.json.tck.KnockoutTCK similarity index 100% rename from teavm-html4j/src/test/resources/META-INF/services/org.apidesign.html.json.tck.KnockoutTCK rename to teavm-html4j/src/test/resources/META-INF/services/org.netbeans.html.json.tck.KnockoutTCK