Skip to content

Commit d42aaf8

Browse files
committed
[Java.Interop] Remove unnecessary test, fix varible names
The test is not really needed, because the sourceValue.Type in the `JavaPeerableValueMarshaler` should always implement `IJavaPeerable` interface. Use `sourceValue.Name` when constructing variable names. `sourceValue.ToString ()` is equal (by coincidence). To be on the safe side use the `Name` property directly.
1 parent fd8463d commit d42aaf8

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ public override Expression CreateParameterFromManagedExpression (JniValueMarshal
593593
{
594594
var r = CreateIntermediaryExpressionFromManagedExpression (context, sourceValue);
595595

596-
var h = Expression.Variable (typeof (IntPtr), sourceValue + "_handle");
596+
var h = Expression.Variable (typeof (IntPtr), sourceValue.Name + "_handle");
597597
context.LocalVariables.Add (h);
598598
context.CreationStatements.Add (Expression.Assign (h, Expression.Property (r, "Handle")));
599599

@@ -609,12 +609,9 @@ Expression CreateIntermediaryExpressionFromManagedExpression (JniValueMarshalerC
609609
test: Expression.Equal (Expression.Constant (null), sourceValue),
610610
ifTrue: Expression.Assign (r, Expression.New (typeof (JniObjectReference))),
611611
ifFalse: Expression.Assign (r, Expression.Property (sourceValue, "PeerReference"))));
612-
613-
if (typeof (IJavaPeerable).GetTypeInfo ().IsAssignableFrom (sourceValue.Type.GetTypeInfo ())) {
614-
context.CleanupStatements.Add (Expression.IfThen (
615-
test: Expression.NotEqual (Expression.Constant (null), sourceValue),
616-
ifTrue: Expression.Call (sourceValue, typeof (IJavaPeerable).GetTypeInfo ().GetDeclaredMethod ("DisposeUnlessReferenced"))));
617-
}
612+
context.CleanupStatements.Add (Expression.IfThen (
613+
test: Expression.NotEqual (Expression.Constant (null), sourceValue),
614+
ifTrue: Expression.Call (sourceValue, typeof (IJavaPeerable).GetTypeInfo ().GetDeclaredMethod ("DisposeUnlessReferenced"))));
618615

619616
return r;
620617
}
@@ -626,7 +623,7 @@ public override Expression CreateReturnValueFromManagedExpression (JniValueMarsh
626623

627624
public override Expression CreateParameterToManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue, ParameterAttributes synchronize, Type targetType)
628625
{
629-
var r = Expression.Variable (targetType, sourceValue + "_val");
626+
var r = Expression.Variable (targetType, sourceValue.Name + "_val");
630627
context.LocalVariables.Add (r);
631628
context.CreationStatements.Add (
632629
Expression.Assign (r,

src/Java.Interop/Java.Interop/JniValueMarshaler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ Expression CreateSelf (JniValueMarshalerContext context, ParameterExpression sou
162162
public virtual Expression CreateReturnValueFromManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue)
163163
{
164164
CreateParameterFromManagedExpression (context, sourceValue, 0);
165-
var s = context.LocalVariables [sourceValue + "_state"];
165+
var s = context.LocalVariables [sourceValue.Name + "_state"];
166166
return ReturnObjectReferenceToJni (context, sourceValue.Name, Expression.Property (s, "ReferenceValue"));
167167
}
168168

0 commit comments

Comments
 (0)