module bundle
import serialization
-import json::serialization
+import json
import platform
import activities
`}
# FIXME: Java's `char` are encoded on 16-bits whereas Nit's are on 8-bits.
fun put_char(key: JavaString, value: Char) in "Java" `{
- self.putChar(key, value);
+ self.putChar(key, (char)value);
`}
fun put_short(key: JavaString, value: Int) in "Java" `{
self.putShort(key, (short) value);
char[] java_array = new char[(int)Array_of_Char_length(value)];
for(int i=0; i < java_array.length; ++i)
- java_array[i] = Array_of_Char__index(value, i);
+ java_array[i] = (char)Array_of_Char__index(value, i);
self.putCharArray(key, java_array);
`}
return self.getByte(key, (byte) def_value);
`}
# FIXME: Java's `char` are encoded on 16-bits whereas Nit's are on 8-bits.
- fun get_char(key: JavaString): Char in "Java" `{ return self.getChar(key); `}
+ fun get_char(key: JavaString): Char in "Java" `{ return (int)self.getChar(key); `}
# FIXME: Java's `char` are encoded on 16-bits whereas Nit's are on 8-bits.
fun get_char_with_def_value(key: JavaString, def_value: Char): Char in "Java" `{
- return self.getChar(key, def_value);
+ return (int)self.getChar(key, (char)def_value);
`}
fun get_short(key: JavaString): Int in "Java" `{ return (short) self.getShort(key); `}
fun get_short_with_def_value(key: JavaString, def_value: Int): Int in "Java" `{
if (java_array == null) return nit_array;
for(int i=0; i < java_array.length; ++i)
- Array_of_Char_add(nit_array, java_array[i]);
+ Array_of_Char_add(nit_array, (int)java_array[i]);
return nit_array;
`}
# A class mapping `String` keys to various value types
class Bundle
- private var native_bundle: NativeBundle = new NativeBundle is lazy
+ private var native_bundle: NativeBundle = (new NativeBundle).new_global_ref is lazy
# Get a new `Bundle` wrapping `native_bundle`
init from(native_bundle: NativeBundle) do self.native_bundle = native_bundle
# Retrieve an `Object` serialized via `[]=` function
# Returns `null` if there's no serialized object corresponding to the given key
# or if it's the wrong value type
- # Make sure that the serialized object is `auto_serializable` or that it
+ # Make sure that the serialized object is `serialize` or that it
# redefines the appropriate methods. Refer to `Serializable` documentation
# for further details
fun deserialize(key: String): nullable Object
# Retrieve an `Array` of `Object` serialized via `[]=` function
# Returns `null` if there's no serialized `Array` corresponding to the given key
# or if it's the wrong value type
- # Make sure that the serialized objects are `auto_serializable` or that they
+ # Make sure that the serialized objects are `serialize` or that they
# redefine the appropriate methods. Refer to `Serializable` documentation
# for further details
fun deserialize_array(key: String): nullable Array[nullable Object]
# Returns `null` if none or if it's the wrong value type
fun string(key: String): nullable String
do
- sys.jni_env.push_local_frame(1)
- var return_value = native_bundle.get_string(key.to_java_string).to_s
- sys.jni_env.pop_local_frame
+ sys.jni_env.push_local_frame(2)
- if return_value == "" then return null
+ var jstr = native_bundle.get_string(key.to_java_string)
+ var str = null
+ if not jstr.is_java_null then str = jstr.to_s
- return return_value
+ sys.jni_env.pop_local_frame
+
+ return str
end
# Retrieves the `Bool` value corresponding to the given key