Table of Contents
Modules
QWT has a Maven multi-module build with the following modules:
compiler: translates Java to JavaScript.runtime: Java class libraries translated to JavaScript.qooxdoo: Java representation of qooxdoo JavaScript classes.engine: the servlet to drive applications.plugin: integration with Maven.
Compiler Module
Translation
- Ignores synchronization, wait/notify: JavaScript is single threaded.
- Ignores generics: they are compile-time only.
- Strings: augments JavaScripts native
Stringclass. Converting objects before passing them to native code/qooxdoo is not feasible, because this code might access compiled objects (possibly using references from previous invocations). It is just impossible to convert everything. Thus, converting is not a option.
Code Generation
A Java class or interface my.pkg.Name compiles to a class my.pkg.Name.
A class is a construction function object, i.e. a class myClass has the following properties:
(static fields and methods): for example, a static methodmfor classpkg.Nametranslates to a functionpkg_Name.minterfaces: list of class functions of the interfaces implemented by this classprototype: instance of the base class(none-static fields and methods): for example, a non-static methodmtranslates to a functionpkg_Name.prototype.mconstructor: myClassmetadata: Java class name (String) (or class object, assigned by the runtime system (TODO))
</code>
To obtain the class of a given object:
myInstance.proto = myClass.prototype </code>
Classes are the only functions defined in the form
function name() {}
all other code is defined in the form
SomeName = function() {}
A constructor translates like a static method with name init, call is used to pass this in the constructor’s invocation.
Overloading is resolved at compile time by altering the constructor or method name.
Annotations are ignored.
char is translated to integers.
The global namespace is only polluted by runtime code and class objects.
Annotations
The compiler supports Java 1.5, the language is not changed. All features needed for JavaScript are realized with annotations. The following description shows all available annotations and how they are applied. CAUTION: all annotations are currently Javadoc tags, not Java 1.5 annotations ...
Native
- Syntax:
“@native” code - Applies to native methods or classes.
- When applied to methods: inserts the specified JavaScript
codeas the body of the annotated method. When applied to methods: inserts the specified JavaScriptcodeinto the module head, adding pre-dependencies to head and post-dependencies to cinit.
Alias
- Syntax:
“@alias” - Applies to native methods and normal fields. Cannot be applied to constructors.
- Indicates that this declaration is defined elsewhere, the compiler won’t generate any code. Use this annotation to access JavaScript features from Java.
Augment
- Syntax:
“@augment” function - Applies to types with non-logic constructors. Non-logic means there’s nothing but constructor calls inside - which might be needed to satisfy the Java compiler; note that arguments won’t be checked, although they should! Constructors in the augmenting class are kind of native methods.
function: A constructor function that will be used as class function. Take care to protect definitions in the augmented code by the appropriate aliases in the augmenting code. Augmented code is responsible for base class definitions, the compiler does not pass the augmenting base class todefineClass. Constructors in the augmenting class may not have logic, because the compiler does not generate code (this behavior is similar to alias methods).
Escaping
Escape sequences supported by above annotations:
$$ -> $ $@ -> @ $s -> * $l -> <
Qooxdoo Module
Re-packages the original qooxdoo framework into a Maven artifact to make it available for QWT applications. This is similar to a Linux distribution re-packaging software distributed in an arbitrary format to make it available in the distribution’s format. The version number follows the qooxdoo version.
The Qooxdoo module consists of binding classes, qooxdoo resources, and a few Java classes. Binding classes (in qx; one Java class for each qooxdoo JavaScript class) are fully auto-generated from qooxdoo’s JavaScript sources and merged with a small amount of individual patches.
