Up until now, the Jangaroo compiler jooc processed one source file at a time, without taking a look at declarations residing in other source files. However, in certain situations, jooc needs to decide whether a given symbol denotes a class, a package-global function, and whether it is static or a non-static member. This information is important because jooc has to generate different JavaScript code in each case.
jooc based some of these decisions upon heuristics and generated a warning if he wasn't sure (e.g. the warning "undeclared identifier foo, assuming it is an inherited member"), just to tell you about it, giving a chance to review the decision. However, this typically generated a lot of warnings, and nobody actually cared about them any more (broken window effect).
We now took off the blinders and enabled jooc to look into sources other than the single one at hand. This allows the compiler to do his job based on facts, not on assumptions.
On the other hand, now jooc needs to find the definitions of all external symbols which are used within a given source file. We added two new compiler switches which tell jooc where to look for these:
- -sourcepath: a list of source root directories in the same module (e.g. "src/main/joo;target/main/generated-sources/joo;src/test/joo"), and
- -classpath: a list of directories or Jangaroo module jars where to find symbols in module dependencies.
If you are using Maven to build your Jangaroo application (as we do), you are lucky: the new version of the Jangaroo Maven Plugin configures all these new compiler switches with reasonable defaults. Your Jangaroo project should build right out of the box with the new Jangaroo version. The new Jangaroo Maven plugin automatically generates and packages API stubs for every Jangaroo module into the META-INF/joo-api directory within the module jar file.
We also updated the Jangaroo IDEA plugin to take advantage of the new compiler switches. The Plugin is now compatible with IDEA 9.0.2. By the way, a neat side effect of the new API stub packaging is that you may now both get a 'green square' for sources within the IDEA editor and access the API documentation with Quick Documentation Lookup (CTRL-Q) without having to download the source artifacts of dependencies.
Last but not least, here are some additional enhancements which come with the new Jangaroo version:
- Static superclass members are now in scope which means that you do not need to qualify the member with the superclass identifier any more.
- Private members of the same class are now also accessible for parameters and variables. Previously, private members where only accessible if (implicitly or explicitly) qualified by this.
- Old-style type casts are now recognized correctly and commented out in the generated JavaScript code, just like the new-style type casts using the as keyword. Note that we still do not generate any runtime code for both kinds of type cast.
- The restrictions of dynamic class loading are removed, you may now use *-imports and put classes under other source root directories, given you configured the -sourcepath option accordingly.
As always, we’d be glad about feedback and hope you have fun developing with Jangaroo!
0 comments:
Post a Comment