Skip to content

Commit 51f7862

Browse files
committed
[Java.Interop] Purge "Wrapper" from naming.
We need consistent naming, which brings us to the current naming dictionary: https://developer.xamarin.com/guides/android/advanced_topics/garbage_collection/#Cross-VM_Object_Collections Changing certain names to be consistent with Java.Interop, we have: > There are three categories of object types. > > * **Managed objects**: types which do not inherit from `JavaObject`, > e.g. `System.String`. These are collected normally by the GC. > > * **Java objects**: Java types which are present within the [Java] VM > but not exposed to the Mono VM. > > * **Peer objects**: types which implement `IJavaPeerable`, e.g. all > `JavaObject` and `JavaException` subclasses. Instances of these > types have two "halfs" a *managed peer* and a *native peer*. > The managed peer is an instance of the managed type. > The native peer is an instance of a Java class within the Java VM, > and the managed `IJavaPeerable.PeerReference` property contains a > JNI global reference to the native peer. > > There are two types of native peers: > > * **Framework peers**: "Normal" Java types which know nothing of > Java.Interop, e.g. java.lang.String. > * **User peers**: Java Callable Wrappers which exist for each > `JavaObject` subclass present within the app. Notice a word "missing" from that terminology description? "Wrapper". The problem with "wrapper" is that it implies something is being "wrapped", which *is not the case* with User Peers; the "wrapper" would be the corresponding Java instance, the *User peer*, but it's not a wrapper, so using "Wrapper" is misleading. Instead, Xamarin.Android uses the term "Peer" ~fairly consistently, and Java.Interop has been following suite in some areas, e.g. IJava**Peer**able.**Peer**Reference. ;-) Replace all instances of "Wrapper" within Java.Interop.dll and replace with "Peer": * JniRuntime.JniValueManager.CreateWrapper() is now JniRuntime.JniValueManager.CreatePeer(). * JniTypeSignature.GetPrimitiveWrapper() is now JniTypeSignature.GetPrimitivePeerTypeSignature(). * JniTypeSignatureAttribute.GenerateJavaWrapper is now JniTypeSignatureAttribute.GenerateJavaPeer.
1 parent 4e3cae4 commit 51f7862

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

src/Java.Interop/Java.Interop/JavaObjectArray.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static JniObjectReference _NewArray (int length)
1717
if (info.SimpleReference == null)
1818
info = new JniTypeSignature ("java/lang/Object", info.ArrayRank);
1919
if (info.IsKeyword && info.ArrayRank == 0) {
20-
info = info.GetPrimitiveWrapper ();
20+
info = info.GetPrimitivePeerTypeSignature ();
2121
}
2222
using (var t = new JniType (info.Name)) {
2323
return JniEnvironment.Arrays.NewObjectArray (length, t.PeerReference, new JniObjectReference ());

src/Java.Interop/Java.Interop/JniRuntime.JniValueManager.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,30 +196,30 @@ object PeekBoxedObject (JniObjectReference reference)
196196
: null;
197197
}
198198

199-
static readonly KeyValuePair<Type, Type>[] WrapperTypeMappings = new []{
199+
static readonly KeyValuePair<Type, Type>[] PeerTypeMappings = new []{
200200
new KeyValuePair<Type, Type>(typeof (object), typeof (JavaObject)),
201201
new KeyValuePair<Type, Type>(typeof (IJavaPeerable), typeof (JavaObject)),
202202
new KeyValuePair<Type, Type>(typeof (Exception), typeof (JavaException)),
203203
};
204204

205-
static Type GetWrapperType (Type type)
205+
static Type GetPeerType (Type type)
206206
{
207-
foreach (var m in WrapperTypeMappings) {
207+
foreach (var m in PeerTypeMappings) {
208208
if (m.Key == type)
209209
return m.Value;
210210
}
211211
return type;
212212
}
213213

214-
public virtual IJavaPeerable CreateWrapper (ref JniObjectReference reference, JniObjectReferenceOptions transfer, Type targetType)
214+
public virtual IJavaPeerable CreatePeer (ref JniObjectReference reference, JniObjectReferenceOptions transfer, Type targetType)
215215
{
216216
targetType = targetType ?? typeof (JavaObject);
217-
targetType = GetWrapperType (targetType);
217+
targetType = GetPeerType (targetType);
218218

219219
if (!typeof (IJavaPeerable).GetTypeInfo ().IsAssignableFrom (targetType.GetTypeInfo ()))
220220
throw new ArgumentException ("targetType must implement IJavaPeerable!", "targetType");
221221

222-
var ctor = GetWrapperConstructor (reference, targetType);
222+
var ctor = GetPeerConstructor (reference, targetType);
223223
if (ctor == null)
224224
throw new NotSupportedException (string.Format ("Could not find an appropriate constructable wrapper type for Java type '{0}', targetType='{1}'.",
225225
JniEnvironment.Types.GetJniTypeNameFromInstance (reference), targetType));
@@ -237,7 +237,7 @@ public virtual IJavaPeerable CreateWrapper (ref JniObjectReference reference, Jn
237237

238238
static readonly Type ByRefJniObjectReference = typeof (JniObjectReference).MakeByRefType ();
239239

240-
ConstructorInfo GetWrapperConstructor (JniObjectReference instance, Type fallbackType)
240+
ConstructorInfo GetPeerConstructor (JniObjectReference instance, Type fallbackType)
241241
{
242242
var klass = JniEnvironment.Types.GetObjectClass (instance);
243243
var jniTypeName = JniEnvironment.Types.GetJniTypeNameFromClass (klass);
@@ -505,7 +505,7 @@ public override IJavaPeerable CreateGenericValue (ref JniObjectReference referen
505505
var marshaler = jvm.ValueManager.GetValueMarshaler (targetType ?? typeof(IJavaPeerable));
506506
if (marshaler != Instance)
507507
return (IJavaPeerable) marshaler.CreateValue (ref reference, options, targetType);
508-
return jvm.ValueManager.CreateWrapper (ref reference, options, targetType);
508+
return jvm.ValueManager.CreatePeer (ref reference, options, targetType);
509509
}
510510

511511
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IJavaPeerable value, ParameterAttributes synchronize)
@@ -626,7 +626,7 @@ public override object CreateGenericValue (ref JniObjectReference reference, Jni
626626
return target;
627627
}
628628
// Punt! Hope it's a java.lang.Object
629-
return jvm.ValueManager.CreateWrapper (ref reference, options, targetType);
629+
return jvm.ValueManager.CreatePeer (ref reference, options, targetType);
630630
}
631631

632632
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (object value, ParameterAttributes synchronize)

src/Java.Interop/Java.Interop/JniTypeSignature.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public JniTypeSignature AddArrayRank (int rank)
5757
return new JniTypeSignature (SimpleReference, ArrayRank + rank, IsKeyword);
5858
}
5959

60-
public JniTypeSignature GetPrimitiveWrapper ()
60+
public JniTypeSignature GetPrimitivePeerTypeSignature ()
6161
{
6262
if (!IsKeyword)
6363
return this;

src/Java.Interop/Java.Interop/JniTypeSignatureAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public int ArrayRank {
3333
}
3434
}
3535

36-
public bool GenerateJavaWrapper {get; set;}
36+
public bool GenerateJavaPeer {get; set;}
3737
}
3838
}
3939

0 commit comments

Comments
 (0)