Support of html4j version 1.0. Better support of JavaScriptBody

callbacks.
This commit is contained in:
konsoletyper 2014-10-19 16:13:43 +04:00
parent 3de49d6d54
commit a24652a576
8 changed files with 37 additions and 35 deletions

View File

@ -66,7 +66,7 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sonatypeOssDistMgmtSnapshotsUrl>https://oss.sonatype.org/content/repositories/snapshots/</sonatypeOssDistMgmtSnapshotsUrl> <sonatypeOssDistMgmtSnapshotsUrl>https://oss.sonatype.org/content/repositories/snapshots/</sonatypeOssDistMgmtSnapshotsUrl>
<html4j.version>0.9</html4j.version> <html4j.version>1.0</html4j.version>
<jetty.version>9.2.1.v20140609</jetty.version> <jetty.version>9.2.1.v20140609</jetty.version>
<slf4j.version>1.7.7</slf4j.version> <slf4j.version>1.7.7</slf4j.version>
</properties> </properties>

View File

@ -138,7 +138,7 @@ public class JavaScriptBodyDependency implements DependencyListener {
if (!methodDep.isMissing()) { if (!methodDep.isMissing()) {
if (reader.hasModifier(ElementModifier.STATIC) || reader.hasModifier(ElementModifier.FINAL)) { if (reader.hasModifier(ElementModifier.STATIC) || reader.hasModifier(ElementModifier.FINAL)) {
methodDep.use(); methodDep.use();
for (int i = 0; i <= methodDep.getParameterCount(); ++i) { for (int i = 0; i < methodDep.getParameterCount(); ++i) {
allClassesNode.connect(methodDep.getVariable(i)); allClassesNode.connect(methodDep.getVariable(i));
} }
} else { } else {

View File

@ -85,9 +85,15 @@ public class JavaScriptBodyGenerator implements Generator {
MethodDescriptor desc = MethodDescriptor.parse(method + params + "V"); MethodDescriptor desc = MethodDescriptor.parse(method + params + "V");
MethodReader reader = findMethod(fqn, desc); MethodReader reader = findMethod(fqn, desc);
StringBuilder sb = new StringBuilder(); 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) { 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("("); sb.append(") { return ").append(naming.getFullNameFor(JavaScriptConvGenerator.toJsMethod)).append("(");
if (ident == null) { if (ident == null) {
@ -105,7 +111,9 @@ public class JavaScriptBodyGenerator implements Generator {
.append(Renderer.typeToClsString(naming, reader.parameterType(i))).append(")"); .append(Renderer.typeToClsString(naming, reader.parameterType(i))).append(")");
} }
sb.append(")); })("); sb.append(")); })(");
sb.append(ident == null ? "null" : ident); if (ident != null) {
sb.append(ident);
}
return sb.toString(); return sb.toString();
} }
private MethodReader findMethod(String clsName, MethodDescriptor desc) { private MethodReader findMethod(String clsName, MethodDescriptor desc) {

View File

@ -26,28 +26,22 @@ import org.teavm.model.*;
* @author Alexey Andreev <konsoletyper@gmail.com> * @author Alexey Andreev <konsoletyper@gmail.com>
*/ */
public class JavaScriptConvGenerator implements Generator { public class JavaScriptConvGenerator implements Generator {
private static final String convCls = JavaScriptConv.class.getName(); static final MethodReference intValueMethod = new MethodReference(Integer.class, "intValue", int.class);
static final MethodReference intValueMethod = new MethodReference("java.lang.Integer", static final MethodReference booleanValueMethod = new MethodReference(Boolean.class, "booleanValue", boolean.class);
new MethodDescriptor("intValue", ValueType.INTEGER)); static final MethodReference doubleValueMethod = new MethodReference(Double.class, "doubleValue", double.class);
static final MethodReference booleanValueMethod = new MethodReference("java.lang.Boolean", static final MethodReference charValueMethod = new MethodReference(Character.class, "charValue", char.class);
new MethodDescriptor("booleanValue", ValueType.BOOLEAN)); static final MethodReference valueOfIntMethod = new MethodReference(Integer.class, "valueOf",
static final MethodReference doubleValueMethod = new MethodReference("java.lang.Double", int.class, Integer.class);
new MethodDescriptor("doubleValue", ValueType.DOUBLE)); static final MethodReference valueOfBooleanMethod = new MethodReference(Boolean.class, "valueOf",
static final MethodReference charValueMethod = new MethodReference("java.lang.Character", boolean.class, Boolean.class);
new MethodDescriptor("charValue", ValueType.CHARACTER)); static final MethodReference valueOfDoubleMethod = new MethodReference(Double.class, "valueOf",
static final MethodReference valueOfIntMethod = new MethodReference("java.lang.Integer", double.class, Double.class);
new MethodDescriptor("valueOf", ValueType.INTEGER, ValueType.object("java.lang.Integer"))); static final MethodReference valueOfCharMethod = new MethodReference(Character.class, "valueOf",
static final MethodReference valueOfBooleanMethod = new MethodReference("java.lang.Boolean", char.class, Character.class);
new MethodDescriptor("valueOf", ValueType.BOOLEAN, ValueType.object("java.lang.Boolean"))); static final MethodReference toJsMethod = new MethodReference(JavaScriptConv.class, "toJavaScript",
static final MethodReference valueOfDoubleMethod = new MethodReference("java.lang.Double", Object.class, Object.class);
new MethodDescriptor("valueOf", ValueType.DOUBLE, ValueType.object("java.lang.Double"))); static final MethodReference fromJsMethod = new MethodReference(JavaScriptConv.class, "fromJavaScript",
static final MethodReference valueOfCharMethod = new MethodReference("java.lang.Character", Object.class, Object.class, Object.class);
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));
@Override @Override
public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef) throws IOException { public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef) throws IOException {

View File

@ -107,7 +107,7 @@ abstract class JsCallback {
} }
sb.append(callMethod(refId, fqn, method, params)); sb.append(callMethod(refId, fqn, method, params));
if (body.charAt(paramBeg + 1) != (')')) { if (body.charAt(paramBeg + 1) != ')') {
sb.append(","); sb.append(",");
} }
pos = paramBeg + 1; pos = paramBeg + 1;

View File

@ -18,7 +18,7 @@ package org.teavm.html4j.testing;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Collections; 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.model.MethodReader;
import org.teavm.testing.TestAdapter; import org.teavm.testing.TestAdapter;

View File

@ -51,12 +51,12 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import net.java.html.BrwsrCtx; import net.java.html.BrwsrCtx;
import net.java.html.js.JavaScriptBody; import net.java.html.js.JavaScriptBody;
import org.apidesign.html.boot.spi.Fn; import org.netbeans.html.boot.spi.Fn;
import org.apidesign.html.context.spi.Contexts; import org.netbeans.html.context.spi.Contexts;
import org.apidesign.html.json.spi.JSONCall; import org.netbeans.html.json.spi.JSONCall;
import org.apidesign.html.json.spi.Technology; import org.netbeans.html.json.spi.Technology;
import org.apidesign.html.json.spi.Transfer; import org.netbeans.html.json.spi.Transfer;
import org.apidesign.html.json.tck.KnockoutTCK; import org.netbeans.html.json.tck.KnockoutTCK;
import org.netbeans.html.ko4j.KO4J; import org.netbeans.html.ko4j.KO4J;
import org.testng.Assert; import org.testng.Assert;