(IEnumerable parameters, Func
getParameterType, Func
getExportKind, T returnType, ExportParameterKind returnExportKind, Func getJniTypeName, bool isConstructor)
+ static string? GetJniSignature (IEnumerable parameters, Func
getParameterType, Func
getExportKind, T returnType, ExportParameterKind returnExportKind, Func getJniTypeName, bool isConstructor)
{
StringBuilder sb = new StringBuilder ().Append ("(");
foreach (P p in parameters) {
- string jniType = getJniTypeName (getParameterType (p), getExportKind (p));
+ var jniType = getJniTypeName (getParameterType (p), getExportKind (p));
if (jniType == null)
return null;
sb.Append (jniType);
@@ -318,7 +322,7 @@ public static string ToJniNameFromAttributes (Type type)
if (isConstructor)
sb.Append ("V");
else {
- string jniType = getJniTypeName (returnType, returnExportKind);
+ var jniType = getJniTypeName (returnType, returnExportKind);
if (jniType == null)
return null;
sb.Append (jniType);
@@ -326,7 +330,7 @@ public static string ToJniNameFromAttributes (Type type)
return sb.ToString ();
}
- static string GetJniTypeName (TR typeRef, ExportParameterKind exportKind, Func
resolve, Func
> getArrayInfo, Func getFullName, Func | toJniName)
+ static string? GetJniTypeName |
(TR typeRef, ExportParameterKind exportKind, Func
resolve, Func
> getArrayInfo, Func getFullName, Func | toJniName)
{
TD ptype = resolve (typeRef);
var p = getArrayInfo (typeRef);
@@ -343,7 +347,7 @@ public static string ToJniNameFromAttributes (Type type)
// Probably a (IntPtr, JniHandleOwnership) parameter; skip
return null;
- string pJniName = toJniName (ptype, exportKind);
+ var pJniName = toJniName (ptype, exportKind);
if (pJniName == null) {
return null;
}
@@ -357,7 +361,7 @@ static ExportParameterKind GetExportKind (System.Reflection.ICustomAttributeProv
return ExportParameterKind.Unspecified;
}
- public static string GetJniSignature (MethodInfo method)
+ public static string? GetJniSignature (MethodInfo method)
{
return GetJniSignature (method.GetParameters (),
p => p.ParameterType,
@@ -368,21 +372,21 @@ public static string GetJniSignature (MethodInfo method)
method.IsConstructor);
}
- public static string GetJniTypeName (Type typeRef)
+ public static string? GetJniTypeName (Type typeRef)
{
return GetJniTypeName (typeRef, ExportParameterKind.Unspecified);
}
- internal static string GetJniTypeName (Type typeRef, ExportParameterKind exportKind)
+ internal static string? GetJniTypeName (Type typeRef, ExportParameterKind exportKind)
{
return GetJniTypeName (typeRef, exportKind, t => t, t => {
Type etype;
int rank = GetArrayInfo (t, out etype);
return new KeyValuePair (rank, etype);
- }, t => t.FullName, (t, k) => ToJniNameWhichShouldReplaceExistingToJniName (t, k));
+ }, t => t.FullName!, (t, k) => ToJniNameWhichShouldReplaceExistingToJniName (t, k));
}
- static string ToJniNameWhichShouldReplaceExistingToJniName (Type type, ExportParameterKind exportKind)
+ static string? ToJniNameWhichShouldReplaceExistingToJniName (Type type, ExportParameterKind exportKind)
{
// we need some method that exactly does the same as ToJniName(TypeDefinition)
var ret = ToJniNameFromAttributes (type);
@@ -407,7 +411,7 @@ internal static ExportParameterAttribute ToExportParameterAttribute (CustomAttri
public static bool IsApplication (TypeDefinition type) =>
IsApplication (type, cache: null);
- public static bool IsApplication (TypeDefinition type, TypeDefinitionCache cache)
+ public static bool IsApplication (TypeDefinition type, TypeDefinitionCache? cache)
{
return type.GetBaseTypes (cache).Any (b => b.FullName == "Android.App.Application");
}
@@ -416,17 +420,17 @@ public static bool IsApplication (TypeDefinition type, TypeDefinitionCache cache
public static bool IsInstrumentation (TypeDefinition type) =>
IsInstrumentation (type, cache: null);
- public static bool IsInstrumentation (TypeDefinition type, TypeDefinitionCache cache)
+ public static bool IsInstrumentation (TypeDefinition type, TypeDefinitionCache? cache)
{
return type.GetBaseTypes (cache).Any (b => b.FullName == "Android.App.Instrumentation");
}
// moved from JavaTypeInfo
[Obsolete ("Use the TypeDefinitionCache overload for better performance.")]
- public static string GetJniSignature (MethodDefinition method) =>
+ public static string? GetJniSignature (MethodDefinition method) =>
GetJniSignature (method, cache: null);
- public static string GetJniSignature (MethodDefinition method, TypeDefinitionCache cache)
+ public static string? GetJniSignature (MethodDefinition method, TypeDefinitionCache? cache)
{
return GetJniSignature (
method.Parameters,
@@ -440,15 +444,15 @@ public static string GetJniSignature (MethodDefinition method, TypeDefinitionCac
// moved from JavaTypeInfo
[Obsolete ("Use the TypeDefinitionCache overload for better performance.")]
- public static string GetJniTypeName (TypeReference typeRef) =>
+ public static string? GetJniTypeName (TypeReference typeRef) =>
GetJniTypeName (typeRef, cache: null);
- public static string GetJniTypeName (TypeReference typeRef, TypeDefinitionCache cache)
+ public static string? GetJniTypeName (TypeReference typeRef, TypeDefinitionCache? cache)
{
return GetJniTypeName (typeRef, ExportParameterKind.Unspecified, cache);
}
- internal static string GetJniTypeName (TypeReference typeRef, ExportParameterKind exportKind, TypeDefinitionCache cache)
+ internal static string? GetJniTypeName (TypeReference typeRef, ExportParameterKind exportKind, TypeDefinitionCache? cache)
{
return GetJniTypeName (typeRef, exportKind, t => t.Resolve (), t => {
TypeReference etype;
@@ -461,7 +465,7 @@ internal static string GetJniTypeName (TypeReference typeRef, ExportParameterKin
public static string ToCompatJniName (TypeDefinition type) =>
ToCompatJniName (type, cache: null);
- public static string ToCompatJniName (TypeDefinition type, TypeDefinitionCache cache)
+ public static string ToCompatJniName (TypeDefinition type, TypeDefinitionCache? cache)
{
return ToJniName (type, t => t.DeclaringType, t => t.Name, ToCompatPackageName, ToJniNameFromAttributes, t => IsNonStaticInnerClass (t as TypeDefinition, cache));
}
@@ -475,13 +479,13 @@ static string ToCompatPackageName (TypeDefinition type)
public static string ToJniName (TypeDefinition type) =>
ToJniName (type, cache: null);
- public static string ToJniName (TypeDefinition type, TypeDefinitionCache cache)
+ public static string ToJniName (TypeDefinition type, TypeDefinitionCache? cache)
{
return ToJniName (type, ExportParameterKind.Unspecified, cache) ??
"java/lang/Object";
}
- static string ToJniName (TypeDefinition type, ExportParameterKind exportKind, TypeDefinitionCache cache)
+ static string? ToJniName (TypeDefinition type, ExportParameterKind exportKind, TypeDefinitionCache? cache)
{
if (type == null)
throw new ArgumentNullException ("type");
@@ -499,13 +503,13 @@ static string ToJniName (TypeDefinition type, ExportParameterKind exportKind, Ty
return ToJniName (type, t => t.DeclaringType, t => t.Name, t => GetPackageName (t, cache), ToJniNameFromAttributes, t => IsNonStaticInnerClass (t as TypeDefinition, cache));
}
- static string ToJniNameFromAttributes (TypeDefinition type)
+ static string? ToJniNameFromAttributes (TypeDefinition type)
{
#region CustomAttribute alternate name support
var attrs = type.CustomAttributes.Where (a => a.AttributeType.Resolve ().Interfaces.Any (it => it.InterfaceType.FullName == typeof (IJniNameProviderAttribute).FullName));
return attrs.Select (attr => {
var ap = attr.Properties.FirstOrDefault (p => p.Name == "Name");
- string name = null;
+ string? name = null;
if (ap.Name == null) {
var ca = attr.ConstructorArguments.FirstOrDefault ();
if (ca.Type == null || ca.Type.FullName != "System.String")
@@ -533,7 +537,7 @@ public static int GetArrayInfo (Mono.Cecil.TypeReference type, out Mono.Cecil.Ty
return rank;
}
- static string GetPrimitiveClass (Mono.Cecil.TypeDefinition type)
+ static string? GetPrimitiveClass (Mono.Cecil.TypeDefinition type)
{
if (type.IsEnum)
return GetPrimitiveClass (type.Fields.First (f => f.IsSpecialName).FieldType.Resolve ());
@@ -560,7 +564,7 @@ static string GetPrimitiveClass (Mono.Cecil.TypeDefinition type)
public static string GetPackageName (TypeDefinition type) =>
GetPackageName (type, cache: null);
- public static string GetPackageName (TypeDefinition type, TypeDefinitionCache cache)
+ public static string GetPackageName (TypeDefinition type, TypeDefinitionCache? cache)
{
if (IsPackageNamePreservedForAssembly (type.GetPartialAssemblyName (cache)))
return type.Namespace.ToLowerInvariant ();
@@ -578,11 +582,11 @@ public static string GetPackageName (TypeDefinition type, TypeDefinitionCache ca
}
#endif
- static string ToJniName (T type, Func decl, Func name, Func ns, Func overrideName, Func shouldUpdateName)
+ static string ToJniName (T type, Func decl, Func name, Func ns, Func overrideName, Func shouldUpdateName)
where T : class
{
var nameParts = new List ();
- var typeName = (string) null;
+ var typeName = (string?) null;
var nsType = type;
for (var declType = type ; declType != null; declType = decl (declType)) {
@@ -617,7 +621,7 @@ static string ToJniName (T type, Func decl, Func name, Func<
}
#if HAVE_CECIL
- internal static bool IsNonStaticInnerClass (TypeDefinition type, TypeDefinitionCache cache)
+ internal static bool IsNonStaticInnerClass (TypeDefinition? type, TypeDefinitionCache? cache)
{
if (type == null)
return false;
@@ -631,7 +635,7 @@ internal static bool IsNonStaticInnerClass (TypeDefinition type, TypeDefinitionC
.Any (ctor => ctor.Parameters.Any (p => p.Name == "__self"));
}
- static IEnumerable GetBaseConstructors (TypeDefinition type, TypeDefinitionCache cache)
+ static IEnumerable GetBaseConstructors (TypeDefinition type, TypeDefinitionCache? cache)
{
var baseType = type.GetBaseTypes (cache).FirstOrDefault (t => t.GetCustomAttributes (typeof (RegisterAttribute)).Any ());
if (baseType != null)
diff --git a/src/Java.Interop/Java.Interop.csproj b/src/Java.Interop/Java.Interop.csproj
index 825c512a3..d085be3f4 100644
--- a/src/Java.Interop/Java.Interop.csproj
+++ b/src/Java.Interop/Java.Interop.csproj
@@ -19,6 +19,7 @@
DEBUG;$(DefineConstants)
+
diff --git a/src/Java.Interop/Java.Interop/JavaObjectArray.cs b/src/Java.Interop/Java.Interop/JavaObjectArray.cs
index 34735e0db..7a41a6274 100644
--- a/src/Java.Interop/Java.Interop/JavaObjectArray.cs
+++ b/src/Java.Interop/Java.Interop/JavaObjectArray.cs
@@ -158,7 +158,7 @@ public override IList CreateGenericValue (ref JniObjectReference reference, J
});
}
- public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IList value, ParameterAttributes synchronize)
+ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull]IList value, ParameterAttributes synchronize)
{
return JavaArray.CreateArgumentState (value, synchronize, (list, copy) => {
var a = copy
@@ -169,7 +169,7 @@ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState
});
}
- public override void DestroyGenericArgumentState (IList value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
+ public override void DestroyGenericArgumentState ([AllowNull]IList value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
{
JavaArray.DestroyArgumentState> (value, ref state, synchronize);
}
diff --git a/src/Java.Interop/Java.Interop/JniRuntime.JniMarshalMemberBuilder.cs b/src/Java.Interop/Java.Interop/JniRuntime.JniMarshalMemberBuilder.cs
index cb167a8a9..909184bb0 100644
--- a/src/Java.Interop/Java.Interop/JniRuntime.JniMarshalMemberBuilder.cs
+++ b/src/Java.Interop/Java.Interop/JniRuntime.JniMarshalMemberBuilder.cs
@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
@@ -203,7 +204,7 @@ public override JniValueMarshalerState CreateArgumentState (object? value, Param
throw new NotSupportedException ();
}
- public override JniValueMarshalerState CreateGenericArgumentState (IntPtr value, ParameterAttributes synchronize)
+ public override JniValueMarshalerState CreateGenericArgumentState ([MaybeNull]IntPtr value, ParameterAttributes synchronize)
{
throw new NotSupportedException ();
}
@@ -213,7 +214,7 @@ public override JniValueMarshalerState CreateObjectReferenceArgumentState (objec
throw new NotSupportedException ();
}
- public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IntPtr value, ParameterAttributes synchronize)
+ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull]IntPtr value, ParameterAttributes synchronize)
{
throw new NotSupportedException ();
}
diff --git a/src/Java.Interop/Java.Interop/JniRuntime.JniTypeManager.cs b/src/Java.Interop/Java.Interop/JniRuntime.JniTypeManager.cs
index c4de63a81..41d8ba07e 100644
--- a/src/Java.Interop/Java.Interop/JniRuntime.JniTypeManager.cs
+++ b/src/Java.Interop/Java.Interop/JniRuntime.JniTypeManager.cs
@@ -155,7 +155,7 @@ static Type GetUnderlyingType (Type type, out int rank)
}
// `type` will NOT be an array type.
- protected virtual string GetSimpleReference (Type type)
+ protected virtual string? GetSimpleReference (Type type)
{
return GetSimpleReferences (type).FirstOrDefault ();
}
diff --git a/src/Java.Interop/Java.Interop/JniRuntime.JniValueManager.cs b/src/Java.Interop/Java.Interop/JniRuntime.JniValueManager.cs
index 347e8f1e8..b344c0b2b 100644
--- a/src/Java.Interop/Java.Interop/JniRuntime.JniValueManager.cs
+++ b/src/Java.Interop/Java.Interop/JniRuntime.JniValueManager.cs
@@ -199,7 +199,7 @@ public virtual void DisposePeerUnlessReferenced (IJavaPeerable value)
DisposePeer (h, value);
}
- public abstract IJavaPeerable PeekPeer (JniObjectReference reference);
+ public abstract IJavaPeerable? PeekPeer (JniObjectReference reference);
public object? PeekValue (JniObjectReference reference)
{
@@ -261,7 +261,7 @@ static Type GetPeerType (Type type)
return type;
}
- public virtual IJavaPeerable CreatePeer (ref JniObjectReference reference, JniObjectReferenceOptions transfer, Type? targetType)
+ public virtual IJavaPeerable? CreatePeer (ref JniObjectReference reference, JniObjectReferenceOptions transfer, Type? targetType)
{
if (disposed)
throw new ObjectDisposedException (GetType ().Name);
@@ -396,7 +396,9 @@ public T CreateValue (ref JniObjectReference reference, JniObjectReferenceOpt
targetType = targetType ?? typeof (T);
if (typeof (IJavaPeerable).IsAssignableFrom (targetType)) {
+#pragma warning disable CS8601 // Possible null reference assignment.
return (T) JavaPeerableValueMarshaler.Instance.CreateGenericValue (ref reference, options, targetType);
+#pragma warning restore CS8601 // Possible null reference assignment.
}
var marshaler = GetValueMarshaler ();
@@ -473,7 +475,9 @@ public T GetValue (ref JniObjectReference reference, JniObjectReferenceOption
}
if (typeof (IJavaPeerable).IsAssignableFrom (targetType)) {
+#pragma warning disable CS8601 // Possible null reference assignment.
return (T) JavaPeerableValueMarshaler.Instance.CreateGenericValue (ref reference, options, targetType);
+#pragma warning restore CS8601 // Possible null reference assignment.
}
var marshaler = GetValueMarshaler ();
@@ -607,12 +611,12 @@ public override void DestroyArgumentState (object? value, ref JniValueMarshalerS
}
}
- sealed class JavaPeerableValueMarshaler : JniValueMarshaler {
+ sealed class JavaPeerableValueMarshaler : JniValueMarshaler {
internal static JavaPeerableValueMarshaler Instance = new JavaPeerableValueMarshaler ();
[return: MaybeNull]
- public override IJavaPeerable CreateGenericValue (ref JniObjectReference reference, JniObjectReferenceOptions options, Type? targetType)
+ public override IJavaPeerable? CreateGenericValue (ref JniObjectReference reference, JniObjectReferenceOptions options, Type? targetType)
{
var jvm = JniEnvironment.Runtime;
var marshaler = jvm.ValueManager.GetValueMarshaler (targetType ?? typeof(IJavaPeerable));
@@ -621,7 +625,7 @@ public override IJavaPeerable CreateGenericValue (ref JniObjectReference referen
return jvm.ValueManager.CreatePeer (ref reference, options, targetType);
}
- public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IJavaPeerable value, ParameterAttributes synchronize)
+ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull]IJavaPeerable? value, ParameterAttributes synchronize)
{
if (value == null || !value.PeerReference.IsValid)
return new JniValueMarshalerState ();
@@ -629,7 +633,7 @@ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState
return new JniValueMarshalerState (r);
}
- public override void DestroyGenericArgumentState (IJavaPeerable value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
+ public override void DestroyGenericArgumentState ([MaybeNull]IJavaPeerable? value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
{
var r = state.ReferenceValue;
JniObjectReference.Dispose (ref r);
@@ -694,12 +698,12 @@ public override T CreateGenericValue (ref JniObjectReference reference, JniObjec
return (T) ValueMarshaler.CreateValue (ref reference, options, targetType ?? typeof (T))!;
}
- public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (T value, ParameterAttributes synchronize)
+ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull]T value, ParameterAttributes synchronize)
{
return ValueMarshaler.CreateObjectReferenceArgumentState (value, synchronize);
}
- public override void DestroyGenericArgumentState (T value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
+ public override void DestroyGenericArgumentState ([AllowNull]T value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
{
ValueMarshaler.DestroyArgumentState (value, ref state, synchronize);
}
@@ -720,12 +724,12 @@ public override Expression CreateReturnValueFromManagedExpression (JniValueMarsh
}
}
- sealed class ProxyValueMarshaler : JniValueMarshaler |