Skip to content

Commit

Permalink
Rename CreateCopy to NewRef.
Browse files Browse the repository at this point in the history
Some additional discussion on #207.

PiperOrigin-RevId: 581787792
  • Loading branch information
jwhpryor authored and copybara-github committed Nov 13, 2023
1 parent 6033afe commit 231bc05
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions implementation/global_object_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ using ::jni::AdoptGlobal;
using ::jni::AdoptLocal;
using ::jni::Class;
using ::jni::Constructor;
using ::jni::CreateCopy;
using ::jni::Field;
using ::jni::GlobalObject;
using ::jni::LocalObject;
using ::jni::Method;
using ::jni::NewRef;
using ::jni::Params;
using ::jni::PromoteToGlobal;
using ::jni::test::AsGlobal;
Expand Down Expand Up @@ -133,7 +133,7 @@ TEST_F(JniTest, GlobalObject_CallsNewGlobalRefOnCopy) {
EXPECT_CALL(*env_, DeleteGlobalRef(Fake<jobject>(2)));
EXPECT_CALL(*env_, DeleteLocalRef(Fake<jobject>(1))).Times(0);

GlobalObject<kClass> global_object{CreateCopy{}, Fake<jobject>(1)};
GlobalObject<kClass> global_object{NewRef{}, Fake<jobject>(1)};
EXPECT_EQ(jobject{global_object}, Fake<jobject>(2));
}

Expand Down
4 changes: 2 additions & 2 deletions implementation/local_object_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
namespace {

using ::jni::Class;
using ::jni::CreateCopy;
using ::jni::Field;
using ::jni::kDefaultClassLoader;
using ::jni::kDefaultJvm;
using ::jni::LocalObject;
using ::jni::Method;
using ::jni::NewRef;
using ::jni::Params;
using ::jni::test::AsNewLocalReference;
using ::jni::test::Fake;
Expand Down Expand Up @@ -82,7 +82,7 @@ TEST_F(JniTest, LocalObject_CallsNewLocalRefOnCopy) {
EXPECT_CALL(*env_, NewLocalRef).WillOnce(::testing::Return(Fake<jobject>(2)));
EXPECT_CALL(*env_, DeleteLocalRef(Fake<jobject>(2)));

LocalObject<kClass> obj{CreateCopy{}, Fake<jobject>(1)};
LocalObject<kClass> obj{NewRef{}, Fake<jobject>(1)};
EXPECT_EQ(jobject{obj}, Fake<jobject>(2));
}

Expand Down
4 changes: 2 additions & 2 deletions implementation/promotion_mechanics.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct EntryBase : public Base {
EntryBase(AdoptLocal, ViableSpan object) : Base(object) {}

// "Copy" constructor: Additional reference to object will be created.
EntryBase(CreateCopy, ViableSpan object)
EntryBase(NewRef, ViableSpan object)
: EntryBase(AdoptLocal{},
object
? static_cast<Span>(
Expand Down Expand Up @@ -122,7 +122,7 @@ struct EntryBase<Base, LifecycleType::GLOBAL, JniT, ViableSpan> : public Base {
LifecycleType::GLOBAL>::Promote(rhs.Release())) {}

// "Copy" constructor: Additional reference to object will be created.
EntryBase(CreateCopy, ViableSpan object)
EntryBase(NewRef, ViableSpan object)
: Base(static_cast<Span>(
LifecycleHelper<Span, LifecycleType::GLOBAL>::NewReference(
static_cast<Span>(object)))) {}
Expand Down
2 changes: 1 addition & 1 deletion implementation/promotion_mechanics_tags.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct AdoptLocal {};

// Creates an additional reference to the underlying object.
// When used for local, presumes local, for global, presumes global.
struct CreateCopy {};
struct NewRef {};

// This tag allows the constructor to promote underlying jobject for you.
struct PromoteToGlobal {};
Expand Down
6 changes: 3 additions & 3 deletions implementation/string_ref_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
namespace {

using ::jni::AdoptGlobal;
using ::jni::CreateCopy;
using ::jni::GlobalObject;
using ::jni::GlobalString;
using ::jni::kJavaLangString;
using ::jni::LocalObject;
using ::jni::LocalString;
using ::jni::NewRef;
using ::jni::UtfStringView;
using ::jni::test::AsNewLocalReference;
using ::jni::test::Fake;
Expand Down Expand Up @@ -68,7 +68,7 @@ TEST_F(JniTest, LocalString_CopiesFromObject) {
EXPECT_CALL(*env_, DeleteLocalRef(AsNewLocalReference(Fake<jobject>())));
EXPECT_CALL(*env_, NewLocalRef(Fake<jobject>()));

LocalString decorated_object{CreateCopy{}, Fake<jobject>()};
LocalString decorated_object{NewRef{}, Fake<jobject>()};

EXPECT_EQ(jstring{decorated_object}, AsNewLocalReference(Fake<jobject>()));
}
Expand All @@ -78,7 +78,7 @@ TEST_F(JniTest, LocalString_CopiesFromJString) {
EXPECT_CALL(*env_, NewLocalRef(Fake<jstring>(1)))
.WillOnce(::testing::Return(Fake<jstring>(2)));

LocalString decorated_object{CreateCopy{}, Fake<jstring>(1)};
LocalString decorated_object{NewRef{}, Fake<jstring>(1)};

EXPECT_EQ(jstring{decorated_object}, Fake<jstring>(2));
}
Expand Down
4 changes: 2 additions & 2 deletions javatests/com/jnibind/test/context_test_jni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

namespace {

using ::jni::CreateCopy;
using ::jni::GlobalObject;
using ::jni::NewRef;
using ::jni::PromoteToGlobal;

// A struct that could represent context to be maintained across multiple native
Expand Down Expand Up @@ -72,7 +72,7 @@ Java_com_jnibind_test_ContextTest_nativeCreateContextWithCopy(JNIEnv* env,
jclass,
jobject val) {
return reinterpret_cast<jlong>(new ContextStruct{
.obj = GlobalObject<kObjectTestHelperClass>{CreateCopy{}, val}});
.obj = GlobalObject<kObjectTestHelperClass>{NewRef{}, val}});
}

JNIEXPORT jobject JNICALL
Expand Down
4 changes: 2 additions & 2 deletions javatests/com/jnibind/test/string_test_jni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
#include "jni_bind.h"

using ::jni::Class;
using ::jni::CreateCopy;
using ::jni::GlobalString;
using ::jni::LocalObject;
using ::jni::LocalString;
using ::jni::Method;
using ::jni::NewRef;
using ::jni::Params;
using ::jni::PromoteToGlobal;
using ::jni::Return;
Expand Down Expand Up @@ -66,7 +66,7 @@ Java_com_jnibind_test_StringTest_jniPassesStringsInManyWays(
JNIEnv* env, jclass, jobject test_fixture_object, jstring input) {
LocalObject<kMethodTestHelper> fixture{test_fixture_object};

GlobalString global_string_lval{CreateCopy{}, input};
GlobalString global_string_lval{NewRef{}, input};
LocalString string_lval{input};

const char* kSimpleTestString{"SimpleTestString"};
Expand Down
6 changes: 3 additions & 3 deletions jni_bind_release.h
Original file line number Diff line number Diff line change
Expand Up @@ -6951,7 +6951,7 @@ namespace jni {

// Creates an additional reference to the underlying object.
// When used for local, presumes local, for global, presumes global.
struct CreateCopy {};
struct NewRef {};

// This tag allows the constructor to promote underlying jobject for you.
struct PromoteToGlobal {};
Expand All @@ -6977,7 +6977,7 @@ struct EntryBase : public Base {
EntryBase(T&& rhs) : Base(rhs.Release()) {}

// "Copy" constructor: Additional reference to object will be created.
EntryBase(CreateCopy, ViableSpan object)
EntryBase(NewRef, ViableSpan object)
: Base(static_cast<Span>(
LifecycleHelper<Span, lifecycleType>::NewReference(
static_cast<Span>(object)))) {}
Expand Down Expand Up @@ -7033,7 +7033,7 @@ struct EntryBase<Base, LifecycleType::GLOBAL, JniT, ViableSpan> : public Base {
LifecycleType::GLOBAL>::Promote(rhs.Release())) {}

// "Copy" constructor: Additional reference to object will be created.
EntryBase(CreateCopy, ViableSpan object)
EntryBase(NewRef, ViableSpan object)
: Base(static_cast<Span>(
LifecycleHelper<Span, LifecycleType::GLOBAL>::NewReference(
static_cast<Span>(object)))) {}
Expand Down

0 comments on commit 231bc05

Please sign in to comment.