contrib/objcwrapper: add type knowledge checks to ObjcModel
[nit.git] / contrib / objcwrapper / src / objc_model.nit
index 46589c9..a082d22 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