contrib/jwrapper: comment out all primitive arrays
[nit.git] / contrib / jwrapper / src / code_generator.nit
index 684db9c..939c160 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
@@ -99,7 +94,7 @@ class CodeGenerator
                end
 
                if stub_for_unknown_types then
-                       for jtype in model.unknown_types do
+                       for jtype, nit_type in model.unknown_types do
                                generate_unknown_class_header(jtype)
                                file_out.write "\n"
                        end
@@ -127,7 +122,7 @@ class CodeGenerator
 
        private fun generate_class_header(jtype: JavaType)
        do
-               var nit_type = jtype.to_nit_type
+               var nit_type = model.java_to_nit_type(jtype)
                file_out.write "# Java class: {jtype.to_package_name}\n"
                file_out.write "extern class {nit_type} in \"Java\" `\{ {jtype.to_package_name} `\}\n"
                file_out.write "\tsuper JavaObject\n\n"
@@ -154,24 +149,12 @@ class CodeGenerator
                # Parameters
                for i in [0..jparam_list.length[ do
                        var jparam = jparam_list[i]
-                       var nit_type = jparam.to_nit_type
-
-                       if not nit_type.is_complete then
-                               if jparam.is_wrapped then
-                                       java_class.imports.add nit_type.mod.as(not null)
-                               else
-                                       model.unknown_types.add jparam
-                                       if comment_unknown_types then
-                                               comment = "#"
-                                       else
-                                               nit_type = jparam.extern_name
-                                       end
-                               end
-                       end
+                       var nit_type = model.java_to_nit_type(jparam)
 
-                       var cast = ""
+                       if not nit_type.is_known then comment = "#"
+                       if jparam.is_primitive_array then comment = "#"
 
-                       if not jparam.is_collection then cast = jparam.param_cast
+                       var cast = jparam.param_cast
 
                        nit_types.add(nit_type)
 
@@ -201,22 +184,11 @@ class CodeGenerator
                end
 
                var return_type = null
-
                if not jreturn_type.is_void then
-                       return_type = jreturn_type.to_nit_type
-
-                       if not return_type.is_complete then
-                               if jreturn_type.is_wrapped then
-                                       java_class.imports.add return_type.mod.as(not null)
-                               else
-                                       model.unknown_types.add jreturn_type
-                                       if comment_unknown_types then
-                                               comment = "#"
-                                       else
-                                               return_type = jreturn_type.extern_name
-                                       end
-                               end
-                       end
+                       return_type = model.java_to_nit_type(jreturn_type)
+
+                       if not return_type.is_known then comment = "#"
+                       if jreturn_type.is_primitive_array then comment = "#"
 
                        nit_signature.add ": {return_type} "
                end
@@ -247,6 +219,7 @@ class CodeGenerator
 
                var c = ""
                if not nit_type.is_known then c = "#"
+               if java_type.is_primitive_array then c = "#"
 
                file_out.write """
        # Java getter: {{{java_class}}}.{{{java_id}}}
@@ -282,6 +255,7 @@ class CodeGenerator
                                param_id = param_id.successor(1)
 
                                if not nit_type.is_known then c = "#"
+                               if java_type.is_primitive_array then c = "#"
                        end
 
                        nit_params_s = "(" + nit_params.join(", ") + ")"
@@ -302,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