contrib/jwrapper: fix commenting out unknown types on `-u comment` only
[nit.git] / contrib / jwrapper / src / code_generator.nit
index c390d1b..5e3d770 100644 (file)
@@ -70,13 +70,8 @@ class CodeGenerator
                        generate_class_header(jclass.class_type)
 
                        for id, signatures in jclass.methods do
-                               var c = 0
                                for signature in signatures do
-                                       var nid = id
-                                       if c > 0 then nid += c.to_s
-                                       c += 1
-
-                                       generate_method(jclass, id, nid, signature.return_type, signature.params)
+                                       generate_method(jclass, id, id, signature.return_type, signature.params)
                                        file_out.write "\n"
                                end
                        end
@@ -156,7 +151,8 @@ class CodeGenerator
                        var jparam = jparam_list[i]
                        var nit_type = model.java_to_nit_type(jparam)
 
-                       if not nit_type.is_known then comment = "#"
+                       if not nit_type.is_known and comment_unknown_types then comment = "#"
+                       if jparam.is_primitive_array then comment = "#"
 
                        var cast = jparam.param_cast
 
@@ -191,7 +187,8 @@ class CodeGenerator
                if not jreturn_type.is_void then
                        return_type = model.java_to_nit_type(jreturn_type)
 
-                       if not return_type.is_known then comment = "#"
+                       if not return_type.is_known and comment_unknown_types then comment = "#"
+                       if jreturn_type.is_primitive_array then comment = "#"
 
                        nit_signature.add ": {return_type} "
                end
@@ -221,7 +218,8 @@ class CodeGenerator
                nit_id = java_class.nit_name_for(nit_id, [java_type], false)
 
                var c = ""
-               if not nit_type.is_known then c = "#"
+               if not nit_type.is_known and comment_unknown_types then c = "#"
+               if java_type.is_primitive_array then c = "#"
 
                file_out.write """
        # Java getter: {{{java_class}}}.{{{java_id}}}
@@ -256,7 +254,8 @@ class CodeGenerator
                                nit_params.add  "{param_id}: {nit_type}"
                                param_id = param_id.successor(1)
 
-                               if not nit_type.is_known then c = "#"
+                               if not nit_type.is_known and comment_unknown_types then c = "#"
+                               if java_type.is_primitive_array then c = "#"
                        end
 
                        nit_params_s = "(" + nit_params.join(", ") + ")"
@@ -277,11 +276,17 @@ 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: Array[String] = ["abort", "abstract", "and", "assert",
+       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"]
+               "protected", "public", "return", "self", "super", "then", "true", "type", "var", "while",
+
+       # Top-level methods
+               "class_name", "get_time", "hash", "is_same_type", "is_same_instance", "output",
+
+       # Pointer or JavaObject methods
+               "free"])
 end
 
 redef class String
@@ -294,13 +299,6 @@ redef class String
        fun to_nit_method_name: String
        do
                var name = self.to_snake_case
-               if name.has_prefix("get_") then
-                       name = name.substring_from(4)
-               else if name.has_prefix("set_") then
-                       name = name.substring_from(4)
-                       if nit_keywords.has(name) then name += "_"
-                       name += "="
-               end
 
                # Strip the '_' prefix
                while name.has_prefix("_") do name = name.substring(1, name.length-1)