Improving documentation of the @JavaScriptBody's callback mechanism
authorJaroslav Tulach <jtulach@netbeans.org>
Wed, 02 Dec 2015 08:44:31 +0100
changeset 10222f6f1d20fa7a
parent 1021 c918924ad3c5
child 1023 4f906bde3a2e
child 1026 cda94194f901
Improving documentation of the @JavaScriptBody's callback mechanism
boot/src/main/java/net/java/html/js/package.html
     1.1 --- a/boot/src/main/java/net/java/html/js/package.html	Thu Nov 26 20:59:51 2015 +0100
     1.2 +++ b/boot/src/main/java/net/java/html/js/package.html	Wed Dec 02 08:44:31 2015 +0100
     1.3 @@ -113,9 +113,9 @@
     1.4          function <code>mul</code> and use it.
     1.5          <p></p>
     1.6          <em>Real code tip:</em>
     1.7 -        <a href="http://hg.netbeans.org/html4j/file/release-0.7/ko4j/src/main/java/org/netbeans/html/ko4j/Knockout.java">this</a> 
     1.8 +        <a target="top" href="http://hg.netbeans.org/html4j/file/release-0.7/ko4j/src/main/java/org/netbeans/html/ko4j/Knockout.java">this</a> 
     1.9          is the way 
    1.10 -        the <a href="http://knockoutjs.com">knockout.js</a> library
    1.11 +        the <a target="top" href="http://knockoutjs.com">knockout.js</a> library
    1.12          is included in its <em>ko4j</em> library.
    1.13          
    1.14          <h3>Callback to Java</h3>
    1.15 @@ -152,13 +152,88 @@
    1.16          <p></p>
    1.17          Please note that to turn the special Java callback syntax on, one
    1.18          needs to set the {@link net.java.html.js.JavaScriptBody#javacall()}
    1.19 -        attribute to <b>true</b>.
    1.20 +        attribute to <b>true</b>. The callback syntax consists of
    1.21 +        following parts:
    1.22          <p></p>
    1.23 -        <em>Editing hint:</em> there is an associated annotation processor 
    1.24 +        <pre>[instance.]@classname::methodname(signature)(arguments)</pre>
    1.25 +        <ul>
    1.26 +            <li><b>instance</b> - must be present when calling an 
    1.27 +                instance method and must be absent when calling a 
    1.28 +                static method</li>
    1.29 +            <li><b>classname</b> - fully qualified name of the class in 
    1.30 +                which the method is declared 
    1.31 +            </li>
    1.32 +            <li><b>signature</b> - internal JVM method signature 
    1.33 +                (as specified at 
    1.34 +                <a target="top" href="http://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/types.html#wp16432">JNI type Signatures</a>) 
    1.35 +                without the trailing signature of the method return type</li>
    1.36 +            <li><b>arguments</b> - the actual values to pass to the called Java method
    1.37 +            </li>
    1.38 +        </ul>
    1.39 +
    1.40 +        <p>Here is the <a target="top" href="http://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/types.html#wp16432">JNI type signatures table</a>
    1.41 +            one can use to convert
    1.42 +            Java parameters to JVM's internal <em>letter</em> based 
    1.43 +            representation:</p>
    1.44 +        
    1.45 +        <table border=1 width='100%'>
    1.46 +            <tr>
    1.47 +                <td><b>Type Signature</b></td>
    1.48 +                <td><b>Java Type</b></td>
    1.49 +            </tr>
    1.50 +            <tr>
    1.51 +              <td>Z</td>
    1.52 +              <td>boolean</td>
    1.53 +            </tr>
    1.54 +            <tr>
    1.55 +              <td>B</td>
    1.56 +              <td>byte</td>
    1.57 +            </tr>
    1.58 +            <tr>
    1.59 +              <td>C</td>
    1.60 +              <td>char</td>
    1.61 +            </tr>
    1.62 +            <tr>
    1.63 +              <td>S</td>
    1.64 +              <td>short</td>
    1.65 +            </tr>
    1.66 +            <tr>
    1.67 +              <td>I</td>
    1.68 +              <td>int</td>
    1.69 +            </tr>
    1.70 +            <tr>
    1.71 +              <td>J</td>
    1.72 +              <td>long</td>
    1.73 +            </tr>
    1.74 +            <tr>
    1.75 +              <td>F</td>
    1.76 +              <td>float</td>
    1.77 +            </tr>
    1.78 +            <tr>
    1.79 +              <td>D</td>
    1.80 +              <td>double</td>
    1.81 +            </tr>
    1.82 +            <tr>
    1.83 +              <td>L fully-qualified-class ;</td>
    1.84 +              <td>fully-qualified-class</td>
    1.85 +            </tr>
    1.86 +            <tr>
    1.87 +              <td>[ type</td>
    1.88 +              <td>type[]</td>
    1.89 +            </tr>
    1.90 +          </tbody>
    1.91 +        </table>
    1.92 +        <p></p>
    1.93 +        <em>Editing hint:</em> The callback syntax may seem complicated at
    1.94 +        first, however there is an associated <b>annotation processor</b> 
    1.95          that checks the syntax and verifies the referenced class and
    1.96 -        method of the right signature exist. If they do not, the
    1.97 -        compilation fails. Thus don't despair seeing the syntax, you'll get early
    1.98 -        warnings when there is a typo.
    1.99 +        method with the requested signature exist. If it does not, the
   1.100 +        <em>compilation fails offering correct alternatives</em>. 
   1.101 +        Thus don't despair seeing the syntax, make sure you get the
   1.102 +        fully qualified name of the callback class right. 
   1.103 +        You'll get warning and help 
   1.104 +        if there is a typo in the specified signature then -
   1.105 +        during compilation of your code.
   1.106          
   1.107          <h3>Overloaded Methods</h3>
   1.108