diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d2c0b759..f1664dff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: test - run: bazel query --output=label 'kind("...", //...) except attr("tags", "cpp20", "//...")' | xargs bazel test --cxxopt='-Werror' --cxxopt='-std=c++17' --repo_env=CC=clang --test_output=errors + run: bazel test --cxxopt='-Werror' --cxxopt='-std=c++17' --repo_env=CC=clang --test_output=errors //implementation/legacy/... ubuntu-latest-cpp20: runs-on: ubuntu-latest @@ -29,7 +29,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: test - run: bazel query --output=label 'kind("...", //...) except attr(tags, "cpp20", //...)' | xargs bazel test --cxxopt='-Werror' --cxxopt='-std=c++17' --repo_env=CC=clang --test_output=errors + run: bazel test --cxxopt='-Werror' --cxxopt='-std=c++17' --repo_env=CC=clang --test_output=errors //implementation/legacy/... macos-latest-cpp20: runs-on: macos-latest diff --git a/BUILD b/BUILD index 7949e520..f3d79daf 100644 --- a/BUILD +++ b/BUILD @@ -82,6 +82,7 @@ cc_library( "//implementation/jni_helper:static_field_value", "//metaprogramming:corpus", "//metaprogramming:corpus_tag", + "//metaprogramming:string_literal", ], ) diff --git a/implementation/BUILD b/implementation/BUILD index 32f82380..079548f3 100644 --- a/implementation/BUILD +++ b/implementation/BUILD @@ -186,14 +186,17 @@ cc_library( hdrs = ["class_loader_ref.h"], deps = [ ":class_loader", + ":class_ref", ":default_class_loader", ":global_object", ":id", ":id_type", ":jni_type", + ":jvm", ":local_object", ":no_idx", ":promotion_mechanics", + ":promotion_mechanics_tags", "//:jni_dep", "//class_defs:java_lang_classes", "//implementation/jni_helper:jni_env", diff --git a/implementation/array_view_test.cc b/implementation/array_view_test.cc index 66496d2f..2403b8fc 100644 --- a/implementation/array_view_test.cc +++ b/implementation/array_view_test.cc @@ -318,7 +318,7 @@ TEST_F(JniTest, ArrayView_RichObjectsAreIterable) { int fake_result = 123; for (LocalObject obj : obj_view) { EXPECT_CALL(*env_, CallIntMethodV).WillOnce(::testing::Return(fake_result)); - EXPECT_EQ(obj("Foo"), fake_result); + EXPECT_EQ(obj.Call<"Foo">(), fake_result); fake_result++; } } diff --git a/implementation/class_loader_ref.h b/implementation/class_loader_ref.h index 7bc295bd..3a2ce23d 100644 --- a/implementation/class_loader_ref.h +++ b/implementation/class_loader_ref.h @@ -21,6 +21,7 @@ #include "class_defs/java_lang_classes.h" #include "implementation/class_loader.h" +#include "implementation/class_ref.h" #include "implementation/default_class_loader.h" #include "implementation/global_object.h" #include "implementation/id.h" @@ -29,9 +30,11 @@ #include "implementation/jni_helper/lifecycle.h" #include "implementation/jni_helper/lifecycle_object.h" #include "implementation/jni_type.h" +#include "implementation/jvm.h" #include "implementation/local_object.h" #include "implementation/no_idx.h" #include "implementation/promotion_mechanics.h" +#include "implementation/promotion_mechanics_tags.h" #include "jni_dep.h" namespace jni { @@ -73,10 +76,19 @@ class ClassLoaderRef : public ClassLoaderImpl { kDefaultClassLoader) { ClassRef_t>::PrimeJClassFromClassLoader([&]() { - // Prevent the object (which is a runtime instance of a class) from - // falling out of scope so it is not released. + // Prevent the object (which is a runtime instance of a class) from + // falling out of scope so it is not released. + +#if __cplusplus >= 202002L + LocalObject loaded_class = + (*this).template Call<"loadClass">(IdClassT::kNameUsingDots); +#elif __clang__ LocalObject loaded_class = (*this)("loadClass", IdClassT::kNameUsingDots); +#else + static_assert( + false, "JNI Bind requires C++20 (or later) or C++17 with clang."); +#endif // We only want to create global references if we are actually going // to use them so that they do not leak. diff --git a/implementation/class_loader_ref_second_test.cc b/implementation/class_loader_ref_second_test.cc index 50424733..de27b6dc 100644 --- a/implementation/class_loader_ref_second_test.cc +++ b/implementation/class_loader_ref_second_test.cc @@ -91,7 +91,7 @@ TEST_F(JniTestWithNoDefaultJvmRef, auto second_custom_loader_object = class_loader.BuildLocalObject(jint{2}); - EXPECT_EQ(custom_loader_object("methodNoCrossTalk", jint{2}), 123); + EXPECT_EQ(custom_loader_object.Call<"methodNoCrossTalk">(jint{2}), 123); TearDown(); } diff --git a/implementation/class_loader_ref_test.cc b/implementation/class_loader_ref_test.cc index 66388550..c743b2fb 100644 --- a/implementation/class_loader_ref_test.cc +++ b/implementation/class_loader_ref_test.cc @@ -118,7 +118,7 @@ TEST_F(JniTest, LocalObject_SupportsPassingAnObjectWithAClassLoader) { // LocalObject a{}; // doesn't compile (good). LocalObject a{Fake()}; LocalObject b{}; - b("Foo", a); + b.Call<"Foo">(a); default_globals_made_that_should_be_released_.clear(); } @@ -130,7 +130,7 @@ TEST_F(JniTestForClassLoaders, LocalClassLoader local_class_loader{Fake()}; auto a = local_class_loader.BuildLocalObject(); LocalObject b{a}; - b("Foo", a); + b.Call<"Foo">(a); default_globals_made_that_should_be_released_.clear(); TearDown(); @@ -143,7 +143,7 @@ TEST_F(JniTestForClassLoaders, LocalClassLoader local_class_loader{Fake()}; auto a = local_class_loader.BuildGlobalObject(); LocalObject b{a}; - b("Foo", a); + b.Call<"Foo">(a); default_globals_made_that_should_be_released_.clear(); TearDown(); @@ -160,7 +160,7 @@ TEST_F(JniTestForClassLoaders, LocalObject a = local_class_loader.BuildLocalObject(); LocalObject b{a}; - b("Foo", a); + b.Call<"Foo">(a); TearDown(); } @@ -172,7 +172,7 @@ TEST_F(JniTestForClassLoaders, ClassLoaderRefTest_ConstructsFromRValue) { LocalObject b{ local_class_loader.BuildLocalObject()}; - LocalObject c{b("Foo")}; + LocalObject c{b.Call<"Foo">()}; TearDown(); } @@ -186,7 +186,7 @@ TEST_F(JniTestForClassLoaders, LocalObject a{}; LocalObject b = local_class_loader.BuildLocalObject(a); - b("Foo", a); + b.Call<"Foo">(a); TearDown(); } @@ -235,7 +235,7 @@ TEST_F(JniTestWithNoDefaultJvmRef, LocalObject a = local_class_loader.BuildLocalObject(); LocalObject b{}; - b("Foo", a); + b.Call<"Foo">(a); TearDown(); } @@ -309,7 +309,7 @@ TEST_F(JniTestWithNoDefaultJvmRef, kDefaultConfiguration}; jni::LocalObject obj1{AdoptLocal{}, Fake(1)}; - obj1("Foo"); + obj1.Call<"Foo">(); this->TearDown(); } diff --git a/implementation/field_ref_test.cc b/implementation/field_ref_test.cc index 1aa5244a..2ae6be6f 100644 --- a/implementation/field_ref_test.cc +++ b/implementation/field_ref_test.cc @@ -59,8 +59,8 @@ TEST_F(JniTest, Field_SimpleGetAndSet) { Field("SomeField", jint{})}; GlobalObject obj{}; - EXPECT_EQ(999, obj["SomeField"].Get()); - obj["SomeField"].Set(123); + EXPECT_EQ(999, obj.Access<"SomeField">().Get()); + obj.Access<"SomeField">().Set(123); } TEST_F(JniTest, Field_BooleanField) { @@ -68,8 +68,8 @@ TEST_F(JniTest, Field_BooleanField) { EXPECT_CALL(*env_, SetBooleanField); LocalObject obj{}; - obj["booleanField"].Get(); - obj["booleanField"].Set(true); + obj.Access<"booleanField">().Get(); + obj.Access<"booleanField">().Set(true); } TEST_F(JniTest, Field_ByteField) { @@ -77,8 +77,8 @@ TEST_F(JniTest, Field_ByteField) { EXPECT_CALL(*env_, SetByteField); LocalObject obj{}; - obj["byteField"].Get(); - obj["byteField"].Set(jbyte{123}); + obj.Access<"byteField">().Get(); + obj.Access<"byteField">().Set(jbyte{123}); } TEST_F(JniTest, Field_CharField) { @@ -86,8 +86,8 @@ TEST_F(JniTest, Field_CharField) { EXPECT_CALL(*env_, SetCharField); LocalObject obj{}; - obj["charField"].Get(); - obj["charField"].Set(jchar{'a'}); + obj.Access<"charField">().Get(); + obj.Access<"charField">().Set(jchar{'a'}); } TEST_F(JniTest, Field_ShortField) { @@ -95,8 +95,8 @@ TEST_F(JniTest, Field_ShortField) { EXPECT_CALL(*env_, SetShortField); LocalObject obj{}; - obj["shortField"].Get(); - obj["shortField"].Set(jshort{123}); + obj.Access<"shortField">().Get(); + obj.Access<"shortField">().Set(jshort{123}); } TEST_F(JniTest, Field_intField) { @@ -104,8 +104,8 @@ TEST_F(JniTest, Field_intField) { EXPECT_CALL(*env_, SetIntField); LocalObject obj{}; - obj["intField"].Get(); - obj["intField"].Set(123); + obj.Access<"intField">().Get(); + obj.Access<"intField">().Set(123); } TEST_F(JniTest, Field_longField) { @@ -113,24 +113,24 @@ TEST_F(JniTest, Field_longField) { EXPECT_CALL(*env_, SetLongField); LocalObject obj{}; - obj["longField"].Get(); - obj["longField"].Set(123); + obj.Access<"longField">().Get(); + obj.Access<"longField">().Set(123); } TEST_F(JniTest, Field_floatField) { LocalObject obj{}; EXPECT_CALL(*env_, GetFloatField); EXPECT_CALL(*env_, SetFloatField); - obj["floatField"].Get(); - obj["floatField"].Set(123.f); + obj.Access<"floatField">().Get(); + obj.Access<"floatField">().Set(123.f); } TEST_F(JniTest, Field_doubleField) { LocalObject obj{}; EXPECT_CALL(*env_, GetDoubleField); EXPECT_CALL(*env_, SetDoubleField); - obj["doubleField"].Get(); - obj["doubleField"].Set(123.); + obj.Access<"doubleField">().Get(); + obj.Access<"doubleField">().Set(123.); } TEST_F(JniTest, Field_ObjectGet) { @@ -144,7 +144,7 @@ TEST_F(JniTest, Field_ObjectGet) { static constexpr Class kClass2{"kClass2"}; LocalObject obj{}; - LocalObject obj2 = obj["classField"].Get(); + LocalObject obj2 = obj.Access<"classField">().Get(); } TEST_F(JniTest, Field_ObjectSet) { @@ -161,10 +161,11 @@ TEST_F(JniTest, Field_ObjectSet) { LocalObject obj{}; LocalObject some_obj{AdoptLocal{}, Fake()}; - obj["classField"].Set(Fake()); - obj["classField"].Set(LocalObject{AdoptLocal{}, Fake()}); - obj["classField"].Set(some_obj); - obj["classField"].Set(std::move(some_obj)); + obj.Access<"classField">().Set(Fake()); + obj.Access<"classField">().Set( + LocalObject{AdoptLocal{}, Fake()}); + obj.Access<"classField">().Set(some_obj); + obj.Access<"classField">().Set(std::move(some_obj)); } } // namespace diff --git a/implementation/find_class_fallback.h b/implementation/find_class_fallback.h index ca68bf24..6125a248 100644 --- a/implementation/find_class_fallback.h +++ b/implementation/find_class_fallback.h @@ -39,7 +39,15 @@ inline jclass FindClassFallback(const char* class_name) { GlobalClassLoader loader{AdoptGlobal{}, FallbackLoader()}; +#if __cplusplus >= 202002L + jni::LocalObject loaded_class = loader.Call<"loadClass">(class_name); +#elif __clang__ jni::LocalObject loaded_class = loader("loadClass", class_name); +#else + static_assert(false, + "JNI Bind requires C++20 (or later) or C++17 with clang."); +#endif + jclass ret{static_cast(static_cast(loaded_class.Release()))}; loader.Release(); diff --git a/implementation/global_object_test.cc b/implementation/global_object_test.cc index 3d5af1df..5ce2829f 100644 --- a/implementation/global_object_test.cc +++ b/implementation/global_object_test.cc @@ -200,15 +200,15 @@ TEST_F(JniTest, GlobalObject_ValuesWorkAfterMoveConstructor) { Method{"Foo", jni::Return{}, Params{}}, Field{"BarField", jint{}}}; GlobalObject global_object_1{AdoptGlobal{}, Fake(1)}; - global_object_1("Foo", 1); - global_object_1("Foo", 2); - global_object_1["BarField"].Set(1); + global_object_1.Call<"Foo">(1); + global_object_1.Call<"Foo">(2); + global_object_1.Access<"BarField">().Set(1); GlobalObject global_object_2{std::move(global_object_1)}; - global_object_2("Foo", 3); - global_object_2["BarField"].Set(2); - global_object_2["BarField"].Set(3); - global_object_2["BarField"].Set(4); + global_object_2.Call<"Foo">(3); + global_object_2.Access<"BarField">().Set(2); + global_object_2.Access<"BarField">().Set(3); + global_object_2.Access<"BarField">().Set(4); GlobalObject global_object_3{AdoptGlobal{}, Fake(1)}; } @@ -245,10 +245,10 @@ TEST_F(JniTest, GlobalObject_ObjectReturnsInstanceMethods) { Params{}}}; GlobalObject global_object{}; - global_object("Foo", 1); - global_object("Baz", 2.f); - global_object( - "AMethodWithAReallyLongNameThatWouldPossiblyBeHardForTemplatesToHandle", + global_object.Call<"Foo">(1); + global_object.Call<"Baz">(2.f); + global_object.Call< + "AMethodWithAReallyLongNameThatWouldPossiblyBeHardForTemplatesToHandle">( int{}, float{}, int{}, float{}, double{}); } @@ -268,7 +268,7 @@ TEST_F(JniTest, GlobalObject_SupportsPassingAPrvalue) { GlobalObject a{}; GlobalObject b{}; - b("Foo", std::move(a)); + b.Call<"Foo">(std::move(a)); } TEST_F(JniTest, GlobalObjects_PromoteRValuesFromEmittedLValues) { @@ -277,9 +277,9 @@ TEST_F(JniTest, GlobalObjects_PromoteRValuesFromEmittedLValues) { "TestClass2", Method{"Foo", jni::Return{kClass1}, jni::Params{}}}; LocalObject b{}; - GlobalObject a{b("Foo")}; + GlobalObject a{b.Call<"Foo">()}; - a = b("Foo"); + a = b.Call<"Foo">(); } } // namespace diff --git a/implementation/jvm_ref.h b/implementation/jvm_ref.h index a924983e..7e30cd4b 100644 --- a/implementation/jvm_ref.h +++ b/implementation/jvm_ref.h @@ -163,8 +163,17 @@ class JvmRef : public JvmRefBase { // Sets a "fallback" loader for use when default Jvm classes fail to load. // `host_object *must* be local and will *not* be released. void SetFallbackClassLoaderFromJObject(jobject host_object) { +#if __cplusplus >= 202002L + SetFallbackClassLoader(LocalObject{host_object} + .Call<"getClass">() + .Call<"getClassLoader">()); +#elif __clang__ SetFallbackClassLoader(LocalObject{host_object}( "getClass")("getClassLoader")); +#else + static_assert(false, + "JNI Bind requires C++20 (or later) or C++17 with clang."); +#endif } private: diff --git a/implementation/local_array_field_multidimensional_test.cc b/implementation/local_array_field_multidimensional_test.cc index b4a977ed..f9668afa 100644 --- a/implementation/local_array_field_multidimensional_test.cc +++ b/implementation/local_array_field_multidimensional_test.cc @@ -72,23 +72,23 @@ TEST_F(JniTest, LocalArrayField_Rank2) { LocalObject obj{AdoptLocal{}, Fake()}; - EXPECT_EQ(static_cast(obj["BooleanArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"BooleanArray">().Get()), Fake(1)); - EXPECT_EQ(static_cast(obj["ByteArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"ByteArray">().Get()), Fake(2)); - EXPECT_EQ(static_cast(obj["CharArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"CharArray">().Get()), Fake(3)); - EXPECT_EQ(static_cast(obj["ShortArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"ShortArray">().Get()), Fake(4)); - EXPECT_EQ(static_cast(obj["IntArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"IntArray">().Get()), Fake(5)); - EXPECT_EQ(static_cast(obj["FloatArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"FloatArray">().Get()), Fake(6)); - EXPECT_EQ(static_cast(obj["DoubleArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"DoubleArray">().Get()), Fake(7)); - EXPECT_EQ(static_cast(obj["LongArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"LongArray">().Get()), Fake(8)); - EXPECT_EQ(static_cast(obj["ObjectArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"ObjectArray">().Get()), Fake(9)); } @@ -129,23 +129,23 @@ TEST_F(JniTest, LocalArrayField_Rank3) { LocalObject obj{AdoptLocal{}, Fake()}; - EXPECT_EQ(static_cast(obj["BooleanArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"BooleanArray">().Get()), Fake(1)); - EXPECT_EQ(static_cast(obj["ByteArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"ByteArray">().Get()), Fake(2)); - EXPECT_EQ(static_cast(obj["CharArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"CharArray">().Get()), Fake(3)); - EXPECT_EQ(static_cast(obj["ShortArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"ShortArray">().Get()), Fake(4)); - EXPECT_EQ(static_cast(obj["IntArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"IntArray">().Get()), Fake(5)); - EXPECT_EQ(static_cast(obj["FloatArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"FloatArray">().Get()), Fake(6)); - EXPECT_EQ(static_cast(obj["DoubleArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"DoubleArray">().Get()), Fake(7)); - EXPECT_EQ(static_cast(obj["LongArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"LongArray">().Get()), Fake(8)); - EXPECT_EQ(static_cast(obj["ObjectArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"ObjectArray">().Get()), Fake(9)); } diff --git a/implementation/local_array_field_test.cc b/implementation/local_array_field_test.cc index e20f60a1..eecb24bb 100644 --- a/implementation/local_array_field_test.cc +++ b/implementation/local_array_field_test.cc @@ -69,7 +69,7 @@ TEST_F(JniTest, ArrayField_Object_Iteration_Rank_1) { int i = 100; LocalObject obj{Fake()}; - for (LocalObject a : obj["ObjectArrayRank1"].Get().Pin()) { + for (LocalObject a : obj.Access<"ObjectArrayRank1">().Get().Pin()) { EXPECT_EQ(static_cast(a), Fake(i)); i++; } @@ -87,7 +87,7 @@ TEST_F(JniTest, ArrayField_Object_Iteration_Rank_2) { int i = 100; LocalObject obj{Fake(1)}; for (LocalArray a : - obj["ObjectArrayRank2"].Get().Pin()) { + obj.Access<"ObjectArrayRank2">().Get().Pin()) { EXPECT_EQ(static_cast(a), Fake(i)); i++; } @@ -124,26 +124,27 @@ TEST_F(JniTest, Array_FieldTests) { LocalObject obj{AdoptLocal{}, Fake()}; - EXPECT_EQ(static_cast(obj["BooleanArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"BooleanArray">().Get()), Fake()); - EXPECT_EQ(static_cast(obj["ByteArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"ByteArray">().Get()), Fake()); - EXPECT_EQ(static_cast(obj["CharArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"CharArray">().Get()), Fake()); - EXPECT_EQ(static_cast(obj["ShortArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"ShortArray">().Get()), Fake()); - EXPECT_EQ(static_cast(obj["IntArray"].Get()), Fake()); - EXPECT_EQ(static_cast(obj["FloatArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"IntArray">().Get()), + Fake()); + EXPECT_EQ(static_cast(obj.Access<"FloatArray">().Get()), Fake()); - EXPECT_EQ(static_cast(obj["DoubleArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"DoubleArray">().Get()), Fake()); - EXPECT_EQ(static_cast(obj["LongArray"].Get()), + EXPECT_EQ(static_cast(obj.Access<"LongArray">().Get()), Fake()); - EXPECT_EQ(static_cast(obj["ObjectArrayRank1"].Get()), + EXPECT_EQ(static_cast(obj.Access<"ObjectArrayRank1">().Get()), Fake(1)); - EXPECT_EQ(static_cast(obj["ObjectArrayRank2"].Get()), + EXPECT_EQ(static_cast(obj.Access<"ObjectArrayRank2">().Get()), Fake(2)); - EXPECT_EQ(static_cast(obj["ObjectArrayRank3"].Get()), + EXPECT_EQ(static_cast(obj.Access<"ObjectArrayRank3">().Get()), Fake(3)); } @@ -166,16 +167,18 @@ TEST_F(JniTest, Array_Field_Boolean_Test) { fake_storage_ptr.get(), JNI_ABORT)); LocalObject obj{AdoptLocal{}, Fake()}; - LocalArray arr{obj["BooleanArray"].Get()}; + LocalArray arr{obj.Access<"BooleanArray">().Get()}; LocalArray arr2{AdoptLocal{}, Fake()}; - obj["BooleanArray"].Set(Fake()); - obj["BooleanArray"].Set( + obj.Access<"BooleanArray">().Set(Fake()); + obj.Access<"BooleanArray">().Set( LocalArray{AdoptLocal{}, Fake()}); - obj["BooleanArray"].Set(arr2); - obj["BooleanArray"].Set(obj["BooleanArray"].Get()); + obj.Access<"BooleanArray">().Set(arr2); + obj.Access<"BooleanArray">().Set(obj.Access<"BooleanArray">().Get()); - EXPECT_EQ(obj["BooleanArray"].Get().Pin().ptr(), fake_storage_ptr.get()); - EXPECT_EQ(obj["BooleanArray"].Get().Pin(false).ptr(), fake_storage_ptr.get()); + EXPECT_EQ(obj.Access<"BooleanArray">().Get().Pin().ptr(), + fake_storage_ptr.get()); + EXPECT_EQ(obj.Access<"BooleanArray">().Get().Pin(false).ptr(), + fake_storage_ptr.get()); } TEST_F(JniTest, Array_Field_Byte_Test) { @@ -197,14 +200,17 @@ TEST_F(JniTest, Array_Field_Byte_Test) { fake_storage_ptr.get(), JNI_ABORT)); LocalObject obj{AdoptLocal{}, Fake()}; - LocalArray arr{obj["ByteArray"].Get()}; + LocalArray arr{obj.Access<"ByteArray">().Get()}; LocalArray arr2{AdoptLocal{}, Fake()}; - obj["ByteArray"].Set(Fake()); - obj["ByteArray"].Set(LocalArray{AdoptLocal{}, Fake()}); - obj["ByteArray"].Set(arr2); - obj["ByteArray"].Set(obj["ByteArray"].Get()); - EXPECT_EQ(obj["ByteArray"].Get().Pin().ptr(), fake_storage_ptr.get()); - EXPECT_EQ(obj["ByteArray"].Get().Pin(false).ptr(), fake_storage_ptr.get()); + obj.Access<"ByteArray">().Set(Fake()); + obj.Access<"ByteArray">().Set( + LocalArray{AdoptLocal{}, Fake()}); + obj.Access<"ByteArray">().Set(arr2); + obj.Access<"ByteArray">().Set(obj.Access<"ByteArray">().Get()); + EXPECT_EQ(obj.Access<"ByteArray">().Get().Pin().ptr(), + fake_storage_ptr.get()); + EXPECT_EQ(obj.Access<"ByteArray">().Get().Pin(false).ptr(), + fake_storage_ptr.get()); } TEST_F(JniTest, Array_Field_Char_Test) { @@ -226,14 +232,17 @@ TEST_F(JniTest, Array_Field_Char_Test) { fake_storage_ptr.get(), JNI_ABORT)); LocalObject obj{AdoptLocal{}, Fake()}; - LocalArray arr{obj["CharArray"].Get()}; + LocalArray arr{obj.Access<"CharArray">().Get()}; LocalArray arr2{AdoptLocal{}, Fake()}; - obj["CharArray"].Set(Fake()); - obj["CharArray"].Set(LocalArray{AdoptLocal{}, Fake()}); - obj["CharArray"].Set(arr2); - obj["CharArray"].Set(obj["CharArray"].Get()); - EXPECT_EQ(obj["CharArray"].Get().Pin().ptr(), fake_storage_ptr.get()); - EXPECT_EQ(obj["CharArray"].Get().Pin(false).ptr(), fake_storage_ptr.get()); + obj.Access<"CharArray">().Set(Fake()); + obj.Access<"CharArray">().Set( + LocalArray{AdoptLocal{}, Fake()}); + obj.Access<"CharArray">().Set(arr2); + obj.Access<"CharArray">().Set(obj.Access<"CharArray">().Get()); + EXPECT_EQ(obj.Access<"CharArray">().Get().Pin().ptr(), + fake_storage_ptr.get()); + EXPECT_EQ(obj.Access<"CharArray">().Get().Pin(false).ptr(), + fake_storage_ptr.get()); } TEST_F(JniTest, Array_Field_Short_Test) { @@ -255,14 +264,17 @@ TEST_F(JniTest, Array_Field_Short_Test) { fake_storage_ptr.get(), JNI_ABORT)); LocalObject obj{AdoptLocal{}, Fake()}; - LocalArray arr{obj["ShortArray"].Get()}; + LocalArray arr{obj.Access<"ShortArray">().Get()}; LocalArray arr2{AdoptLocal{}, Fake()}; - obj["ShortArray"].Set(Fake()); - obj["ShortArray"].Set(LocalArray{AdoptLocal{}, Fake()}); - obj["ShortArray"].Set(arr2); - obj["ShortArray"].Set(obj["ShortArray"].Get()); - EXPECT_EQ(obj["ShortArray"].Get().Pin().ptr(), fake_storage_ptr.get()); - EXPECT_EQ(obj["ShortArray"].Get().Pin(false).ptr(), fake_storage_ptr.get()); + obj.Access<"ShortArray">().Set(Fake()); + obj.Access<"ShortArray">().Set( + LocalArray{AdoptLocal{}, Fake()}); + obj.Access<"ShortArray">().Set(arr2); + obj.Access<"ShortArray">().Set(obj.Access<"ShortArray">().Get()); + EXPECT_EQ(obj.Access<"ShortArray">().Get().Pin().ptr(), + fake_storage_ptr.get()); + EXPECT_EQ(obj.Access<"ShortArray">().Get().Pin(false).ptr(), + fake_storage_ptr.get()); } TEST_F(JniTest, Array_Field_Int_Test) { @@ -283,14 +295,16 @@ TEST_F(JniTest, Array_Field_Int_Test) { Fake(), fake_storage_ptr.get(), JNI_ABORT)); LocalObject obj{AdoptLocal{}, Fake()}; - LocalArray arr{obj["IntArray"].Get()}; + LocalArray arr{obj.Access<"IntArray">().Get()}; LocalArray arr2{AdoptLocal{}, Fake()}; - obj["IntArray"].Set(Fake()); - obj["IntArray"].Set(LocalArray{AdoptLocal{}, Fake()}); - obj["IntArray"].Set(arr2); - obj["IntArray"].Set(obj["IntArray"].Get()); - EXPECT_EQ(obj["IntArray"].Get().Pin().ptr(), fake_storage_ptr.get()); - EXPECT_EQ(obj["IntArray"].Get().Pin(false).ptr(), fake_storage_ptr.get()); + obj.Access<"IntArray">().Set(Fake()); + obj.Access<"IntArray">().Set( + LocalArray{AdoptLocal{}, Fake()}); + obj.Access<"IntArray">().Set(arr2); + obj.Access<"IntArray">().Set(obj.Access<"IntArray">().Get()); + EXPECT_EQ(obj.Access<"IntArray">().Get().Pin().ptr(), fake_storage_ptr.get()); + EXPECT_EQ(obj.Access<"IntArray">().Get().Pin(false).ptr(), + fake_storage_ptr.get()); } TEST_F(JniTest, Array_Field_Float_Test) { @@ -312,14 +326,17 @@ TEST_F(JniTest, Array_Field_Float_Test) { fake_storage_ptr.get(), JNI_ABORT)); LocalObject obj{AdoptLocal{}, Fake()}; - LocalArray arr{obj["FloatArray"].Get()}; + LocalArray arr{obj.Access<"FloatArray">().Get()}; LocalArray arr2{AdoptLocal{}, Fake()}; - obj["FloatArray"].Set(Fake()); - obj["FloatArray"].Set(LocalArray{AdoptLocal{}, Fake()}); - obj["FloatArray"].Set(arr2); - obj["FloatArray"].Set(obj["FloatArray"].Get()); - EXPECT_EQ(obj["FloatArray"].Get().Pin().ptr(), fake_storage_ptr.get()); - EXPECT_EQ(obj["FloatArray"].Get().Pin(false).ptr(), fake_storage_ptr.get()); + obj.Access<"FloatArray">().Set(Fake()); + obj.Access<"FloatArray">().Set( + LocalArray{AdoptLocal{}, Fake()}); + obj.Access<"FloatArray">().Set(arr2); + obj.Access<"FloatArray">().Set(obj.Access<"FloatArray">().Get()); + EXPECT_EQ(obj.Access<"FloatArray">().Get().Pin().ptr(), + fake_storage_ptr.get()); + EXPECT_EQ(obj.Access<"FloatArray">().Get().Pin(false).ptr(), + fake_storage_ptr.get()); } TEST_F(JniTest, Array_Field_Double_Test) { @@ -341,15 +358,17 @@ TEST_F(JniTest, Array_Field_Double_Test) { fake_storage_ptr.get(), JNI_ABORT)); LocalObject obj{AdoptLocal{}, Fake()}; - LocalArray arr{obj["DoubleArray"].Get()}; + LocalArray arr{obj.Access<"DoubleArray">().Get()}; LocalArray arr2{AdoptLocal{}, Fake()}; - obj["DoubleArray"].Set(Fake()); - obj["DoubleArray"].Set( + obj.Access<"DoubleArray">().Set(Fake()); + obj.Access<"DoubleArray">().Set( LocalArray{AdoptLocal{}, Fake()}); - obj["DoubleArray"].Set(arr2); - obj["DoubleArray"].Set(obj["DoubleArray"].Get()); - EXPECT_EQ(obj["DoubleArray"].Get().Pin().ptr(), fake_storage_ptr.get()); - EXPECT_EQ(obj["DoubleArray"].Get().Pin(false).ptr(), fake_storage_ptr.get()); + obj.Access<"DoubleArray">().Set(arr2); + obj.Access<"DoubleArray">().Set(obj.Access<"DoubleArray">().Get()); + EXPECT_EQ(obj.Access<"DoubleArray">().Get().Pin().ptr(), + fake_storage_ptr.get()); + EXPECT_EQ(obj.Access<"DoubleArray">().Get().Pin(false).ptr(), + fake_storage_ptr.get()); } TEST_F(JniTest, Array_Field_Long_Test) { @@ -371,14 +390,17 @@ TEST_F(JniTest, Array_Field_Long_Test) { fake_storage_ptr.get(), JNI_ABORT)); LocalObject obj{AdoptLocal{}, Fake()}; - LocalArray arr{obj["LongArray"].Get()}; + LocalArray arr{obj.Access<"LongArray">().Get()}; LocalArray arr2{AdoptLocal{}, Fake()}; - obj["LongArray"].Set(Fake()); - obj["LongArray"].Set(LocalArray{AdoptLocal{}, Fake()}); - obj["LongArray"].Set(arr2); - obj["LongArray"].Set(obj["LongArray"].Get()); - EXPECT_EQ(obj["LongArray"].Get().Pin().ptr(), fake_storage_ptr.get()); - EXPECT_EQ(obj["LongArray"].Get().Pin(false).ptr(), fake_storage_ptr.get()); + obj.Access<"LongArray">().Set(Fake()); + obj.Access<"LongArray">().Set( + LocalArray{AdoptLocal{}, Fake()}); + obj.Access<"LongArray">().Set(arr2); + obj.Access<"LongArray">().Set(obj.Access<"LongArray">().Get()); + EXPECT_EQ(obj.Access<"LongArray">().Get().Pin().ptr(), + fake_storage_ptr.get()); + EXPECT_EQ(obj.Access<"LongArray">().Get().Pin(false).ptr(), + fake_storage_ptr.get()); } TEST_F(JniTest, Array_Field_Object_Test) { @@ -394,13 +416,13 @@ TEST_F(JniTest, Array_Field_Object_Test) { LocalObject obj{AdoptLocal{}, Fake()}; LocalArray arr2{AdoptLocal{}, Fake()}; - LocalArray arr{obj["ObjectArrayRank1"].Get()}; - obj["ObjectArrayRank1"].Set(Fake()); - obj["ObjectArrayRank1"].Set( + LocalArray arr{obj.Access<"ObjectArrayRank1">().Get()}; + obj.Access<"ObjectArrayRank1">().Set(Fake()); + obj.Access<"ObjectArrayRank1">().Set( LocalArray{AdoptLocal{}, Fake()}); - obj["ObjectArrayRank1"].Set(arr2); - obj["ObjectArrayRank1"].Set(obj["ObjectArrayRank1"].Get()); - obj["ObjectArrayRank1"].Get().Get(2); + obj.Access<"ObjectArrayRank1">().Set(arr2); + obj.Access<"ObjectArrayRank1">().Set(obj.Access<"ObjectArrayRank1">().Get()); + obj.Access<"ObjectArrayRank1">().Get().Get(2); } TEST_F(JniTest, Array_Field_HandlesLValueLocalObject_Rank_1) { @@ -414,7 +436,7 @@ TEST_F(JniTest, Array_Field_HandlesLValueLocalObject_Rank_1) { EXPECT_CALL(*env_, GetFieldID(_, StrEq("Foo"), StrEq("[LkClass2;"))); LocalObject obj{Fake()}; - LocalArray{obj["Foo"].Get()}; + LocalArray{obj.Access<"Foo">().Get()}; } TEST_F(JniTest, Array_Field_HandlesLValueLocalObject_Rank_2) { @@ -428,7 +450,7 @@ TEST_F(JniTest, Array_Field_HandlesLValueLocalObject_Rank_2) { EXPECT_CALL(*env_, GetFieldID(_, StrEq("Foo"), StrEq("[[LkClass2;"))); LocalObject obj{Fake()}; - LocalArray arr_from_field{obj["Foo"].Get()}; + LocalArray arr_from_field{obj.Access<"Foo">().Get()}; } TEST_F(JniTest, Array_Field_HandlesLValueLocalObject_Rank_2_Iteration) { @@ -471,7 +493,7 @@ TEST_F(JniTest, Array_Field_HandlesLValueLocalObject_Rank_2_Iteration) { LocalObject obj{AdoptLocal{}, Fake(1)}; int i = 100; - for (LocalArray obj : obj["Foo"].Get().Pin()) { + for (LocalArray obj : obj.Access<"Foo">().Get().Pin()) { EXPECT_EQ(static_cast(obj), Fake(i)); i++; } diff --git a/implementation/local_array_method_multidimensional_test.cc b/implementation/local_array_method_multidimensional_test.cc index f10f97dd..21671b6a 100644 --- a/implementation/local_array_method_multidimensional_test.cc +++ b/implementation/local_array_method_multidimensional_test.cc @@ -48,7 +48,7 @@ TEST_F(JniTest, V_2I) { EXPECT_CALL(*env_, GetMethodID(_, StrEq("I"), StrEq("()[[I"))); LocalObject obj{Fake()}; - obj("I"); + obj.Call<"I">(); } TEST_F(JniTest, V_2LkClass) { @@ -58,7 +58,7 @@ TEST_F(JniTest, V_2LkClass) { EXPECT_CALL(*env_, GetMethodID(_, StrEq("Foo"), StrEq("()[[LkClass2;"))); LocalObject obj{Fake()}; - obj("Foo"); + obj.Call<"Foo">(); } //////////////////////////////////////////////////////////////////////////////// @@ -77,7 +77,7 @@ TEST_F(JniTest, 3I1D_2LkClass) { GetMethodID(_, StrEq("Bar"), StrEq("([[[I[D)[[LkClass3;"))); LocalObject obj{Fake()}; - obj("Bar", Fake(), Fake()); + obj.Call<"Bar">(Fake(), Fake()); } TEST_F(JniTest, 2I_I) { @@ -88,8 +88,8 @@ TEST_F(JniTest, 2I_I) { LocalObject obj{Fake()}; // obj("I", jintArray{nullptr}); // doesn't compile (good). - obj("I", Fake()); - obj("I", LocalArray{Fake()}); + obj.Call<"I">(Fake()); + obj.Call<"I">(LocalArray{Fake()}); } TEST_F(JniTest, 3I_1LkClass) { @@ -103,8 +103,7 @@ TEST_F(JniTest, 3I_1LkClass) { // TODO(b/143908983): CTAD is failing. // LocalArray ret = obj("Baz", jobjectArray{nullptr}); - - LocalArray ret = obj("Baz", Fake()); + LocalArray ret = obj.Call<"Baz">(Fake()); static_assert(std::is_same_v>); } @@ -113,7 +112,7 @@ TEST_F(JniTest, 3I1D_1LkClass) { GetMethodID(_, StrEq("Bar"), StrEq("([[[I[D)[[LkClass3;"))); LocalObject obj{Fake()}; - obj("Bar", Fake(), Fake()); + obj.Call<"Bar">(Fake(), Fake()); } } // namespace diff --git a/implementation/local_array_method_test.cc b/implementation/local_array_method_test.cc index 24e27609..b5332474 100644 --- a/implementation/local_array_method_test.cc +++ b/implementation/local_array_method_test.cc @@ -78,31 +78,31 @@ TEST_F(JniTest, ReturnSmokeTest) { EXPECT_CALL(*env_, GetMethodID(_, StrEq("ObjectArray"), StrEq("()[LkClass2;"))); - LocalArray bool_array{obj("BooleanArray")}; + LocalArray bool_array{obj.Call<"BooleanArray">()}; EXPECT_EQ((static_cast(bool_array)), (Fake())); - LocalArray byte_array{obj("ByteArray")}; + LocalArray byte_array{obj.Call<"ByteArray">()}; EXPECT_EQ((static_cast(byte_array)), (Fake())); - LocalArray char_array{obj("CharArray")}; + LocalArray char_array{obj.Call<"CharArray">()}; EXPECT_EQ((static_cast(char_array)), (Fake())); - LocalArray short_array{obj("ShortArray")}; + LocalArray short_array{obj.Call<"ShortArray">()}; EXPECT_EQ((static_cast(short_array)), (Fake())); - LocalArray int_array{obj("IntArray")}; + LocalArray int_array{obj.Call<"IntArray">()}; EXPECT_EQ((static_cast(int_array)), (Fake())); - LocalArray long_array{obj("LongArray")}; + LocalArray long_array{obj.Call<"LongArray">()}; EXPECT_EQ((static_cast(long_array)), (Fake())); - LocalArray float_array{obj("FloatArray")}; + LocalArray float_array{obj.Call<"FloatArray">()}; EXPECT_EQ((static_cast(float_array)), (Fake())); - LocalArray double_array{obj("DoubleArray")}; + LocalArray double_array{obj.Call<"DoubleArray">()}; EXPECT_EQ((static_cast(double_array)), (Fake())); - LocalArray object_array{obj("ObjectArray")}; + LocalArray object_array{obj.Call<"ObjectArray">()}; EXPECT_EQ((static_cast(object_array)), (Fake())); } @@ -135,15 +135,16 @@ TEST_F(JniTest, ParamsSmokeTest) { EXPECT_CALL(*env_, GetMethodID(_, StrEq("ObjectArray"), StrEq("([LkClass2;)V"))); - obj("BooleanArray", LocalArray{Fake()}); - obj("ByteArray", LocalArray{Fake()}); - obj("CharArray", LocalArray{Fake()}); - obj("ShortArray", LocalArray{Fake()}); - obj("IntArray", LocalArray{Fake()}); - obj("FloatArray", LocalArray{Fake()}); - obj("DoubleArray", LocalArray{Fake()}); - obj("LongArray", LocalArray{Fake()}); - obj("ObjectArray", LocalArray{Fake()}); + obj.Call<"BooleanArray">(LocalArray{Fake()}); + obj.Call<"ByteArray">(LocalArray{Fake()}); + obj.Call<"CharArray">(LocalArray{Fake()}); + obj.Call<"ShortArray">(LocalArray{Fake()}); + obj.Call<"IntArray">(LocalArray{Fake()}); + obj.Call<"FloatArray">(LocalArray{Fake()}); + obj.Call<"DoubleArray">(LocalArray{Fake()}); + obj.Call<"LongArray">(LocalArray{Fake()}); + obj.Call<"ObjectArray">( + LocalArray{Fake()}); } //////////////////////////////////////////////////////////////////////////////// @@ -189,39 +190,39 @@ TEST_F(JniTest, ComplexSmokeTest) { StrEq("([LkClass2;)[LkClass2;"))); LocalArray bool_array{ - obj("BooleanArray", LocalArray{Fake()})}; + obj.Call<"BooleanArray">(LocalArray{Fake()})}; EXPECT_EQ((static_cast(bool_array)), (Fake())); LocalArray byte_array{ - obj("ByteArray", LocalArray{Fake()})}; + obj.Call<"ByteArray">(LocalArray{Fake()})}; EXPECT_EQ((static_cast(byte_array)), (Fake())); LocalArray char_array{ - obj("CharArray", LocalArray{Fake()})}; + obj.Call<"CharArray">(LocalArray{Fake()})}; EXPECT_EQ((static_cast(char_array)), (Fake())); LocalArray short_array{ - obj("ShortArray", LocalArray{Fake()})}; + obj.Call<"ShortArray">(LocalArray{Fake()})}; EXPECT_EQ((static_cast(short_array)), (Fake())); LocalArray int_array{ - obj("IntArray", LocalArray{Fake()})}; + obj.Call<"IntArray">(LocalArray{Fake()})}; EXPECT_EQ((static_cast(int_array)), (Fake())); LocalArray float_array{ - obj("FloatArray", LocalArray{Fake()})}; + obj.Call<"FloatArray">(LocalArray{Fake()})}; EXPECT_EQ((static_cast(float_array)), (Fake())); LocalArray double_array{ - obj("DoubleArray", LocalArray{Fake()})}; + obj.Call<"DoubleArray">(LocalArray{Fake()})}; EXPECT_EQ((static_cast(double_array)), (Fake())); LocalArray long_array{ - obj("LongArray", LocalArray{Fake()})}; + obj.Call<"LongArray">(LocalArray{Fake()})}; EXPECT_EQ((static_cast(long_array)), (Fake())); - LocalArray object_array{obj( - "ObjectArray", LocalArray{Fake()})}; + LocalArray object_array{obj.Call<"ObjectArray">( + LocalArray{Fake()})}; EXPECT_EQ((static_cast(object_array)), (Fake())); } diff --git a/implementation/local_array_string_test.cc b/implementation/local_array_string_test.cc index b0990e20..3bcf7d21 100644 --- a/implementation/local_array_string_test.cc +++ b/implementation/local_array_string_test.cc @@ -72,7 +72,7 @@ TEST_F(JniTest, Array_CorrectSignatureForStringParams) { LocalObject obj{jobject{nullptr}}; LocalArray arr{3}; - obj("StringArray", arr); + obj.Call<"StringArray">(arr); } //////////////////////////////////////////////////////////////////////////////// @@ -128,7 +128,7 @@ TEST_F(JniTest, Array_CorrectReturnSignatureForStrings) { LocalObject obj{Fake()}; EXPECT_CALL(*env_, GetMethodID(_, StrEq("StringArray"), StrEq("()[Ljava/lang/String;"))); - LocalArray arr = obj("StringArray"); + LocalArray arr = obj.Call<"StringArray">(); } //////////////////////////////////////////////////////////////////////////////// @@ -144,7 +144,7 @@ TEST_F(JniTest, Array_CorrectParamSignatureForStrings) { EXPECT_CALL(*env_, GetMethodID(_, StrEq("StringArray"), StrEq("([Ljava/lang/String;)V"))); LocalArray arr{2}; - obj("StringArray", arr); + obj.Call<"StringArray">(arr); } TEST_F(JniTest, LocalStringArray_ConstructsObjectsForLValues) { @@ -196,9 +196,9 @@ TEST_F(JniTest, Array_CorrectFieldSignatureForStrings) { EXPECT_CALL(*env_, GetFieldID(_, StrEq("StringArrayRank3"), StrEq("[[[Ljava/lang/String;"))); - LocalArray arr1 = obj["StringArrayRank1"].Get(); - LocalArray arr2 = obj["StringArrayRank2"].Get(); - LocalArray arr3 = obj["StringArrayRank3"].Get(); + LocalArray arr1 = obj.Access<"StringArrayRank1">().Get(); + LocalArray arr2 = obj.Access<"StringArrayRank2">().Get(); + LocalArray arr3 = obj.Access<"StringArrayRank3">().Get(); } } // namespace diff --git a/implementation/local_object_test.cc b/implementation/local_object_test.cc index ef193ac3..c0e2ea38 100644 --- a/implementation/local_object_test.cc +++ b/implementation/local_object_test.cc @@ -124,9 +124,10 @@ TEST_F(JniTest, LocalObject_ObjectReturnsInstanceMethods) { EXPECT_CALL(*env_, DeleteLocalRef(Fake())).Times(1); LocalObject obj{}; - obj("Foo", 12345); - obj("Baz", 12345.f); - obj("AMethodWithAReallyLongNameThatWouldPossiblyBeHardForTemplatesToHandle", + obj.Call<"Foo">(12345); + obj.Call<"Baz">(12345.f); + obj.Call< + "AMethodWithAReallyLongNameThatWouldPossiblyBeHardForTemplatesToHandle">( 12345, 12345.f, 12345, 12345.f, jdouble{12345}); } @@ -164,15 +165,15 @@ TEST_F(JniTest, LocalObject_ValuesWorkAfterMoveConstructor) { EXPECT_CALL(*env_, SetIntField).Times(4); LocalObject obj_1{Fake()}; - obj_1("Foo", 1); - obj_1("Foo", 2); - obj_1["BarField"].Set(1); + obj_1.Call<"Foo">(1); + obj_1.Call<"Foo">(2); + obj_1.Access<"BarField">().Set(1); LocalObject obj_2{std::move(obj_1)}; - obj_2("Foo", 3); - obj_2["BarField"].Set(2); - obj_2["BarField"].Set(3); - obj_2["BarField"].Set(4); + obj_2.Call<"Foo">(3); + obj_2.Access<"BarField">().Set(2); + obj_2.Access<"BarField">().Set(3); + obj_2.Access<"BarField">().Set(4); } TEST_F(JniTest, LocalObject_ReleasesLocalsForAlternateConstructors) { @@ -249,7 +250,7 @@ TEST_F(JniTest, LocalObject_SupportsPassingAnObjectAsAnLvalue) { LocalObject a{}; LocalObject b{}; - b("Foo", a); + b.Call<"Foo">(a); } TEST_F(JniTest, LocalObject_SupportsReturningAClass) { @@ -257,7 +258,7 @@ TEST_F(JniTest, LocalObject_SupportsReturningAClass) { "Class1", Method{"Foo", jni::Return{kClass2}, jni::Params{}}}; LocalObject a{}; - a("Foo"); + a.Call<"Foo">(); } TEST_F(JniTest, LocalObject_SupportsReturningAString) { @@ -265,13 +266,13 @@ TEST_F(JniTest, LocalObject_SupportsReturningAString) { "Class1", Method{"Foo", jni::Return{}, jni::Params{}}}; LocalObject a{}; - a("Foo"); + a.Call<"Foo">(); } jobject ReturnOutputOfMethod() { static constexpr Class kClass2{"Class2", Method{"Foo", jni::Return{kClass}}}; - return LocalObject{}("Foo").Release(); + return LocalObject{}.Call<"Foo">().Release(); } TEST_F(JniTest, LocalObject_CompilesWhenReturnReleasing) { @@ -284,7 +285,7 @@ TEST_F(JniTest, LocalObject_SupportsPassingAnObjectAsAnPrvalue) { LocalObject a{}; LocalObject b{}; - b("Foo", std::move(a)); + b.Call<"Foo">(std::move(a)); } TEST_F(JniTest, LocalObject_SupportsPassingAnObjectAsAnXvalue) { @@ -292,7 +293,7 @@ TEST_F(JniTest, LocalObject_SupportsPassingAnObjectAsAnXvalue) { "Class2", Method{"Foo", jni::Return{}, jni::Params{kClass}}}; LocalObject b{}; - b("Foo", LocalObject{}); + b.Call<"Foo">(LocalObject{}); } TEST_F(JniTest, LocalObject_MovesInContainerStruct) { @@ -320,8 +321,8 @@ TEST_F(JniTest, LocalObject_DoesntCrossTalkOverClassMethodIds) { LocalObject obj_2{Fake(2)}; // These are different method IDs (they are different classes). - obj_1("Foo", 1); - obj_2("Foo", 1); + obj_1.Call<"Foo">(1); + obj_2.Call<"Foo">(1); } } // namespace diff --git a/implementation/method_ref_test.cc b/implementation/method_ref_test.cc index 65c907ef..3406428a 100644 --- a/implementation/method_ref_test.cc +++ b/implementation/method_ref_test.cc @@ -193,7 +193,7 @@ TEST_F(JniTest, MethodRef_ReturnsObjects) { EXPECT_CALL(*env_, NewObjectV).WillOnce(testing::Return(Fake())); GlobalObject global_object{}; - LocalObject new_obj{global_object("Foo", 5)}; + LocalObject new_obj{global_object.Call<"Foo">(5)}; } TEST_F(JniTest, MethodRef_PassesObjects) { @@ -209,7 +209,7 @@ TEST_F(JniTest, MethodRef_PassesObjects) { EXPECT_CALL(*env_, GetMethodID(_, StrEq("Foo"), StrEq("(Lcom/google/Bazz;)I"))); - global_object("Foo", local_object); + global_object.Call<"Foo">(local_object); } TEST_F(JniTest, MethodRef_PassesAndReturnsMultipleObjects) { @@ -229,7 +229,7 @@ TEST_F(JniTest, MethodRef_PassesAndReturnsMultipleObjects) { LocalObject obj4{Fake(4)}; LocalObject object_under_test{Fake(5)}; - LocalObject obj5{object_under_test("Foo", obj1, obj2, obj3, obj4)}; + LocalObject obj5{object_under_test.Call<"Foo">(obj1, obj2, obj3, obj4)}; } TEST_F(JniTest, MethodRef_SupportsForwardDefines) { @@ -255,20 +255,21 @@ TEST_F(JniTest, MethodRef_SupportsForwardDefines) { LocalObject c2_obj1{Fake(3)}; LocalObject c2_obj2{Fake(4)}; - c1_obj1("m1", c1_obj1); - c1_obj1("m2", c2_obj1); - c1_obj1("m1", c1_obj1("m3")); - c1_obj1("m2", c1_obj1("m4")); + c1_obj1.Call<"m1">(c1_obj1); + c1_obj1.Call<"m2">(c2_obj1); + c1_obj1.Call<"m1">(c1_obj1.Call<"m3">()); + c1_obj1.Call<"m2">(c1_obj1.Call<"m4">()); - c2_obj1("m1", c1_obj1); - c2_obj1("m2", c2_obj2); - c2_obj1("m2", std::move(std::move(c2_obj2))); + c2_obj1.Call<"m1">(c1_obj1); + c2_obj1.Call<"m2">(c2_obj2); + c2_obj1.Call<"m2">(std::move(std::move(c2_obj2))); - c1_obj1("m2", std::move(c2_obj1)); + c1_obj1.Call<"m2">(std::move(c2_obj1)); - // c2_obj1("m1", c1_obj1); // illegal! triggers warnings (post move read). - // c2_obj1("m2", c2_obj2); // illegal! triggers warnings (post move read). - // c2_obj1("m2", std::move(c2_obj2)); // illegal! triggers warnings (post + // c2_obj1.Call<"m1">(c1_obj1); // illegal! triggers warnings (post move + // read). c2_obj1.Call<"m2">(c2_obj2); // illegal! triggers warnings (post + // move read). c2_obj1.Call<"m2">(std::move(c2_obj2)); // illegal! triggers + // warnings (post // move read). } @@ -281,9 +282,9 @@ TEST_F(JniTest, MethodRef_SupportsStrings) { }; LocalObject obj1{Fake()}; - obj1("Foo", "This is a method."); - obj1("Bar", "This is a method.", "It takes strings"); - obj1("Baz"); + obj1.Call<"Foo">("This is a method."); + obj1.Call<"Bar">("This is a method.", "It takes strings"); + obj1.Call<"Baz">(); } TEST_F(JniTest, MethodRef_SupportsArrays) { @@ -295,7 +296,7 @@ TEST_F(JniTest, MethodRef_SupportsArrays) { LocalArray local_array{nullptr}; LocalObject obj1{Fake()}; - obj1("Foo", local_array); + obj1.Call<"Foo">(local_array); } } // namespace diff --git a/implementation/multi_type_test.cc b/implementation/multi_type_test.cc index 3aceb6b0..b926bdbb 100644 --- a/implementation/multi_type_test.cc +++ b/implementation/multi_type_test.cc @@ -71,13 +71,13 @@ TEST_F(JniTest, MultiTypeTest_SimpleSmokeTestForSingleObject) { EXPECT_CALL(*env_, DeleteGlobalRef(Fake(2))).Times(1); jni::GlobalObject obj{}; - obj("Foo", 1, 2.f); - obj("Baz", 1.f); - obj("Baz", 1.f); - obj("Baz", 2.f); - obj("Baz", 3.f); - obj("Bar"); - obj["SomeField"].Get(); + obj.Call<"Foo">(1, 2.f); + obj.Call<"Baz">(1.f); + obj.Call<"Baz">(1.f); + obj.Call<"Baz">(2.f); + obj.Call<"Baz">(3.f); + obj.Call<"Bar">(); + obj.Access<"SomeField">().Get(); } TEST_F(JniTest, MultiTypeTest_MethodsOfSameNameButDifferentClassAreUnique) { @@ -94,21 +94,21 @@ TEST_F(JniTest, MultiTypeTest_MethodsOfSameNameButDifferentClassAreUnique) { jni::LocalObject obj1{Fake(1)}; jni::LocalObject obj2{Fake(2)}; - obj1("Foo", 12345); - obj2("Foo", 12345); + obj1.Call<"Foo">(12345); + obj2.Call<"Foo">(12345); // All of these calls ought not query for a method ID again. - obj1("Foo", 12345); - obj1("Foo", 12345); - obj1("Foo", 12345); - obj1("Foo", 12345); - obj2("Foo", 12345); - obj2("Foo", 12345); - obj2("Foo", 12345); + obj1.Call<"Foo">(12345); + obj1.Call<"Foo">(12345); + obj1.Call<"Foo">(12345); + obj1.Call<"Foo">(12345); + obj2.Call<"Foo">(12345); + obj2.Call<"Foo">(12345); + obj2.Call<"Foo">(12345); jni::LocalObject obj3{Fake(3)}; - obj3("Foo", 12345); - obj3("Foo", 12345); + obj3.Call<"Foo">(12345); + obj3.Call<"Foo">(12345); } } // namespace diff --git a/implementation/overload_ref_test.cc b/implementation/overload_ref_test.cc index b42e71e6..d452b9b3 100644 --- a/implementation/overload_ref_test.cc +++ b/implementation/overload_ref_test.cc @@ -40,7 +40,7 @@ TEST_F(JniTest, MethodRef_AsksForCorrectMethods1) { EXPECT_CALL(*env_, GetMethodID(_, StrEq("Foo"), StrEq("(Ljava/lang/String;)V"))); - obj("Foo", "test"); + obj.Call<"Foo">("test"); } TEST_F(JniTest, MethodRef_AsksForCorrectMethods2) { @@ -54,9 +54,9 @@ TEST_F(JniTest, MethodRef_AsksForCorrectMethods2) { EXPECT_CALL(*env_, GetMethodID(_, StrEq("Foo"), StrEq("(Ljava/lang/String;)V"))); - obj("Foo", 1); - // obj("Foo", 2.f); doesn't compile (good). - obj("Foo", "test"); + obj.Call<"Foo">(1); + // obj.Call<"Foo">(2.f); doesn't compile (good). + obj.Call<"Foo">("test"); } TEST_F(JniTest, MethodRef_AsksForCorrectMethods3) { @@ -77,11 +77,11 @@ TEST_F(JniTest, MethodRef_AsksForCorrectMethods3) { GetMethodID(_, StrEq("Foo"), StrEq("(Ljava/lang/String;Ljava/lang/String;)V"))); - obj("Foo", 1); - // obj("Foo", 2.f); // doesn't compile (good). - obj("Foo", "test"); - obj("Foo", "test1", "test2"); - obj("Foo", "this_doesnt", "trigger_method_lookup"); + obj.Call<"Foo">(1); + // obj.Call<"Foo">(2.f); // doesn't compile (good). + obj.Call<"Foo">("test"); + obj.Call<"Foo">("test1", "test2"); + obj.Call<"Foo">("this_doesnt", "trigger_method_lookup"); } TEST_F(JniTest, MethodRef_AsksForCorrectMethodsWhenMultiplePresent4) { @@ -113,14 +113,14 @@ TEST_F(JniTest, MethodRef_AsksForCorrectMethodsWhenMultiplePresent4) { StrEq("(Ljava/lang/String;Ljava/lang/String;)V"))); EXPECT_CALL(*env_, GetMethodID(_, StrEq("Baz"), StrEq("(FF)V"))); - obj("Foo", 1); - // obj("Foo", 2.f); // doesn't compile (good). - obj("Foo", "test"); - obj("Foo", "test1", "test2"); - obj("Foo", "this_doesnt", "trigger_method_lookup"); - obj("Baz", 1); - obj("Baz", "test3", "test4"); - obj("Baz", 1234.f, 5678.f); + obj.Call<"Foo">(1); + // obj.Call<"Foo">(2.f); // doesn't compile (good). + obj.Call<"Foo">("test"); + obj.Call<"Foo">("test1", "test2"); + obj.Call<"Foo">("this_doesnt", "trigger_method_lookup"); + obj.Call<"Baz">(1); + obj.Call<"Baz">("test3", "test4"); + obj.Call<"Baz">(1234.f, 5678.f); } } // namespace diff --git a/implementation/proxy_test.cc b/implementation/proxy_test.cc index 50652843..3a9a15e5 100644 --- a/implementation/proxy_test.cc +++ b/implementation/proxy_test.cc @@ -191,28 +191,28 @@ TEST_F(JniTest, MaterializationTests) { // Objects can be rvalues (here an x-value). LocalObject generator_obj{}; - LocalObject local_1{generator_obj("ReturnsObj")}; + LocalObject local_1{generator_obj.Call<"ReturnsObj">()}; // Objects can also be described with no actual class definition. // These objects won't be usable, but they are "name-safe". - LocalObject local_2{generator_obj("ReturnsObj")}; + LocalObject local_2{generator_obj.Call<"ReturnsObj">()}; // doesn't compile because of invalid class (good). - // LocalObject local_3 { generator_obj("ReturnsObj") }; } + // LocalObject local_3 { generator_obj.Call<"ReturnsObj">() }; } // Globals can be built from locals. - GlobalObject global_1{generator_obj("ReturnsObj")}; - global_1("Bar"); + GlobalObject global_1{generator_obj.Call<"ReturnsObj">()}; + global_1.Call<"Bar">(); // Globals can be built from expiring locals without a full type. - GlobalObject global_2{generator_obj("ReturnsObj")}; + GlobalObject global_2{generator_obj.Call<"ReturnsObj">()}; // But they lack sufficient definition to have any invocation! - // global_2("Bar"); + // global_2.Call<"Bar">(); // They can be promoted however, and thus restore their type info. GlobalObject global_3{std::move(global_2)}; - global_3("Bar"); + global_3.Call<"Bar">(); } } // namespace jni diff --git a/implementation/self_test.cc b/implementation/self_test.cc index 68e81d25..d2fd2e81 100644 --- a/implementation/self_test.cc +++ b/implementation/self_test.cc @@ -44,7 +44,7 @@ TEST_F(JniTest, SelfCanBeUsedAsAReturnValue) { StrEq("()LBuilder;"))); LocalObject obj{Fake()}; - obj("build"); + obj.Call<"build">(); } TEST_F(JniTest, SelfCanBeUsedAsAReturnValueAndMaintainsRichDecoration) { @@ -52,7 +52,7 @@ TEST_F(JniTest, SelfCanBeUsedAsAReturnValueAndMaintainsRichDecoration) { EXPECT_CALL(*env_, GetMethodID(_, StrEq("build"), StrEq("()LBuilder;"))); LocalObject obj{Fake()}; - obj("build")("build")("build"); + obj.Call<"build">().Call<"build">().Call<"build">(); } TEST_F(JniTest, SelfCanBeUsedAsParam) { @@ -62,7 +62,7 @@ TEST_F(JniTest, SelfCanBeUsedAsParam) { LocalObject obj_1{Fake(1)}; LocalObject obj_2{Fake(2)}; - obj_1("takesBuilder", obj_2); + obj_1.Call<"takesBuilder">(obj_2); } } // namespace diff --git a/implementation/static_ref_test.cc b/implementation/static_ref_test.cc index 2a560458..27ce5d4b 100644 --- a/implementation/static_ref_test.cc +++ b/implementation/static_ref_test.cc @@ -73,8 +73,8 @@ TEST_F(JniTest, StaticBooleanField) { EXPECT_CALL(*env_, SetStaticBooleanField(_, Fake(), true)); LocalObject obj; - EXPECT_TRUE(StaticRef{}["booleanField"].Get()); - StaticRef{}["booleanField"].Set(true); + EXPECT_TRUE(StaticRef{}.Access<"booleanField">().Get()); + StaticRef{}.Access<"booleanField">().Set(true); } TEST_F(JniTest, StaticByteField) { @@ -85,8 +85,8 @@ TEST_F(JniTest, StaticByteField) { EXPECT_CALL(*env_, SetStaticByteField(_, Fake(), true)); LocalObject obj; - EXPECT_TRUE(StaticRef{}["byteField"].Get()); - StaticRef{}["byteField"].Set(true); + EXPECT_TRUE(StaticRef{}.Access<"byteField">().Get()); + StaticRef{}.Access<"byteField">().Set(true); } TEST_F(JniTest, StaticCharField) { @@ -97,8 +97,8 @@ TEST_F(JniTest, StaticCharField) { EXPECT_CALL(*env_, SetStaticCharField(_, Fake(), true)); LocalObject obj; - EXPECT_TRUE(StaticRef{}["charField"].Get()); - StaticRef{}["charField"].Set(true); + EXPECT_TRUE(StaticRef{}.Access<"charField">().Get()); + StaticRef{}.Access<"charField">().Set(true); } TEST_F(JniTest, StaticShortField) { @@ -109,8 +109,8 @@ TEST_F(JniTest, StaticShortField) { EXPECT_CALL(*env_, SetStaticShortField(_, Fake(), true)); LocalObject obj; - EXPECT_TRUE(StaticRef{}["shortField"].Get()); - StaticRef{}["shortField"].Set(true); + EXPECT_TRUE(StaticRef{}.Access<"shortField">().Get()); + StaticRef{}.Access<"shortField">().Set(true); } TEST_F(JniTest, StaticIntField) { @@ -121,8 +121,8 @@ TEST_F(JniTest, StaticIntField) { EXPECT_CALL(*env_, SetStaticIntField(_, Fake(), true)); LocalObject obj; - EXPECT_TRUE(StaticRef{}["intField"].Get()); - StaticRef{}["intField"].Set(true); + EXPECT_TRUE(StaticRef{}.Access<"intField">().Get()); + StaticRef{}.Access<"intField">().Set(true); } TEST_F(JniTest, StaticLongField) { @@ -133,8 +133,8 @@ TEST_F(JniTest, StaticLongField) { EXPECT_CALL(*env_, SetStaticLongField(_, Fake(), true)); LocalObject obj; - EXPECT_TRUE(StaticRef{}["longField"].Get()); - StaticRef{}["longField"].Set(true); + EXPECT_TRUE(StaticRef{}.Access<"longField">().Get()); + StaticRef{}.Access<"longField">().Set(true); } TEST_F(JniTest, StaticFloatField) { @@ -145,8 +145,8 @@ TEST_F(JniTest, StaticFloatField) { EXPECT_CALL(*env_, SetStaticFloatField(_, Fake(), true)); LocalObject obj; - EXPECT_TRUE(StaticRef{}["floatField"].Get()); - StaticRef{}["floatField"].Set(true); + EXPECT_TRUE(StaticRef{}.Access<"floatField">().Get()); + StaticRef{}.Access<"floatField">().Set(true); } TEST_F(JniTest, StaticDoubleField) { @@ -157,8 +157,8 @@ TEST_F(JniTest, StaticDoubleField) { EXPECT_CALL(*env_, SetStaticDoubleField(_, Fake(), true)); LocalObject obj; - EXPECT_TRUE(StaticRef{}["doubleField"].Get()); - StaticRef{}["doubleField"].Set(true); + EXPECT_TRUE(StaticRef{}.Access<"doubleField">().Get()); + StaticRef{}.Access<"doubleField">().Set(true); } TEST_F(JniTest, StaticField_ObjectGet) { @@ -168,7 +168,8 @@ TEST_F(JniTest, StaticField_ObjectGet) { EXPECT_CALL(*env_, GetStaticObjectField(_, Fake())) .WillOnce(Return(Fake())); - jni::LocalObject obj = StaticRef{}["classField"].Get(); + jni::LocalObject obj = + StaticRef{}.Access<"classField">().Get(); } TEST_F(JniTest, StaticField_StringSet) { @@ -178,7 +179,7 @@ TEST_F(JniTest, StaticField_StringSet) { EXPECT_CALL(*env_, SetStaticObjectField(_, Fake(), Fake())); - StaticRef{}["stringField"].Set( + StaticRef{}.Access<"stringField">().Set( LocalString{AdoptLocal{}, Fake()}); } @@ -189,7 +190,7 @@ TEST_F(JniTest, StaticField_ObjectSet) { EXPECT_CALL(*env_, SetStaticObjectField(_, Fake(), Fake())); - StaticRef{}["classField"].Set( + StaticRef{}.Access<"classField">().Set( LocalObject{AdoptLocal{}, Fake()}); } @@ -199,7 +200,8 @@ TEST_F(JniTest, StaticField_SelfGet) { EXPECT_CALL(*env_, GetStaticObjectField(_, Fake())) .WillOnce(Return(Fake())); - jni::LocalObject obj = StaticRef{}["selfField"].Get(); + jni::LocalObject obj = + StaticRef{}.Access<"selfField">().Get(); } TEST_F(JniTest, StaticField_SelfSet) { @@ -208,7 +210,7 @@ TEST_F(JniTest, StaticField_SelfSet) { EXPECT_CALL(*env_, SetStaticObjectField(_, Fake(), Fake())); - StaticRef{}["selfField"].Set( + StaticRef{}.Access<"selfField">().Set( LocalObject{AdoptLocal{}, Fake()}); } @@ -276,21 +278,21 @@ TEST_F(JniTest, StaticExerciseAllReturns) { EXPECT_CALL(*env_, CallStaticObjectMethodV).Times(5); - StaticRef{}("booleanMethod"); - StaticRef{}("byteMethod"); - StaticRef{}("charMethod"); - StaticRef{}("shortMethod"); - StaticRef{}("intMethod"); - StaticRef{}("longMethod"); - StaticRef{}("floatMethod"); - StaticRef{}("doubleMethod"); - StaticRef{}("stringMethod"); - - StaticRef{}("objectMethod"); - StaticRef{}("rank1ArrayMethod"); - StaticRef{}("rank2ArrayMethod"); - - LocalObject self_ret = StaticRef{}("selfMethod"); + StaticRef{}.Call<"booleanMethod">(); + StaticRef{}.Call<"byteMethod">(); + StaticRef{}.Call<"charMethod">(); + StaticRef{}.Call<"shortMethod">(); + StaticRef{}.Call<"intMethod">(); + StaticRef{}.Call<"longMethod">(); + StaticRef{}.Call<"floatMethod">(); + StaticRef{}.Call<"doubleMethod">(); + StaticRef{}.Call<"stringMethod">(); + + StaticRef{}.Call<"objectMethod">(); + StaticRef{}.Call<"rank1ArrayMethod">(); + StaticRef{}.Call<"rank2ArrayMethod">(); + + LocalObject self_ret = StaticRef{}.Call<"selfMethod">(); } // clang-format off @@ -339,23 +341,23 @@ TEST_F(JniTest, StaticExerciseAllTypesThroughSingleParam) { EXPECT_CALL(*env_, CallStaticVoidMethodV).Times(13); - StaticRef{}("booleanMethod", jboolean{true}); - StaticRef{}("byteMethod", jbyte{1}); - StaticRef{}("charMethod", jchar{'a'}); - StaticRef{}("shortMethod", jshort{1}); - StaticRef{}("intMethod", jint{123}); - StaticRef{}("longMethod", jlong{456}); - StaticRef{}("floatMethod", jfloat{789.f}); - StaticRef{}("doubleMethod", jdouble{101.}); - StaticRef{}("stringMethod", "test"); + StaticRef{}.Call<"booleanMethod">(jboolean{true}); + StaticRef{}.Call<"byteMethod">(jbyte{1}); + StaticRef{}.Call<"charMethod">(jchar{'a'}); + StaticRef{}.Call<"shortMethod">(jshort{1}); + StaticRef{}.Call<"intMethod">(jint{123}); + StaticRef{}.Call<"longMethod">(jlong{456}); + StaticRef{}.Call<"floatMethod">(jfloat{789.f}); + StaticRef{}.Call<"doubleMethod">(jdouble{101.}); + StaticRef{}.Call<"stringMethod">("test"); // It would be more complete to exercise all types here. - StaticRef{}("objectMethod", Fake()); - StaticRef{}("rank1ArrayMethod", - Fake()); - StaticRef{}("rank2ArrayMethod", - Fake()); - StaticRef{}("selfMethod", Fake()); + StaticRef{}.Call<"objectMethod">(Fake()); + StaticRef{}.Call<"rank1ArrayMethod">( + Fake()); + StaticRef{}.Call<"rank2ArrayMethod">( + Fake()); + StaticRef{}.Call<"selfMethod">(Fake()); } TEST_F(JniTest, StaticExerciseComplexSetOfParams) { @@ -365,9 +367,9 @@ TEST_F(JniTest, StaticExerciseComplexSetOfParams) { EXPECT_CALL(*env_, GetStaticMethodID(_, StrEq("complexFunc"), StrEq("([[LkClass2;IFLkClass3;)F"))); - StaticRef{}("simpleFunc", 123.f); - StaticRef{}("complexFunc", jobjectArray{nullptr}, 123, 456.f, - jobject{nullptr}); + StaticRef{}.Call<"simpleFunc">(123.f); + StaticRef{}.Call<"complexFunc">(jobjectArray{nullptr}, 123, + 456.f, jobject{nullptr}); } } // namespace diff --git a/implementation/string_ref_test.cc b/implementation/string_ref_test.cc index 08156c61..f9ab2920 100644 --- a/implementation/string_ref_test.cc +++ b/implementation/string_ref_test.cc @@ -91,7 +91,7 @@ TEST_F(JniTest, LocalString_CopiesFromJString) { TEST_F(JniTest, LocalString_ConstructsFromOutputOfMethod) { LocalObject obj{}; - LocalString str{obj("Foo")}; + LocalString str{obj.Call<"Foo">()}; } TEST_F(JniTest, LocalString_ConstructsFromByteArray) { @@ -151,12 +151,12 @@ TEST_F(JniTest, LocalString_PinsAndUnpinsMemoryForLocals) { TEST_F(JniTest, LocalString_AllowsLValueLocalString) { LocalObject obj{}; LocalString local_string{"abcde"}; - obj("TakesStrParam", local_string); + obj.Call<"TakesStrParam">(local_string); } TEST_F(JniTest, LocalString_AllowsRValueLocalString) { LocalObject obj{}; - obj("TakesStrParam", LocalString{"abcde"}); + obj.Call<"TakesStrParam">(LocalString{"abcde"}); } //////////////////////////////////////////////////////////////////////////////// @@ -180,7 +180,7 @@ TEST_F(JniTest, GlobalString_GlobalsReleaseWithGlobalMechanism) { TEST_F(JniTest, GlobalString_ConstructsFromOutputOfMethod) { LocalObject obj{}; - GlobalString str{obj("Foo")}; + GlobalString str{obj.Call<"Foo">()}; } TEST_F(JniTest, GlobalString_ConstructsFromByteArray) { @@ -227,12 +227,12 @@ TEST_F(JniTest, GlobalString_PinsAndUnpinsMemoryForLocals) { TEST_F(JniTest, GlobalString_AllowsLValueGlobalString) { LocalObject obj{}; GlobalString global_string{"abcde"}; - obj("TakesStrParam", global_string); + obj.Call<"TakesStrParam">(global_string); } TEST_F(JniTest, GlobalString_AllowsRValueGlobalString) { LocalObject obj{}; - obj("TakesStrParam", GlobalString{"abcde"}); + obj.Call<"TakesStrParam">(GlobalString{"abcde"}); } } // namespace diff --git a/implementation/thread_guard_test.cc b/implementation/thread_guard_test.cc index 4ecd1ab2..5d054c44 100644 --- a/implementation/thread_guard_test.cc +++ b/implementation/thread_guard_test.cc @@ -99,7 +99,7 @@ TEST_F(JniTest, AllowsMoveCtorIntoLambdaWithThreadGuardUsage) { std::thread worker{[gobj{std::move(global_obj)}]() mutable { ThreadGuard thread_guard{}; - gobj["intVal1"].Get(); + gobj.Access<"intVal1">().Get(); }}; worker.join(); diff --git a/java/com/google/main.cc b/java/com/google/main.cc index de5ea5ea..df9fca2f 100644 --- a/java/com/google/main.cc +++ b/java/com/google/main.cc @@ -46,7 +46,7 @@ void RunIterationsToCompletion(jni::JvmRef *jvm_ref) { for (int i = 0; i < kNumIterations; ++i) { printf("Iteration %i: %s\n", i, - random_string("format").Pin().ToString().data()); + random_string.Call<"format">().Pin().ToString().data()); } } diff --git a/javatests/com/jnibind/android/array_test_jni.cc b/javatests/com/jnibind/android/array_test_jni.cc index e193bf68..864f8c6b 100644 --- a/javatests/com/jnibind/android/array_test_jni.cc +++ b/javatests/com/jnibind/android/array_test_jni.cc @@ -55,11 +55,11 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeBooleanTests( // Simple lvalue pass through works as expected. LocalArray local_arr{boolean_array}; - rjni_test_helper("rJniBooleanArray", false, local_arr); + rjni_test_helper.Call<"rJniBooleanArray">(false, local_arr); // Simple rvalue pass through works as expected. - rjni_test_helper("rJniBooleanArray", false, - LocalArray{boolean_array}); + rjni_test_helper.Call<"rJniBooleanArray">( + false, LocalArray{boolean_array}); // Building a new array, and setting all the values by hand works. LocalArray new_array{8}; @@ -69,7 +69,7 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeBooleanTests( array_view.ptr()[i] = true; } } - rjni_test_helper("rJniBooleanArray", true, new_array); + rjni_test_helper.Call<"rJniBooleanArray">(true, new_array); // You can pull the view multiple times. { @@ -78,7 +78,7 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeBooleanTests( array_view.ptr()[i] = true; } } - rjni_test_helper("rJniBooleanArray", true, new_array); + rjni_test_helper.Call<"rJniBooleanArray">(true, new_array); } JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeByteTests( @@ -87,10 +87,11 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeByteTests( // Simple lvalue pass through works as expected. LocalArray local_arr{byte_array}; - rjni_test_helper("rJniByteArray", jbyte{0}, local_arr); + rjni_test_helper.Call<"rJniByteArray">(jbyte{0}, local_arr); // Simple rvalue pass through works as expected. - rjni_test_helper("rJniByteArray", jbyte{0}, LocalArray{byte_array}); + rjni_test_helper.Call<"rJniByteArray">(jbyte{0}, + LocalArray{byte_array}); // Building a new array, and setting all the values by hand works. LocalArray new_array{8}; @@ -100,7 +101,7 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeByteTests( array_view.ptr()[i] = static_cast(i); } } - rjni_test_helper("rJniByteArray", jbyte{0}, new_array); + rjni_test_helper.Call<"rJniByteArray">(jbyte{0}, new_array); // You can pull the view multiple times. { @@ -109,7 +110,7 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeByteTests( array_view.ptr()[i] += 5; } } - rjni_test_helper("rJniByteArray", jbyte{5}, new_array); + rjni_test_helper.Call<"rJniByteArray">(jbyte{5}, new_array); } JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeCharTests( @@ -118,10 +119,11 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeCharTests( // Simple lvalue pass through works as expected. LocalArray local_arr{char_array}; - rjni_test_helper("rJniCharArray", jchar{0}, local_arr); + rjni_test_helper.Call<"rJniCharArray">(jchar{0}, local_arr); // Simple rvalue pass through works as expected. - rjni_test_helper("rJniCharArray", jchar{0}, LocalArray{char_array}); + rjni_test_helper.Call<"rJniCharArray">(jchar{0}, + LocalArray{char_array}); // Building a new array, and setting all the values by hand works. LocalArray new_array{8}; @@ -131,7 +133,7 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeCharTests( array_view.ptr()[i] = static_cast(i); } } - rjni_test_helper("rJniCharArray", jchar{0}, new_array); + rjni_test_helper.Call<"rJniCharArray">(jchar{0}, new_array); // You can pull the view multiple times. { @@ -140,7 +142,7 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeCharTests( array_view.ptr()[i] += 5; } } - rjni_test_helper("rJniCharArray", jchar{5}, new_array); + rjni_test_helper.Call<"rJniCharArray">(jchar{5}, new_array); } JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeShortTests( @@ -149,11 +151,11 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeShortTests( // Simple lvalue pass through works as expected. LocalArray local_arr{short_array}; - rjni_test_helper("rJniShortArray", jshort{0}, local_arr); + rjni_test_helper.Call<"rJniShortArray">(jshort{0}, local_arr); // Simple rvalue pass through works as expected. - rjni_test_helper("rJniShortArray", jshort{0}, - LocalArray{short_array}); + rjni_test_helper.Call<"rJniShortArray">(jshort{0}, + LocalArray{short_array}); // Building a new array, and setting all the values by hand works. LocalArray new_array{8}; @@ -163,7 +165,7 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeShortTests( array_view.ptr()[i] = static_cast(i); } } - rjni_test_helper("rJniShortArray", jshort{0}, new_array); + rjni_test_helper.Call<"rJniShortArray">(jshort{0}, new_array); // You can pull the view multiple times. { @@ -172,7 +174,7 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeShortTests( array_view.ptr()[i] += 5; } } - rjni_test_helper("rJniShortArray", jshort{5}, new_array); + rjni_test_helper.Call<"rJniShortArray">(jshort{5}, new_array); } JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeIntTests( @@ -181,10 +183,10 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeIntTests( // Simple lvalue pass through works as expected. LocalArray local_arr{int_array}; - rjni_test_helper("rJniIntArray", 0, local_arr); + rjni_test_helper.Call<"rJniIntArray">(0, local_arr); // Simple rvalue pass through works as expected. - rjni_test_helper("rJniIntArray", 0, LocalArray{int_array}); + rjni_test_helper.Call<"rJniIntArray">(0, LocalArray{int_array}); // Building a new array, and setting all the values by hand works. LocalArray new_array{8}; @@ -194,7 +196,7 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeIntTests( array_view.ptr()[i] = i; } } - rjni_test_helper("rJniIntArray", 0, new_array); + rjni_test_helper.Call<"rJniIntArray">(0, new_array); // You can pull the view multiple times. { @@ -203,7 +205,7 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeIntTests( array_view.ptr()[i] += 5; } } - rjni_test_helper("rJniIntArray", 5, new_array); + rjni_test_helper.Call<"rJniIntArray">(5, new_array); } JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeLongTests( @@ -212,10 +214,11 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeLongTests( // Simple lvalue pass through works as expected. LocalArray local_arr{long_array}; - rjni_test_helper("rJniLongArray", jlong{0}, local_arr); + rjni_test_helper.Call<"rJniLongArray">(jlong{0}, local_arr); // Simple rvalue pass through works as expected. - rjni_test_helper("rJniLongArray", jlong{0}, LocalArray{long_array}); + rjni_test_helper.Call<"rJniLongArray">(jlong{0}, + LocalArray{long_array}); // Building a new array, and setting all the values by hand works. LocalArray new_array{8}; @@ -225,7 +228,7 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeLongTests( array_view.ptr()[i] = static_cast(i); } } - rjni_test_helper("rJniLongArray", jlong{0}, new_array); + rjni_test_helper.Call<"rJniLongArray">(jlong{0}, new_array); // You can pull the view multiple times. { @@ -234,7 +237,7 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeLongTests( array_view.ptr()[i] += 5; } } - rjni_test_helper("rJniLongArray", jlong{5}, new_array); + rjni_test_helper.Call<"rJniLongArray">(jlong{5}, new_array); } JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeFloatTests( @@ -242,7 +245,7 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeFloatTests( LocalObject rjni_test_helper{test_fixture}; LocalArray local_arr{float_array}; - rjni_test_helper("rJniFloatArray", 0.f, local_arr); + rjni_test_helper.Call<"rJniFloatArray">(0.f, local_arr); { ArrayView array_view{local_arr.Pin(true)}; @@ -250,7 +253,7 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeFloatTests( array_view.ptr()[i] += 2.5f; } } - rjni_test_helper("rJniFloatArray", 2.5f, local_arr); + rjni_test_helper.Call<"rJniFloatArray">(2.5f, local_arr); } JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeDoubleTests( @@ -259,11 +262,11 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeDoubleTests( // Simple lvalue pass through works as expected. LocalArray local_arr{double_array}; - rjni_test_helper("rJniDoubleArray", jdouble{0}, local_arr); + rjni_test_helper.Call<"rJniDoubleArray">(jdouble{0}, local_arr); // Simple rvalue pass through works as expected. - rjni_test_helper("rJniDoubleArray", jdouble{0}, - LocalArray{double_array}); + rjni_test_helper.Call<"rJniDoubleArray">(jdouble{0}, + LocalArray{double_array}); // Building a new array, and setting all the values by hand works. LocalArray new_array{8}; @@ -273,7 +276,7 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeDoubleTests( array_view.ptr()[i] = static_cast(i); } } - rjni_test_helper("rJniDoubleArray", jdouble{0}, new_array); + rjni_test_helper.Call<"rJniDoubleArray">(jdouble{0}, new_array); // You can pull the view multiple times. { @@ -282,7 +285,7 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeDoubleTests( array_view.ptr()[i] += 5; } } - rjni_test_helper("rJniDoubleArray", jdouble{5}, new_array); + rjni_test_helper.Call<"rJniDoubleArray">(jdouble{5}, new_array); } JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeObjectTests( @@ -291,12 +294,12 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeObjectTests( // Simple lvalue pass through works as expected. LocalArray local_arr{object_array}; - rjni_test_helper("rJniObjectArray", 0, local_arr); + rjni_test_helper.Call<"rJniObjectArray">(0, local_arr); // Simple rvalue pass through works as expected. - rjni_test_helper("rJniObjectArray", 5, - LocalArray{ - 1, LocalObject{5, 5, 5}}); + rjni_test_helper.Call<"rJniObjectArray">( + 5, LocalArray{ + 1, LocalObject{5, 5, 5}}); // Building a new array, and setting all the values by hand works. LocalObject obj{0, 0, 0}; @@ -307,17 +310,17 @@ JNIEXPORT void JNICALL Java_com_jnibind_android_ArrayTest_nativeObjectTests( i, LocalObject{jint{i}, jint{i}, jint{i}}); } } - rjni_test_helper("rJniObjectArray", 0, new_array); + rjni_test_helper.Call<"rJniObjectArray">(0, new_array); // You can pull the view multiple times. { for (int i = 0; i < new_array.Length(); ++i) { - new_array.Set(i, - LocalObject{2, 2, 2}( - "returnNewObjectWithFieldSetToSum", new_array.Get(i))); + new_array.Set( + i, LocalObject{2, 2, 2} + .Call<"returnNewObjectWithFieldSetToSum">(new_array.Get(i))); } } - rjni_test_helper("rJniObjectArray", 2, new_array); + rjni_test_helper.Call<"rJniObjectArray">(2, new_array); } } // extern "C" diff --git a/javatests/com/jnibind/android/class_loader_test_jni.cc b/javatests/com/jnibind/android/class_loader_test_jni.cc index 83f84975..9a8da85b 100644 --- a/javatests/com/jnibind/android/class_loader_test_jni.cc +++ b/javatests/com/jnibind/android/class_loader_test_jni.cc @@ -74,8 +74,8 @@ Java_com_jnibind_android_ClassLoaderTest_jniBuildNewObjectsFromClassLoader( LocalObject helper_obj = class_loader.BuildLocalObject(1, 2, 3); return LocalObject{jtest_obj}( - "methodTakesLocalObjectReturnsNewObject", helper_obj) + kJvmWithCustomClassLoaderSupport>{jtest_obj} + .Call<"methodTakesLocalObjectReturnsNewObject">(helper_obj) .Release(); } @@ -85,8 +85,8 @@ Java_com_jnibind_android_ClassLoaderTest_jniBuildNewObjectsFromDefaultClassLoade GlobalClassLoader class_loader{PromoteToGlobal{}, jclass_loader_obj}; LocalObject helper_obj{2, 3, 4}; - return LocalObject{jtest_obj}( - "methodTakesLocalObjectReturnsNewObject", helper_obj) + return LocalObject{jtest_obj} + .Call<"methodTakesLocalObjectReturnsNewObject">(helper_obj) .Release(); } @@ -101,9 +101,9 @@ Java_com_jnibind_android_ClassLoaderTest_jniBuildsRemoteSubclassFromClassLoader( jint{value}); LocalObject - parent_obj{helper_obj("castToParent")}; + parent_obj{helper_obj.Call<"castToParent">()}; - return parent_obj("getValue"); + return parent_obj.Call<"getValue">(); } JNIEXPORT jint JNICALL @@ -116,7 +116,7 @@ Java_com_jnibind_android_ClassLoaderTest_jniBuildsRemoteClassFromClassLoader( helper_obj = class_loader.BuildLocalObject(jint{value}); - return helper_obj("getValue"); + return helper_obj.Call<"getValue">(); } } // extern "C" diff --git a/javatests/com/jnibind/android/context_test_jni.cc b/javatests/com/jnibind/android/context_test_jni.cc index 6ae2de6e..faef1225 100644 --- a/javatests/com/jnibind/android/context_test_jni.cc +++ b/javatests/com/jnibind/android/context_test_jni.cc @@ -39,15 +39,16 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* pjvm, void* reserved) { } JNIEXPORT void JNICALL Java_com_jnibind_android_ContextTest_DoSetup(JNIEnv* env, - jclass) { + jclass) { jvm.reset(new jni::JvmRef{env}); } JNIEXPORT jlong JNICALL -Java_com_jnibind_android_ContextTest_CreateNativeContextObject(JNIEnv* env, jclass, - jint val) { +Java_com_jnibind_android_ContextTest_CreateNativeContextObject(JNIEnv* env, + jclass, + jint val) { auto* ctx_struct = new ContextStruct{GlobalObject{}}; - ctx_struct->obj["intVal1"].Set(jint{val}); + ctx_struct->obj.Access<"intVal1">().Set(jint{val}); return reinterpret_cast(ctx_struct); } @@ -57,25 +58,28 @@ Java_com_jnibind_android_ContextTest_CreateNativeContextObjectSetValToSum( JNIEnv* env, jclass, jint val1, jint val2) { // Creates a temporary test helper, calls its member method, and releases the // returned object across the C API boundary (then destroys the temporary). - return jni::LocalObject{}( - "returnNewObjectWithFieldSetToSum", val1, val2) + return jni::LocalObject{} + .Call<"returnNewObjectWithFieldSetToSum">(val1, val2) .Release(); } -JNIEXPORT jobject JNICALL Java_com_jnibind_android_ContextTest_QueryNativeObject( - JNIEnv* env, jclass, void* ctx_void_ptr) { +JNIEXPORT jobject JNICALL +Java_com_jnibind_android_ContextTest_QueryNativeObject(JNIEnv* env, jclass, + void* ctx_void_ptr) { ContextStruct* ctx_struct = static_cast(ctx_void_ptr); return jobject{ctx_struct->obj}; } -JNIEXPORT jobject JNICALL Java_com_jnibind_android_ContextTest_ExtractNativeObject( - JNIEnv* env, jclass, void* ctx_void_ptr) { +JNIEXPORT jobject JNICALL +Java_com_jnibind_android_ContextTest_ExtractNativeObject(JNIEnv* env, jclass, + void* ctx_void_ptr) { ContextStruct* ctx_struct = static_cast(ctx_void_ptr); return ctx_struct->obj.Release(); } -JNIEXPORT void JNICALL Java_com_jnibind_android_ContextTest_DestroyNativeContext( - JNIEnv* env, jclass, void* ctx_void_ptr) { +JNIEXPORT void JNICALL +Java_com_jnibind_android_ContextTest_DestroyNativeContext(JNIEnv* env, jclass, + void* ctx_void_ptr) { delete static_cast(ctx_void_ptr); } diff --git a/javatests/com/jnibind/android/field_test_jni.cc b/javatests/com/jnibind/android/field_test_jni.cc index 0b7fcc0a..569b5672 100644 --- a/javatests/com/jnibind/android/field_test_jni.cc +++ b/javatests/com/jnibind/android/field_test_jni.cc @@ -42,22 +42,22 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* pjvm, void* reserved) { JNIEXPORT jint JNICALL Java_com_jnibind_android_FieldTest_jniIntField( JNIEnv* env, jclass, jobject object, jint val) { LocalObject rjni_test_helper{object}; - rjni_test_helper["intField"].Set(jint{val}); - return rjni_test_helper["intField"].Get(); + rjni_test_helper.Access<"intField">().Set(jint{val}); + return rjni_test_helper.Access<"intField">().Get(); } JNIEXPORT jfloat JNICALL Java_com_jnibind_android_FieldTest_jniFloatField( JNIEnv* env, jclass, jobject object, jfloat val) { LocalObject rjni_test_helper{object}; - rjni_test_helper["floatField"].Set(jfloat{val}); - return rjni_test_helper["floatField"].Get(); + rjni_test_helper.Access<"floatField">().Set(jfloat{val}); + return rjni_test_helper.Access<"floatField">().Get(); } JNIEXPORT jdouble JNICALL Java_com_jnibind_android_FieldTest_jniDoubleField( JNIEnv* env, jclass, jobject object, jdouble val) { LocalObject rjni_test_helper{object}; - rjni_test_helper["doubleField"].Set(jdouble{val}); - return rjni_test_helper["doubleField"].Get(); + rjni_test_helper.Access<"doubleField">().Set(jdouble{val}); + return rjni_test_helper.Access<"doubleField">().Get(); } } // extern "C" diff --git a/javatests/com/jnibind/android/global_object_test_jni.cc b/javatests/com/jnibind/android/global_object_test_jni.cc index aa296ff1..6808682d 100644 --- a/javatests/com/jnibind/android/global_object_test_jni.cc +++ b/javatests/com/jnibind/android/global_object_test_jni.cc @@ -32,7 +32,8 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* pjvm, void* reserved) { } JNIEXPORT jobject JNICALL -Java_com_jnibind_android_GlobalObjectTest_jniCreateNewObject(JNIEnv* env, jclass) { +Java_com_jnibind_android_GlobalObjectTest_jniCreateNewObject(JNIEnv* env, + jclass) { return jni::GlobalObject{1, 2, 3}.Release(); } @@ -46,8 +47,8 @@ JNIEXPORT jobject JNICALL Java_com_jnibind_android_GlobalObjectTest_jniBuildNewObjectsFromExistingObjects( JNIEnv* env, jclass, jobject test_helper_object, jobject object_to_mutate) { jni::LocalObject helper_obj{object_to_mutate}; - return jni::LocalObject{test_helper_object}( - "methodTakesGlobalObjectReturnsNewObject", helper_obj) + return jni::LocalObject{test_helper_object} + .Call<"methodTakesGlobalObjectReturnsNewObject">(helper_obj) .Release(); } @@ -55,17 +56,17 @@ JNIEXPORT jobject JNICALL Java_com_jnibind_android_GlobalObjectTest_jniManipulateNewGlobalObjectSetIntVal238( JNIEnv* env, jclass, jobject jtest_obj) { jni::GlobalObject helper_obj{2, 3, 8}; - return jni::LocalObject{jtest_obj}( - "methodTakesGlobalObjectReturnsNewObject", std::move(helper_obj)) + return jni::LocalObject{jtest_obj} + .Call<"methodTakesGlobalObjectReturnsNewObject">(std::move(helper_obj)) .Release(); } JNIEXPORT jobject JNICALL Java_com_jnibind_android_GlobalObjectTest_jniMaterializeNewGlobalObjectSetIntVal159( JNIEnv* env, jclass, jobject jtest_obj) { - return jni::LocalObject{jtest_obj}( - "methodTakesGlobalObjectReturnsNewObject", - jni::GlobalObject{1, 5, 9}) + return jni::LocalObject{jtest_obj} + .Call<"methodTakesGlobalObjectReturnsNewObject">( + jni::GlobalObject{1, 5, 9}) .Release(); } diff --git a/javatests/com/jnibind/android/local_object_test_jni.cc b/javatests/com/jnibind/android/local_object_test_jni.cc index 0ce67f13..9897466f 100644 --- a/javatests/com/jnibind/android/local_object_test_jni.cc +++ b/javatests/com/jnibind/android/local_object_test_jni.cc @@ -32,7 +32,8 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* pjvm, void* reserved) { } JNIEXPORT jobject JNICALL -Java_com_jnibind_android_LocalObjectTest_jniCreateNewObject(JNIEnv* env, jclass) { +Java_com_jnibind_android_LocalObjectTest_jniCreateNewObject(JNIEnv* env, + jclass) { return jni::LocalObject{1, 2, 3}.Release(); } @@ -53,8 +54,8 @@ JNIEXPORT jobject JNICALL Java_com_jnibind_android_LocalObjectTest_jniBuildNewObjectsFromExistingObjects( JNIEnv* env, jclass, jobject jtest_obj, jobject jhelper_obj) { jni::LocalObject helper_obj{jhelper_obj}; - return jni::LocalObject{jtest_obj}( - "methodTakesLocalObjectReturnsNewObject", helper_obj) + return jni::LocalObject{jtest_obj} + .Call<"methodTakesLocalObjectReturnsNewObject">(helper_obj) .Release(); } @@ -62,17 +63,17 @@ JNIEXPORT jobject JNICALL Java_com_jnibind_android_LocalObjectTest_jniManipulateNewLocalObjectSetIntVal238( JNIEnv* env, jclass, jobject jtest_obj) { jni::LocalObject helper_obj{2, 3, 8}; - return jni::LocalObject{jtest_obj}( - "methodTakesLocalObjectReturnsNewObject", std::move(helper_obj)) + return jni::LocalObject{jtest_obj} + .Call<"methodTakesLocalObjectReturnsNewObject">(std::move(helper_obj)) .Release(); } JNIEXPORT jobject JNICALL Java_com_jnibind_android_LocalObjectTest_jniMaterializeNewLocalObjectSetIntVal159( JNIEnv* env, jclass, jobject jtest_obj) { - return jni::LocalObject{jtest_obj}( - "methodTakesLocalObjectReturnsNewObject", - jni::LocalObject{1, 5, 9}) + return jni::LocalObject{jtest_obj} + .Call<"methodTakesLocalObjectReturnsNewObject">( + jni::LocalObject{1, 5, 9}) .Release(); } diff --git a/javatests/com/jnibind/android/method_test_jni.cc b/javatests/com/jnibind/android/method_test_jni.cc index b558a0a1..d4337188 100644 --- a/javatests/com/jnibind/android/method_test_jni.cc +++ b/javatests/com/jnibind/android/method_test_jni.cc @@ -78,42 +78,39 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* pjvm, void* reserved) { JNIEXPORT void JNICALL Java_com_jnibind_android_MethodTest_jniVoidMethod( JNIEnv* env, jclass, jobject object) { LocalObject rjni_test_helper{object}; - rjni_test_helper("voidMethod"); + rjni_test_helper.Call<"voidMethod">(); } JNIEXPORT void JNICALL -Java_com_jnibind_android_MethodTest_jniVoidMethodTakesOneInt(JNIEnv* env, jclass, - jobject object, - jint i) { +Java_com_jnibind_android_MethodTest_jniVoidMethodTakesOneInt(JNIEnv* env, + jclass, + jobject object, + jint i) { LocalObject rjni_test_helper{object}; - rjni_test_helper("voidMethodTakesOneInt", jint{i}); + rjni_test_helper.Call<"voidMethodTakesOneInt">(jint{i}); } JNIEXPORT void JNICALL -Java_com_jnibind_android_MethodTest_jniVoidMethodTakesFiveInts(JNIEnv* env, jclass, - jobject object, - jint i1, jint i2, - jint i3, jint i4, - jint i5) { +Java_com_jnibind_android_MethodTest_jniVoidMethodTakesFiveInts( + JNIEnv* env, jclass, jobject object, jint i1, jint i2, jint i3, jint i4, + jint i5) { LocalObject rjni_test_helper{object}; - rjni_test_helper("voidMethodTakesFiveInts", jint{i1}, jint{i2}, jint{i3}, - jint{i4}, jint{i5}); + rjni_test_helper.Call<"voidMethodTakesFiveInts">(jint{i1}, jint{i2}, jint{i3}, + jint{i4}, jint{i5}); } /** Boolean Method Tests. */ JNIEXPORT jboolean JNICALL Java_com_jnibind_android_MethodTest_jniBooleanMethod( JNIEnv* env, jclass, jobject object) { LocalObject rjni_test_helper{object}; - return rjni_test_helper("booleanMethod"); + return rjni_test_helper.Call<"booleanMethod">(); } JNIEXPORT jboolean JNICALL -Java_com_jnibind_android_MethodTest_jniBooleanMethodTakesOneBoolean(JNIEnv* env, - jclass, - jobject object, - jboolean i) { +Java_com_jnibind_android_MethodTest_jniBooleanMethodTakesOneBoolean( + JNIEnv* env, jclass, jobject object, jboolean i) { LocalObject rjni_test_helper{object}; - return rjni_test_helper("booleanMethodTakesOneBoolean", jboolean{i}); + return rjni_test_helper.Call<"booleanMethodTakesOneBoolean">(jboolean{i}); } JNIEXPORT jboolean JNICALL @@ -121,48 +118,48 @@ Java_com_jnibind_android_MethodTest_jniBooleanMethodTakesFiveBooleans( JNIEnv* env, jclass, jobject object, jboolean i1, jboolean i2, jboolean i3, jboolean i4, jboolean i5) { LocalObject rjni_test_helper{object}; - return rjni_test_helper("booleanMethodTakesFiveBooleans", jboolean{i1}, - jboolean{i2}, jboolean{i3}, jboolean{i4}, - jboolean{i5}); + return rjni_test_helper.Call<"booleanMethodTakesFiveBooleans">( + jboolean{i1}, jboolean{i2}, jboolean{i3}, jboolean{i4}, jboolean{i5}); } /** Int Method Tests. */ JNIEXPORT jint JNICALL Java_com_jnibind_android_MethodTest_jniIntMethod( JNIEnv* env, jclass, jobject object) { LocalObject rjni_test_helper{object}; - return rjni_test_helper("intMethod"); + return rjni_test_helper.Call<"intMethod">(); } -JNIEXPORT jint JNICALL Java_com_jnibind_android_MethodTest_jniIntMethodTakesOneInt( - JNIEnv* env, jclass, jobject object, jint i) { +JNIEXPORT jint JNICALL +Java_com_jnibind_android_MethodTest_jniIntMethodTakesOneInt(JNIEnv* env, jclass, + jobject object, + jint i) { LocalObject rjni_test_helper{object}; - return rjni_test_helper("intMethodTakesOneInt", jint{i}); + return rjni_test_helper.Call<"intMethodTakesOneInt">(jint{i}); } JNIEXPORT jint JNICALL -Java_com_jnibind_android_MethodTest_jniIntMethodTakesFiveInts(JNIEnv* env, jclass, - jobject object, - jint i1, jint i2, - jint i3, jint i4, - jint i5) { +Java_com_jnibind_android_MethodTest_jniIntMethodTakesFiveInts( + JNIEnv* env, jclass, jobject object, jint i1, jint i2, jint i3, jint i4, + jint i5) { LocalObject rjni_test_helper{object}; - return rjni_test_helper("intMethodTakesFiveInts", jint{i1}, jint{i2}, - jint{i3}, jint{i4}, jint{i5}); + return rjni_test_helper.Call<"intMethodTakesFiveInts">( + jint{i1}, jint{i2}, jint{i3}, jint{i4}, jint{i5}); } /** Long Method Tests. */ JNIEXPORT jlong JNICALL Java_com_jnibind_android_MethodTest_jniLongMethod( JNIEnv* env, jclass, jobject object) { LocalObject rjni_test_helper{object}; - return rjni_test_helper("longMethod"); + return rjni_test_helper.Call<"longMethod">(); } JNIEXPORT jlong JNICALL -Java_com_jnibind_android_MethodTest_jniLongMethodTakesOneLong(JNIEnv* env, jclass, - jobject object, - jlong i) { +Java_com_jnibind_android_MethodTest_jniLongMethodTakesOneLong(JNIEnv* env, + jclass, + jobject object, + jlong i) { LocalObject rjni_test_helper{object}; - return rjni_test_helper("longMethodTakesOneLong", jlong{i}); + return rjni_test_helper.Call<"longMethodTakesOneLong">(jlong{i}); } JNIEXPORT jlong JNICALL @@ -170,24 +167,24 @@ Java_com_jnibind_android_MethodTest_jniLongMethodTakesFiveLongs( JNIEnv* env, jclass, jobject object, jlong i1, jlong i2, jlong i3, jlong i4, jlong i5) { LocalObject rjni_test_helper{object}; - return rjni_test_helper("longMethodTakesFiveLongs", jlong{i1}, jlong{i2}, - jlong{i3}, jlong{i4}, jlong{i5}); + return rjni_test_helper.Call<"longMethodTakesFiveLongs">( + jlong{i1}, jlong{i2}, jlong{i3}, jlong{i4}, jlong{i5}); } /** Float Method Tests. */ JNIEXPORT jfloat JNICALL Java_com_jnibind_android_MethodTest_jniFloatMethod( JNIEnv* env, jclass, jobject object) { LocalObject rjni_test_helper{object}; - return rjni_test_helper("floatMethod"); + return rjni_test_helper.Call<"floatMethod">(); } JNIEXPORT jfloat JNICALL Java_com_jnibind_android_MethodTest_jniFloatMethodTakesOneFloat(JNIEnv* env, - jclass, - jobject object, - jfloat i) { + jclass, + jobject object, + jfloat i) { LocalObject rjni_test_helper{object}; - return rjni_test_helper("floatMethodTakesOneFloat", jfloat{i}); + return rjni_test_helper.Call<"floatMethodTakesOneFloat">(jfloat{i}); } JNIEXPORT jfloat JNICALL @@ -195,24 +192,22 @@ Java_com_jnibind_android_MethodTest_jniFloatMethodTakesFiveFloats( JNIEnv* env, jclass, jobject object, jfloat i1, jfloat i2, jfloat i3, jfloat i4, jfloat i5) { LocalObject rjni_test_helper{object}; - return rjni_test_helper("floatMethodTakesFiveFloats", jfloat{i1}, jfloat{i2}, - jfloat{i3}, jfloat{i4}, jfloat{i5}); + return rjni_test_helper.Call<"floatMethodTakesFiveFloats">( + jfloat{i1}, jfloat{i2}, jfloat{i3}, jfloat{i4}, jfloat{i5}); } /** Double Method Tests. */ JNIEXPORT jdouble JNICALL Java_com_jnibind_android_MethodTest_jniDoubleMethod( JNIEnv* env, jclass, jobject object) { LocalObject rjni_test_helper{object}; - return rjni_test_helper("doubleMethod"); + return rjni_test_helper.Call<"doubleMethod">(); } JNIEXPORT jdouble JNICALL -Java_com_jnibind_android_MethodTest_jniDoubleMethodTakesOneDouble(JNIEnv* env, - jclass, - jobject object, - jdouble i) { +Java_com_jnibind_android_MethodTest_jniDoubleMethodTakesOneDouble( + JNIEnv* env, jclass, jobject object, jdouble i) { LocalObject rjni_test_helper{object}; - return rjni_test_helper("doubleMethodTakesOneDouble", jdouble{i}); + return rjni_test_helper.Call<"doubleMethodTakesOneDouble">(jdouble{i}); } JNIEXPORT jdouble JNICALL @@ -220,27 +215,27 @@ Java_com_jnibind_android_MethodTest_jniDoubleMethodTakesFiveDoubles( JNIEnv* env, jclass, jobject object, jdouble i1, jdouble i2, jdouble i3, jdouble i4, jdouble i5) { LocalObject rjni_test_helper{object}; - return rjni_test_helper("doubleMethodTakesFiveDoubles", jdouble{i1}, - jdouble{i2}, jdouble{i3}, jdouble{i4}, jdouble{i5}); + return rjni_test_helper.Call<"doubleMethodTakesFiveDoubles">( + jdouble{i1}, jdouble{i2}, jdouble{i3}, jdouble{i4}, jdouble{i5}); } /** Overload Method Tests. */ JNIEXPORT int JNICALL Java_com_jnibind_android_MethodTest_jniCallFooOverload1( JNIEnv* env, jclass, jobject object) { LocalObject rjni_test_helper{object}; - return rjni_test_helper("foo"); + return rjni_test_helper.Call<"foo">(); } JNIEXPORT int JNICALL Java_com_jnibind_android_MethodTest_jniCallFooOverload2( JNIEnv* env, jclass, jobject object) { LocalObject rjni_test_helper{object}; - return rjni_test_helper("foo", 123.f); + return rjni_test_helper.Call<"foo">(123.f); } JNIEXPORT int JNICALL Java_com_jnibind_android_MethodTest_jniCallFooOverload3( JNIEnv* env, jclass, jobject object) { LocalObject rjni_test_helper{object}; - return rjni_test_helper("foo", 123.f, 456.f); + return rjni_test_helper.Call<"foo">(123.f, 456.f); } } // extern "C" diff --git a/javatests/com/jnibind/android/string_test_jni.cc b/javatests/com/jnibind/android/string_test_jni.cc index b75ae007..e440eed2 100644 --- a/javatests/com/jnibind/android/string_test_jni.cc +++ b/javatests/com/jnibind/android/string_test_jni.cc @@ -51,9 +51,10 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* pjvm, void* reserved) { /** Void return type tests. */ JNIEXPORT void JNICALL -Java_com_jnibind_android_StringTest_jniVoidMethodTakesString(JNIEnv* env, jclass, - jobject object, - jstring string) { +Java_com_jnibind_android_StringTest_jniVoidMethodTakesString(JNIEnv* env, + jclass, + jobject object, + jstring string) { LocalObject r_jni_string_test_helper{object}; // TODO(b/175083373): The following (and below) should compile with overload // sets. @@ -62,17 +63,17 @@ Java_com_jnibind_android_StringTest_jniVoidMethodTakesString(JNIEnv* env, jclass r_jni_string_test_helper.GetMethod("voidMethodTakesString", std::string{LocalString{string}.Pin().ToString()}); */ - r_jni_string_test_helper("voidMethodTakesString", - std::string{LocalString{string}.Pin().ToString()}); + r_jni_string_test_helper.Call<"voidMethodTakesString">( + std::string{LocalString{string}.Pin().ToString()}); } JNIEXPORT void JNICALL Java_com_jnibind_android_StringTest_jniVoidMethodTakesTwoStrings( JNIEnv* env, jclass, jobject object, jstring s1, jstring s2) { LocalObject r_jni_string_test_helper{object}; - r_jni_string_test_helper("voidMethodTakesTwoStrings", - std::string{LocalString{s1}.Pin().ToString()}, - std::string{LocalString{s2}.Pin().ToString()}); + r_jni_string_test_helper.Call<"voidMethodTakesTwoStrings">( + std::string{LocalString{s1}.Pin().ToString()}, + std::string{LocalString{s2}.Pin().ToString()}); } JNIEXPORT void JNICALL @@ -80,26 +81,26 @@ Java_com_jnibind_android_StringTest_jniVoidMethodTakesFiveStrings( JNIEnv* env, jclass, jobject object, jstring s1, jstring s2, jstring s3, jstring s4, jstring s5) { LocalObject r_jni_string_test_helper{object}; - r_jni_string_test_helper("voidMethodTakesFiveStrings", - std::string{LocalString{s1}.Pin().ToString()}, - std::string{LocalString{s2}.Pin().ToString()}, - std::string{LocalString{s3}.Pin().ToString()}, - std::string{LocalString{s4}.Pin().ToString()}, - std::string{LocalString{s5}.Pin().ToString()}); + r_jni_string_test_helper.Call<"voidMethodTakesFiveStrings">( + std::string{LocalString{s1}.Pin().ToString()}, + std::string{LocalString{s2}.Pin().ToString()}, + std::string{LocalString{s3}.Pin().ToString()}, + std::string{LocalString{s4}.Pin().ToString()}, + std::string{LocalString{s5}.Pin().ToString()}); } /** String return type tests. */ JNIEXPORT jstring JNICALL -Java_com_jnibind_android_StringTest_jniStringMethodTakesString(JNIEnv* env, jclass, - jobject object, - jstring string) { +Java_com_jnibind_android_StringTest_jniStringMethodTakesString(JNIEnv* env, + jclass, + jobject object, + jstring string) { LocalObject r_jni_string_test_helper{object}; - // TODO(b/174272629): This declaration is clumsy because Return is - // an ObjectRef and thus not implicitly convertible to jstring. The following - // needs to be simpler to express. - return LocalString{r_jni_string_test_helper( - "stringMethodTakesString", + // TODO(b/174272629): This declaration is clumsy because Return + // is an ObjectRef and thus not implicitly convertible to jstring. The + // following needs to be simpler to express. + return LocalString{r_jni_string_test_helper.Call<"stringMethodTakesString">( std::string{LocalString{string}.Pin().ToString()})} .Release(); } @@ -109,9 +110,9 @@ Java_com_jnibind_android_StringTest_jniStringMethodTakesTwoStrings( JNIEnv* env, jclass, jobject object, jstring s1, jstring s2) { LocalObject r_jni_string_test_helper{object}; return LocalString{ - r_jni_string_test_helper("stringMethodTakesTwoStrings", - std::string{LocalString{s1}.Pin().ToString()}, - std::string{LocalString{s2}.Pin().ToString()})} + r_jni_string_test_helper.Call<"stringMethodTakesTwoStrings">( + std::string{LocalString{s1}.Pin().ToString()}, + std::string{LocalString{s2}.Pin().ToString()})} .Release(); } @@ -121,12 +122,12 @@ Java_com_jnibind_android_StringTest_jniStringMethodTakesFiveStrings( jstring s4, jstring s5) { LocalObject r_jni_string_test_helper{object}; return LocalString{ - r_jni_string_test_helper("stringMethodTakesFiveStrings", - std::string{LocalString{s1}.Pin().ToString()}, - std::string{LocalString{s2}.Pin().ToString()}, - std::string{LocalString{s3}.Pin().ToString()}, - std::string{LocalString{s4}.Pin().ToString()}, - std::string{LocalString{s5}.Pin().ToString()})} + r_jni_string_test_helper.Call<"stringMethodTakesFiveStrings">( + std::string{LocalString{s1}.Pin().ToString()}, + std::string{LocalString{s2}.Pin().ToString()}, + std::string{LocalString{s3}.Pin().ToString()}, + std::string{LocalString{s4}.Pin().ToString()}, + std::string{LocalString{s5}.Pin().ToString()})} .Release(); } diff --git a/javatests/com/jnibind/android/thread_test_jni.cc b/javatests/com/jnibind/android/thread_test_jni.cc index 992db5ba..305d07e0 100644 --- a/javatests/com/jnibind/android/thread_test_jni.cc +++ b/javatests/com/jnibind/android/thread_test_jni.cc @@ -62,7 +62,7 @@ Java_com_jnibind_android_ThreadTest_runsThreadedWorkOnObject(JNIEnv* env, ThreadGuard thread_guard{}; // This will crash without fallback loader (`jclass` will be unknown). - fixture["objectTestHelper"].Get()("foo"); + fixture.Access<"objectTestHelper">().Get().Call<"foo">(); }}; worker.join(); diff --git a/javatests/com/jnibind/test/BUILD b/javatests/com/jnibind/test/BUILD index 8af8d7f6..1f95abc6 100644 --- a/javatests/com/jnibind/test/BUILD +++ b/javatests/com/jnibind/test/BUILD @@ -53,6 +53,7 @@ cc_library( ":object_test_helper_jni", "//:jni_bind", "//metaprogramming:lambda_string", + "//metaprogramming:string_literal", ], alwayslink = True, ) diff --git a/javatests/com/jnibind/test/array_test_field_rank_1_jni.cc b/javatests/com/jnibind/test/array_test_field_rank_1_jni.cc index 21abf4c9..8bc52f48 100644 --- a/javatests/com/jnibind/test/array_test_field_rank_1_jni.cc +++ b/javatests/com/jnibind/test/array_test_field_rank_1_jni.cc @@ -33,6 +33,7 @@ using ::jni::LocalArray; using ::jni::LocalObject; using ::jni::LocalString; using ::jni::StaticRef; +using ::jni::metaprogramming::StringLiteral; static std::unique_ptr> jvm; @@ -58,17 +59,14 @@ static constexpr Class kArrayTestFieldRank1 { // Generic field test suitable for simple primitive types. // Strings are passed through lambdas as field indexing is compile time. -template +template void GenericFieldTest(LocalObject fixture, - SpanType max_val, SpanType base, SpanType stride, - FieldNameLambda field_name_lambda, - MethodNameLambda method_name_lambda) { + SpanType max_val, SpanType base, SpanType stride) { // Field starts in default state. - LocalArray arr{fixture[field_name_lambda()].Get()}; - StaticRef{}(method_name_lambda(), SpanType{0}, - SpanType{0}, - fixture[field_name_lambda()].Get()); + LocalArray arr{fixture.Access().Get()}; + StaticRef{}.Call( + SpanType{0}, SpanType{0}, fixture.Access().Get()); // Updating the field manually works. { @@ -78,9 +76,8 @@ void GenericFieldTest(LocalObject fixture, } } - StaticRef{}(method_name_lambda(), SpanType{0}, - SpanType{1}, - fixture[field_name_lambda()].Get()); + StaticRef{}.Call( + SpanType{0}, SpanType{1}, fixture.Access().Get()); // Updating the field repeatedly works. { @@ -89,13 +86,15 @@ void GenericFieldTest(LocalObject fixture, pin.ptr()[i] = base + static_cast(stride * i); } } - StaticRef{}(method_name_lambda(), base, stride, - fixture[field_name_lambda()].Get()); + StaticRef{}.Call( + base, stride, fixture.Access().Get()); // Not pinning the value has no effect. - { std::memset(arr.Pin(false).ptr(), 0, arr.Length() * sizeof(SpanType)); } - StaticRef{}(method_name_lambda(), base, stride, - fixture[field_name_lambda()].Get()); + { + std::memset(arr.Pin(false).ptr(), 0, arr.Length() * sizeof(SpanType)); + } + StaticRef{}.Call( + base, stride, fixture.Access().Get()); } extern "C" { @@ -113,64 +112,64 @@ JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestFieldRank1_jniTearDown( JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestFieldRank1_nativeBooleanTests( JNIEnv* env, jclass, jobject test_fixture) { - GenericFieldTest(LocalObject{test_fixture}, - jboolean{true}, jboolean{0}, jboolean{true}, - STR("booleanArrayField"), STR("assertBoolean1D")); + GenericFieldTest( + LocalObject{test_fixture}, jboolean{true}, + jboolean{0}, jboolean{true}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestFieldRank1_nativeByteTests( JNIEnv* env, jclass, jobject test_fixture) { - GenericFieldTest(LocalObject{test_fixture}, - std::numeric_limits::max(), jbyte{10}, jbyte{1}, - STR("byteArrayField"), STR("assertByte1D")); + GenericFieldTest( + LocalObject{test_fixture}, + std::numeric_limits::max(), jbyte{10}, jbyte{1}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestFieldRank1_nativeCharTests( JNIEnv* env, jclass, jobject test_fixture) { - GenericFieldTest(LocalObject{test_fixture}, - std::numeric_limits::max(), jchar{10}, jchar{1}, - STR("charArrayField"), STR("assertChar1D")); + GenericFieldTest( + LocalObject{test_fixture}, + std::numeric_limits::max(), jchar{10}, jchar{1}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestFieldRank1_nativeShortTests( JNIEnv* env, jclass, jobject test_fixture) { - GenericFieldTest(LocalObject{test_fixture}, - std::numeric_limits::max(), jshort{10}, jshort{1}, - STR("shortArrayField"), STR("assertShort1D")); + GenericFieldTest( + LocalObject{test_fixture}, + std::numeric_limits::max(), jshort{10}, jshort{1}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestFieldRank1_nativeIntTests( JNIEnv* env, jclass, jobject test_fixture) { - GenericFieldTest(LocalObject{test_fixture}, - std::numeric_limits::max(), jint{10}, jint{1}, - STR("intArrayField"), STR("assertInt1D")); + GenericFieldTest( + LocalObject{test_fixture}, + std::numeric_limits::max(), jint{10}, jint{1}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestFieldRank1_nativeLongTests( JNIEnv* env, jclass, jobject test_fixture) { - GenericFieldTest(LocalObject{test_fixture}, - std::numeric_limits::max(), jlong{10}, jlong{1}, - STR("longArrayField"), STR("assertLong1D")); + GenericFieldTest( + LocalObject{test_fixture}, + std::numeric_limits::max(), jlong{10}, jlong{1}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestFieldRank1_nativeFloatTests( JNIEnv* env, jclass, jobject test_fixture) { - GenericFieldTest(LocalObject{test_fixture}, - std::numeric_limits::max(), jfloat{10.f}, - jfloat{1.f}, STR("floatArrayField"), STR("assertFloat1D")); + GenericFieldTest( + LocalObject{test_fixture}, + std::numeric_limits::max(), jfloat{10.f}, jfloat{1.f}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestFieldRank1_nativeDoubleTests( JNIEnv* env, jclass, jobject test_fixture) { - GenericFieldTest(LocalObject{test_fixture}, - std::numeric_limits::max(), jdouble{10}, jdouble{1}, - STR("doubleArrayField"), STR("assertDouble1D")); + GenericFieldTest( + LocalObject{test_fixture}, + std::numeric_limits::max(), jdouble{10}, jdouble{1}); } JNIEXPORT void JNICALL @@ -179,41 +178,43 @@ Java_com_jnibind_test_ArrayTestFieldRank1_nativeStringTests( LocalObject fixture{test_fixture}; // Field starts in default state. - StaticRef{}( - "assertString1D", fixture["stringArrayField"].Get(), jboolean{false}); + StaticRef{}.Call<"assertString1D">( + fixture.Access<"stringArrayField">().Get(), jboolean{false}); // Updating the field manually works. - LocalArray arr = fixture["stringArrayField"].Get(); + LocalArray arr = fixture.Access<"stringArrayField">().Get(); arr.Set(0, LocalString{"Foo"}); arr.Set(1, LocalString{"Baz"}); arr.Set(2, LocalString{"Bar"}); - StaticRef{}("assertString1D", arr, true); + StaticRef{}.Call<"assertString1D">(arr, true); // Updating the field repeatedly works. arr.Set(0, LocalString{"FAKE"}); arr.Set(1, LocalString{"DEAD"}); arr.Set(2, LocalString{"BEEF"}); - StaticRef{}("assertString1D", arr, false); + StaticRef{}.Call<"assertString1D">(arr, false); // Updating the field repeatedly works. arr.Set(0, "Foo"); const char* kBaz = "Baz"; arr.Set(1, kBaz); arr.Set(2, std::string{"Bar"}); - StaticRef{}("assertString1D", arr, true); + StaticRef{}.Call<"assertString1D">(arr, true); // Iterating over values works. static constexpr std::array vals{"Foo", "Baz", "Bar"}; int i = 0; for (LocalString local_string : arr.Pin()) { - StaticRef{}("assertString", local_string, vals[i]); + StaticRef{}.Call<"assertString">(local_string, + vals[i]); ++i; } // Iterating over passed values works. i = 0; for (LocalString local_string : LocalArray{object_array}.Pin()) { - StaticRef{}("assertString", local_string, vals[i]); + StaticRef{}.Call<"assertString">(local_string, + vals[i]); ++i; } } @@ -223,12 +224,12 @@ Java_com_jnibind_test_ArrayTestFieldRank1_nativeObjectTests( JNIEnv* env, jclass, jobject test_fixture, jobjectArray) { LocalObject fixture{test_fixture}; LocalArray arr = - fixture["objectArrayField"].Get(); + fixture.Access<"objectArrayField">().Get(); int i = 0; for (LocalObject new_obj : - fixture["objectArrayField"].Get().Pin()) { - StaticRef{}("assertObject", i, new_obj); + fixture.Access<"objectArrayField">().Get().Pin()) { + StaticRef{}.Call<"assertObject">(i, new_obj); i++; } } diff --git a/javatests/com/jnibind/test/array_test_field_rank_2_jni.cc b/javatests/com/jnibind/test/array_test_field_rank_2_jni.cc index a645e6ef..db4c6f1a 100644 --- a/javatests/com/jnibind/test/array_test_field_rank_2_jni.cc +++ b/javatests/com/jnibind/test/array_test_field_rank_2_jni.cc @@ -23,6 +23,7 @@ #include "object_test_helper_jni.h" #include "jni_bind.h" #include "metaprogramming/lambda_string.h" +#include "metaprogramming/string_literal.h" using ::jni::Array; using ::jni::ArrayView; @@ -33,6 +34,7 @@ using ::jni::LocalObject; using ::jni::Modulo; using ::jni::Rank; using ::jni::StaticRef; +using ::jni::metaprogramming::StringLiteral; static std::unique_ptr> jvm; @@ -58,18 +60,15 @@ static constexpr Class kArrayTestFieldRank2 { // Generic field test suitable for simple primitive types. // Strings are passed through lambdas as field indexing is compile time. -template +template void GenericFieldTest(LocalObject fixture, - SpanType max_val, SpanType base, SpanType stride, - FieldNameLambda field_name_lambda, - MethodNameLambda method_name_lambda) { - LocalArray arr{fixture[field_name_lambda()].Get()}; + SpanType max_val, SpanType base, SpanType stride) { + LocalArray arr{fixture.Access().Get()}; // Field starts in default state. - StaticRef{}(method_name_lambda(), SpanType{0}, - SpanType{0}, - fixture[field_name_lambda()].Get()); + StaticRef{}.Call( + SpanType{0}, SpanType{0}, fixture.Access().Get()); // Updating the field manually works. { @@ -82,8 +81,8 @@ void GenericFieldTest(LocalObject fixture, } } - StaticRef{}(method_name_lambda(), base, SpanType{1}, - fixture[field_name_lambda()].Get()); + StaticRef{}.Call( + base, SpanType{1}, fixture.Access().Get()); } // Updating the field repeatedly works. @@ -101,8 +100,8 @@ void GenericFieldTest(LocalObject fixture, } } } - StaticRef{}(method_name_lambda(), base, stride, - fixture[field_name_lambda()].Get()); + StaticRef{}.Call( + base, stride, fixture.Access().Get()); } } @@ -113,8 +112,8 @@ void GenericFieldTest(LocalObject fixture, arr_rank_1.Length() * sizeof(SpanType)); } } - StaticRef{}(method_name_lambda(), base, stride, - fixture[field_name_lambda()].Get()); + StaticRef{}.Call( + base, stride, fixture.Access().Get()); } extern "C" { @@ -132,68 +131,68 @@ JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestFieldRank2_jniTearDown( JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestFieldRank2_nativeBooleanTests( JNIEnv* env, jclass, jobject test_fixture) { - GenericFieldTest(LocalObject{test_fixture}, jboolean{2}, - jboolean{0}, jboolean{1}, STR("booleanArrayField"), - STR("assertBoolean2D")); + GenericFieldTest( + LocalObject{test_fixture}, jboolean{2}, jboolean{0}, + jboolean{1}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestFieldRank2_nativeByteTests( JNIEnv* env, jclass, jobject test_fixture) { - GenericFieldTest(LocalObject{test_fixture}, - std::numeric_limits::max(), jbyte{10}, jbyte{2}, - STR("byteArrayField"), STR("assertByte2D")); + GenericFieldTest( + LocalObject{test_fixture}, + std::numeric_limits::max(), jbyte{10}, jbyte{2}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestFieldRank2_nativeCharTests( JNIEnv* env, jclass, jobject test_fixture) { - GenericFieldTest(LocalObject{test_fixture}, - std::numeric_limits::max(), jchar{0}, jchar{1}, - STR("charArrayField"), STR("assertChar2D")); + GenericFieldTest( + LocalObject{test_fixture}, + std::numeric_limits::max(), jchar{0}, jchar{1}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestFieldRank2_nativeShortTests( JNIEnv* env, jclass, jobject test_fixture) { - GenericFieldTest(LocalObject{test_fixture}, - std::numeric_limits::max(), jshort{0}, jshort{1}, - STR("shortArrayField"), STR("assertShort2D")); + GenericFieldTest( + LocalObject{test_fixture}, + std::numeric_limits::max(), jshort{0}, jshort{1}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestFieldRank2_nativeIntTests( JNIEnv* env, jclass, jobject test_fixture) { - GenericFieldTest(LocalObject{test_fixture}, - std::numeric_limits::max(), jint{0}, jint{1}, - STR("intArrayField"), STR("assertInt2D")); + GenericFieldTest( + LocalObject{test_fixture}, + std::numeric_limits::max(), jint{0}, jint{1}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestFieldRank2_nativeLongTests( JNIEnv* env, jclass, jobject test_fixture) { - GenericFieldTest(LocalObject{test_fixture}, - std::numeric_limits::max(), jlong{0}, jlong{1}, - STR("longArrayField"), STR("assertLong2D")); + GenericFieldTest( + LocalObject{test_fixture}, + std::numeric_limits::max(), jlong{0}, jlong{1}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestFieldRank2_nativeFloatTests( JNIEnv* env, jclass, jobject test_fixture) { - GenericFieldTest(LocalObject{test_fixture}, - std::numeric_limits::max(), jfloat{0.f}, jfloat{1.f}, - STR("floatArrayField"), STR("assertFloat2D")); + GenericFieldTest( + LocalObject{test_fixture}, + std::numeric_limits::max(), jfloat{0.f}, jfloat{1.f}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestFieldRank2_nativeDoubleTests( JNIEnv* env, jclass, jobject test_fixture) { - GenericFieldTest(LocalObject{test_fixture}, - std::numeric_limits::max(), jdouble{0}, jdouble{1}, - STR("doubleArrayField"), STR("assertDouble2D")); + GenericFieldTest( + LocalObject{test_fixture}, + std::numeric_limits::max(), jdouble{0}, jdouble{1}); } // TODO(b/143908983): This is broken, but using regular `jobject` works, -// so there is still an alternative path to be take. +// so there is still an alternative path to be taken. JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestFieldRank2_nativeStringTests( JNIEnv* env, jclass, jobject test_fixture) { @@ -202,40 +201,43 @@ Java_com_jnibind_test_ArrayTestFieldRank2_nativeStringTests( // Field starts in default state. StaticRef{}( - "assertString1D", fixture["stringArrayField"].Get(), jboolean{false}); + "assertString1D", fixture.Access<"stringArrayField">().Get(), + jboolean{false}); // Updating the field manually works. - LocalArray arr = fixture["stringArrayField"].Get(); + LocalArray arr = fixture.Access<"stringArrayField">().Get(); arr.Set(0, LocalString{"Foo"}); arr.Set(1, LocalString{"Baz"}); arr.Set(2, LocalString{"Bar"}); - StaticRef{}("assertString1D", arr, true); + StaticRef{}.Call<"assertString1D">( arr, true); // Updating the field repeatedly works. arr.Set(0, LocalString{"FAKE"}); arr.Set(1, LocalString{"DEAD"}); arr.Set(2, LocalString{"BEEF"}); - StaticRef{}("assertString1D", arr, false); + StaticRef{}.Call<"assertString1D">( arr, false); // Updating the field repeatedly works. arr.Set(0, "Foo"); const char* kBaz = "Baz"; arr.Set(1, kBaz); arr.Set(2, std::string{"Bar"}); - StaticRef{}("assertString1D", arr, true); + StaticRef{}.Call<"assertString1D">( arr, true); // Iterating over values works. static constexpr std::array vals{"Foo", "Baz", "Bar"}; int i = 0; for (LocalString local_string : arr.Pin()) { - StaticRef{}("assertString", local_string, vals[i]); + StaticRef{}.Call<"assertString">( local_string, + vals[i]); ++i; } // Iterating over passed values works. i = 0; for (LocalString local_string : LocalArray{object_array}.Pin()) { - StaticRef{}("assertString", local_string, vals[i]); + StaticRef{}.Call<"assertString">( local_string, + vals[i]); ++i; } */ @@ -245,29 +247,29 @@ void Java_com_jnibind_test_ArrayTestFieldRank2_nativeObjectTests( JNIEnv* env, jclass, jobject test_fixture) { LocalObject fixture{test_fixture}; LocalArray arr = - fixture["objectArrayField"].Get(); + fixture.Access<"objectArrayField">().Get(); int i = 0; { for (LocalArray arr_rank_1 : arr.Pin()) { for (LocalObject obj : arr_rank_1.Pin()) { - obj["intVal1"].Set(i); + obj.Access<"intVal1">().Set(i); i++; - obj["intVal2"].Set(i); + obj.Access<"intVal2">().Set(i); i++; - obj["intVal3"].Set(i); + obj.Access<"intVal3">().Set(i); i++; } } } // Object on fixture is already updated. - StaticRef{}("assertObject2D", 0, 1, - fixture["objectArrayField"].Get()); + StaticRef{}.Call<"assertObject2D">( + 0, 1, fixture.Access<"objectArrayField">().Get()); // But using local reference works too. - StaticRef{}("assertObject2D", 0, 1, arr); + StaticRef{}.Call<"assertObject2D">(0, 1, arr); } } // extern "C" diff --git a/javatests/com/jnibind/test/array_test_method_rank_1_jni.cc b/javatests/com/jnibind/test/array_test_method_rank_1_jni.cc index 42d85212..db6e8354 100644 --- a/javatests/com/jnibind/test/array_test_method_rank_1_jni.cc +++ b/javatests/com/jnibind/test/array_test_method_rank_1_jni.cc @@ -21,7 +21,6 @@ #include "array_test_helpers_native.h" #include "object_test_helper_jni.h" #include "jni_bind.h" -#include "metaprogramming/lambda_string.h" using ::jni::ArrayView; using ::jni::LocalArray; @@ -29,21 +28,21 @@ using ::jni::LocalObject; using ::jni::LocalString; using ::jni::RegularToArrayTypeMap_t; using ::jni::StaticRef; +using ::jni::metaprogramming::StringLiteral; static std::unique_ptr> jvm; // Generic method test suitable for simple primitive types. // Strings are passed through lambdas as method indexing is compile time. -template -void GenericMethodTest(LocalArray local_arr, SpanType base, - MethodNameLambda method_name_lambda) { +template +void GenericMethodTest(LocalArray local_arr, SpanType base) { // Simple lvalue pass through works as expected. - StaticRef{}(method_name_lambda(), base, SpanType{1}, - local_arr); + StaticRef{}.Call( + base, SpanType{1}, local_arr); // Simple rvalue pass through works as expected. - StaticRef{}(method_name_lambda(), base, SpanType{1}, - std::move(local_arr)); + StaticRef{}.Call( + base, SpanType{1}, std::move(local_arr)); // Building a new array, and setting all the values by hand works. LocalArray new_array{8}; @@ -53,8 +52,8 @@ void GenericMethodTest(LocalArray local_arr, SpanType base, array_view.ptr()[i] = base + static_cast(i); } } - StaticRef{}(method_name_lambda(), base, SpanType{1}, - new_array); + StaticRef{}.Call( + base, SpanType{1}, new_array); // You can pull the view multiple times. { @@ -72,8 +71,8 @@ void GenericMethodTest(LocalArray local_arr, SpanType base, val = base + i; i++; } - StaticRef{}(method_name_lambda(), base, SpanType{1}, - new_array); + StaticRef{}.Call( + base, SpanType{1}, new_array); // You can build an array of null values and set the values manually. LocalArray arr_built_from_null{5}; @@ -84,8 +83,8 @@ void GenericMethodTest(LocalArray local_arr, SpanType base, val = base + j; j++; } - StaticRef{}(method_name_lambda(), base, SpanType{1}, - new_array); + StaticRef{}.Call( + base, SpanType{1}, new_array); } extern "C" { @@ -103,57 +102,57 @@ JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestMethodRank1_jniTearDown( JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestMethodRank1_nativeBooleanTests( JNIEnv* env, jclass, jbooleanArray boolean_array) { - GenericMethodTest(LocalArray{boolean_array}, jboolean{true}, - STR("assertBoolean1D")); + GenericMethodTest( + LocalArray{boolean_array}, jboolean{true}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestMethodRank1_nativeByteTests( JNIEnv* env, jclass, jbyteArray byte_array) { - GenericMethodTest(LocalArray{byte_array}, jbyte{0}, - STR("assertByte1D")); + GenericMethodTest(LocalArray{byte_array}, + jbyte{0}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestMethodRank1_nativeCharTests( JNIEnv* env, jclass, jcharArray char_array) { - GenericMethodTest(LocalArray{char_array}, jchar{0}, - STR("assertChar1D")); + GenericMethodTest(LocalArray{char_array}, + jchar{0}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestMethodRank1_nativeShortTests( JNIEnv* env, jclass, jshortArray short_array) { - GenericMethodTest(LocalArray{short_array}, jshort{0}, - STR("assertShort1D")); + GenericMethodTest(LocalArray{short_array}, + jshort{0}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestMethodRank1_nativeIntTests(JNIEnv* env, jclass, jintArray int_array) { - GenericMethodTest(LocalArray{int_array}, jint{0}, STR("assertInt1D")); + GenericMethodTest(LocalArray{int_array}, jint{0}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestMethodRank1_nativeLongTests( JNIEnv* env, jclass, jlongArray long_array) { - GenericMethodTest(LocalArray{long_array}, jlong{0}, - STR("assertLong1D")); + GenericMethodTest(LocalArray{long_array}, + jlong{0}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestMethodRank1_nativeFloatTests( JNIEnv* env, jclass, jfloatArray float_array) { - GenericMethodTest(LocalArray{float_array}, jfloat{0}, - STR("assertFloat1D")); + GenericMethodTest(LocalArray{float_array}, + jfloat{0}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestMethodRank1_nativeDoubleTests( JNIEnv* env, jclass, jdoubleArray double_array) { - GenericMethodTest(LocalArray{double_array}, jdouble{0}, - STR("assertDouble1D")); + GenericMethodTest( + LocalArray{double_array}, jdouble{0}); } JNIEXPORT void JNICALL @@ -161,7 +160,7 @@ Java_com_jnibind_test_ArrayTestMethodRank1_nativeStringTests( JNIEnv* env, jclass, jobjectArray object_array) { // Simple lvalue pass through works as expected. LocalArray local_arr{object_array}; - StaticRef{}("assertString1D", local_arr, true); + StaticRef{}.Call<"assertString1D">(local_arr, true); // TODO(b/143908983): Currently not possible to write. // Simple rvalue pass through works as expected. @@ -177,7 +176,7 @@ Java_com_jnibind_test_ArrayTestMethodRank1_nativeStringTests( new_array.Set(0, LocalString{"Foo"}); new_array.Set(1, LocalString{"Baz"}); new_array.Set(2, LocalString{"Bar"}); - StaticRef{}("assertString1D", new_array, true); + StaticRef{}.Call<"assertString1D">(new_array, true); // And it can be iterated over. std::size_t i = 0; @@ -187,7 +186,8 @@ Java_com_jnibind_test_ArrayTestMethodRank1_nativeStringTests( i++; } - StaticRef{}("assertString1D", validator_array, true); + StaticRef{}.Call<"assertString1D">(validator_array, + true); } JNIEXPORT void JNICALL @@ -195,18 +195,17 @@ Java_com_jnibind_test_ArrayTestMethodRank1_nativeObjectTests( JNIEnv* env, jclass, jobjectArray object_array) { // Creating arrays of nulls with just size works. LocalArray local_arr_nulls{5}; - StaticRef{}("assertObjectArrayOfNulls1D", - local_arr_nulls); + StaticRef{}.Call<"assertObjectArrayOfNulls1D">( + local_arr_nulls); // Simple lvalue pass through works as expected. LocalArray local_arr{object_array}; - StaticRef{}("assertObject1D", 0, local_arr); + StaticRef{}.Call<"assertObject1D">(0, local_arr); // Simple rvalue pass through works as expected. - StaticRef{}( - "assertObject1D", 5, - LocalArray{ - 1, LocalObject{5, 5, 5}}); + StaticRef{}.Call<"assertObject1D">( + 5, LocalArray{ + 1, LocalObject{5, 5, 5}}); // Building a new array, and setting all the values by hand works. LocalObject obj{0, 0, 0}; @@ -217,14 +216,14 @@ Java_com_jnibind_test_ArrayTestMethodRank1_nativeObjectTests( i, LocalObject{jint{i}, jint{i}, jint{i}}); } } - StaticRef{}("assertObject1D", 0, new_array); + StaticRef{}.Call<"assertObject1D">(0, new_array); // You can pull the view multiple times. { for (int i = 0; i < new_array.Length(); ++i) { - new_array.Set(i, - LocalObject{2, 2, 2}( - "returnNewObjectWithFieldSetToSum", new_array.Get(i))); + new_array.Set( + i, LocalObject{2, 2, 2} + .Call<"returnNewObjectWithFieldSetToSum">(new_array.Get(i))); } } @@ -233,12 +232,12 @@ Java_com_jnibind_test_ArrayTestMethodRank1_nativeObjectTests( // is being iterated over, and upcast to a LocalObject. // Also note: Pin is not to contiguous memory, so no copyback bool either. for (LocalObject val : new_array.Pin()) { - val["intVal1"].Set(val["intVal1"].Get() + 3); - val["intVal2"].Set(val["intVal2"].Get() + 3); - val["intVal3"].Set(val["intVal3"].Get() + 3); + val.Access<"intVal1">().Set(val.Access<"intVal1">().Get() + 3); + val.Access<"intVal2">().Set(val.Access<"intVal2">().Get() + 3); + val.Access<"intVal3">().Set(val.Access<"intVal3">().Get() + 3); } - StaticRef{}("assertObject1D", 2 + 3, new_array); + StaticRef{}.Call<"assertObject1D">(2 + 3, new_array); } } // extern "C" diff --git a/javatests/com/jnibind/test/array_test_method_rank_2_jni.cc b/javatests/com/jnibind/test/array_test_method_rank_2_jni.cc index 6de4baa4..40d535f8 100644 --- a/javatests/com/jnibind/test/array_test_method_rank_2_jni.cc +++ b/javatests/com/jnibind/test/array_test_method_rank_2_jni.cc @@ -22,29 +22,29 @@ #include "modulo.h" #include "javatests/com/jnibind/test/object_test_helper_jni.h" #include "jni_bind.h" -#include "metaprogramming/lambda_string.h" using ::jni::LocalArray; using ::jni::LocalObject; using ::jni::Modulo; using ::jni::RegularToArrayTypeMap_t; using ::jni::StaticRef; +using ::jni::metaprogramming::StringLiteral; static std::unique_ptr> jvm; // Generic method test suitable for simple primitive types. // Strings are passed through lambdas as method indexing is compile time. -template +template void GenericMethodTest( - MethodNameLambda method_name_lambda, LocalArray arr, + LocalArray arr, SpanType max_val = std::numeric_limits::max()) { // Simple lvalue pass through works as expected. - StaticRef{}(method_name_lambda(), SpanType{0}, - SpanType{1}, arr); + StaticRef{}.Call( + SpanType{0}, SpanType{1}, arr); // Simple rvalue pass through works as expected. - StaticRef{}(method_name_lambda(), SpanType{0}, - SpanType{1}, std::move(arr)); + StaticRef{}.Call( + SpanType{0}, SpanType{1}, std::move(arr)); // Building a new array, and setting all the values by hand works. LocalArray new_array{3}; @@ -69,8 +69,8 @@ void GenericMethodTest( new_array.Set(1, row2); new_array.Set(2, row3); - StaticRef{}(method_name_lambda(), SpanType{0}, - SpanType{1}, new_array); + StaticRef{}.Call( + SpanType{0}, SpanType{1}, new_array); } // You can pull the view multiple times with iterators (each value ticked 1). @@ -80,8 +80,8 @@ void GenericMethodTest( val = Modulo(1, val, max_val); } } - StaticRef{}(method_name_lambda(), SpanType{1}, - SpanType{1}, new_array); + StaticRef{}.Call( + SpanType{1}, SpanType{1}, new_array); } // You can pull the view multiple times with raw loops. @@ -98,8 +98,8 @@ void GenericMethodTest( } // Each variant increments base by 1, so 2 is used here. - StaticRef{}( - method_name_lambda(), Modulo(2, {0}, max_val), SpanType{1}, new_array); + StaticRef{}.Call( + Modulo(2, {0}, max_val), SpanType{1}, new_array); } extern "C" { @@ -118,53 +118,53 @@ JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestMethodRank2_nativeBooleanTests2D( JNIEnv*, jclass, jobjectArray arr) { // Boolean has a max of "2" which makes the generic moduloing logic work. - GenericMethodTest(STR("assertBoolean2D"), LocalArray{arr}, - jboolean{2}); + GenericMethodTest(LocalArray{arr}, + jboolean{2}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestMethodRank2_nativeByteTests2D(JNIEnv*, jclass, jobjectArray arr) { - GenericMethodTest(STR("assertByte2D"), LocalArray{arr}); + GenericMethodTest(LocalArray{arr}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestMethodRank2_nativeCharTests2D(JNIEnv*, jclass, jobjectArray arr) { - GenericMethodTest(STR("assertChar2D"), LocalArray{arr}); + GenericMethodTest(LocalArray{arr}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestMethodRank2_nativeShortTests2D( JNIEnv*, jclass, jobjectArray arr) { - GenericMethodTest(STR("assertShort2D"), LocalArray{arr}); + GenericMethodTest(LocalArray{arr}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestMethodRank2_nativeIntTests2D(JNIEnv*, jclass, jobjectArray arr) { - GenericMethodTest(STR("assertInt2D"), LocalArray{arr}); + GenericMethodTest(LocalArray{arr}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestMethodRank2_nativeLongTests2D(JNIEnv*, jclass, jobjectArray arr) { - GenericMethodTest(STR("assertLong2D"), LocalArray{arr}); + GenericMethodTest(LocalArray{arr}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestMethodRank2_nativeFloatTests2D( JNIEnv*, jclass, jobjectArray arr) { - GenericMethodTest(STR("assertFloat2D"), LocalArray{arr}); + GenericMethodTest(LocalArray{arr}); } JNIEXPORT void JNICALL Java_com_jnibind_test_ArrayTestMethodRank2_nativeDoubleTests2D( JNIEnv*, jclass, jobjectArray arr) { - GenericMethodTest(STR("assertDouble2D"), LocalArray{arr}); + GenericMethodTest(LocalArray{arr}); } JNIEXPORT void JNICALL @@ -172,10 +172,11 @@ Java_com_jnibind_test_ArrayTestMethodRank2_nativeObjectTests2D( JNIEnv* env, jclass, jobjectArray arr_jobjectArray) { // Simple lvalue pass through works as expected. LocalArray arr{arr_jobjectArray}; - StaticRef{}("assertObject2D", 0, 1, arr); + StaticRef{}.Call<"assertObject2D">(0, 1, arr); // Simple rvalue pass through works as expected. - StaticRef{}("assertObject2D", 0, 1, std::move(arr)); + StaticRef{}.Call<"assertObject2D">(0, 1, + std::move(arr)); // Building a new array, and setting all the values by hand works. LocalArray new_array{3, nullptr}; @@ -199,18 +200,18 @@ Java_com_jnibind_test_ArrayTestMethodRank2_nativeObjectTests2D( new_array.Set(1, row2); new_array.Set(2, row3); - StaticRef{}("assertObject2D", 0, 1, new_array); + StaticRef{}.Call<"assertObject2D">(0, 1, new_array); // You can pull the view multiple times with iterators (each value ticked 1). { int i = 0; for (LocalArray inner_array : new_array.Pin()) { for (LocalObject obj : inner_array.Pin()) { - obj["intVal1"].Set(i); + obj.Access<"intVal1">().Set(i); i++; - obj["intVal2"].Set(i); + obj.Access<"intVal2">().Set(i); i++; - obj["intVal3"].Set(i); + obj.Access<"intVal3">().Set(i); i++; } } @@ -222,13 +223,13 @@ Java_com_jnibind_test_ArrayTestMethodRank2_nativeObjectTests2D( for (int i = 0; i < new_array.Length(); ++i) { LocalArray inn_arr{new_array.Get(i)}; for (int j = 0; j < inn_arr.Length(); ++j) { - inn_arr.Get(j)("increment", 1); + inn_arr.Get(j).Call<"increment">(1); } } } // Each variant increments base by 1, so 2 is used here. - StaticRef{}("assertObject2D", 1, 1, new_array); + StaticRef{}.Call<"assertObject2D">(1, 1, new_array); } } // extern "C" diff --git a/javatests/com/jnibind/test/builder_jni.cc b/javatests/com/jnibind/test/builder_jni.cc index a5719432..5f927494 100644 --- a/javatests/com/jnibind/test/builder_jni.cc +++ b/javatests/com/jnibind/test/builder_jni.cc @@ -56,8 +56,11 @@ JNI_BIND_EXPORT jint JNI_BIND_CALL JNI_OnLoad(JavaVM* pjvm, void* reserved) { JNI_MTHD(void, nativeJniTeardown) { jvm = nullptr; } JNI_MTHD(jobject, useBuilderToCreateObject) { - return LocalObject{}("setOne", 111)("setTwo", 222)("setThree", - 333)("build") + return LocalObject{} + .Call<"setOne">(111) + .Call<"setTwo">(222) + .Call<"setThree">(333) + .Call<"build">() .Release(); } diff --git a/javatests/com/jnibind/test/context_test_jni.cc b/javatests/com/jnibind/test/context_test_jni.cc index 0786406c..54fb9366 100644 --- a/javatests/com/jnibind/test/context_test_jni.cc +++ b/javatests/com/jnibind/test/context_test_jni.cc @@ -55,7 +55,7 @@ JNIEXPORT void JNICALL Java_com_jnibind_test_ContextTest_DoSetup(JNIEnv* env, JNIEXPORT jlong JNICALL Java_com_jnibind_test_ContextTest_nativeCreateContext( JNIEnv* env, jclass, jint val) { auto* ctx_struct = new ContextStruct{GlobalObject{}}; - ctx_struct->obj["intVal1"].Set(jint{val}); + ctx_struct->obj.Access<"intVal1">().Set(jint{val}); return reinterpret_cast(ctx_struct); } @@ -82,8 +82,8 @@ Java_com_jnibind_test_ContextTest_nativeCreateContextSetValToSum(JNIEnv* env, jint val2) { // Creates a temporary test helper, calls its member method, and releases the // returned object across the C API boundary (then destroys the temporary). - return jni::LocalObject{}( - "returnNewObjectWithFieldSetToSum", val1, val2) + return jni::LocalObject{} + .Call<"returnNewObjectWithFieldSetToSum">(val1, val2) .Release(); } diff --git a/javatests/com/jnibind/test/field_test_jni.cc b/javatests/com/jnibind/test/field_test_jni.cc index 349daa14..cfa09b08 100644 --- a/javatests/com/jnibind/test/field_test_jni.cc +++ b/javatests/com/jnibind/test/field_test_jni.cc @@ -60,33 +60,33 @@ Java_com_jnibind_test_FieldTest_jniTearDown(JavaVM* pjvm, void* reserved) { JNIEXPORT jint JNICALL Java_com_jnibind_test_FieldTest_jniIntField( JNIEnv* env, jclass, jobject object, jint val) { LocalObject rjni_test_helper{object}; - rjni_test_helper["intField"].Set(jint{val}); + rjni_test_helper.Access<"intField">().Set(jint{val}); - return rjni_test_helper["intField"].Get(); + return rjni_test_helper.Access<"intField">().Get(); } JNIEXPORT jfloat JNICALL Java_com_jnibind_test_FieldTest_jniFloatField( JNIEnv* env, jclass, jobject object, jfloat val) { LocalObject rjni_test_helper{object}; - rjni_test_helper["floatField"].Set(jfloat{val}); + rjni_test_helper.Access<"floatField">().Set(jfloat{val}); - return rjni_test_helper["floatField"].Get(); + return rjni_test_helper.Access<"floatField">().Get(); } JNIEXPORT jdouble JNICALL Java_com_jnibind_test_FieldTest_jniDoubleField( JNIEnv* env, jclass, jobject object, jdouble val) { LocalObject rjni_test_helper{object}; - rjni_test_helper["doubleField"].Set(jdouble{val}); + rjni_test_helper.Access<"doubleField">().Set(jdouble{val}); - return rjni_test_helper["doubleField"].Get(); + return rjni_test_helper.Access<"doubleField">().Get(); } JNIEXPORT jstring JNICALL Java_com_jnibind_test_FieldTest_jniStringField( JNIEnv* env, jclass, jobject object, jstring val) { LocalObject rjni_test_helper{object}; - rjni_test_helper["stringField"].Set(val); + rjni_test_helper.Access<"stringField">().Set(val); - return rjni_test_helper["stringField"].Get().Release(); + return rjni_test_helper.Access<"stringField">().Get().Release(); } JNIEXPORT void JNICALL Java_com_jnibind_test_FieldTest_jniObjectFieldSet( @@ -95,12 +95,15 @@ JNIEXPORT void JNICALL Java_com_jnibind_test_FieldTest_jniObjectFieldSet( LocalObject field_test{test_class}; LocalObject obj{intVal, floatVal, doubleVal}; - field_test["fieldTestHelper"].Set(obj); + field_test.Access<"fieldTestHelper">().Set(obj); } JNIEXPORT jobject JNICALL Java_com_jnibind_test_FieldTest_jniObjectFieldGet( JNIEnv* env, jclass, jobject test_class) { - return LocalObject{test_class}["fieldTestHelper"].Get().Release(); + return LocalObject{test_class} + .Access<"fieldTestHelper">() + .Get() + .Release(); } } // extern "C" diff --git a/javatests/com/jnibind/test/global_object_test_jni.cc b/javatests/com/jnibind/test/global_object_test_jni.cc index ee27b44d..97fe83b5 100644 --- a/javatests/com/jnibind/test/global_object_test_jni.cc +++ b/javatests/com/jnibind/test/global_object_test_jni.cc @@ -63,8 +63,8 @@ Java_com_jnibind_test_GlobalObjectTest_jniBuildNewObjectsFromExistingObjects( JNIEnv* env, jclass, jobject test_helper_object, jobject object_to_mutate) { jni::LocalObject helper_obj{object_to_mutate}; - return jni::LocalObject{test_helper_object}( - "methodTakesGlobalObjectReturnsNewObject", helper_obj) + return jni::LocalObject{test_helper_object} + .Call<"methodTakesGlobalObjectReturnsNewObject">(helper_obj) .Release(); } @@ -73,17 +73,17 @@ Java_com_jnibind_test_GlobalObjectTest_jniManipulateNewGlobalObjectSetIntVal238( JNIEnv* env, jclass, jobject jtest_obj) { jni::GlobalObject helper_obj{2, 3, 8}; - return jni::LocalObject{jtest_obj}( - "methodTakesGlobalObjectReturnsNewObject", std::move(helper_obj)) + return jni::LocalObject{jtest_obj} + .Call<"methodTakesGlobalObjectReturnsNewObject">(std::move(helper_obj)) .Release(); } JNIEXPORT jobject JNICALL Java_com_jnibind_test_GlobalObjectTest_jniMaterializeNewGlobalObjectSetIntVal159( JNIEnv* env, jclass, jobject jtest_obj) { - return jni::LocalObject{jtest_obj}( - "methodTakesGlobalObjectReturnsNewObject", - jni::GlobalObject{1, 5, 9}) + return jni::LocalObject{jtest_obj} + .Call<"methodTakesGlobalObjectReturnsNewObject">( + jni::GlobalObject{1, 5, 9}) .Release(); } diff --git a/javatests/com/jnibind/test/local_object_test_jni.cc b/javatests/com/jnibind/test/local_object_test_jni.cc index f2cf225e..fda520b4 100644 --- a/javatests/com/jnibind/test/local_object_test_jni.cc +++ b/javatests/com/jnibind/test/local_object_test_jni.cc @@ -65,8 +65,8 @@ Java_com_jnibind_test_LocalObjectTest_jniBuildNewObjectsFromExistingObjects( JNIEnv* env, jclass, jobject jtest_obj, jobject jhelper_obj) { jni::LocalObject helper_obj{jhelper_obj}; - return jni::LocalObject{jtest_obj}( - "methodTakesLocalObjectReturnsNewObject", helper_obj) + return jni::LocalObject{jtest_obj} + .Call<"methodTakesLocalObjectReturnsNewObject">(helper_obj) .Release(); } @@ -75,17 +75,17 @@ Java_com_jnibind_test_LocalObjectTest_jniManipulateNewLocalObjectSetIntVal238( JNIEnv* env, jclass, jobject jtest_obj) { jni::LocalObject helper_obj{2, 3, 8}; - return jni::LocalObject{jtest_obj}( - "methodTakesLocalObjectReturnsNewObject", std::move(helper_obj)) + return jni::LocalObject{jtest_obj} + .Call<"methodTakesLocalObjectReturnsNewObject">(std::move(helper_obj)) .Release(); } JNIEXPORT jobject JNICALL Java_com_jnibind_test_LocalObjectTest_jniMaterializeNewLocalObjectSetIntVal159( JNIEnv* env, jclass, jobject jtest_obj) { - return jni::LocalObject{jtest_obj}( - "methodTakesLocalObjectReturnsNewObject", - jni::LocalObject{1, 5, 9}) + return jni::LocalObject{jtest_obj} + .Call<"methodTakesLocalObjectReturnsNewObject">( + jni::LocalObject{1, 5, 9}) .Release(); } diff --git a/javatests/com/jnibind/test/method_test_jni.cc b/javatests/com/jnibind/test/method_test_jni.cc index f298c5b3..51928989 100644 --- a/javatests/com/jnibind/test/method_test_jni.cc +++ b/javatests/com/jnibind/test/method_test_jni.cc @@ -92,7 +92,7 @@ Java_com_jnibind_test_MethodTest_jniTearDown(JavaVM* pjvm, void* reserved) { JNIEXPORT void JNICALL Java_com_jnibind_test_MethodTest_jniVoidMethod( JNIEnv* env, jclass, jobject object) { LocalObject gtest_helper{object}; - gtest_helper("voidMethod"); + gtest_helper.Call<"voidMethod">(); } JNIEXPORT void JNICALL @@ -100,7 +100,7 @@ Java_com_jnibind_test_MethodTest_jniVoidMethodTakesOneInt(JNIEnv* env, jclass, jobject object, jint i) { LocalObject gtest_helper{object}; - gtest_helper("voidMethodTakesOneInt", jint{i}); + gtest_helper.Call<"voidMethodTakesOneInt">(jint{i}); } JNIEXPORT void JNICALL @@ -110,8 +110,8 @@ Java_com_jnibind_test_MethodTest_jniVoidMethodTakesFiveInts(JNIEnv* env, jclass, jint i3, jint i4, jint i5) { LocalObject gtest_helper{object}; - gtest_helper("voidMethodTakesFiveInts", jint{i1}, jint{i2}, jint{i3}, - jint{i4}, jint{i5}); + gtest_helper.Call<"voidMethodTakesFiveInts">(jint{i1}, jint{i2}, jint{i3}, + jint{i4}, jint{i5}); } /** Boolean Method Tests. */ @@ -119,7 +119,7 @@ JNIEXPORT jboolean JNICALL Java_com_jnibind_test_MethodTest_jniBooleanMethod( JNIEnv* env, jclass, jobject object) { LocalObject gtest_helper{object}; - return gtest_helper("booleanMethod"); + return gtest_helper.Call<"booleanMethod">(); } JNIEXPORT jboolean JNICALL @@ -128,7 +128,7 @@ Java_com_jnibind_test_MethodTest_jniBooleanMethodTakesOneBoolean(JNIEnv* env, jobject object, jboolean i) { LocalObject gtest_helper{object}; - return gtest_helper("booleanMethodTakesOneBoolean", jboolean{i}); + return gtest_helper.Call<"booleanMethodTakesOneBoolean">(jboolean{i}); } JNIEXPORT jboolean JNICALL @@ -137,8 +137,8 @@ Java_com_jnibind_test_MethodTest_jniBooleanMethodTakesFiveBooleans( jboolean i4, jboolean i5) { LocalObject gtest_helper{object}; - return gtest_helper("booleanMethodTakesFiveBooleans", jboolean{i1}, - jboolean{i2}, jboolean{i3}, jboolean{i4}, jboolean{i5}); + return gtest_helper.Call<"booleanMethodTakesFiveBooleans">( + jboolean{i1}, jboolean{i2}, jboolean{i3}, jboolean{i4}, jboolean{i5}); } /** Int Method Tests. */ @@ -146,14 +146,14 @@ JNIEXPORT jint JNICALL Java_com_jnibind_test_MethodTest_jniIntMethod( JNIEnv* env, jclass, jobject object) { LocalObject gtest_helper{object}; - return gtest_helper("intMethod"); + return gtest_helper.Call<"intMethod">(); } JNIEXPORT jint JNICALL Java_com_jnibind_test_MethodTest_jniIntMethodTakesOneInt( JNIEnv* env, jclass, jobject object, jint i) { LocalObject gtest_helper{object}; - return gtest_helper("intMethodTakesOneInt", jint{i}); + return gtest_helper.Call<"intMethodTakesOneInt">(jint{i}); } JNIEXPORT jint JNICALL @@ -164,8 +164,8 @@ Java_com_jnibind_test_MethodTest_jniIntMethodTakesFiveInts(JNIEnv* env, jclass, jint i5) { LocalObject gtest_helper{object}; - return gtest_helper("intMethodTakesFiveInts", jint{i1}, jint{i2}, jint{i3}, - jint{i4}, jint{i5}); + return gtest_helper.Call<"intMethodTakesFiveInts">( + jint{i1}, jint{i2}, jint{i3}, jint{i4}, jint{i5}); } /** Long Method Tests. */ @@ -173,7 +173,7 @@ JNIEXPORT jlong JNICALL Java_com_jnibind_test_MethodTest_jniLongMethod( JNIEnv* env, jclass, jobject object) { LocalObject gtest_helper{object}; - return gtest_helper("longMethod"); + return gtest_helper.Call<"longMethod">(); } JNIEXPORT jlong JNICALL @@ -182,7 +182,7 @@ Java_com_jnibind_test_MethodTest_jniLongMethodTakesOneLong(JNIEnv* env, jclass, jlong i) { LocalObject gtest_helper{object}; - return gtest_helper("longMethodTakesOneLong", jlong{i}); + return gtest_helper.Call<"longMethodTakesOneLong">(jlong{i}); } JNIEXPORT jlong JNICALL @@ -191,8 +191,8 @@ Java_com_jnibind_test_MethodTest_jniLongMethodTakesFiveLongs( jlong i5) { LocalObject gtest_helper{object}; - return gtest_helper("longMethodTakesFiveLongs", jlong{i1}, jlong{i2}, - jlong{i3}, jlong{i4}, jlong{i5}); + return gtest_helper.Call<"longMethodTakesFiveLongs">( + jlong{i1}, jlong{i2}, jlong{i3}, jlong{i4}, jlong{i5}); } /** Float Method Tests. */ @@ -200,7 +200,7 @@ JNIEXPORT jfloat JNICALL Java_com_jnibind_test_MethodTest_jniFloatMethod( JNIEnv* env, jclass, jobject object) { LocalObject gtest_helper{object}; - return gtest_helper("floatMethod"); + return gtest_helper.Call<"floatMethod">(); } JNIEXPORT jfloat JNICALL @@ -210,7 +210,7 @@ Java_com_jnibind_test_MethodTest_jniFloatMethodTakesOneFloat(JNIEnv* env, jfloat i) { LocalObject gtest_helper{object}; - return gtest_helper("floatMethodTakesOneFloat", jfloat{i}); + return gtest_helper.Call<"floatMethodTakesOneFloat">(jfloat{i}); } JNIEXPORT jfloat JNICALL @@ -219,8 +219,8 @@ Java_com_jnibind_test_MethodTest_jniFloatMethodTakesFiveFloats( jfloat i4, jfloat i5) { LocalObject gtest_helper{object}; - return gtest_helper("floatMethodTakesFiveFloats", jfloat{i1}, jfloat{i2}, - jfloat{i3}, jfloat{i4}, jfloat{i5}); + return gtest_helper.Call<"floatMethodTakesFiveFloats">( + jfloat{i1}, jfloat{i2}, jfloat{i3}, jfloat{i4}, jfloat{i5}); } /** Double Method Tests. */ @@ -228,7 +228,7 @@ JNIEXPORT jdouble JNICALL Java_com_jnibind_test_MethodTest_jniDoubleMethod( JNIEnv* env, jclass, jobject object) { LocalObject gtest_helper{object}; - return gtest_helper("doubleMethod"); + return gtest_helper.Call<"doubleMethod">(); } JNIEXPORT jdouble JNICALL @@ -238,7 +238,7 @@ Java_com_jnibind_test_MethodTest_jniDoubleMethodTakesOneDouble(JNIEnv* env, jdouble i) { LocalObject gtest_helper{object}; - return gtest_helper("doubleMethodTakesOneDouble", jdouble{i}); + return gtest_helper.Call<"doubleMethodTakesOneDouble">(jdouble{i}); } JNIEXPORT jdouble JNICALL @@ -247,8 +247,8 @@ Java_com_jnibind_test_MethodTest_jniDoubleMethodTakesFiveDoubles( jdouble i4, jdouble i5) { LocalObject gtest_helper{object}; - return gtest_helper("doubleMethodTakesFiveDoubles", jdouble{i1}, jdouble{i2}, - jdouble{i3}, jdouble{i4}, jdouble{i5}); + return gtest_helper.Call<"doubleMethodTakesFiveDoubles">( + jdouble{i1}, jdouble{i2}, jdouble{i3}, jdouble{i4}, jdouble{i5}); } /** Overload Method Tests. */ @@ -256,29 +256,29 @@ JNIEXPORT int JNICALL Java_com_jnibind_test_MethodTest_jniCallFooOverload1( JNIEnv* env, jclass, jobject object) { LocalObject gtest_helper{object}; - return gtest_helper("foo"); + return gtest_helper.Call<"foo">(); } JNIEXPORT int JNICALL Java_com_jnibind_test_MethodTest_jniCallFooOverload2( JNIEnv* env, jclass, jobject object) { LocalObject gtest_helper{object}; - return gtest_helper("foo", 123.f); + return gtest_helper.Call<"foo">(123.f); } JNIEXPORT int JNICALL Java_com_jnibind_test_MethodTest_jniCallFooOverload3( JNIEnv* env, jclass, jobject object) { LocalObject gtest_helper{object}; - return gtest_helper("foo", 123.f, 456.f); + return gtest_helper.Call<"foo">(123.f, 456.f); } /** Overload int/double disambiguation. */ JNIEXPORT void JNICALL Java_com_jnibind_test_MethodTest_jniCallFooOverload4( JNIEnv* env, jclass, jobject object) { LocalObject gtest_helper{object}; - gtest_helper("intDouble", 123, 456.); - gtest_helper("intDouble", 456., 123); + gtest_helper.Call<"intDouble">(123, 456.); + gtest_helper.Call<"intDouble">(456., 123); } } // extern "C" diff --git a/javatests/com/jnibind/test/static_test_jni.cc b/javatests/com/jnibind/test/static_test_jni.cc index 26260150..558bdcda 100644 --- a/javatests/com/jnibind/test/static_test_jni.cc +++ b/javatests/com/jnibind/test/static_test_jni.cc @@ -73,49 +73,49 @@ Java_com_jnibind_test_StaticTest_jniTearDown(JavaVM* pjvm, void* reserved) { //////////////////////////////////////////////////////////////////////////////// JNIEXPORT void JNICALL Java_com_jnibind_test_StaticTest_voidMethodTestNative( JavaVM* pjvm, void* reserved) { - StaticRef{}("voidFunc"); + StaticRef{}.Call<"voidFunc">(); } JNIEXPORT jbyte JNICALL Java_com_jnibind_test_StaticTest_byteMethodTestNative( JavaVM* pjvm, void* reserved) { - return StaticRef{}("byteFunc"); + return StaticRef{}.Call<"byteFunc">(); } JNIEXPORT jchar JNICALL Java_com_jnibind_test_StaticTest_charMethodTestNative( JavaVM* pjvm, void* reserved) { - return StaticRef{}("charFunc"); + return StaticRef{}.Call<"charFunc">(); } JNIEXPORT jshort JNICALL Java_com_jnibind_test_StaticTest_shortMethodTestNative( JavaVM* pjvm, void* reserved) { - return StaticRef{}("shortFunc"); + return StaticRef{}.Call<"shortFunc">(); } JNIEXPORT jint JNICALL Java_com_jnibind_test_StaticTest_intMethodTestNative( JavaVM* pjvm, void* reserved) { - return StaticRef{}("intFunc"); + return StaticRef{}.Call<"intFunc">(); } JNIEXPORT jlong JNICALL Java_com_jnibind_test_StaticTest_longMethodTestNative( JavaVM* pjvm, void* reserved) { - return StaticRef{}("longFunc"); + return StaticRef{}.Call<"longFunc">(); } JNIEXPORT jfloat JNICALL Java_com_jnibind_test_StaticTest_floatMethodTestNative( JavaVM* pjvm, void* reserved) { - return StaticRef{}("floatFunc"); + return StaticRef{}.Call<"floatFunc">(); } JNIEXPORT jdouble JNICALL Java_com_jnibind_test_StaticTest_doubleMethodTestNative(JavaVM* pjvm, void* reserved) { - return StaticRef{}("doubleFunc"); + return StaticRef{}.Call<"doubleFunc">(); } JNIEXPORT jobject JNICALL Java_com_jnibind_test_StaticTest_objectMethodTestNative(JavaVM* pjvm, void* reserved) { - return StaticRef{}("objectFunc").Release(); + return StaticRef{}.Call<"objectFunc">().Release(); } JNIEXPORT jstring JNICALL @@ -123,7 +123,7 @@ Java_com_jnibind_test_StaticTest_complexMethodTestNative(JavaVM* pjvm, void* reserved, jint a, jfloat b, jstring c, jobjectArray d) { - return StaticRef{}("complexFunc", a, b, c, d).Release(); + return StaticRef{}.Call<"complexFunc">(a, b, c, d).Release(); } //////////////////////////////////////////////////////////////////////////////// @@ -131,57 +131,57 @@ Java_com_jnibind_test_StaticTest_complexMethodTestNative(JavaVM* pjvm, //////////////////////////////////////////////////////////////////////////////// JNIEXPORT bool JNICALL Java_com_jnibind_test_StaticTest_booleanFieldTestNative( JavaVM* pjvm, void* reserved, bool val) { - StaticRef{}["booleanField"].Set(val); - return StaticRef{}["booleanField"].Get(); + StaticRef{}.Access<"booleanField">().Set(val); + return StaticRef{}.Access<"booleanField">().Get(); } JNIEXPORT jbyte JNICALL Java_com_jnibind_test_StaticTest_byteFieldTestNative( JavaVM* pjvm, void* reserved, jbyte val) { - StaticRef{}["byteField"].Set(val); - return StaticRef{}["byteField"].Get(); + StaticRef{}.Access<"byteField">().Set(val); + return StaticRef{}.Access<"byteField">().Get(); } JNIEXPORT char JNICALL Java_com_jnibind_test_StaticTest_charFieldTestNative( JavaVM* pjvm, void* reserved, jchar val) { - StaticRef{}["charField"].Set(val); - return StaticRef{}["charField"].Get(); + StaticRef{}.Access<"charField">().Set(val); + return StaticRef{}.Access<"charField">().Get(); } JNIEXPORT short JNICALL Java_com_jnibind_test_StaticTest_shortFieldTestNative( JavaVM* pjvm, void* reserved, jshort val) { - StaticRef{}["shortField"].Set(val); - return StaticRef{}["shortField"].Get(); + StaticRef{}.Access<"shortField">().Set(val); + return StaticRef{}.Access<"shortField">().Get(); } JNIEXPORT int JNICALL Java_com_jnibind_test_StaticTest_intFieldTestNative( JavaVM* pjvm, void* reserved, jint val) { - StaticRef{}["intField"].Set(val); - return StaticRef{}["intField"].Get(); + StaticRef{}.Access<"intField">().Set(val); + return StaticRef{}.Access<"intField">().Get(); } JNIEXPORT long JNICALL Java_com_jnibind_test_StaticTest_longFieldTestNative( JavaVM* pjvm, void* reserved, jlong val) { - StaticRef{}["longField"].Set(val); - return StaticRef{}["longField"].Get(); + StaticRef{}.Access<"longField">().Set(val); + return StaticRef{}.Access<"longField">().Get(); } JNIEXPORT float JNICALL Java_com_jnibind_test_StaticTest_floatFieldTestNative( JavaVM* pjvm, void* reserved, jfloat val) { - StaticRef{}["floatField"].Set(val); - return StaticRef{}["floatField"].Get(); + StaticRef{}.Access<"floatField">().Set(val); + return StaticRef{}.Access<"floatField">().Get(); } JNIEXPORT double JNICALL Java_com_jnibind_test_StaticTest_doubleFieldTestNative( JavaVM* pjvm, void* reserved, jdouble val) { - StaticRef{}["doubleField"].Set(val); - return StaticRef{}["doubleField"].Get(); + StaticRef{}.Access<"doubleField">().Set(val); + return StaticRef{}.Access<"doubleField">().Get(); } JNIEXPORT jobject JNICALL Java_com_jnibind_test_StaticTest_objectFieldTestNative(JavaVM* pjvm, void* reserved, jobject val) { - StaticRef{}["objectField"].Set(val); - return StaticRef{}["objectField"].Get().Release(); + StaticRef{}.Access<"objectField">().Set(val); + return StaticRef{}.Access<"objectField">().Get().Release(); } } diff --git a/javatests/com/jnibind/test/string_test_jni.cc b/javatests/com/jnibind/test/string_test_jni.cc index d4aa07af..df33093f 100644 --- a/javatests/com/jnibind/test/string_test_jni.cc +++ b/javatests/com/jnibind/test/string_test_jni.cc @@ -71,15 +71,15 @@ Java_com_jnibind_test_StringTest_jniPassesStringsInManyWays( LocalString string_lval{input}; const char* kSimpleTestString{"SimpleTestString"}; - fixture("voidMethodTakesString", "SimpleTestString"); - fixture("voidMethodTakesString", kSimpleTestString); - fixture("voidMethodTakesString", std::string_view{"SimpleTestString"}); - fixture("voidMethodTakesString", std::string{"SimpleTestString"}); - fixture("voidMethodTakesString", input); - fixture("voidMethodTakesString", string_lval); - fixture("voidMethodTakesString", global_string_lval); - fixture("voidMethodTakesString", LocalString{input}); - fixture("voidMethodTakesString", GlobalString{PromoteToGlobal{}, input}); + fixture.Call<"voidMethodTakesString">("SimpleTestString"); + fixture.Call<"voidMethodTakesString">(kSimpleTestString); + fixture.Call<"voidMethodTakesString">(std::string_view{"SimpleTestString"}); + fixture.Call<"voidMethodTakesString">(std::string{"SimpleTestString"}); + fixture.Call<"voidMethodTakesString">(input); + fixture.Call<"voidMethodTakesString">(string_lval); + fixture.Call<"voidMethodTakesString">(global_string_lval); + fixture.Call<"voidMethodTakesString">(LocalString{input}); + fixture.Call<"voidMethodTakesString">(GlobalString{PromoteToGlobal{}, input}); } /** Void return type tests. */ @@ -89,15 +89,15 @@ Java_com_jnibind_test_StringTest_jniVoidMethodTakesString(JNIEnv* env, jclass, jstring string) { LocalObject r_jni_string_test_helper{object}; LocalString lValue{string}; - r_jni_string_test_helper("voidMethodTakesString", LocalString{string}); + r_jni_string_test_helper.Call<"voidMethodTakesString">(LocalString{string}); } JNIEXPORT void JNICALL Java_com_jnibind_test_StringTest_jniVoidMethodTakesTwoStrings( JNIEnv* env, jclass, jobject object, jstring s1, jstring s2) { LocalObject r_jni_string_test_helper{object}; - r_jni_string_test_helper("voidMethodTakesTwoStrings", LocalString{s1}, - LocalString{s2}); + r_jni_string_test_helper.Call<"voidMethodTakesTwoStrings">(LocalString{s1}, + LocalString{s2}); } JNIEXPORT void JNICALL @@ -107,9 +107,9 @@ Java_com_jnibind_test_StringTest_jniVoidMethodTakesFiveStrings( LocalObject r_jni_string_test_helper{object}; std::string s4_string{LocalString{s4}.Pin().ToString()}; - r_jni_string_test_helper("voidMethodTakesFiveStrings", - LocalString{s1}.Pin().ToString(), LocalString{s2}, - s3, s4_string, LocalString{s5}.Pin().ToString()); + r_jni_string_test_helper.Call<"voidMethodTakesFiveStrings">( + LocalString{s1}.Pin().ToString(), LocalString{s2}, s3, s4_string, + LocalString{s5}.Pin().ToString()); } /** String return type tests. */ @@ -118,8 +118,8 @@ Java_com_jnibind_test_StringTest_jniStringMethodTakesString(JNIEnv* env, jclass, jobject object, jstring string) { LocalObject r_jni_string_test_helper{object}; - return r_jni_string_test_helper("stringMethodTakesString", - LocalString{string}) + return r_jni_string_test_helper + .Call<"stringMethodTakesString">(LocalString{string}) .Release(); } @@ -128,8 +128,8 @@ Java_com_jnibind_test_StringTest_jniStringMethodTakesTwoStrings( JNIEnv* env, jclass, jobject object, jstring s1, jstring s2) { LocalObject r_jni_string_test_helper{object}; return LocalString{ - r_jni_string_test_helper("stringMethodTakesTwoStrings", LocalString{s1}, - std::string{LocalString{s2}.Pin().ToString()})} + r_jni_string_test_helper.Call<"stringMethodTakesTwoStrings">( + LocalString{s1}, std::string{LocalString{s2}.Pin().ToString()})} .Release(); } @@ -138,10 +138,10 @@ Java_com_jnibind_test_StringTest_jniStringMethodTakesFiveStrings( JNIEnv* env, jclass, jobject object, jstring s1, jstring s2, jstring s3, jstring s4, jstring s5) { LocalObject r_jni_string_test_helper{object}; - return LocalString{r_jni_string_test_helper("stringMethodTakesFiveStrings", - LocalString{s1}, LocalString{s2}, - LocalString{s3}, LocalString{s4}, - LocalString{s5})} + return LocalString{ + r_jni_string_test_helper.Call<"stringMethodTakesFiveStrings">( + LocalString{s1}, LocalString{s2}, LocalString{s3}, LocalString{s4}, + LocalString{s5})} .Release(); } diff --git a/javatests/com/jnibind/test/thread_test_jni.cc b/javatests/com/jnibind/test/thread_test_jni.cc index 4ea7d098..f1d6072e 100644 --- a/javatests/com/jnibind/test/thread_test_jni.cc +++ b/javatests/com/jnibind/test/thread_test_jni.cc @@ -57,7 +57,7 @@ Java_com_jnibind_test_ThreadTest_RunsThreadedWorkOnObject(JNIEnv* env, jclass, std::thread worker{ [global_object_lambda_scope{std::move(global_obj)}]() mutable { ThreadGuard thread_guard{}; - global_object_lambda_scope("foo"); + global_object_lambda_scope.Call<"foo">(); }}; worker.join(); diff --git a/jni_bind.h b/jni_bind.h index 6c4c79c3..dfaca903 100644 --- a/jni_bind.h +++ b/jni_bind.h @@ -50,6 +50,7 @@ static constexpr Configuration kConfig{ #include "implementation/jni_helper/jni_helper.h" #include "implementation/jni_helper/lifecycle.h" #include "implementation/jni_helper/static_field_value.h" +#include "metaprogramming/string_literal.h" // Headers for static definitions. #include "implementation/array.h" diff --git a/release_header_smoke_test.cc b/release_header_smoke_test.cc index 6e7072e8..b0d38b18 100644 --- a/release_header_smoke_test.cc +++ b/release_header_smoke_test.cc @@ -23,13 +23,13 @@ TEST_F(JniTest, SmokeTest_SimplyRun) { }; jni::GlobalObject obj{}; - obj("Foo", 1, 2.f); - obj("Baz", 1.f); - obj("Baz", 1.f); - obj("Baz", 2.f); - obj("Baz", 3.f); - obj("Bar"); - obj["SomeField"].Get(); + obj.Call<"Foo">(1, 2.f); + obj.Call<"Baz">(1.f); + obj.Call<"Baz">(1.f); + obj.Call<"Baz">(2.f); + obj.Call<"Baz">(3.f); + obj.Call<"Bar">(); + obj.Access<"SomeField">().Get(); } } // namespace