mac.Foundation: safeInvoke appcode/163.2543 appcode/163.3075 appcode/163.3263
authorVyacheslav Karpukhin <Vyacheslav.Karpukhin@jetbrains.com>
Thu, 21 Jul 2016 15:57:32 +0000 (17:57 +0200)
committerVyacheslav Karpukhin <Vyacheslav.Karpukhin@jetbrains.com>
Wed, 10 Aug 2016 19:16:48 +0000 (21:16 +0200)
platform/util/src/com/intellij/ui/mac/foundation/Foundation.java

index 3e4e67e414524d63d9573a3bc4c6a31e1e0d0191..ca470eb03560b25659b0957f05e6deeffb47a6f2 100644 (file)
@@ -79,10 +79,27 @@ public class Foundation {
     return invoke(getObjcClass(cls), createSelector(selector), args);
   }
 
+  public static ID safeInvoke(final String stringCls, final String stringSelector, Object... args) {
+    ID cls = getObjcClass(stringCls);
+    Pointer selector = createSelector(stringSelector);
+    if (invoke(cls, "respondsToSelector:", selector).intValue() == 0) {
+      throw new RuntimeException(String.format("Missing selector %s for %s", stringSelector, stringCls));
+    }
+    return invoke(cls, selector, args);
+  }
+
   public static ID invoke(final ID id, final String selector, Object... args) {
     return invoke(id, createSelector(selector), args);
   }
 
+  public static ID safeInvoke(final ID id, final String stringSelector, Object... args) {
+    Pointer selector = createSelector(stringSelector);
+    if (!id.equals(ID.NIL) && invoke(id, "respondsToSelector:", selector).intValue() == 0) {
+      throw new RuntimeException(String.format("Missing selector %s for %s", stringSelector, toStringViaUTF8(invoke(id, "description"))));
+    }
+    return invoke(id, selector, args);
+  }
+
   public static ID allocateObjcClassPair(ID superCls, String name) {
     return myFoundationLibrary.objc_allocateClassPair(superCls, name, 0);
   }