Home Features Docs Blog Support GitHub

NatJ bind selectors to Java methods without @Selector annotation


#1

Is it possible to manually tell NatJ to bridge a certain objc selector to a certain Java method, without using the @Selector annotation? I’m using the @Selector annotation now on Java methods that should be accessible from my objc code, which works perfectly fine. However, because adding annotations to a class or method of course requires you to have access to the source code and needs the MOE dependency in that project, registering the selector by adding annotations is not always on option.

So, as an example (taken from https://github.com/migeran/moe-java-samples/blob/master/ObjCProtoFactory/src/main/java/com/migeran/objcapp/ICounterService.java), instead of this code:

public interface CounterService {
    @Selector("increment")
    int increment();

    @Selector("count")
    int getCount();
}

It would be nice to be able to do something along these lines:

// standard java class coming from a non-MOE package
public interface CounterService {
    int increment();
    int getCount();
}
// inside of the MOE project
public static void main(String[] args) {
   NatJ.registerProtocol("CounterService", CounterService.class);
   NatJ.registerSelector("CounterService", "increment", CounterService.class.getMethod("increment"));
   NatJ.registerSelector("CounterService", "count", CounterService.class.getMethod("getCount"));
}

Or something similar, as long as it doesn’t require adding these annotations.

Does something that covers this use case already exist? Or maybe something in gradle? Or some sort of natj file, similar to a proguard file, to place all of these mappings in?

Right now, to be able to add these annotations, I have to wrap every single Java class (coming from a different package) that I want to use in objc into a new Java class.


#2

I’m guessing that this is a feature request then? @kisg