contrib/objcwrapper: minor style fix
[nit.git] / contrib / objcwrapper / src / objc_generator.nit
index 845a3b1..f2f04a9 100644 (file)
@@ -131,11 +131,12 @@ extern class {{{classe.name}}} in "ObjC" `{ {{{classe.name}}} * `}
                        write_attribute(attribute, file)
                end
 
-               # Methods
+               # Instance methods '-'
                for method in classe.methods do
                        if not model.knows_all_types(method) then method.is_commented = true
 
                        if not opt_init_as_methods.value and method.is_init then continue
+                       if method.is_class_property then continue
 
                        write_method_signature(method, file)
                        write_objc_method_call(method, file)
@@ -144,6 +145,14 @@ extern class {{{classe.name}}} in "ObjC" `{ {{{classe.name}}} * `}
                file.write """
 end
 """
+
+               # Class methods '+'
+               for method in classe.methods do
+                       if not method.is_class_property then continue
+
+                       write_method_signature(method, file)
+                       write_objc_method_call(method, file)
+               end
        end
 
        private fun write_constructors(classe: ObjcClass, file: Writer)
@@ -167,7 +176,7 @@ end
 
                        write_method_signature(method, file)
 
-                               write_objc_init_call(classe.name, method, file)
+                       write_objc_init_call(classe.name, method, file)
                end
        end
 
@@ -222,6 +231,9 @@ end
 
                if name == "init" then name = ""
 
+               # If class method, prefix with class name
+               if method.is_class_property then name = "{method.objc_class.name.to_snake_case}_{name}"
+
                # Kind of method
                var fun_keyword = "fun"
                if not opt_init_as_methods.value and method.is_init then
@@ -245,7 +257,7 @@ end
                end
 
                file.write """
-{{{c}}}        {{{fun_keyword}}} {{{name}}}{{{params_with_par}}}{{{ret}}} in "ObjC" `{
+{{{c}}}{{{fun_keyword}}} {{{name}}}{{{params_with_par}}}{{{ret}}} in "ObjC" `{
 """
        end
 
@@ -263,8 +275,8 @@ end
                var c = method.comment_str
 
                file.write """
-{{{c}}}                return [[{{{class_name}}} alloc] {{{params.join(" ")}}}];
-{{{c}}}        `}
+{{{c}}}        return [[{{{class_name}}} alloc] {{{params.join(" ")}}}];
+{{{c}}}`}
 
 """
        end
@@ -283,11 +295,15 @@ end
                        else params.add param.name
                end
 
+               # Receiver, instance or class
+               var recv = "self"
+               if method.is_class_property then recv = method.objc_class.name
+
                var c = method.comment_str
 
                file.write """
-{{{c}}}                {{{ret}}}[self {{{params.join(" ")}}}];
-{{{c}}}        `}
+{{{c}}}        {{{ret}}}[{{{recv}}} {{{params.join(" ")}}}];
+{{{c}}}`}
 
 """
        end
@@ -307,8 +323,14 @@ redef class Text
        end
 end
 
-redef class Property
+redef class ObjcProperty
        private fun comment_str: String do if is_commented then
                return "#"
        else return ""
 end
+
+redef class ObjcMethod
+       private fun indent: String do return if is_class_property then "" else "\t"
+
+       redef fun comment_str do return indent + super
+end