X-Git-Url: http://nitlanguage.org?ds=sidebyside diff --git a/src/common_ffi/java.nit b/src/common_ffi/java.nit index a03f67d..f6e44f7 100644 --- a/src/common_ffi/java.nit +++ b/src/common_ffi/java.nit @@ -66,7 +66,7 @@ class JavaLanguage // retrieve the implementation Java class java_class = Sys_load_jclass(sys, "{{{mmodule.impl_java_class_name}}}"); if (java_class == NULL) { - fprintf(stderr, "Nit FFI with Java error: failed to load class.\\n"); + PRINT_ERROR("Nit FFI with Java error: failed to load class.\\n"); (*nit_ffi_jni_env)->ExceptionDescribe(nit_ffi_jni_env); exit(1); } @@ -82,7 +82,7 @@ class JavaLanguage // retreive the implementation static function java_meth_id = (*nit_ffi_jni_env)->GetStaticMethodID(nit_ffi_jni_env, java_class, "{{{java_fun_name}}}", "{{{jni_format}}}"); if (java_meth_id == NULL) { - fprintf(stderr, "Nit FFI with Java error: Java implementation not found.\\n"); + PRINT_ERROR("Nit FFI with Java error: Java implementation not found.\\n"); (*nit_ffi_jni_env)->ExceptionDescribe(nit_ffi_jni_env); exit(1); } @@ -131,7 +131,7 @@ class JavaLanguage // execute implementation code {{{ccall}}} if ((*nit_ffi_jni_env)->ExceptionCheck(nit_ffi_jni_env)) { - fprintf(stderr, "Nit FFI with Java error: Exception after call.\\n"); + PRINT_ERROR("Nit FFI with Java error: Exception after call.\\n"); (*nit_ffi_jni_env)->ExceptionDescribe(nit_ffi_jni_env); exit(1); } @@ -225,7 +225,7 @@ redef class MModule }; jint res = (*env)->RegisterNatives(env, jclazz, methods, n_methods); if (res != JNI_OK) { - fprintf(stderr, "RegisterNatives failed\\n"); + PRINT_ERROR("RegisterNatives failed\\n"); (*env)->ExceptionDescribe(env); exit(1); } @@ -290,8 +290,10 @@ redef class AExternPropdef var sys_class = modelbuilder.try_get_mclass_by_name(self, mmodule, "Sys") assert sys_class != null var sys_jni_env_meth = modelbuilder.try_get_mproperty_by_name2(self, mmodule, sys_class.mclass_type, "jni_env") - assert sys_jni_env_meth != null - assert sys_jni_env_meth isa MMethod + if sys_jni_env_meth == null or not sys_jni_env_meth isa MMethod then + toolcontext.error(self.location, "Java FFI error: you must import the `java` module when using the FFI with Java") + return + end explicit_call = new MExplicitCall(sys_class.mclass_type, sys_jni_env_meth, mmodule) fcc.callbacks.add(explicit_call) @@ -349,7 +351,7 @@ class JavaFile super ExternFile redef fun makefile_rule_name do return "{filename.basename(".java")}.class" - redef fun makefile_rule_content do return "javac {filename} -d ." + redef fun makefile_rule_content do return "javac {filename.basename("")} -d ." redef fun add_to_jar do return true end @@ -463,7 +465,7 @@ redef class MClassType do var ftype = mclass.ftype if ftype isa ForeignJavaType then return ftype.java_type. - replace('/', ".").replace('$', ".").replace(' ', "") + replace('/', ".").replace('$', ".").replace(' ', "").replace('\n',"") if mclass.name == "Bool" then return "boolean" if mclass.name == "Char" then return "char" if mclass.name == "Int" then return "int" @@ -485,7 +487,7 @@ redef class MClassType redef fun jni_format do var ftype = mclass.ftype - if ftype isa ForeignJavaType then return "L{ftype.java_type.replace('.', "/").replace(' ', "")};" + if ftype isa ForeignJavaType then return "L{ftype.java_type.replace('.', "/").replace(' ', "").replace('\n', "")};" if mclass.name == "Bool" then return "Z" if mclass.name == "Char" then return "C" if mclass.name == "Int" then return "I"