Merge: String Stats
[nit.git] / contrib / jwrapper / src / code_generator.nit
index 02a3cb5..fda1a57 100644 (file)
@@ -18,6 +18,8 @@
 # Services to generate extern class `in "Java"`
 module code_generator
 
+import gen_nit
+
 intrude import model
 
 class CodeGenerator
@@ -146,6 +148,8 @@ class CodeGenerator
        # Serialize `model` to a file next to `file_name`
        fun write_model_to_file
        do
+               if not sys.opt_save_model.value then return
+
                # Write the model to file next to the Nit module
                var model_path = file_name.strip_extension + ".jwrapper.bin"
                var model_stream = model_path.to_path.open_wo
@@ -415,18 +419,12 @@ redef class Sys
        # List of Nit keywords
        #
        # These may also be keywords in Java, but there they would be used capitalized.
-       private var nit_keywords = new HashSet[String].from(["abort", "abstract", "and", "assert",
-               "break", "class", "continue", "do", "else", "end", "enum", "extern", "false", "implies",
-               "import", "init", "interface", "intrude", "if", "in", "is", "isa", "isset", "for", "label",
-               "loop", "module", "new", "not", "null", "nullable", "or", "package", "private",
-               "protected", "public", "return", "self", "super", "then", "true", "type", "var", "while",
-
-       # Top-level methods
-               "class_name", "get_time", "hash", "inspect", "inspect_head", "is_same_type",
-               "is_same_instance", "object_id", "output", "output_class_name", "sys", "to_s",
-
-       # Pointer or JavaObject methods
-               "free"])
+       private var nit_keywords: Set[String] is lazy do
+               var set = new HashSet[String]
+               set.add_all keywords
+               set.add_all methods_in_pointer
+               return set
+       end
 
        # Name of methods used at the top-level
        #
@@ -435,6 +433,9 @@ redef class Sys
 
        # Option to _not_ generate properties (static or from classes)
        var opt_no_properties = new OptionBool("Do not wrap properties, only classes and basic services", "-n", "--no-properties")
+
+       # Should the model be serialized to a file?
+       var opt_save_model = new OptionBool("Save the model next to the generated Nit module", "-s", "--save-model")
 end
 
 redef class String