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