lib/java: fix typo
[nit.git] / lib / java / java.nit
index e724a6a..6358430 100644 (file)
@@ -27,8 +27,8 @@
 # most of JNI functions. You can use it to further customize the behavior
 # of your code.
 module java is
-       c_compiler_option("-I $(JAVA_HOME)/include/")
-       c_linker_option("-L $(JNI_LIB_PATH) -ljvm")
+       cflags "-I $(JAVA_HOME)/include/ -I $(JAVA_HOME)/include/linux/"
+       ldflags "-L $(JNI_LIB_PATH) -ljvm"
        new_annotation extra_java_files
 end
 
@@ -98,8 +98,6 @@ end
 extern class JavaString in "Java" `{ java.lang.String `}
        super JavaObject
 
-       redef type SELF: JavaString
-
        # Get the string from Java and copy it to Nit memory
        fun to_cstring: NativeString import sys, Sys.jni_env `{
                Sys sys = JavaString_sys(recv);
@@ -140,7 +138,6 @@ redef class Text
 end
 
 redef extern class JavaObject
-       type SELF: JavaObject
 
        # Returns a global reference to the Java object behind this reference
        #
@@ -168,7 +165,7 @@ redef extern class JavaObject
 
        # Pops the current local reference frame and return a valid reference to self
        #
-       # Similiar to `JavaVM::pop_local_frame` but returns a value.
+       # Similar to `JavaVM::pop_local_frame` but returns a value.
        fun pop_from_local_frame: SELF
        do
                var jni_env = sys.jni_env
@@ -190,4 +187,14 @@ redef extern class JavaObject
        # is not a Java null. In case it is, you should replace it by a normal Nit
        # `null`.
        fun is_java_null: Bool in "Java" `{ return recv == null; `}
+
+       # `JavaString` representation of `self` using Java's `toString`
+       fun to_java_string: JavaString in "Java" `{ return recv.toString(); `}
+
+       # Use Java's `toString` for any `JavaObject`
+       redef fun to_s
+       do
+               if is_java_null then return super
+               return to_java_string.to_s
+       end
 end