forked from GitHub/gf-core
fixes in the Java binding
This commit is contained in:
@@ -62,13 +62,13 @@ throw_jstring_exception(JNIEnv *env, const char* class_name, jstring msg)
|
|||||||
{
|
{
|
||||||
jclass exception_class = (*env)->FindClass(env, class_name);
|
jclass exception_class = (*env)->FindClass(env, class_name);
|
||||||
if (!exception_class)
|
if (!exception_class)
|
||||||
return NULL;
|
return;
|
||||||
jmethodID constrId = (*env)->GetMethodID(env, exception_class, "<init>", "(Ljava/lang/String;)V");
|
jmethodID constrId = (*env)->GetMethodID(env, exception_class, "<init>", "(Ljava/lang/String;)V");
|
||||||
if (!constrId)
|
if (!constrId)
|
||||||
return NULL;
|
return;
|
||||||
jobject exception = (*env)->NewObject(env, exception_class, constrId, msg);
|
jobject exception = (*env)->NewObject(env, exception_class, constrId, msg);
|
||||||
if (!exception)
|
if (!exception)
|
||||||
return NULL;
|
return;
|
||||||
(*env)->Throw(env, exception);
|
(*env)->Throw(env, exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ throw_string_exception(JNIEnv *env, const char* class_name, const char* msg)
|
|||||||
{
|
{
|
||||||
jstring jmsg = (*env)->NewStringUTF(env, msg);
|
jstring jmsg = (*env)->NewStringUTF(env, msg);
|
||||||
if (!jmsg)
|
if (!jmsg)
|
||||||
return NULL;
|
return;
|
||||||
throw_jstring_exception(env, class_name, jmsg);
|
throw_jstring_exception(env, class_name, jmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ Java_org_grammaticalframework_pgf_PGF_readPGF(JNIEnv *env, jclass cls, jstring s
|
|||||||
if (gu_exn_caught(err) == gu_type(GuErrno)) {
|
if (gu_exn_caught(err) == gu_type(GuErrno)) {
|
||||||
throw_jstring_exception(env, "java/io/FileNotFoundException", s);
|
throw_jstring_exception(env, "java/io/FileNotFoundException", s);
|
||||||
} else {
|
} else {
|
||||||
throw_string_exception(env, "org/grammaticalframework/PGFError", "The grammar cannot be loaded");
|
throw_string_exception(env, "org/grammaticalframework/pgf/PGFError", "The grammar cannot be loaded");
|
||||||
}
|
}
|
||||||
gu_pool_free(pool);
|
gu_pool_free(pool);
|
||||||
gu_pool_free(tmp_pool);
|
gu_pool_free(tmp_pool);
|
||||||
@@ -220,9 +220,9 @@ Java_org_grammaticalframework_pgf_Parser_parse
|
|||||||
pgf_lexer_current_token(lexer);
|
pgf_lexer_current_token(lexer);
|
||||||
|
|
||||||
if (gu_string_eq(tok, gu_empty_string))
|
if (gu_string_eq(tok, gu_empty_string))
|
||||||
throw_string_exception(env, "org/grammaticalframework/PGFError", "The sentence cannot be parsed");
|
throw_string_exception(env, "org/grammaticalframework/pgf/PGFError", "The sentence cannot be parsed");
|
||||||
else
|
else
|
||||||
throw_jstring_exception(env, "org/grammaticalframework/ParseError", gu2j_string(env, tok));
|
throw_jstring_exception(env, "org/grammaticalframework/pgf/ParseError", gu2j_string(env, tok));
|
||||||
|
|
||||||
gu_pool_free(pool);
|
gu_pool_free(pool);
|
||||||
gu_pool_free(out_pool);
|
gu_pool_free(out_pool);
|
||||||
@@ -290,7 +290,7 @@ Java_org_grammaticalframework_pgf_Expr_showExpr(JNIEnv* env, jclass clazz, jlong
|
|||||||
GuStringBuf* sbuf = gu_string_buf(tmp_pool);
|
GuStringBuf* sbuf = gu_string_buf(tmp_pool);
|
||||||
GuWriter* wtr = gu_string_buf_writer(sbuf);
|
GuWriter* wtr = gu_string_buf_writer(sbuf);
|
||||||
|
|
||||||
pgf_print_expr(gu_variant_from_ptr(ref), NULL, 0, wtr, err);
|
pgf_print_expr(gu_variant_from_ptr((void*)ref), NULL, 0, wtr, err);
|
||||||
|
|
||||||
GuString str = gu_string_buf_freeze(sbuf, tmp_pool);
|
GuString str = gu_string_buf_freeze(sbuf, tmp_pool);
|
||||||
jstring jstr = gu2j_string(env, str);
|
jstring jstr = gu2j_string(env, str);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import java.io.*;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class PGF {
|
public class PGF {
|
||||||
public static native PGF readPGF(String path) throws FileNotFoundException;
|
public static native PGF readPGF(String path) throws FileNotFoundException;
|
||||||
|
|
||||||
public native String getAbstractName();
|
public native String getAbstractName();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user