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