Skip to content

Commit

Permalink
Support of html4j version 1.0. Better support of JavaScriptBody
Browse files Browse the repository at this point in the history
callbacks.
  • Loading branch information
konsoletyper committed Oct 19, 2014
1 parent 6859254 commit c3a6c5f
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 35 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<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>
<slf4j.version>1.7.7</slf4j.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public GeneratorJsCallback(DependencyAgent agent, MethodDependency caller) {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,15 @@ public GeneratorJsCallback(ClassReaderSource classSource, NamingStrategy naming)
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) {
Expand All @@ -105,7 +111,9 @@ public GeneratorJsCallback(ClassReaderSource classSource, NamingStrategy naming)
.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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,22 @@
* @author Alexey Andreev <konsoletyper@gmail.com>
*/
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ final String parse(String body) {
}

sb.append(callMethod(refId, fqn, method, params));
if (body.charAt(paramBeg + 1) != (')')) {
if (body.charAt(paramBeg + 1) != ')') {
sb.append(",");
}
pos = paramBeg + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@
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;

Expand Down

0 comments on commit c3a6c5f

Please sign in to comment.