Callback type of 'self' needs to be java.lang.Object otherwise FX presenter cannot wrap its values in Weak reference
1.1 --- a/boot/src/main/java/org/netbeans/html/boot/impl/FnUtils.java Wed Dec 17 16:48:27 2014 +0100
1.2 +++ b/boot/src/main/java/org/netbeans/html/boot/impl/FnUtils.java Wed Dec 17 17:34:16 2014 +0100
1.3 @@ -150,7 +150,12 @@
1.4 String ident, String fqn, String method, String params
1.5 ) {
1.6 StringBuilder sb = new StringBuilder();
1.7 - sb.append("vm.").append(mangle(fqn, method, params));
1.8 + if (ident != null) {
1.9 + sb.append("vm.raw$");
1.10 + } else {
1.11 + sb.append("vm.");
1.12 + }
1.13 + sb.append(mangle(fqn, method, params));
1.14 sb.append("(");
1.15 if (ident != null) {
1.16 sb.append(ident);
2.1 --- a/boot/src/main/java/org/netbeans/html/boot/impl/JavaScriptProcesor.java Wed Dec 17 16:48:27 2014 +0100
2.2 +++ b/boot/src/main/java/org/netbeans/html/boot/impl/JavaScriptProcesor.java Wed Dec 17 17:34:16 2014 +0100
2.3 @@ -367,83 +367,8 @@
2.4 for (Map.Entry<String, ExecutableElement> entry : map.entrySet()) {
2.5 final String mangled = entry.getKey();
2.6 final ExecutableElement m = entry.getValue();
2.7 - final boolean isStatic = m.getModifiers().contains(Modifier.STATIC);
2.8 -
2.9 - source.append("\n public java.lang.Object ")
2.10 - .append(mangled)
2.11 - .append("(");
2.12 -
2.13 - String sep = "";
2.14 - if (!isStatic) {
2.15 - source.append(((TypeElement)m.getEnclosingElement()).getQualifiedName());
2.16 - source.append(" self");
2.17 - sep = ", ";
2.18 - }
2.19 -
2.20 - int cnt = 0;
2.21 - StringBuilder convert = new StringBuilder();
2.22 - for (VariableElement ve : m.getParameters()) {
2.23 - source.append(sep);
2.24 - ++cnt;
2.25 - final TypeMirror t = ve.asType();
2.26 - if (!t.getKind().isPrimitive()) {
2.27 - source.append("Object");
2.28 - convert.append(" if (p instanceof org.netbeans.html.boot.spi.Fn.FromJavaScript) {\n");
2.29 - convert.append(" arg").append(cnt).
2.30 - append(" = ((org.netbeans.html.boot.spi.Fn.FromJavaScript)p).toJava(arg").append(cnt).
2.31 - append(");\n");
2.32 - convert.append(" }\n");
2.33 - } else {
2.34 - source.append(t);
2.35 - }
2.36 - source.append(" arg").append(cnt);
2.37 - sep = ", ";
2.38 - }
2.39 - source.append(") throws Throwable {\n");
2.40 - source.append(convert);
2.41 - if (useTryResources()) {
2.42 - source.append(" try (java.io.Closeable a = org.netbeans.html.boot.spi.Fn.activate(p)) { \n");
2.43 - } else {
2.44 - source.append(" java.io.Closeable a = org.netbeans.html.boot.spi.Fn.activate(p); try {\n");
2.45 - }
2.46 - source.append(" ");
2.47 - if (m.getReturnType().getKind() != TypeKind.VOID) {
2.48 - source.append("Object $ret = ");
2.49 - }
2.50 - if (isStatic) {
2.51 - source.append(((TypeElement)m.getEnclosingElement()).getQualifiedName());
2.52 - source.append('.');
2.53 - } else {
2.54 - source.append("self.");
2.55 - }
2.56 - source.append(m.getSimpleName());
2.57 - source.append("(");
2.58 - cnt = 0;
2.59 - sep = "";
2.60 - for (VariableElement ve : m.getParameters()) {
2.61 - source.append(sep);
2.62 - source.append("(").append(ve.asType());
2.63 - source.append(")arg").append(++cnt);
2.64 - sep = ", ";
2.65 - }
2.66 - source.append(");\n");
2.67 - if (m.getReturnType().getKind() == TypeKind.VOID) {
2.68 - source.append(" return null;\n");
2.69 - } else {
2.70 - source.append(" if (p instanceof org.netbeans.html.boot.spi.Fn.ToJavaScript) {\n");
2.71 - source.append(" $ret = ((org.netbeans.html.boot.spi.Fn.ToJavaScript)p).toJavaScript($ret);\n");
2.72 - source.append(" }\n");
2.73 - source.append(" return $ret;\n");
2.74 - }
2.75 - if (useTryResources()) {
2.76 - source.append(" }\n");
2.77 - } else {
2.78 -
2.79 - source.append(" } finally {\n");
2.80 - source.append(" a.close();\n");
2.81 - source.append(" }\n");
2.82 - }
2.83 - source.append(" }\n");
2.84 + generateMethod(false, m, source, mangled);
2.85 + generateMethod(true, m, source, "raw$" + mangled);
2.86 }
2.87 source.append("}\n");
2.88 final String srcName = pkgName + ".$JsCallbacks$";
2.89 @@ -461,6 +386,105 @@
2.90 }
2.91 }
2.92
2.93 + private void generateMethod(boolean selfObj, final ExecutableElement m, StringBuilder source, final String mangled) {
2.94 + final boolean isStatic = m.getModifiers().contains(Modifier.STATIC);
2.95 + if (isStatic && selfObj) {
2.96 + return;
2.97 + }
2.98 + final TypeElement selfType = (TypeElement)m.getEnclosingElement();
2.99 +
2.100 + source.append("\n public java.lang.Object ")
2.101 + .append(mangled)
2.102 + .append("(");
2.103 +
2.104 + String sep = "";
2.105 + StringBuilder convert = new StringBuilder();
2.106 + if (!isStatic) {
2.107 + if (selfObj) {
2.108 + source.append("Object self");
2.109 + convert.append(" if (p instanceof org.netbeans.html.boot.spi.Fn.FromJavaScript) {\n");
2.110 + convert.append(" self").
2.111 + append(" = ((org.netbeans.html.boot.spi.Fn.FromJavaScript)p).toJava(self").
2.112 + append(");\n");
2.113 + convert.append(" }\n");
2.114 + } else {
2.115 + source.append(selfType.getQualifiedName());
2.116 + source.append(" self");
2.117 + }
2.118 + sep = ", ";
2.119 + }
2.120 +
2.121 + int cnt = 0;
2.122 + for (VariableElement ve : m.getParameters()) {
2.123 + source.append(sep);
2.124 + ++cnt;
2.125 + final TypeMirror t = ve.asType();
2.126 + if (!t.getKind().isPrimitive()) {
2.127 + source.append("Object");
2.128 + convert.append(" if (p instanceof org.netbeans.html.boot.spi.Fn.FromJavaScript) {\n");
2.129 + convert.append(" arg").append(cnt).
2.130 + append(" = ((org.netbeans.html.boot.spi.Fn.FromJavaScript)p).toJava(arg").append(cnt).
2.131 + append(");\n");
2.132 + convert.append(" }\n");
2.133 + } else {
2.134 + source.append(t);
2.135 + }
2.136 + source.append(" arg").append(cnt);
2.137 + sep = ", ";
2.138 + }
2.139 + source.append(") throws Throwable {\n");
2.140 + source.append(convert);
2.141 + if (useTryResources()) {
2.142 + source.append(" try (java.io.Closeable a = org.netbeans.html.boot.spi.Fn.activate(p)) { \n");
2.143 + } else {
2.144 + source.append(" java.io.Closeable a = org.netbeans.html.boot.spi.Fn.activate(p); try {\n");
2.145 + }
2.146 + source.append(" ");
2.147 + if (m.getReturnType().getKind() != TypeKind.VOID) {
2.148 + source.append("Object $ret = ");
2.149 + }
2.150 + if (isStatic) {
2.151 + source.append(((TypeElement)m.getEnclosingElement()).getQualifiedName());
2.152 + source.append('.');
2.153 + } else {
2.154 + if (selfObj) {
2.155 + source.append("((");
2.156 + source.append(selfType.getQualifiedName());
2.157 + source.append(")self).");
2.158 + } else {
2.159 + source.append("self.");
2.160 + }
2.161 + }
2.162 + source.append(m.getSimpleName());
2.163 + source.append("(");
2.164 + cnt = 0;
2.165 + sep = "";
2.166 + for (VariableElement ve : m.getParameters()) {
2.167 + source.append(sep);
2.168 + source.append("(").append(ve.asType());
2.169 + source.append(")arg").append(++cnt);
2.170 + sep = ", ";
2.171 + }
2.172 + source.append(");\n");
2.173 + if (m.getReturnType().getKind() == TypeKind.VOID) {
2.174 + source.append(" return null;\n");
2.175 + } else {
2.176 + source.append(" if (p instanceof org.netbeans.html.boot.spi.Fn.ToJavaScript) {\n");
2.177 + source.append(" $ret = ((org.netbeans.html.boot.spi.Fn.ToJavaScript)p).toJavaScript($ret);\n");
2.178 + source.append(" }\n");
2.179 + source.append(" return $ret;\n");
2.180 + }
2.181 + if (useTryResources()) {
2.182 + source.append(" }\n");
2.183 + } else {
2.184 +
2.185 + source.append(" } finally {\n");
2.186 + source.append(" a.close();\n");
2.187 + source.append(" }\n");
2.188 + }
2.189 + source.append(" }\n");
2.190 + }
2.191 +
2.192 private boolean useTryResources() {
2.193 try {
2.194 return processingEnv.getSourceVersion().compareTo(SourceVersion.RELEASE_7) >= 0;