Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions Documentation/Motivation.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ intended to fix some of the shortcomings and design mistakes I've made over the

In particular, it attempts to fix the following issues:

* Split out the core invocation logic so that the containing assembly is in the
`xbuild-frameworks\MonoAndroid\v1.0` directory, allowing low-level JNI use
without taking an API-level constraint.
* Make the assembly a PCL lib.
* Split out the core invocation logic so it can be used without taking an
API-level constraint.
* Make the assembly a reusable .NET library.
* Support use of the lib on "desktop" Java VMs. This would allow more testing
without an Android device, could allow using Xamarin.Android Views to be shown
in the GUI designer, etc.
Expand All @@ -28,4 +27,3 @@ which returns a global reference while most other methods return a local ref.

The `JNIEnv` API is also huge, unwieldy, and terrible.


Original file line number Diff line number Diff line change
Expand Up @@ -788,4 +788,3 @@ static string ToLowerCase (string value)
}
}


3 changes: 1 addition & 2 deletions src/Java.Interop/Java.Interop/JavaArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public int Length {

[MaybeNull]
public abstract T this [int index] {
// I think this will be fixable in .NET5+ with support for "T?"
// Keep this until nullable annotations can fully express this indexer contract.
#pragma warning disable CS8766 // Nullability of reference types in return type doesn't match implicitly implemented member (possibly because of nullability attributes).
get;
#pragma warning restore CS8766
Expand Down Expand Up @@ -422,4 +422,3 @@ internal static T[] ToArray (IEnumerable<T> value)
}
}
}

3 changes: 0 additions & 3 deletions src/Java.Interop/Java.Interop/JavaTypeParametersAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;

#if NET

Comment thread
simonrozsival marked this conversation as resolved.
namespace Java.Interop
{
Expand All @@ -16,5 +15,3 @@ public JavaTypeParametersAttribute (string [] typeParameters)
public string [] TypeParameters { get; }
}
}

#endif // NET
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System;
using System.Diagnostics.CodeAnalysis;

#if NET

namespace Java.Interop
{
Expand All @@ -16,5 +15,3 @@ public JniConstructorSignatureAttribute (string memberSignature)
}
}
}

#endif // NET
6 changes: 2 additions & 4 deletions src/Java.Interop/Java.Interop/JniEnvironment.Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ static IntPtr RawCallStaticObjectMethodA (IntPtr env, out IntPtr thrown, IntPtr
#endif // FEATURE_JNIENVIRONMENT_JI_FUNCTION_POINTERS
}

#if NET
public static bool TryFindClass (string classname, out JniObjectReference instance)
{
if (classname == null)
Expand All @@ -208,7 +207,6 @@ public static bool TryFindClass (string classname, out JniObjectReference instan
instance = TryFindClass (classname, throwOnError: false);
return instance.IsValid;
}
#endif // NET

public static JniType? GetTypeFromInstance (JniObjectReference instance)
{
Expand Down Expand Up @@ -265,7 +263,7 @@ public static void RegisterNatives (JniObjectReference type, JniNativeMethodRegi
throw new ArgumentOutOfRangeException (nameof (numMethods), numMethods,
$"`numMethods` must be between 0 and `methods.Length` ({methods?.Length ?? 0})!");
}
#if DEBUG && NETCOREAPP
#if DEBUG
for (int i = 0; methods != null && i < numMethods; ++i) {
var m = methods [i];
if (m.Marshaler != null && m.Marshaler.GetType ().GenericTypeArguments.Length != 0) {
Expand All @@ -275,7 +273,7 @@ public static void RegisterNatives (JniObjectReference type, JniNativeMethodRegi
Debug.WriteLine ($" Marshaler Type={m.Marshaler.GetType ().FullName} Method={method.DeclaringType?.FullName}.{method.Name}");
}
}
#endif // DEBUG && NETCOREAPP
#endif // DEBUG

int r = _RegisterNatives (type, methods ?? Array.Empty<JniNativeMethodRegistration>(), numMethods);

Expand Down
4 changes: 0 additions & 4 deletions src/Java.Interop/Java.Interop/JniMemberSignature.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#nullable enable

#if NET

using System;
using System.Diagnostics.CodeAnalysis;
using System.Collections.Generic;
Expand Down Expand Up @@ -146,5 +144,3 @@ public override string ToString ()
public static bool operator!= (JniMemberSignature a, JniMemberSignature b) => !a.Equals (b);
}
}

#endif // NET
3 changes: 0 additions & 3 deletions src/Java.Interop/Java.Interop/JniMemberSignatureAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using System;

#if NET

namespace Java.Interop
{
Expand All @@ -23,5 +22,3 @@ internal JniMemberSignatureAttribute (string memberName, string memberSignature)
public string MemberSignature {get;}
}
}

#endif // NET
2 changes: 0 additions & 2 deletions src/Java.Interop/Java.Interop/JniMethodInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ public sealed class JniMethodInfo

public bool IsStatic {get; private set;}

#if NET
internal JniType? StaticRedirect;
internal int? ParameterCount;
#endif //NET

internal bool IsValid {
get {return ID != IntPtr.Zero;}
Expand Down
3 changes: 0 additions & 3 deletions src/Java.Interop/Java.Interop/JniMethodSignatureAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System;
using System.Diagnostics.CodeAnalysis;

#if NET

namespace Java.Interop
{
Expand All @@ -16,5 +15,3 @@ public JniMethodSignatureAttribute (string memberName, string memberSignature)
}
}
}

#endif // NET
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ internal JniInstanceMethods GetConstructorsForType (Type declaringType)
// at Java.Interop.JniPeerMembers.JniInstanceMethods..ctor(Type declaringType) in /Users/jon/Developer/src/xamarin/java.interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods.cs:line 27
// at Java.Interop.JniPeerMembers.JniInstanceMethods.GetConstructorsForType(Type declaringType) in /Users/jon/Developer/src/xamarin/java.interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods.cs:line 77
// at Java.Interop.JniPeerMembers.JniInstanceMethods.StartCreateInstance(String constructorSignature, Type declaringType, JniArgumentValue* parameters) in /Users/jon/Developer/src/xamarin/java.interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods.cs:line 146
// at Java.Lang.Object..ctor() in /Users/jon/Developer/src/xamarin/java.interop/src/Java.Base/obj/Debug-net7.0/mcw/Java.Lang.Object.cs:line 32
// at Java.Lang.Object..ctor() in /Users/jon/Developer/src/xamarin/java.interop/src/Java.Base/obj/Debug/mcw/Java.Lang.Object.cs:line 32
// at Java.BaseTests.MyIntConsumer..ctor(Action`1 action) in /Users/jon/Developer/src/xamarin/java.interop/tests/Java.Base-Tests/Java.Base/JavaToManagedTests.cs:line 77
// at Java.BaseTests.JavaToManagedTests.InterfaceInvokerMethod() in /Users/jon/Developer/src/xamarin/java.interop/tests/Java.Base-Tests/Java.Base/JavaToManagedTests.cs:line 26
methods = new JniInstanceMethods (declaringType);
Expand Down Expand Up @@ -133,7 +133,6 @@ public JniMethodInfo GetMethodInfo (string encodedMember)

JniMethodInfo GetMethodInfo (string method, string signature)
{
#if NET
var m = (JniMethodInfo?) null;
var newMethod = JniEnvironment.Runtime.TypeManager.GetReplacementMethodInfo (Members.JniPeerTypeName, method, signature);
if (newMethod.HasValue) {
Expand All @@ -153,7 +152,6 @@ JniMethodInfo GetMethodInfo (string method, string signature)
}
Console.Error.WriteLine ($"warning: For declared method `{Members.JniPeerTypeName}.{method}.{signature}`, could not find requested method `{typeName}.{methodName}.{methodSig}`!");
}
#endif // NET
return JniPeerType.GetInstanceMethod (method, signature);
}

Expand Down Expand Up @@ -205,4 +203,3 @@ public unsafe void FinishCreateInstance (string constructorSignature, IJavaPeera
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ partial class JniInstanceMethods {
static unsafe bool TryInvokeVoidStaticRedirect (JniMethodInfo method, IJavaPeerable self, JniArgumentValue* parameters)
{

#if !NET
return false;
#else // NET
if (method.StaticRedirect == null || !method.ParameterCount.HasValue) {
return false;
}
Expand All @@ -30,7 +27,6 @@ static unsafe bool TryInvokeVoidStaticRedirect (JniMethodInfo method, IJavaPeera

JniEnvironment.StaticMethods.CallStaticVoidMethod (method.StaticRedirect.PeerReference, method, p);
return true;
#endif // NET
}
#pragma warning restore CA1801

Expand Down Expand Up @@ -102,9 +98,6 @@ public unsafe void InvokeNonvirtualVoidMethod (string encodedMember, IJavaPeerab
static unsafe bool TryInvokeBooleanStaticRedirect (JniMethodInfo method, IJavaPeerable self, JniArgumentValue* parameters, out bool r)
{
r = default;
#if !NET
return false;
#else // NET
if (method.StaticRedirect == null || !method.ParameterCount.HasValue) {
return false;
}
Expand All @@ -119,7 +112,6 @@ static unsafe bool TryInvokeBooleanStaticRedirect (JniMethodInfo method, IJavaPe

r = JniEnvironment.StaticMethods.CallStaticBooleanMethod (method.StaticRedirect.PeerReference, method, p);
return true;
#endif // NET
}
#pragma warning restore CA1801

Expand Down Expand Up @@ -191,9 +183,6 @@ public unsafe bool InvokeNonvirtualBooleanMethod (string encodedMember, IJavaPee
static unsafe bool TryInvokeSByteStaticRedirect (JniMethodInfo method, IJavaPeerable self, JniArgumentValue* parameters, out sbyte r)
{
r = default;
#if !NET
return false;
#else // NET
if (method.StaticRedirect == null || !method.ParameterCount.HasValue) {
return false;
}
Expand All @@ -208,7 +197,6 @@ static unsafe bool TryInvokeSByteStaticRedirect (JniMethodInfo method, IJavaPeer

r = JniEnvironment.StaticMethods.CallStaticByteMethod (method.StaticRedirect.PeerReference, method, p);
return true;
#endif // NET
}
#pragma warning restore CA1801

Expand Down Expand Up @@ -280,9 +268,6 @@ public unsafe sbyte InvokeNonvirtualSByteMethod (string encodedMember, IJavaPeer
static unsafe bool TryInvokeCharStaticRedirect (JniMethodInfo method, IJavaPeerable self, JniArgumentValue* parameters, out char r)
{
r = default;
#if !NET
return false;
#else // NET
if (method.StaticRedirect == null || !method.ParameterCount.HasValue) {
return false;
}
Expand All @@ -297,7 +282,6 @@ static unsafe bool TryInvokeCharStaticRedirect (JniMethodInfo method, IJavaPeera

r = JniEnvironment.StaticMethods.CallStaticCharMethod (method.StaticRedirect.PeerReference, method, p);
return true;
#endif // NET
}
#pragma warning restore CA1801

Expand Down Expand Up @@ -369,9 +353,6 @@ public unsafe char InvokeNonvirtualCharMethod (string encodedMember, IJavaPeerab
static unsafe bool TryInvokeInt16StaticRedirect (JniMethodInfo method, IJavaPeerable self, JniArgumentValue* parameters, out short r)
{
r = default;
#if !NET
return false;
#else // NET
if (method.StaticRedirect == null || !method.ParameterCount.HasValue) {
return false;
}
Expand All @@ -386,7 +367,6 @@ static unsafe bool TryInvokeInt16StaticRedirect (JniMethodInfo method, IJavaPeer

r = JniEnvironment.StaticMethods.CallStaticShortMethod (method.StaticRedirect.PeerReference, method, p);
return true;
#endif // NET
}
#pragma warning restore CA1801

Expand Down Expand Up @@ -458,9 +438,6 @@ public unsafe short InvokeNonvirtualInt16Method (string encodedMember, IJavaPeer
static unsafe bool TryInvokeInt32StaticRedirect (JniMethodInfo method, IJavaPeerable self, JniArgumentValue* parameters, out int r)
{
r = default;
#if !NET
return false;
#else // NET
if (method.StaticRedirect == null || !method.ParameterCount.HasValue) {
return false;
}
Expand All @@ -475,7 +452,6 @@ static unsafe bool TryInvokeInt32StaticRedirect (JniMethodInfo method, IJavaPeer

r = JniEnvironment.StaticMethods.CallStaticIntMethod (method.StaticRedirect.PeerReference, method, p);
return true;
#endif // NET
}
#pragma warning restore CA1801

Expand Down Expand Up @@ -547,9 +523,6 @@ public unsafe int InvokeNonvirtualInt32Method (string encodedMember, IJavaPeerab
static unsafe bool TryInvokeInt64StaticRedirect (JniMethodInfo method, IJavaPeerable self, JniArgumentValue* parameters, out long r)
{
r = default;
#if !NET
return false;
#else // NET
if (method.StaticRedirect == null || !method.ParameterCount.HasValue) {
return false;
}
Expand All @@ -564,7 +537,6 @@ static unsafe bool TryInvokeInt64StaticRedirect (JniMethodInfo method, IJavaPeer

r = JniEnvironment.StaticMethods.CallStaticLongMethod (method.StaticRedirect.PeerReference, method, p);
return true;
#endif // NET
}
#pragma warning restore CA1801

Expand Down Expand Up @@ -636,9 +608,6 @@ public unsafe long InvokeNonvirtualInt64Method (string encodedMember, IJavaPeera
static unsafe bool TryInvokeSingleStaticRedirect (JniMethodInfo method, IJavaPeerable self, JniArgumentValue* parameters, out float r)
{
r = default;
#if !NET
return false;
#else // NET
if (method.StaticRedirect == null || !method.ParameterCount.HasValue) {
return false;
}
Expand All @@ -653,7 +622,6 @@ static unsafe bool TryInvokeSingleStaticRedirect (JniMethodInfo method, IJavaPee

r = JniEnvironment.StaticMethods.CallStaticFloatMethod (method.StaticRedirect.PeerReference, method, p);
return true;
#endif // NET
}
#pragma warning restore CA1801

Expand Down Expand Up @@ -725,9 +693,6 @@ public unsafe float InvokeNonvirtualSingleMethod (string encodedMember, IJavaPee
static unsafe bool TryInvokeDoubleStaticRedirect (JniMethodInfo method, IJavaPeerable self, JniArgumentValue* parameters, out double r)
{
r = default;
#if !NET
return false;
#else // NET
if (method.StaticRedirect == null || !method.ParameterCount.HasValue) {
return false;
}
Expand All @@ -742,7 +707,6 @@ static unsafe bool TryInvokeDoubleStaticRedirect (JniMethodInfo method, IJavaPee

r = JniEnvironment.StaticMethods.CallStaticDoubleMethod (method.StaticRedirect.PeerReference, method, p);
return true;
#endif // NET
}
#pragma warning restore CA1801

Expand Down Expand Up @@ -814,9 +778,6 @@ public unsafe double InvokeNonvirtualDoubleMethod (string encodedMember, IJavaPe
static unsafe bool TryInvokeObjectStaticRedirect (JniMethodInfo method, IJavaPeerable self, JniArgumentValue* parameters, out JniObjectReference r)
{
r = default;
#if !NET
return false;
#else // NET
if (method.StaticRedirect == null || !method.ParameterCount.HasValue) {
return false;
}
Expand All @@ -831,7 +792,6 @@ static unsafe bool TryInvokeObjectStaticRedirect (JniMethodInfo method, IJavaPee

r = JniEnvironment.StaticMethods.CallStaticObjectMethod (method.StaticRedirect.PeerReference, method, p);
return true;
#endif // NET
}
#pragma warning restore CA1801

Expand Down
Loading