buildtools/nasgen/README

Tue, 06 Jun 2017 10:03:12 -0700

author
asaha
date
Tue, 06 Jun 2017 10:03:12 -0700
changeset 2063
905b35451b21
parent 0
b1a7da25b547
permissions
-rw-r--r--

Added tag jdk8u141-b12 for changeset 31e8c2a1e8f7

aoqi@0 1 Nasgen is a tool for processing Java classes that implement native
aoqi@0 2 JavaScript objects. It does so by looking for the
aoqi@0 3 com.oracle.nashorn.objects.annotations.ScriptClass annotation and other
aoqi@0 4 annotations in that package.
aoqi@0 5
aoqi@0 6 For each class "C", nasgen instruments the original class and generates
aoqi@0 7 two additional classes: a "C$Prototype" class for the JavaScript
aoqi@0 8 prototype object, and a "C$Constructor" class for the JavaScript
aoqi@0 9 constructor function.
aoqi@0 10
aoqi@0 11 Each class instrumented or generated by nasgen contains a private static
aoqi@0 12 "$nasgenmap$" field of type com.oracle.nashorn.runtime.PropertyMap and
aoqi@0 13 static initializer block to initialize the field to the object's
aoqi@0 14 JavaScript properties.
aoqi@0 15
aoqi@0 16 Members annotated with @Function, @Property, @Getter, and @Setter are
aoqi@0 17 mapped to the $Constructor, $Prototype, or main class, depending on the
aoqi@0 18 value of the annotation's 'where' field. By default, @Property, @Getter,
aoqi@0 19 and @Setter belong to the main class while @Function methods without
aoqi@0 20 explicit 'where' field belong to the $Prototype class. The @Constructor
aoqi@0 21 annotation marks a method to be invoked as JavaScript constructor.
aoqi@0 22
aoqi@0 23 Nasgen enforces all @Function/@Getter/@Setter/@Constructor annotated
aoqi@0 24 methods to be declared as static. Static final @Property fields remain
aoqi@0 25 in the main class while other @Property fields are moved to respective
aoqi@0 26 classes depending on the annotation's 'where' value. For functions
aoqi@0 27 mapped to the $Prototype or $Constructor class, nasgen also generates
aoqi@0 28 getters and setters prefixed by G$ and S$, respectively.
aoqi@0 29
aoqi@0 30 Nasgen-generated classes are hidden from normal ClassLoaders by giving
aoqi@0 31 them a ".clazz" file name extension instead of the standard ".class"
aoqi@0 32 extension. This allows script classes to be loaded independently by each
aoqi@0 33 Nashorn context through the com.oracle.nashorn.runtime.StructureLoader
aoqi@0 34 class loader.

mercurial