Warning |
Dragons be here! (The magic starts here) |
rebuildClasses loops through all the ClassDefinition(s) in classnames and do the following for each of them:
rebuildClasses loops through all the ConstructorDefintion(s) in constantnames, translates it and checks whether it forms part of the class. If it does it is added to the ClassDefinition in the Vector constructors using the method addConstructor. It also adds it to the Vector matched. It then loops through all the MethodDefintion (s) in methodnames, translates it and checks whether it forms part of the class. If it does it is added to the ClassDefinition in the Vector methods using the method addMethod. It also adds it to the Vector matched.
rebuildClasses then saves the ClassDefinition to it's files and removes all the elements in the Vector matchedc and the Vector matched from the Vector constantnames and the Vector methodnames.
After doing the above for all ClassDefinition(s) in constantnames, rebuildClasses creates a ClassDefinition for the current module. All remaining methods are then translated and added to the base ClassDefinition in the Vector methods using the method addMethod. rebuildClasses then saves the ClassDefinition to the files. Enums also generate their own classes to ensure correct typing.
To work correctly, rebuildClasses must have a sorted classnames Vector, and that has been done in addClassDefinition. This is necessary so that GtkMenuItem class is not confused with an hypothetical GtkMenu.item() method.
The saveCHeader method first gets the C header filename, opens it and writes the header to the file using the emitHeader method. It then writes the relevant #include statements and the required #ifndef and #ifdef statements. The constructor and default constructor definitions are then written using the emitNativeHeader method (of the (Default)ConstructorDefinition class - inherited from MethodDefinition class). The method definitions are then written to the header file using the emitNativeHeader method (of the MethodDefinition class). Finally the #endif statements which goes with the #ifndef and #ifdef statements are written to the file and the file is closed.
The saveCGlue method first gets the C glue filename, opens it and writes the header to the file using the emitHeader method. It then writes the relevant #include statements and the required #ifdef statements. The constructors and default constructor code are then written using the printNativeFunction method (of the (Default)ConstructorDefinition class - inherited from MethodDefinition class). The method codes are then written to the glue file using the printNativeFunction method (of the MethodDefinition class). Finally the #endif statements which goes with the #ifdef statements are written to the file and the file is closed.
The method saveFile of ClassDefinition first gets the Java filename, opens it and then writes the header to the file using the emitHeader method. It then writes the necessary import statements to the file. The start of the class (with it's extends statements if required) is then writen.
saveFile then determines whether the ClassDefinition has a default constructor. The constructors are then written to the file using the using the method emitJavaMethod (of the ConstructorDefinition class - inherited from the MethodDefinition class). If it does not have a default constructor a default constructor is created and it is then written to the file using the same method.
All the methods are then written to the file using the method emitJavaMethod (of the MethodDefinition class). Finally the closing brace is writen to the file and the file is closed.
The C header file and the C glue file are then written using the saveCHeader and saveCGlue methods.