Skip to content

Commit f1f615b

Browse files
committed
[Java.Interop] Rename IJavaObject to IJavaPeerable
Fixes: #21 Xamarin.Android has an Android.Runtime.IJavaObject interface type. While Java.Interop.IJavaObject is in a different namespace, having identical type names still means you'd need to fully qualify or use a `using-alias`, which is annoying. Rename IJavaObject to IJavaPeerable, which is also somewhat in keeping with commit 25de1f3 which renamed IJavaObject.SafeHandle to IJavaObject.PeerReference. Now, the property is IJavaPeerable.PeerReference, further emphasizing the nature of what the interface represents: a wrapper of a Java-side "peer" instance. Related (for terminology): http://developer.xamarin.com/guides/android/advanced_topics/garbage_collection/ Modified to be consistent with this commit/name change: > **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 C# class. The native peer is an instance of a > Java class within JVM, and the C# IJavaPeerable.PeerReference > property contains a JNI object reference to the native peer.
1 parent 25de1f3 commit f1f615b

37 files changed

+372
-372
lines changed

src/Android.Interop/Java.Interop/AndroidVM.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ internal AndroidVM (AndroidVMBuilder builder)
4444
get {return current;}
4545
}
4646

47-
protected override bool TryGC (IJavaObject value, ref JniObjectReference handle)
47+
protected override bool TryGC (IJavaPeerable value, ref JniObjectReference handle)
4848
{
4949
if (!handle.IsValid)
5050
return true;

src/Java.Interop.Dynamic/Java.Interop.Dynamic/DynamicJavaClass.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ protected override bool HasSelf {
9797

9898
protected override Expression GetSelf ()
9999
{
100-
return Expression.Constant (null, typeof (IJavaObject));
100+
return Expression.Constant (null, typeof (IJavaPeerable));
101101
}
102102

103103
public override DynamicMetaObject BindInvoke (InvokeBinder binder, DynamicMetaObject[] args)
@@ -124,7 +124,7 @@ public override DynamicMetaObject BindInvoke (InvokeBinder binder, DynamicMetaOb
124124
new[]{value},
125125
Expression.Condition (
126126
test: Expression.Call (Expression.Constant (klass.info), invoke.Method,
127-
Expression.Constant (null, typeof (IJavaObject)), Expression.Constant (applicable), Expression.Constant (args), value),
127+
Expression.Constant (null, typeof (IJavaPeerable)), Expression.Constant (applicable), Expression.Constant (args), value),
128128
ifTrue: value,
129129
ifFalse: fallback.Expression)
130130
);
@@ -148,8 +148,8 @@ static JavaModifiers ()
148148
struct JniArgumentMarshalInfo {
149149
JValue jvalue;
150150
JniObjectReference lref;
151-
IJavaObject obj;
152-
Action<IJavaObject, object> cleanup;
151+
IJavaPeerable obj;
152+
Action<IJavaPeerable, object> cleanup;
153153

154154
internal JniArgumentMarshalInfo (object value, Type valueType)
155155
{

src/Java.Interop.Dynamic/Java.Interop.Dynamic/DynamicJavaInstance.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class DynamicJavaInstance : IDynamicMetaObjectProvider, IDisposable {
1818

1919
JavaClassInfo klass;
2020

21-
public DynamicJavaInstance (IJavaObject value)
21+
public DynamicJavaInstance (IJavaPeerable value)
2222
{
2323
if (value == null)
2424
throw new ArgumentNullException ("value");
@@ -31,7 +31,7 @@ public DynamicJavaInstance (IJavaObject value)
3131

3232
bool disposed;
3333

34-
public IJavaObject Value {get; private set;}
34+
public IJavaPeerable Value {get; private set;}
3535

3636
public void Dispose ()
3737
{
@@ -45,7 +45,7 @@ protected virtual void Dispose (bool disposing)
4545
return;
4646

4747
if (disposing) {
48-
var java = Value as IJavaObject;
48+
var java = Value as IJavaPeerable;
4949
if (java != null) {
5050
java.DisposeUnlessRegistered ();
5151
}
@@ -85,12 +85,12 @@ protected override JniObjectReference ConversionTarget {
8585
}
8686

8787
protected override bool HasSelf {
88-
get {return (instance.Value as IJavaObject) != null;}
88+
get {return (instance.Value as IJavaPeerable) != null;}
8989
}
9090

9191
protected override Expression GetSelf ()
9292
{
93-
return Expression.Constant (instance.Value as IJavaObject, typeof (IJavaObject));
93+
return Expression.Constant (instance.Value as IJavaPeerable, typeof (IJavaPeerable));
9494
}
9595
}
9696
}

src/Java.Interop.Dynamic/Java.Interop.Dynamic/JavaClassInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ static bool IsStatic (JniObjectReference member)
288288
return (s & JavaModifiers.Static) == JavaModifiers.Static;
289289
}
290290

291-
internal unsafe bool TryInvokeMember (IJavaObject self, JavaMethodBase[] overloads, DynamicMetaObject[] args, out object value)
291+
internal unsafe bool TryInvokeMember (IJavaPeerable self, JavaMethodBase[] overloads, DynamicMetaObject[] args, out object value)
292292
{
293293
value = null;
294294
var margs = (List<JniArgumentMarshalInfo>) null;

src/Java.Interop.Dynamic/Java.Interop.Dynamic/JavaConstructorInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected override string JniReturnType {
3838
get {return "V";}
3939
}
4040

41-
public override unsafe object Invoke (IJavaObject self, JValue* arguments)
41+
public override unsafe object Invoke (IJavaPeerable self, JValue* arguments)
4242
{
4343
if (self == null) {
4444
var h = members.InstanceMethods.StartCreateInstance (JniSignature, typeof (JavaInstanceProxy), arguments);

src/Java.Interop.Dynamic/Java.Interop.Dynamic/JavaFieldInfo.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public override string Name {
4040
}
4141
}
4242

43-
public object GetValue (IJavaObject self)
43+
public object GetValue (IJavaPeerable self)
4444
{
4545
AssertSelf (self);
4646

@@ -49,7 +49,7 @@ public object GetValue (IJavaObject self)
4949
return GetInstanceValue (self);
5050
}
5151

52-
void AssertSelf (IJavaObject self)
52+
void AssertSelf (IJavaPeerable self)
5353
{
5454
if (IsStatic && self != null)
5555
throw new ArgumentException (
@@ -82,7 +82,7 @@ object GetStaticValue ()
8282
}
8383
}
8484

85-
object GetInstanceValue (IJavaObject self)
85+
object GetInstanceValue (IJavaPeerable self)
8686
{
8787
var n = GetSignatureStartIndex ();
8888
switch (JniSignature [n + 1]) {
@@ -112,7 +112,7 @@ int GetSignatureStartIndex ()
112112
return n;
113113
}
114114

115-
public void SetValue (IJavaObject self, object value)
115+
public void SetValue (IJavaPeerable self, object value)
116116
{
117117
AssertSelf (self);
118118

@@ -149,7 +149,7 @@ void SetStaticValue (object value)
149149
}
150150
}
151151

152-
void SetInstanceValue (IJavaObject self, object value)
152+
void SetInstanceValue (IJavaPeerable self, object value)
153153
{
154154
var n = GetSignatureStartIndex ();
155155
switch (JniSignature [n + 1]) {

src/Java.Interop.Dynamic/Java.Interop.Dynamic/JavaMethodBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ abstract class JavaMethodBase : JavaMemberInfo {
1919

2020
public abstract bool IsConstructor {get;}
2121

22-
public abstract unsafe object Invoke (IJavaObject self, JValue* arguments);
22+
public abstract unsafe object Invoke (IJavaPeerable self, JValue* arguments);
2323

2424
protected abstract string JniReturnType {get;}
2525

src/Java.Interop.Dynamic/Java.Interop.Dynamic/JavaMethodInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected override string JniReturnType {
5858
}
5959
}
6060

61-
public override unsafe object Invoke (IJavaObject self, JValue* arguments)
61+
public override unsafe object Invoke (IJavaPeerable self, JValue* arguments)
6262
{
6363
AssertSelf (self);
6464

@@ -67,7 +67,7 @@ public override unsafe object Invoke (IJavaObject self, JValue* arguments)
6767
return InvokeInstanceMethod (self, arguments);
6868
}
6969

70-
void AssertSelf (IJavaObject self)
70+
void AssertSelf (IJavaPeerable self)
7171
{
7272
if (IsStatic && self != null)
7373
throw new ArgumentException (
@@ -79,7 +79,7 @@ void AssertSelf (IJavaObject self)
7979
"self");
8080
}
8181

82-
unsafe object InvokeInstanceMethod (IJavaObject self, JValue* arguments)
82+
unsafe object InvokeInstanceMethod (IJavaPeerable self, JValue* arguments)
8383
{
8484
var e = GetSignatureReturnTypeStartIndex ();
8585
switch (JniSignature [e + 1]) {

src/Java.Interop.Dynamic/Java.Interop.Dynamic/JniMetaObject.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Java.Interop.Dynamic {
1717

1818
abstract class JniMetaObject : DynamicMetaObject
1919
{
20-
protected delegate bool TryInvokeMember (IJavaObject self, JavaMethodBase[] overloads, DynamicMetaObject[] args, out object value);
20+
protected delegate bool TryInvokeMember (IJavaPeerable self, JavaMethodBase[] overloads, DynamicMetaObject[] args, out object value);
2121

2222
JavaClassInfo info;
2323

@@ -73,7 +73,7 @@ public override DynamicMetaObject BindGetMember (GetMemberBinder binder)
7373

7474
var field = overloads.FirstOrDefault (f => f.IsStatic == true);
7575

76-
Func<IJavaObject, object> getValue = field.GetValue;
76+
Func<IJavaPeerable, object> getValue = field.GetValue;
7777

7878
var e = Expression.Call (Expression.Constant (field), getValue.Method, GetSelf ());
7979
return new DynamicMetaObject (e, BindingRestrictions.GetInstanceRestriction (Expression, Value));
@@ -147,7 +147,7 @@ public override DynamicMetaObject BindSetMember (SetMemberBinder binder, Dynamic
147147

148148
var field = overloads.FirstOrDefault (f => f.IsStatic == true);
149149

150-
Action<IJavaObject, object> setValue = field.SetValue;
150+
Action<IJavaPeerable, object> setValue = field.SetValue;
151151
var e = Expression.Block (
152152
Expression.Call (Expression.Constant (field), setValue.Method,
153153
GetSelf (), Expression.Convert (value.Expression, typeof (object))),

src/Java.Interop.Export/Java.Interop/ExportedMemberBuilder.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ protected virtual Expression GetMarshalFromJniExpression (Expression jvm, Type t
260260
MarshalInfo v;
261261
if (Marshalers.TryGetValue (targetType, out v))
262262
return v.FromJni (jvm, targetType, jniParameter);
263-
if (typeof (IJavaObject).IsAssignableFrom (targetType))
264-
return Marshalers [typeof (IJavaObject)].FromJni (jvm, targetType, jniParameter);
263+
if (typeof (IJavaPeerable).IsAssignableFrom (targetType))
264+
return Marshalers [typeof (IJavaPeerable)].FromJni (jvm, targetType, jniParameter);
265265
return null;
266266
}
267267

@@ -270,8 +270,8 @@ protected virtual Expression GetMarshalToJniExpression (Type sourceType, Express
270270
MarshalInfo v;
271271
if (Marshalers.TryGetValue (sourceType, out v))
272272
return v.ToJni (managedParameter);
273-
if (typeof (IJavaObject).IsAssignableFrom (sourceType))
274-
return Marshalers [typeof (IJavaObject)].ToJni (managedParameter);
273+
if (typeof (IJavaPeerable).IsAssignableFrom (sourceType))
274+
return Marshalers [typeof (IJavaPeerable)].ToJni (managedParameter);
275275
return null;
276276
}
277277

@@ -280,9 +280,9 @@ protected virtual Expression GetMarshalToJniExpression (Type sourceType, Express
280280
FromJni = (vm, t, p) => Expression.Call (F<IntPtr, string> (JniEnvironment.Strings.ToString).Method, p),
281281
ToJni = p => Expression.Call (F<string, JniObjectReference> (JniEnvironment.Strings.NewString).Method, p)
282282
} },
283-
{ typeof (IJavaObject), new MarshalInfo {
283+
{ typeof (IJavaPeerable), new MarshalInfo {
284284
FromJni = (vm, t, p) => GetThis (vm, t, p),
285-
ToJni = p => Expression.Call (F<IJavaObject, IntPtr> (JniEnvironment.Handles.NewReturnToJniRef).Method, p)
285+
ToJni = p => Expression.Call (F<IJavaPeerable, IntPtr> (JniEnvironment.Handles.NewReturnToJniRef).Method, p)
286286
} },
287287
};
288288

0 commit comments

Comments
 (0)