-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjnipp.h
67 lines (52 loc) · 1.64 KB
/
jnipp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#pragma once
#include "arrays.h"
#include "errors.h"
#include "field_access.h"
#include "jni_types.h"
#include "method_calls.h"
#include "unwrappers.h"
#include "wrappers.h"
#include "class_cast_impl.h"
#include "class_to_string.h"
#include "field_access_impl.h"
#include "method_call_impl.h"
#include <algorithm>
#include <peripherals/stl/any_of.h>
#include <stdexcept>
#include <vector>
namespace jnipp::literals {
FORCEDINLINE jnipp::wrapping::jclass operator"" _jclass(
const char* name, size_t)
{
return jnipp::get_class({name});
}
FORCEDINLINE jnipp::wrapping::jmethod<jnipp::return_type::void_>
operator"" _jmethod(const char* name, size_t)
{
return {jnipp::java::method{name}};
}
FORCEDINLINE jnipp::wrapping::jfield<jnipp::return_type::void_>
operator"" _jfield(const char* name, size_t)
{
return {jnipp::java::field{name}};
}
} // namespace jnipp::literals
inline void jnipp::invocation::call::check_exception()
{
if(GetJNI()->ExceptionCheck() == JNI_TRUE)
{
exception_clear_scope _;
auto exception = java::object({}, GetJNI()->ExceptionOccurred());
GetJNI()->ExceptionClear();
auto exceptionType =
get_class_name(java::object(java::clazz{}, exception));
auto Throwable = get_class(java::clazz{"java.lang.Throwable"});
auto getMessage =
wrapping::jmethod<return_type::void_>(java::method("getMessage"))
.ret("java.lang.String");
auto message = java::type_unwrapper<std::string>(
Throwable(exception)[getMessage]());
throw java_exception(
exceptionType + ": " + static_cast<std::string>(message));
}
}