contrib/objcwrapper: each ObjcProperty keeps track of its declaring class
[nit.git] / contrib / objcwrapper / src / objc_model.nit
index 46589c9..21a34fa 100644 (file)
@@ -19,6 +19,33 @@ module objc_model
 class ObjcModel
        # All analyzed classes
        var classes = new Array[ObjcClass]
+
+       # Is `objc_type` known by this model?
+       fun knows_type(objc_type: Text): Bool
+       do
+               for c in classes do
+                       if c.name == objc_type then return true
+               end
+
+               return imported_types.has(objc_type)
+       end
+
+       # Are all types in the signature or `method` known by this model?
+       fun knows_all_types(method: ObjcMethod): Bool
+       do
+               for param in method.params do
+                       if param.is_single then break
+                       if not knows_type(param.return_type) then return false
+               end
+
+               var r = method.return_type
+               return r == "void" or r == "id" or knows_type(r)
+       end
+
+       # Objective-C types available in imported modules
+       #
+       # TODO seach in existing wrappers
+       private var imported_types: Array[String] = ["NSObject", "NSString"]
 end
 
 # Objective-C class
@@ -38,13 +65,13 @@ end
 
 # Method of an `ObjcClass`
 class ObjcMethod
-       super Property
+       super ObjcProperty
 
-       # Scope: '+' for a static class method, and '-' for an instance method
-       var scope: Char is noinit, writable
+       # Is this a static class method declared with '+'? Otherwise it's an instance method.
+       var is_class_property: Bool = false is writable
 
        # Parameters of the method
-       var params = new Array[Param]
+       var params = new Array[ObjcParam]
 
        # Return type as a `String`
        var return_type: String is noinit, writable
@@ -55,7 +82,7 @@ end
 
 # Attribute of an `ObjcClass`
 class ObjcAttribute
-       super Property
+       super ObjcProperty
 
        # Name of this attribute
        var name: String is noinit, writable
@@ -65,13 +92,16 @@ class ObjcAttribute
 end
 
 # Property of an `ObjcClass`
-class Property
+class ObjcProperty
+       # Introducing class
+       var objc_class: ObjcClass
+
        # Is this property to be commented out?
        var is_commented = false is writable
 end
 
 # Parameter of an `ObjcMethod`
-class Param
+class ObjcParam
        # Parameter name, used by the caller (e.g. `withObject` in `withObject: (NSObject*) obj`)
        var name: String is noinit, writable