We are using SWIG to create the JNI API between C++ API to Java in Android.
So for example lets say that our C++ class is:
class TestAnnotation {
public:
void setMessage(char * message);
char * getMessage();
private:
char* message = nullptr;
};
SWIG produces this auto generated Java class:
public class TestAnnotation {
...
public void setMessage(String message) {
myJNI.TestAnnotation_setMessage(swigCPtr, this, message);
}
public String getMessage() {
return myJNI.TestAnnotation_getMessage(swigCPtr, this);
}
}
As you can see, message
can be null and it is possible for the get & set methods to receive/return a null String
(the JNI auto generated code behaves as expected in this case and allows to either use jstring
or null
).
My question is whether: SWIG is capable of adding annotations like @Nullable
or @NonNull
to match the C++ API (if we need to supply "hints" to SWIG, that would also work).
So in this case the desired auto generated Java API will be:
public class TestAnnotation {
...
public void setMessage(@Nullable String message) {
myJNI.TestAnnotation_setMessage(swigCPtr, this, message);
}
@Nullable
public String getMessage() {
return myJNI.TestAnnotation_getMessage(swigCPtr, this);
}
}
This is important as we are using this Java API with Kotlin and the absence of the annotations make it harder to use the Kotlin smart features.