Skip to content

Commit 10b69a3

Browse files
Remove legacy NET preprocessor paths
Make modern .NET code paths unconditional and remove obsolete non-NET/generated compatibility branches now that Java.Interop targets current .NET or netstandard2.0 only. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b881d21 commit 10b69a3

78 files changed

Lines changed: 11 additions & 472 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Documentation/Motivation.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ intended to fix some of the shortcomings and design mistakes I've made over the
1111

1212
In particular, it attempts to fix the following issues:
1313

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

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

31-

src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,12 @@ public static string ToJniName (Type type)
186186
}, _ => false);
187187
}
188188

189-
#if !NETSTANDARD2_0
190189
static readonly Lazy<Type> IJavaPeerableType = new Lazy<Type> (() =>
191190
Type.GetType ("Java.Interop.IJavaPeerable, Java.Interop", throwOnError: true)!
192191
);
193-
#endif
194192

195-
// NOTE: NETSTANDARD2_0 could be running in an MSBuild context where Java.Interop.dll is not available.
196-
// Trimming warnings are not enabled for netstandard2.0 in this project.
197193
static bool ShouldCheckSpecialExportJniType (Type type) =>
198-
#if NETSTANDARD2_0
199-
!type.GetInterfaces ().Any (t => t.FullName == "Java.Interop.IJavaPeerable");
200-
#else
201194
!IJavaPeerableType.Value.IsAssignableFrom (type);
202-
#endif
203195

204196
public static string ToJniName (string jniType, int rank)
205197
{
@@ -788,4 +780,3 @@ static string ToLowerCase (string value)
788780
}
789781
}
790782

791-

src/Java.Interop/Java.Interop/JavaArray.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public int Length {
3131

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

src/Java.Interop/Java.Interop/JavaTypeParametersAttribute.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22

3-
#if NET
43

54
namespace Java.Interop
65
{
@@ -16,5 +15,3 @@ public JavaTypeParametersAttribute (string [] typeParameters)
1615
public string [] TypeParameters { get; }
1716
}
1817
}
19-
20-
#endif // NET

src/Java.Interop/Java.Interop/JniConstructorSignatureAttribute.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System;
44
using System.Diagnostics.CodeAnalysis;
55

6-
#if NET
76

87
namespace Java.Interop
98
{
@@ -16,5 +15,3 @@ public JniConstructorSignatureAttribute (string memberSignature)
1615
}
1716
}
1817
}
19-
20-
#endif // NET

src/Java.Interop/Java.Interop/JniEnvironment.Types.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ static IntPtr RawCallStaticObjectMethodA (IntPtr env, out IntPtr thrown, IntPtr
197197
#endif // FEATURE_JNIENVIRONMENT_JI_FUNCTION_POINTERS
198198
}
199199

200-
#if NET
201200
public static bool TryFindClass (string classname, out JniObjectReference instance)
202201
{
203202
if (classname == null)
@@ -208,7 +207,6 @@ public static bool TryFindClass (string classname, out JniObjectReference instan
208207
instance = TryFindClass (classname, throwOnError: false);
209208
return instance.IsValid;
210209
}
211-
#endif // NET
212210

213211
public static JniType? GetTypeFromInstance (JniObjectReference instance)
214212
{
@@ -265,7 +263,7 @@ public static void RegisterNatives (JniObjectReference type, JniNativeMethodRegi
265263
throw new ArgumentOutOfRangeException (nameof (numMethods), numMethods,
266264
$"`numMethods` must be between 0 and `methods.Length` ({methods?.Length ?? 0})!");
267265
}
268-
#if DEBUG && NETCOREAPP
266+
#if DEBUG
269267
for (int i = 0; methods != null && i < numMethods; ++i) {
270268
var m = methods [i];
271269
if (m.Marshaler != null && m.Marshaler.GetType ().GenericTypeArguments.Length != 0) {
@@ -275,7 +273,7 @@ public static void RegisterNatives (JniObjectReference type, JniNativeMethodRegi
275273
Debug.WriteLine ($" Marshaler Type={m.Marshaler.GetType ().FullName} Method={method.DeclaringType?.FullName}.{method.Name}");
276274
}
277275
}
278-
#endif // DEBUG && NETCOREAPP
276+
#endif // DEBUG
279277

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

src/Java.Interop/Java.Interop/JniMemberSignature.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#nullable enable
22

3-
#if NET
4-
53
using System;
64
using System.Diagnostics.CodeAnalysis;
75
using System.Collections.Generic;
@@ -146,5 +144,3 @@ public override string ToString ()
146144
public static bool operator!= (JniMemberSignature a, JniMemberSignature b) => !a.Equals (b);
147145
}
148146
}
149-
150-
#endif // NET

src/Java.Interop/Java.Interop/JniMemberSignatureAttribute.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
using System;
44

5-
#if NET
65

76
namespace Java.Interop
87
{
@@ -23,5 +22,3 @@ internal JniMemberSignatureAttribute (string memberName, string memberSignature)
2322
public string MemberSignature {get;}
2423
}
2524
}
26-
27-
#endif // NET

src/Java.Interop/Java.Interop/JniMethodInfo.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ public sealed class JniMethodInfo
1010

1111
public bool IsStatic {get; private set;}
1212

13-
#if NET
1413
internal JniType? StaticRedirect;
1514
internal int? ParameterCount;
16-
#endif //NET
1715

1816
internal bool IsValid {
1917
get {return ID != IntPtr.Zero;}

src/Java.Interop/Java.Interop/JniMethodSignatureAttribute.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System;
44
using System.Diagnostics.CodeAnalysis;
55

6-
#if NET
76

87
namespace Java.Interop
98
{
@@ -16,5 +15,3 @@ public JniMethodSignatureAttribute (string memberName, string memberSignature)
1615
}
1716
}
1817
}
19-
20-
#endif // NET

0 commit comments

Comments
 (0)