diff --git a/bind/testdata/classes.go.golden b/bind/testdata/classes.go.golden index 5690ea6..eb17775 100644 --- a/bind/testdata/classes.go.golden +++ b/bind/testdata/classes.go.golden @@ -449,6 +449,7 @@ type Java_lang_Runnable interface { type Java_io_InputStream interface { Read(a0 ...interface{}) (int32, error) + ToString() string } type Java_util_concurrent_Future interface { @@ -456,15 +457,19 @@ type Java_util_concurrent_Future interface { } type Java_lang_Object interface { + ToString() string } type Java_util_concurrent_TimeUnit interface { + ToString() string } type Java_util_Spliterators interface { + ToString() string } type Java_lang_System interface { + ToString() string } type Java_Future interface { @@ -474,10 +479,12 @@ type Java_Future interface { type Java_InputStream interface { Read(a0 ...interface{}) (int32, error) + ToString() string Super() Java_InputStream } type Java_Object interface { + ToString() string Super() Java_Object } @@ -512,6 +519,7 @@ type Java_util_Spliterator_OfDouble interface { type Java_io_Console interface { Flush() error + ToString() string } // File is generated by gobind. Do not edit. @@ -710,6 +718,22 @@ func (p *proxy_class_java_io_InputStream) Read(a0 ...interface{}) (int32, error) panic("no overloaded method found for java.io.InputStream.read that matched the arguments") } +func (p *proxy_class_java_io_InputStream) ToString() string { + res := C.cproxy_java_io_InputStream_toString(C.jint(p.Bind_proxy_refnum__())) + _res := decodeString(res.res) + var _exc error + _exc_ref := _seq.FromRefNum(int32(res.exc)) + if _exc_ref != nil { + if res.exc < 0 { // go object + _exc = _exc_ref.Get().(error) + } else { // foreign object + _exc = (*proxy_error)(_exc_ref) + } + } + if (_exc != nil) { panic(_exc) } + return _res +} + var class_java_util_concurrent_Future C.jclass func init_java_util_concurrent_Future() { @@ -817,6 +841,22 @@ type proxy_class_java_lang_Object _seq.Ref func (p *proxy_class_java_lang_Object) Bind_proxy_refnum__() int32 { return (*_seq.Ref)(p).Bind_IncNum() } +func (p *proxy_class_java_lang_Object) ToString() string { + res := C.cproxy_java_lang_Object_toString(C.jint(p.Bind_proxy_refnum__())) + _res := decodeString(res.res) + var _exc error + _exc_ref := _seq.FromRefNum(int32(res.exc)) + if _exc_ref != nil { + if res.exc < 0 { // go object + _exc = _exc_ref.Get().(error) + } else { // foreign object + _exc = (*proxy_error)(_exc_ref) + } + } + if (_exc != nil) { panic(_exc) } + return _res +} + var class_java_util_concurrent_TimeUnit C.jclass func init_java_util_concurrent_TimeUnit() { @@ -842,6 +882,22 @@ type proxy_class_java_util_concurrent_TimeUnit _seq.Ref func (p *proxy_class_java_util_concurrent_TimeUnit) Bind_proxy_refnum__() int32 { return (*_seq.Ref)(p).Bind_IncNum() } +func (p *proxy_class_java_util_concurrent_TimeUnit) ToString() string { + res := C.cproxy_java_util_concurrent_TimeUnit_toString(C.jint(p.Bind_proxy_refnum__())) + _res := decodeString(res.res) + var _exc error + _exc_ref := _seq.FromRefNum(int32(res.exc)) + if _exc_ref != nil { + if res.exc < 0 { // go object + _exc = _exc_ref.Get().(error) + } else { // foreign object + _exc = (*proxy_error)(_exc_ref) + } + } + if (_exc != nil) { panic(_exc) } + return _res +} + var class_java_util_Spliterators C.jclass func init_java_util_Spliterators() { @@ -988,6 +1044,22 @@ type proxy_class_java_util_Spliterators _seq.Ref func (p *proxy_class_java_util_Spliterators) Bind_proxy_refnum__() int32 { return (*_seq.Ref)(p).Bind_IncNum() } +func (p *proxy_class_java_util_Spliterators) ToString() string { + res := C.cproxy_java_util_Spliterators_toString(C.jint(p.Bind_proxy_refnum__())) + _res := decodeString(res.res) + var _exc error + _exc_ref := _seq.FromRefNum(int32(res.exc)) + if _exc_ref != nil { + if res.exc < 0 { // go object + _exc = _exc_ref.Get().(error) + } else { // foreign object + _exc = (*proxy_error)(_exc_ref) + } + } + if (_exc != nil) { panic(_exc) } + return _res +} + var class_java_lang_System C.jclass func init_java_lang_System() { @@ -1037,6 +1109,22 @@ type proxy_class_java_lang_System _seq.Ref func (p *proxy_class_java_lang_System) Bind_proxy_refnum__() int32 { return (*_seq.Ref)(p).Bind_IncNum() } +func (p *proxy_class_java_lang_System) ToString() string { + res := C.cproxy_java_lang_System_toString(C.jint(p.Bind_proxy_refnum__())) + _res := decodeString(res.res) + var _exc error + _exc_ref := _seq.FromRefNum(int32(res.exc)) + if _exc_ref != nil { + if res.exc < 0 { // go object + _exc = _exc_ref.Get().(error) + } else { // foreign object + _exc = (*proxy_error)(_exc_ref) + } + } + if (_exc != nil) { panic(_exc) } + return _res +} + var class_java_Future C.jclass func init_java_Future() { @@ -1264,6 +1352,22 @@ func (p *proxy_class_java_InputStream) Read(a0 ...interface{}) (int32, error) { panic("no overloaded method found for java.InputStream.read that matched the arguments") } +func (p *proxy_class_java_InputStream) ToString() string { + res := C.cproxy_java_InputStream_toString(C.jint(p.Bind_proxy_refnum__())) + _res := decodeString(res.res) + var _exc error + _exc_ref := _seq.FromRefNum(int32(res.exc)) + if _exc_ref != nil { + if res.exc < 0 { // go object + _exc = _exc_ref.Get().(error) + } else { // foreign object + _exc = (*proxy_error)(_exc_ref) + } + } + if (_exc != nil) { panic(_exc) } + return _res +} + func (p *proxy_class_java_InputStream) Super() Java.Java_InputStream { return &super_java_InputStream{p} } @@ -1327,6 +1431,22 @@ func (p *super_java_InputStream) Read(a0 ...interface{}) (int32, error) { panic("no overloaded method found for java.InputStream.read that matched the arguments") } +func (p *super_java_InputStream) ToString() string { + res := C.csuper_java_InputStream_toString(C.jint(p.Bind_proxy_refnum__())) + _res := decodeString(res.res) + var _exc error + _exc_ref := _seq.FromRefNum(int32(res.exc)) + if _exc_ref != nil { + if res.exc < 0 { // go object + _exc = _exc_ref.Get().(error) + } else { // foreign object + _exc = (*proxy_error)(_exc_ref) + } + } + if (_exc != nil) { panic(_exc) } + return _res +} + var class_java_Object C.jclass func init_java_Object() { @@ -1352,12 +1472,44 @@ type proxy_class_java_Object _seq.Ref func (p *proxy_class_java_Object) Bind_proxy_refnum__() int32 { return (*_seq.Ref)(p).Bind_IncNum() } +func (p *proxy_class_java_Object) ToString() string { + res := C.cproxy_java_Object_toString(C.jint(p.Bind_proxy_refnum__())) + _res := decodeString(res.res) + var _exc error + _exc_ref := _seq.FromRefNum(int32(res.exc)) + if _exc_ref != nil { + if res.exc < 0 { // go object + _exc = _exc_ref.Get().(error) + } else { // foreign object + _exc = (*proxy_error)(_exc_ref) + } + } + if (_exc != nil) { panic(_exc) } + return _res +} + func (p *proxy_class_java_Object) Super() Java.Java_Object { return &super_java_Object{p} } type super_java_Object struct {*proxy_class_java_Object} +func (p *super_java_Object) ToString() string { + res := C.csuper_java_Object_toString(C.jint(p.Bind_proxy_refnum__())) + _res := decodeString(res.res) + var _exc error + _exc_ref := _seq.FromRefNum(int32(res.exc)) + if _exc_ref != nil { + if res.exc < 0 { // go object + _exc = _exc_ref.Get().(error) + } else { // foreign object + _exc = (*proxy_error)(_exc_ref) + } + } + if (_exc != nil) { panic(_exc) } + return _res +} + var class_java_Runnable C.jclass func init_java_Runnable() { @@ -1656,6 +1808,22 @@ func (p *proxy_class_java_io_Console) Flush() error { return _exc } +func (p *proxy_class_java_io_Console) ToString() string { + res := C.cproxy_java_io_Console_toString(C.jint(p.Bind_proxy_refnum__())) + _res := decodeString(res.res) + var _exc error + _exc_ref := _seq.FromRefNum(int32(res.exc)) + if _exc_ref != nil { + if res.exc < 0 { // go object + _exc = _exc_ref.Get().(error) + } else { // foreign object + _exc = (*proxy_error)(_exc_ref) + } + } + if (_exc != nil) { panic(_exc) } + return _res +} + // Package gomobile_bind is an autogenerated binder stub for package java. // gobind -lang=go classes // diff --git a/bind/testdata/classes.java.c.golden b/bind/testdata/classes.java.c.golden index c1469b2..579f33a 100644 --- a/bind/testdata/classes.java.c.golden +++ b/bind/testdata/classes.java.c.golden @@ -10,16 +10,20 @@ static jclass class_java_io_InputStream; static jmethodID m_java_io_InputStream_read__; static jmethodID m_java_io_InputStream_read___3B; static jmethodID m_java_io_InputStream_read___3BII; +static jmethodID m_java_io_InputStream_toString; static jclass class_java_util_concurrent_Future; static jmethodID m_java_util_concurrent_Future_get__; static jmethodID m_java_util_concurrent_Future_get__JLjava_util_concurrent_TimeUnit_2; static jclass class_java_lang_Object; +static jmethodID m_java_lang_Object_toString; static jclass class_java_util_concurrent_TimeUnit; +static jmethodID m_java_util_concurrent_TimeUnit_toString; static jclass class_java_util_Spliterators; static jmethodID m_s_java_util_Spliterators_iterator__Ljava_util_Spliterator_2; static jmethodID m_s_java_util_Spliterators_iterator__Ljava_util_Spliterator_00024OfInt_2; static jmethodID m_s_java_util_Spliterators_iterator__Ljava_util_Spliterator_00024OfLong_2; static jmethodID m_s_java_util_Spliterators_iterator__Ljava_util_Spliterator_00024OfDouble_2; +static jmethodID m_java_util_Spliterators_toString; ret_jint cproxy_s_java_util_Spliterators_iterator__Ljava_util_Spliterator_2(jint a0) { JNIEnv *env = go_seq_push_local_frame(1); jobject _a0 = go_seq_from_refnum(env, a0, NULL, NULL); @@ -82,6 +86,7 @@ ret_jint cproxy_s_java_util_Spliterators_iterator__Ljava_util_Spliterator_00024O static jclass class_java_lang_System; static jmethodID m_s_java_lang_System_console; +static jmethodID m_java_lang_System_toString; ret_jint cproxy_s_java_lang_System_console() { JNIEnv *env = go_seq_push_local_frame(0); jobject res = (*env)->CallStaticObjectMethod(env, class_java_lang_System, m_s_java_lang_System_console); @@ -110,8 +115,12 @@ static jmethodID m_java_InputStream_read___3B; static jmethodID sm_java_InputStream_read___3B; static jmethodID m_java_InputStream_read___3BII; static jmethodID sm_java_InputStream_read___3BII; +static jmethodID m_java_InputStream_toString; +static jmethodID sm_java_InputStream_toString; static jclass class_java_Object; static jclass sclass_java_Object; +static jmethodID m_java_Object_toString; +static jmethodID sm_java_Object_toString; static jclass class_java_Runnable; static jclass sclass_java_Runnable; static jmethodID m_java_Runnable_run; @@ -126,6 +135,7 @@ static jclass class_java_util_PrimitiveIterator_OfDouble; static jclass class_java_util_Spliterator_OfDouble; static jclass class_java_io_Console; static jmethodID m_java_io_Console_flush; +static jmethodID m_java_io_Console_toString; void init_proxies() { JNIEnv *env = go_seq_push_local_frame(20); @@ -138,23 +148,28 @@ void init_proxies() { m_java_io_InputStream_read__ = go_seq_get_method_id(clazz, "read", "()I"); m_java_io_InputStream_read___3B = go_seq_get_method_id(clazz, "read", "([B)I"); m_java_io_InputStream_read___3BII = go_seq_get_method_id(clazz, "read", "([BII)I"); + m_java_io_InputStream_toString = go_seq_get_method_id(clazz, "toString", "()Ljava/lang/String;"); clazz = (*env)->FindClass(env, "java/util/concurrent/Future"); class_java_util_concurrent_Future = (*env)->NewGlobalRef(env, clazz); m_java_util_concurrent_Future_get__ = go_seq_get_method_id(clazz, "get", "()Ljava/lang/Object;"); m_java_util_concurrent_Future_get__JLjava_util_concurrent_TimeUnit_2 = go_seq_get_method_id(clazz, "get", "(JLjava/util/concurrent/TimeUnit;)Ljava/lang/Object;"); clazz = (*env)->FindClass(env, "java/lang/Object"); class_java_lang_Object = (*env)->NewGlobalRef(env, clazz); + m_java_lang_Object_toString = go_seq_get_method_id(clazz, "toString", "()Ljava/lang/String;"); clazz = (*env)->FindClass(env, "java/util/concurrent/TimeUnit"); class_java_util_concurrent_TimeUnit = (*env)->NewGlobalRef(env, clazz); + m_java_util_concurrent_TimeUnit_toString = go_seq_get_method_id(clazz, "toString", "()Ljava/lang/String;"); clazz = (*env)->FindClass(env, "java/util/Spliterators"); class_java_util_Spliterators = (*env)->NewGlobalRef(env, clazz); m_s_java_util_Spliterators_iterator__Ljava_util_Spliterator_2 = go_seq_get_static_method_id(clazz, "iterator", "(Ljava/util/Spliterator;)Ljava/util/Iterator;"); m_s_java_util_Spliterators_iterator__Ljava_util_Spliterator_00024OfInt_2 = go_seq_get_static_method_id(clazz, "iterator", "(Ljava/util/Spliterator$OfInt;)Ljava/util/PrimitiveIterator$OfInt;"); m_s_java_util_Spliterators_iterator__Ljava_util_Spliterator_00024OfLong_2 = go_seq_get_static_method_id(clazz, "iterator", "(Ljava/util/Spliterator$OfLong;)Ljava/util/PrimitiveIterator$OfLong;"); m_s_java_util_Spliterators_iterator__Ljava_util_Spliterator_00024OfDouble_2 = go_seq_get_static_method_id(clazz, "iterator", "(Ljava/util/Spliterator$OfDouble;)Ljava/util/PrimitiveIterator$OfDouble;"); + m_java_util_Spliterators_toString = go_seq_get_method_id(clazz, "toString", "()Ljava/lang/String;"); clazz = (*env)->FindClass(env, "java/lang/System"); class_java_lang_System = (*env)->NewGlobalRef(env, clazz); m_s_java_lang_System_console = go_seq_get_static_method_id(clazz, "console", "()Ljava/io/Console;"); + m_java_lang_System_toString = go_seq_get_method_id(clazz, "toString", "()Ljava/lang/String;"); clazz = (*env)->FindClass(env, "java/Future"); class_java_Future = (*env)->NewGlobalRef(env, clazz); sclass_java_Future = (*env)->GetSuperclass(env, clazz); @@ -173,10 +188,14 @@ void init_proxies() { sm_java_InputStream_read___3B = go_seq_get_method_id(sclass_java_InputStream, "read", "([B)I"); m_java_InputStream_read___3BII = go_seq_get_method_id(clazz, "read", "([BII)I"); sm_java_InputStream_read___3BII = go_seq_get_method_id(sclass_java_InputStream, "read", "([BII)I"); + m_java_InputStream_toString = go_seq_get_method_id(clazz, "toString", "()Ljava/lang/String;"); + sm_java_InputStream_toString = go_seq_get_method_id(sclass_java_InputStream, "toString", "()Ljava/lang/String;"); clazz = (*env)->FindClass(env, "java/Object"); class_java_Object = (*env)->NewGlobalRef(env, clazz); sclass_java_Object = (*env)->GetSuperclass(env, clazz); sclass_java_Object = (*env)->NewGlobalRef(env, sclass_java_Object); + m_java_Object_toString = go_seq_get_method_id(clazz, "toString", "()Ljava/lang/String;"); + sm_java_Object_toString = go_seq_get_method_id(sclass_java_Object, "toString", "()Ljava/lang/String;"); clazz = (*env)->FindClass(env, "java/Runnable"); class_java_Runnable = (*env)->NewGlobalRef(env, clazz); sclass_java_Runnable = (*env)->GetSuperclass(env, clazz); @@ -202,6 +221,7 @@ void init_proxies() { clazz = (*env)->FindClass(env, "java/io/Console"); class_java_io_Console = (*env)->NewGlobalRef(env, clazz); m_java_io_Console_flush = go_seq_get_method_id(clazz, "flush", "()V"); + m_java_io_Console_toString = go_seq_get_method_id(clazz, "toString", "()Ljava/lang/String;"); go_seq_pop_local_frame(env); } @@ -268,6 +288,22 @@ ret_jint cproxy_java_io_InputStream_read___3BII(jint this, nbyteslice a0, jint a return __res; } +ret_nstring cproxy_java_io_InputStream_toString(jint this) { + JNIEnv *env = go_seq_push_local_frame(1); + // Must be a Java object + jobject _this = go_seq_from_refnum(env, this, NULL, NULL); + jstring res = (*env)->CallObjectMethod(env, _this, m_java_io_InputStream_toString); + jobject _exc = go_seq_get_exception(env); + int32_t _exc_ref = go_seq_to_refnum(env, _exc); + if (_exc != NULL) { + res = NULL; + } + nstring _res = go_seq_from_java_string(env, res); + go_seq_pop_local_frame(env); + ret_nstring __res = {_res, _exc_ref}; + return __res; +} + ret_jint cproxy_java_util_concurrent_Future_get__(jint this) { JNIEnv *env = go_seq_push_local_frame(1); // Must be a Java object @@ -302,6 +338,70 @@ ret_jint cproxy_java_util_concurrent_Future_get__JLjava_util_concurrent_TimeUnit return __res; } +ret_nstring cproxy_java_lang_Object_toString(jint this) { + JNIEnv *env = go_seq_push_local_frame(1); + // Must be a Java object + jobject _this = go_seq_from_refnum(env, this, NULL, NULL); + jstring res = (*env)->CallObjectMethod(env, _this, m_java_lang_Object_toString); + jobject _exc = go_seq_get_exception(env); + int32_t _exc_ref = go_seq_to_refnum(env, _exc); + if (_exc != NULL) { + res = NULL; + } + nstring _res = go_seq_from_java_string(env, res); + go_seq_pop_local_frame(env); + ret_nstring __res = {_res, _exc_ref}; + return __res; +} + +ret_nstring cproxy_java_util_concurrent_TimeUnit_toString(jint this) { + JNIEnv *env = go_seq_push_local_frame(1); + // Must be a Java object + jobject _this = go_seq_from_refnum(env, this, NULL, NULL); + jstring res = (*env)->CallObjectMethod(env, _this, m_java_util_concurrent_TimeUnit_toString); + jobject _exc = go_seq_get_exception(env); + int32_t _exc_ref = go_seq_to_refnum(env, _exc); + if (_exc != NULL) { + res = NULL; + } + nstring _res = go_seq_from_java_string(env, res); + go_seq_pop_local_frame(env); + ret_nstring __res = {_res, _exc_ref}; + return __res; +} + +ret_nstring cproxy_java_util_Spliterators_toString(jint this) { + JNIEnv *env = go_seq_push_local_frame(1); + // Must be a Java object + jobject _this = go_seq_from_refnum(env, this, NULL, NULL); + jstring res = (*env)->CallObjectMethod(env, _this, m_java_util_Spliterators_toString); + jobject _exc = go_seq_get_exception(env); + int32_t _exc_ref = go_seq_to_refnum(env, _exc); + if (_exc != NULL) { + res = NULL; + } + nstring _res = go_seq_from_java_string(env, res); + go_seq_pop_local_frame(env); + ret_nstring __res = {_res, _exc_ref}; + return __res; +} + +ret_nstring cproxy_java_lang_System_toString(jint this) { + JNIEnv *env = go_seq_push_local_frame(1); + // Must be a Java object + jobject _this = go_seq_from_refnum(env, this, NULL, NULL); + jstring res = (*env)->CallObjectMethod(env, _this, m_java_lang_System_toString); + jobject _exc = go_seq_get_exception(env); + int32_t _exc_ref = go_seq_to_refnum(env, _exc); + if (_exc != NULL) { + res = NULL; + } + nstring _res = go_seq_from_java_string(env, res); + go_seq_pop_local_frame(env); + ret_nstring __res = {_res, _exc_ref}; + return __res; +} + ret_jint cproxy_java_Future_get__(jint this) { JNIEnv *env = go_seq_push_local_frame(1); // Must be a Java object @@ -474,6 +574,70 @@ ret_jint csuper_java_InputStream_read___3BII(jint this, nbyteslice a0, jint a1, return __res; } +ret_nstring cproxy_java_InputStream_toString(jint this) { + JNIEnv *env = go_seq_push_local_frame(1); + // Must be a Java object + jobject _this = go_seq_from_refnum(env, this, NULL, NULL); + jstring res = (*env)->CallObjectMethod(env, _this, m_java_InputStream_toString); + jobject _exc = go_seq_get_exception(env); + int32_t _exc_ref = go_seq_to_refnum(env, _exc); + if (_exc != NULL) { + res = NULL; + } + nstring _res = go_seq_from_java_string(env, res); + go_seq_pop_local_frame(env); + ret_nstring __res = {_res, _exc_ref}; + return __res; +} + +ret_nstring csuper_java_InputStream_toString(jint this) { + JNIEnv *env = go_seq_push_local_frame(1); + // Must be a Java object + jobject _this = go_seq_from_refnum(env, this, NULL, NULL); + jstring res = (*env)->CallNonvirtualObjectMethod(env, _this, sclass_java_InputStream, sm_java_InputStream_toString); + jobject _exc = go_seq_get_exception(env); + int32_t _exc_ref = go_seq_to_refnum(env, _exc); + if (_exc != NULL) { + res = NULL; + } + nstring _res = go_seq_from_java_string(env, res); + go_seq_pop_local_frame(env); + ret_nstring __res = {_res, _exc_ref}; + return __res; +} + +ret_nstring cproxy_java_Object_toString(jint this) { + JNIEnv *env = go_seq_push_local_frame(1); + // Must be a Java object + jobject _this = go_seq_from_refnum(env, this, NULL, NULL); + jstring res = (*env)->CallObjectMethod(env, _this, m_java_Object_toString); + jobject _exc = go_seq_get_exception(env); + int32_t _exc_ref = go_seq_to_refnum(env, _exc); + if (_exc != NULL) { + res = NULL; + } + nstring _res = go_seq_from_java_string(env, res); + go_seq_pop_local_frame(env); + ret_nstring __res = {_res, _exc_ref}; + return __res; +} + +ret_nstring csuper_java_Object_toString(jint this) { + JNIEnv *env = go_seq_push_local_frame(1); + // Must be a Java object + jobject _this = go_seq_from_refnum(env, this, NULL, NULL); + jstring res = (*env)->CallNonvirtualObjectMethod(env, _this, sclass_java_Object, sm_java_Object_toString); + jobject _exc = go_seq_get_exception(env); + int32_t _exc_ref = go_seq_to_refnum(env, _exc); + if (_exc != NULL) { + res = NULL; + } + nstring _res = go_seq_from_java_string(env, res); + go_seq_pop_local_frame(env); + ret_nstring __res = {_res, _exc_ref}; + return __res; +} + jint cproxy_java_Runnable_run(jint this) { JNIEnv *env = go_seq_push_local_frame(1); // Must be a Java object @@ -507,6 +671,22 @@ jint cproxy_java_io_Console_flush(jint this) { return _exc_ref; } +ret_nstring cproxy_java_io_Console_toString(jint this) { + JNIEnv *env = go_seq_push_local_frame(1); + // Must be a Java object + jobject _this = go_seq_from_refnum(env, this, NULL, NULL); + jstring res = (*env)->CallObjectMethod(env, _this, m_java_io_Console_toString); + jobject _exc = go_seq_get_exception(env); + int32_t _exc_ref = go_seq_to_refnum(env, _exc); + if (_exc != NULL) { + res = NULL; + } + nstring _res = go_seq_from_java_string(env, res); + go_seq_pop_local_frame(env); + ret_nstring __res = {_res, _exc_ref}; + return __res; +} + // JNI functions for the Go <=> Java bridge. // gobind -lang=java classes // diff --git a/bind/testdata/classes.java.h.golden b/bind/testdata/classes.java.h.golden index 61aefed..7350e6b 100644 --- a/bind/testdata/classes.java.h.golden +++ b/bind/testdata/classes.java.h.golden @@ -50,8 +50,13 @@ extern jint cproxy_java_lang_Runnable_run(jint this); extern ret_jint cproxy_java_io_InputStream_read__(jint this); extern ret_jint cproxy_java_io_InputStream_read___3B(jint this, nbyteslice a0); extern ret_jint cproxy_java_io_InputStream_read___3BII(jint this, nbyteslice a0, jint a1, jint a2); +extern ret_nstring cproxy_java_io_InputStream_toString(jint this); extern ret_jint cproxy_java_util_concurrent_Future_get__(jint this); extern ret_jint cproxy_java_util_concurrent_Future_get__JLjava_util_concurrent_TimeUnit_2(jint this, jlong a0, jint a1); +extern ret_nstring cproxy_java_lang_Object_toString(jint this); +extern ret_nstring cproxy_java_util_concurrent_TimeUnit_toString(jint this); +extern ret_nstring cproxy_java_util_Spliterators_toString(jint this); +extern ret_nstring cproxy_java_lang_System_toString(jint this); extern ret_jint cproxy_java_Future_get__(jint this); extern ret_jint csuper_java_Future_get__(jint this); extern ret_jint cproxy_java_Future_get__JLjava_util_concurrent_TimeUnit_2(jint this, jlong a0, jint a1); @@ -62,9 +67,14 @@ extern ret_jint cproxy_java_InputStream_read___3B(jint this, nbyteslice a0); extern ret_jint csuper_java_InputStream_read___3B(jint this, nbyteslice a0); extern ret_jint cproxy_java_InputStream_read___3BII(jint this, nbyteslice a0, jint a1, jint a2); extern ret_jint csuper_java_InputStream_read___3BII(jint this, nbyteslice a0, jint a1, jint a2); +extern ret_nstring cproxy_java_InputStream_toString(jint this); +extern ret_nstring csuper_java_InputStream_toString(jint this); +extern ret_nstring cproxy_java_Object_toString(jint this); +extern ret_nstring csuper_java_Object_toString(jint this); extern jint cproxy_java_Runnable_run(jint this); extern jint csuper_java_Runnable_run(jint this); extern jint cproxy_java_io_Console_flush(jint this); +extern ret_nstring cproxy_java_io_Console_toString(jint this); extern ret_jint cproxy_s_java_util_Spliterators_iterator__Ljava_util_Spliterator_2(jint a0); extern ret_jint cproxy_s_java_util_Spliterators_iterator__Ljava_util_Spliterator_00024OfInt_2(jint a0); extern ret_jint cproxy_s_java_util_Spliterators_iterator__Ljava_util_Spliterator_00024OfLong_2(jint a0); diff --git a/bind/testdata/java.go.golden b/bind/testdata/java.go.golden index f512c21..b8b61d7 100644 --- a/bind/testdata/java.go.golden +++ b/bind/testdata/java.go.golden @@ -173,18 +173,22 @@ package Java const Dummy = 0 type Java_lang_Float interface { + ToString() string } type Java_lang_Object interface { + ToString() string } type Java_lang_Runnable interface { } type Java_lang_Character interface { + ToString() string } type Java_lang_Character_Subset interface { + ToString() string } // File is generated by gobind. Do not edit. @@ -257,6 +261,22 @@ type proxy_class_java_lang_Float _seq.Ref func (p *proxy_class_java_lang_Float) Bind_proxy_refnum__() int32 { return (*_seq.Ref)(p).Bind_IncNum() } +func (p *proxy_class_java_lang_Float) ToString() string { + res := C.cproxy_java_lang_Float_toString(C.jint(p.Bind_proxy_refnum__())) + _res := decodeString(res.res) + var _exc error + _exc_ref := _seq.FromRefNum(int32(res.exc)) + if _exc_ref != nil { + if res.exc < 0 { // go object + _exc = _exc_ref.Get().(error) + } else { // foreign object + _exc = (*proxy_error)(_exc_ref) + } + } + if (_exc != nil) { panic(_exc) } + return _res +} + var class_java_lang_Object C.jclass func init_java_lang_Object() { @@ -282,6 +302,22 @@ type proxy_class_java_lang_Object _seq.Ref func (p *proxy_class_java_lang_Object) Bind_proxy_refnum__() int32 { return (*_seq.Ref)(p).Bind_IncNum() } +func (p *proxy_class_java_lang_Object) ToString() string { + res := C.cproxy_java_lang_Object_toString(C.jint(p.Bind_proxy_refnum__())) + _res := decodeString(res.res) + var _exc error + _exc_ref := _seq.FromRefNum(int32(res.exc)) + if _exc_ref != nil { + if res.exc < 0 { // go object + _exc = _exc_ref.Get().(error) + } else { // foreign object + _exc = (*proxy_error)(_exc_ref) + } + } + if (_exc != nil) { panic(_exc) } + return _res +} + var class_java_lang_Runnable C.jclass func init_java_lang_Runnable() { @@ -332,6 +368,22 @@ type proxy_class_java_lang_Character _seq.Ref func (p *proxy_class_java_lang_Character) Bind_proxy_refnum__() int32 { return (*_seq.Ref)(p).Bind_IncNum() } +func (p *proxy_class_java_lang_Character) ToString() string { + res := C.cproxy_java_lang_Character_toString(C.jint(p.Bind_proxy_refnum__())) + _res := decodeString(res.res) + var _exc error + _exc_ref := _seq.FromRefNum(int32(res.exc)) + if _exc_ref != nil { + if res.exc < 0 { // go object + _exc = _exc_ref.Get().(error) + } else { // foreign object + _exc = (*proxy_error)(_exc_ref) + } + } + if (_exc != nil) { panic(_exc) } + return _res +} + var class_java_lang_Character_Subset C.jclass func init_java_lang_Character_Subset() { @@ -357,6 +409,22 @@ type proxy_class_java_lang_Character_Subset _seq.Ref func (p *proxy_class_java_lang_Character_Subset) Bind_proxy_refnum__() int32 { return (*_seq.Ref)(p).Bind_IncNum() } +func (p *proxy_class_java_lang_Character_Subset) ToString() string { + res := C.cproxy_java_lang_Character_Subset_toString(C.jint(p.Bind_proxy_refnum__())) + _res := decodeString(res.res) + var _exc error + _exc_ref := _seq.FromRefNum(int32(res.exc)) + if _exc_ref != nil { + if res.exc < 0 { // go object + _exc = _exc_ref.Get().(error) + } else { // foreign object + _exc = (*proxy_error)(_exc_ref) + } + } + if (_exc != nil) { panic(_exc) } + return _res +} + // Package gomobile_bind is an autogenerated binder stub for package java. // gobind -lang=go java // @@ -374,23 +442,69 @@ import "C" import ( _seq "golang.org/x/mobile/bind/seq" + "java" ) // suppress the error if seq ends up unused var _ = _seq.FromRefNum +//export proxyjava_F_ToString +func proxyjava_F_ToString(refnum C.int32_t) C.nstring { + ref := _seq.FromRefNum(int32(refnum)) + v := ref.Get().(java.F) + res_0 := v.ToString() + _res_0 := encodeString(res_0) + return _res_0 +} + type proxyjava_F _seq.Ref func (p *proxyjava_F) Bind_proxy_refnum__() int32 { return (*_seq.Ref)(p).Bind_IncNum() } +func (p *proxyjava_F) ToString() string { + res := C.cproxyjava_F_ToString(C.int32_t(p.Bind_proxy_refnum__())) + _res := decodeString(res) + return _res +} + +//export proxyjava_O_ToString +func proxyjava_O_ToString(refnum C.int32_t) C.nstring { + ref := _seq.FromRefNum(int32(refnum)) + v := ref.Get().(java.O) + res_0 := v.ToString() + _res_0 := encodeString(res_0) + return _res_0 +} + type proxyjava_O _seq.Ref func (p *proxyjava_O) Bind_proxy_refnum__() int32 { return (*_seq.Ref)(p).Bind_IncNum() } +func (p *proxyjava_O) ToString() string { + res := C.cproxyjava_O_ToString(C.int32_t(p.Bind_proxy_refnum__())) + _res := decodeString(res) + return _res +} + type proxyjava_R _seq.Ref func (p *proxyjava_R) Bind_proxy_refnum__() int32 { return (*_seq.Ref)(p).Bind_IncNum() } +//export proxyjava_S_ToString +func proxyjava_S_ToString(refnum C.int32_t) C.nstring { + ref := _seq.FromRefNum(int32(refnum)) + v := ref.Get().(java.S) + res_0 := v.ToString() + _res_0 := encodeString(res_0) + return _res_0 +} + type proxyjava_S _seq.Ref func (p *proxyjava_S) Bind_proxy_refnum__() int32 { return (*_seq.Ref)(p).Bind_IncNum() } + +func (p *proxyjava_S) ToString() string { + res := C.cproxyjava_S_ToString(C.int32_t(p.Bind_proxy_refnum__())) + _res := decodeString(res) + return _res +} diff --git a/bind/testdata/java.java.c.golden b/bind/testdata/java.java.c.golden index 3fadda6..b1fbd2b 100644 --- a/bind/testdata/java.java.c.golden +++ b/bind/testdata/java.java.c.golden @@ -5,27 +5,99 @@ #include "classes.h" static jclass class_java_lang_Float; +static jmethodID m_java_lang_Float_toString; static jclass class_java_lang_Object; +static jmethodID m_java_lang_Object_toString; static jclass class_java_lang_Runnable; static jclass class_java_lang_Character; +static jmethodID m_java_lang_Character_toString; static jclass class_java_lang_Character_Subset; +static jmethodID m_java_lang_Character_Subset_toString; void init_proxies() { JNIEnv *env = go_seq_push_local_frame(5); jclass clazz; clazz = (*env)->FindClass(env, "java/lang/Float"); class_java_lang_Float = (*env)->NewGlobalRef(env, clazz); + m_java_lang_Float_toString = go_seq_get_method_id(clazz, "toString", "()Ljava/lang/String;"); clazz = (*env)->FindClass(env, "java/lang/Object"); class_java_lang_Object = (*env)->NewGlobalRef(env, clazz); + m_java_lang_Object_toString = go_seq_get_method_id(clazz, "toString", "()Ljava/lang/String;"); clazz = (*env)->FindClass(env, "java/lang/Runnable"); class_java_lang_Runnable = (*env)->NewGlobalRef(env, clazz); clazz = (*env)->FindClass(env, "java/lang/Character"); class_java_lang_Character = (*env)->NewGlobalRef(env, clazz); + m_java_lang_Character_toString = go_seq_get_method_id(clazz, "toString", "()Ljava/lang/String;"); clazz = (*env)->FindClass(env, "java/lang/Character$Subset"); class_java_lang_Character_Subset = (*env)->NewGlobalRef(env, clazz); + m_java_lang_Character_Subset_toString = go_seq_get_method_id(clazz, "toString", "()Ljava/lang/String;"); go_seq_pop_local_frame(env); } +ret_nstring cproxy_java_lang_Float_toString(jint this) { + JNIEnv *env = go_seq_push_local_frame(1); + // Must be a Java object + jobject _this = go_seq_from_refnum(env, this, NULL, NULL); + jstring res = (*env)->CallObjectMethod(env, _this, m_java_lang_Float_toString); + jobject _exc = go_seq_get_exception(env); + int32_t _exc_ref = go_seq_to_refnum(env, _exc); + if (_exc != NULL) { + res = NULL; + } + nstring _res = go_seq_from_java_string(env, res); + go_seq_pop_local_frame(env); + ret_nstring __res = {_res, _exc_ref}; + return __res; +} + +ret_nstring cproxy_java_lang_Object_toString(jint this) { + JNIEnv *env = go_seq_push_local_frame(1); + // Must be a Java object + jobject _this = go_seq_from_refnum(env, this, NULL, NULL); + jstring res = (*env)->CallObjectMethod(env, _this, m_java_lang_Object_toString); + jobject _exc = go_seq_get_exception(env); + int32_t _exc_ref = go_seq_to_refnum(env, _exc); + if (_exc != NULL) { + res = NULL; + } + nstring _res = go_seq_from_java_string(env, res); + go_seq_pop_local_frame(env); + ret_nstring __res = {_res, _exc_ref}; + return __res; +} + +ret_nstring cproxy_java_lang_Character_toString(jint this) { + JNIEnv *env = go_seq_push_local_frame(1); + // Must be a Java object + jobject _this = go_seq_from_refnum(env, this, NULL, NULL); + jstring res = (*env)->CallObjectMethod(env, _this, m_java_lang_Character_toString); + jobject _exc = go_seq_get_exception(env); + int32_t _exc_ref = go_seq_to_refnum(env, _exc); + if (_exc != NULL) { + res = NULL; + } + nstring _res = go_seq_from_java_string(env, res); + go_seq_pop_local_frame(env); + ret_nstring __res = {_res, _exc_ref}; + return __res; +} + +ret_nstring cproxy_java_lang_Character_Subset_toString(jint this) { + JNIEnv *env = go_seq_push_local_frame(1); + // Must be a Java object + jobject _this = go_seq_from_refnum(env, this, NULL, NULL); + jstring res = (*env)->CallObjectMethod(env, _this, m_java_lang_Character_Subset_toString); + jobject _exc = go_seq_get_exception(env); + int32_t _exc_ref = go_seq_to_refnum(env, _exc); + if (_exc != NULL) { + res = NULL; + } + nstring _res = go_seq_from_java_string(env, res); + go_seq_pop_local_frame(env); + ret_nstring __res = {_res, _exc_ref}; + return __res; +} + // JNI functions for the Go <=> Java bridge. // gobind -lang=java java // @@ -39,12 +111,15 @@ void init_proxies() { jclass proxy_class_java_F; jmethodID proxy_class_java_F_cons; +static jmethodID mid_F_ToString; jclass proxy_class_java_O; jmethodID proxy_class_java_O_cons; +static jmethodID mid_O_ToString; jclass proxy_class_java_R; jmethodID proxy_class_java_R_cons; jclass proxy_class_java_S; jmethodID proxy_class_java_S_cons; +static jmethodID mid_S_ToString; JNIEXPORT void JNICALL Java_java_Java__1init(JNIEnv *env, jclass _unused) { @@ -53,11 +128,13 @@ Java_java_Java__1init(JNIEnv *env, jclass _unused) { proxy_class_java_F = (*env)->NewGlobalRef(env, clazz); proxy_class_java_F_cons = (*env)->GetMethodID(env, clazz, "", "(Lgo/Seq$Ref;)V"); clazz = (*env)->FindClass(env, "java/F"); + mid_F_ToString = (*env)->GetMethodID(env, clazz, "toString", "()Ljava/lang/String;"); clazz = (*env)->FindClass(env, "java/Java$proxyO"); proxy_class_java_O = (*env)->NewGlobalRef(env, clazz); proxy_class_java_O_cons = (*env)->GetMethodID(env, clazz, "", "(Lgo/Seq$Ref;)V"); clazz = (*env)->FindClass(env, "java/O"); + mid_O_ToString = (*env)->GetMethodID(env, clazz, "toString", "()Ljava/lang/String;"); clazz = (*env)->FindClass(env, "java/Java$proxyR"); proxy_class_java_R = (*env)->NewGlobalRef(env, clazz); @@ -68,6 +145,58 @@ Java_java_Java__1init(JNIEnv *env, jclass _unused) { proxy_class_java_S = (*env)->NewGlobalRef(env, clazz); proxy_class_java_S_cons = (*env)->GetMethodID(env, clazz, "", "(Lgo/Seq$Ref;)V"); clazz = (*env)->FindClass(env, "java/S"); + mid_S_ToString = (*env)->GetMethodID(env, clazz, "toString", "()Ljava/lang/String;"); } +JNIEXPORT jstring JNICALL +Java_java_Java_00024proxyF_toString(JNIEnv* env, jobject __this__) { + int32_t o = go_seq_to_refnum_go(env, __this__); + nstring r0 = proxyjava_F_ToString(o); + jstring _r0 = go_seq_to_java_string(env, r0); + return _r0; +} + +nstring cproxyjava_F_ToString(int32_t refnum) { + JNIEnv *env = go_seq_push_local_frame(0); + jobject o = go_seq_from_refnum(env, refnum, proxy_class_java_F, proxy_class_java_F_cons); + jstring res = (*env)->CallObjectMethod(env, o, mid_F_ToString); + nstring _res = go_seq_from_java_string(env, res); + go_seq_pop_local_frame(env); + return _res; +} + +JNIEXPORT jstring JNICALL +Java_java_Java_00024proxyO_toString(JNIEnv* env, jobject __this__) { + int32_t o = go_seq_to_refnum_go(env, __this__); + nstring r0 = proxyjava_O_ToString(o); + jstring _r0 = go_seq_to_java_string(env, r0); + return _r0; +} + +nstring cproxyjava_O_ToString(int32_t refnum) { + JNIEnv *env = go_seq_push_local_frame(0); + jobject o = go_seq_from_refnum(env, refnum, proxy_class_java_O, proxy_class_java_O_cons); + jstring res = (*env)->CallObjectMethod(env, o, mid_O_ToString); + nstring _res = go_seq_from_java_string(env, res); + go_seq_pop_local_frame(env); + return _res; +} + +JNIEXPORT jstring JNICALL +Java_java_Java_00024proxyS_toString(JNIEnv* env, jobject __this__) { + int32_t o = go_seq_to_refnum_go(env, __this__); + nstring r0 = proxyjava_S_ToString(o); + jstring _r0 = go_seq_to_java_string(env, r0); + return _r0; +} + +nstring cproxyjava_S_ToString(int32_t refnum) { + JNIEnv *env = go_seq_push_local_frame(0); + jobject o = go_seq_from_refnum(env, refnum, proxy_class_java_S, proxy_class_java_S_cons); + jstring res = (*env)->CallObjectMethod(env, o, mid_S_ToString); + nstring _res = go_seq_from_java_string(env, res); + go_seq_pop_local_frame(env); + return _res; +} + diff --git a/bind/testdata/java.java.golden b/bind/testdata/java.java.golden index f2472fc..dd5fd21 100644 --- a/bind/testdata/java.java.golden +++ b/bind/testdata/java.java.golden @@ -6,7 +6,8 @@ package java; import go.Seq; -public interface F { +public interface F extends R { + public String toString(); } @@ -18,7 +19,8 @@ package java; import go.Seq; -public interface O { +public interface O extends R { + public String toString(); } @@ -42,7 +44,8 @@ package java; import go.Seq; -public interface S { +public interface S extends R { + public String toString(); } @@ -78,6 +81,7 @@ public abstract class Java { proxyF(Seq.Ref ref) { this.ref = ref; } + public native String toString(); } private static final class proxyO implements Seq.Proxy, O { private final Seq.Ref ref; @@ -90,6 +94,7 @@ public abstract class Java { proxyO(Seq.Ref ref) { this.ref = ref; } + public native String toString(); } private static final class proxyR implements Seq.Proxy, R { private final Seq.Ref ref; @@ -114,6 +119,7 @@ public abstract class Java { proxyS(Seq.Ref ref) { this.ref = ref; } + public native String toString(); } diff --git a/bind/testdata/java.java.h.golden b/bind/testdata/java.java.h.golden index a95fe25..0cc218e 100644 --- a/bind/testdata/java.java.h.golden +++ b/bind/testdata/java.java.h.golden @@ -46,6 +46,10 @@ typedef struct ret_nbyteslice { jint exc; } ret_nbyteslice; +extern ret_nstring cproxy_java_lang_Float_toString(jint this); +extern ret_nstring cproxy_java_lang_Object_toString(jint this); +extern ret_nstring cproxy_java_lang_Character_toString(jint this); +extern ret_nstring cproxy_java_lang_Character_Subset_toString(jint this); // JNI function headers for the Go <=> Java bridge. // gobind -lang=java java // @@ -59,13 +63,19 @@ typedef struct ret_nbyteslice { extern jclass proxy_class_java_F; extern jmethodID proxy_class_java_F_cons; +nstring cproxyjava_F_ToString(int32_t refnum); + extern jclass proxy_class_java_O; extern jmethodID proxy_class_java_O_cons; +nstring cproxyjava_O_ToString(int32_t refnum); + extern jclass proxy_class_java_R; extern jmethodID proxy_class_java_R_cons; extern jclass proxy_class_java_S; extern jmethodID proxy_class_java_S_cons; +nstring cproxyjava_S_ToString(int32_t refnum); + #endif diff --git a/internal/importers/java/java.go b/internal/importers/java/java.go index dfba7be..8a4cdef 100644 --- a/internal/importers/java/java.go +++ b/internal/importers/java/java.go @@ -206,6 +206,9 @@ func (j *Importer) Import(refs *importers.References) ([]*Class, error) { } } } + // Make sure toString() is included; it is called when wrapping Java exception types to Go + // errors. + refs.Names["ToString"] = struct{}{} funcRefs := make(map[funcRef]struct{}) for _, ref := range refs.Refs { pkgName := strings.Replace(ref.Pkg, "/", ".", -1) diff --git a/internal/importers/java/java_test.go b/internal/importers/java/java_test.go index 7d25d21..ab0f50f 100644 --- a/internal/importers/java/java_test.go +++ b/internal/importers/java/java_test.go @@ -47,6 +47,14 @@ func TestImport(t *testing.T) { }, }, } + toString := &FuncSet{ + Name: "toString", + GoName: "ToString", + CommonSig: CommonSig{ + Ret: &Type{Kind: String}, HasRet: true, + }, + Funcs: []*Func{&Func{FuncSig: FuncSig{Name: "toString", Desc: "()Ljava/lang/String;"}, ArgDesc: "", JNIName: "toString", Public: true, Ret: &Type{Kind: String}}}, + } for _, test := range tests { refs := &importers.References{ Refs: []importers.PkgRef{test.ref}, @@ -66,8 +74,12 @@ func TestImport(t *testing.T) { if cls.Name != test.name { t.Errorf("got class name %s, expected %s", cls.Name, test.name) } + methods := test.methods + if !cls.Interface { + methods = append(methods, toString) + } loop: - for _, exp := range test.methods { + for _, exp := range methods { for _, got := range cls.AllMethods { if reflect.DeepEqual(exp, got) { continue loop