Skip to content

Commit bff9693

Browse files
committed
More Java.Interop nullability work.
1 parent 0d28dc6 commit bff9693

File tree

7 files changed

+74
-70
lines changed

7 files changed

+74
-70
lines changed

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ internal static ExportParameterAttribute ToExportParameterAttribute (CustomAttri
410410
public static bool IsApplication (TypeDefinition type) =>
411411
IsApplication (type, cache: null);
412412

413-
public static bool IsApplication (TypeDefinition type, TypeDefinitionCache cache)
413+
public static bool IsApplication (TypeDefinition type, TypeDefinitionCache? cache)
414414
{
415415
return type.GetBaseTypes (cache).Any (b => b.FullName == "Android.App.Application");
416416
}
@@ -419,17 +419,17 @@ public static bool IsApplication (TypeDefinition type, TypeDefinitionCache cache
419419
public static bool IsInstrumentation (TypeDefinition type) =>
420420
IsInstrumentation (type, cache: null);
421421

422-
public static bool IsInstrumentation (TypeDefinition type, TypeDefinitionCache cache)
422+
public static bool IsInstrumentation (TypeDefinition type, TypeDefinitionCache? cache)
423423
{
424424
return type.GetBaseTypes (cache).Any (b => b.FullName == "Android.App.Instrumentation");
425425
}
426426

427427
// moved from JavaTypeInfo
428428
[Obsolete ("Use the TypeDefinitionCache overload for better performance.")]
429-
public static string GetJniSignature (MethodDefinition method) =>
429+
public static string? GetJniSignature (MethodDefinition method) =>
430430
GetJniSignature (method, cache: null);
431431

432-
public static string GetJniSignature (MethodDefinition method, TypeDefinitionCache cache)
432+
public static string? GetJniSignature (MethodDefinition method, TypeDefinitionCache? cache)
433433
{
434434
return GetJniSignature<TypeReference,ParameterDefinition> (
435435
method.Parameters,
@@ -443,15 +443,15 @@ public static string GetJniSignature (MethodDefinition method, TypeDefinitionCac
443443

444444
// moved from JavaTypeInfo
445445
[Obsolete ("Use the TypeDefinitionCache overload for better performance.")]
446-
public static string GetJniTypeName (TypeReference typeRef) =>
446+
public static string? GetJniTypeName (TypeReference typeRef) =>
447447
GetJniTypeName (typeRef, cache: null);
448448

449-
public static string GetJniTypeName (TypeReference typeRef, TypeDefinitionCache cache)
449+
public static string? GetJniTypeName (TypeReference typeRef, TypeDefinitionCache? cache)
450450
{
451451
return GetJniTypeName (typeRef, ExportParameterKind.Unspecified, cache);
452452
}
453453

454-
internal static string GetJniTypeName (TypeReference typeRef, ExportParameterKind exportKind, TypeDefinitionCache cache)
454+
internal static string? GetJniTypeName (TypeReference typeRef, ExportParameterKind exportKind, TypeDefinitionCache? cache)
455455
{
456456
return GetJniTypeName<TypeReference, TypeDefinition> (typeRef, exportKind, t => t.Resolve (), t => {
457457
TypeReference etype;
@@ -464,7 +464,7 @@ internal static string GetJniTypeName (TypeReference typeRef, ExportParameterKin
464464
public static string ToCompatJniName (TypeDefinition type) =>
465465
ToCompatJniName (type, cache: null);
466466

467-
public static string ToCompatJniName (TypeDefinition type, TypeDefinitionCache cache)
467+
public static string ToCompatJniName (TypeDefinition type, TypeDefinitionCache? cache)
468468
{
469469
return ToJniName (type, t => t.DeclaringType, t => t.Name, ToCompatPackageName, ToJniNameFromAttributes, t => IsNonStaticInnerClass (t as TypeDefinition, cache));
470470
}
@@ -478,13 +478,13 @@ static string ToCompatPackageName (TypeDefinition type)
478478
public static string ToJniName (TypeDefinition type) =>
479479
ToJniName (type, cache: null);
480480

481-
public static string ToJniName (TypeDefinition type, TypeDefinitionCache cache)
481+
public static string ToJniName (TypeDefinition type, TypeDefinitionCache? cache)
482482
{
483483
return ToJniName (type, ExportParameterKind.Unspecified, cache) ??
484484
"java/lang/Object";
485485
}
486486

487-
static string ToJniName (TypeDefinition type, ExportParameterKind exportKind, TypeDefinitionCache cache)
487+
static string? ToJniName (TypeDefinition type, ExportParameterKind exportKind, TypeDefinitionCache? cache)
488488
{
489489
if (type == null)
490490
throw new ArgumentNullException ("type");
@@ -502,13 +502,13 @@ static string ToJniName (TypeDefinition type, ExportParameterKind exportKind, Ty
502502
return ToJniName (type, t => t.DeclaringType, t => t.Name, t => GetPackageName (t, cache), ToJniNameFromAttributes, t => IsNonStaticInnerClass (t as TypeDefinition, cache));
503503
}
504504

505-
static string ToJniNameFromAttributes (TypeDefinition type)
505+
static string? ToJniNameFromAttributes (TypeDefinition type)
506506
{
507507
#region CustomAttribute alternate name support
508508
var attrs = type.CustomAttributes.Where (a => a.AttributeType.Resolve ().Interfaces.Any (it => it.InterfaceType.FullName == typeof (IJniNameProviderAttribute).FullName));
509509
return attrs.Select (attr => {
510510
var ap = attr.Properties.FirstOrDefault (p => p.Name == "Name");
511-
string name = null;
511+
string? name = null;
512512
if (ap.Name == null) {
513513
var ca = attr.ConstructorArguments.FirstOrDefault ();
514514
if (ca.Type == null || ca.Type.FullName != "System.String")
@@ -536,7 +536,7 @@ public static int GetArrayInfo (Mono.Cecil.TypeReference type, out Mono.Cecil.Ty
536536
return rank;
537537
}
538538

539-
static string GetPrimitiveClass (Mono.Cecil.TypeDefinition type)
539+
static string? GetPrimitiveClass (Mono.Cecil.TypeDefinition type)
540540
{
541541
if (type.IsEnum)
542542
return GetPrimitiveClass (type.Fields.First (f => f.IsSpecialName).FieldType.Resolve ());
@@ -563,7 +563,7 @@ static string GetPrimitiveClass (Mono.Cecil.TypeDefinition type)
563563
public static string GetPackageName (TypeDefinition type) =>
564564
GetPackageName (type, cache: null);
565565

566-
public static string GetPackageName (TypeDefinition type, TypeDefinitionCache cache)
566+
public static string GetPackageName (TypeDefinition type, TypeDefinitionCache? cache)
567567
{
568568
if (IsPackageNamePreservedForAssembly (type.GetPartialAssemblyName (cache)))
569569
return type.Namespace.ToLowerInvariant ();
@@ -620,7 +620,7 @@ static string ToJniName<T> (T type, Func<T, T> decl, Func<T, string> name, Func<
620620
}
621621

622622
#if HAVE_CECIL
623-
internal static bool IsNonStaticInnerClass (TypeDefinition type, TypeDefinitionCache cache)
623+
internal static bool IsNonStaticInnerClass (TypeDefinition? type, TypeDefinitionCache? cache)
624624
{
625625
if (type == null)
626626
return false;
@@ -634,7 +634,7 @@ internal static bool IsNonStaticInnerClass (TypeDefinition type, TypeDefinitionC
634634
.Any (ctor => ctor.Parameters.Any (p => p.Name == "__self"));
635635
}
636636

637-
static IEnumerable<MethodDefinition> GetBaseConstructors (TypeDefinition type, TypeDefinitionCache cache)
637+
static IEnumerable<MethodDefinition> GetBaseConstructors (TypeDefinition type, TypeDefinitionCache? cache)
638638
{
639639
var baseType = type.GetBaseTypes (cache).FirstOrDefault (t => t.GetCustomAttributes (typeof (RegisterAttribute)).Any ());
640640
if (baseType != null)

src/Java.Interop/Java.Interop/JavaObjectArray.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public override IList<T> CreateGenericValue (ref JniObjectReference reference, J
158158
});
159159
}
160160

161-
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IList<T> value, ParameterAttributes synchronize)
161+
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull]IList<T> value, ParameterAttributes synchronize)
162162
{
163163
return JavaArray<T>.CreateArgumentState (value, synchronize, (list, copy) => {
164164
var a = copy
@@ -169,7 +169,7 @@ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState
169169
});
170170
}
171171

172-
public override void DestroyGenericArgumentState (IList<T> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
172+
public override void DestroyGenericArgumentState ([AllowNull]IList<T> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
173173
{
174174
JavaArray<T>.DestroyArgumentState<JavaObjectArray<T>> (value, ref state, synchronize);
175175
}

src/Java.Interop/Java.Interop/JavaPrimitiveArrays.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
using Java.Interop.Expressions;
99
using System.Linq.Expressions;
10+
using System.Diagnostics.CodeAnalysis;
1011

1112
namespace Java.Interop {
1213

@@ -246,7 +247,7 @@ public override IList<Boolean> CreateGenericValue (ref JniObjectReference refere
246247
(ref JniObjectReference h, JniObjectReferenceOptions o) => new JavaBooleanArray (ref h, o));
247248
}
248249

249-
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IList<Boolean> value, ParameterAttributes synchronize)
250+
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull]IList<Boolean> value, ParameterAttributes synchronize)
250251
{
251252
return JavaArray<Boolean>.CreateArgumentState (value, synchronize, (list, copy) => {
252253
var a = copy
@@ -257,7 +258,7 @@ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState
257258
});
258259
}
259260

260-
public override void DestroyGenericArgumentState (IList<Boolean> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
261+
public override void DestroyGenericArgumentState ([AllowNull]IList<Boolean> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
261262
{
262263
JavaArray<Boolean>.DestroyArgumentState<JavaBooleanArray> (value, ref state, synchronize);
263264
}
@@ -422,7 +423,7 @@ public override IList<SByte> CreateGenericValue (ref JniObjectReference referenc
422423
(ref JniObjectReference h, JniObjectReferenceOptions o) => new JavaSByteArray (ref h, o));
423424
}
424425

425-
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IList<SByte> value, ParameterAttributes synchronize)
426+
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull]IList<SByte> value, ParameterAttributes synchronize)
426427
{
427428
return JavaArray<SByte>.CreateArgumentState (value, synchronize, (list, copy) => {
428429
var a = copy
@@ -433,7 +434,7 @@ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState
433434
});
434435
}
435436

436-
public override void DestroyGenericArgumentState (IList<SByte> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
437+
public override void DestroyGenericArgumentState ([AllowNull]IList<SByte> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
437438
{
438439
JavaArray<SByte>.DestroyArgumentState<JavaSByteArray> (value, ref state, synchronize);
439440
}
@@ -598,7 +599,7 @@ public override IList<Char> CreateGenericValue (ref JniObjectReference reference
598599
(ref JniObjectReference h, JniObjectReferenceOptions o) => new JavaCharArray (ref h, o));
599600
}
600601

601-
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IList<Char> value, ParameterAttributes synchronize)
602+
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull]IList<Char> value, ParameterAttributes synchronize)
602603
{
603604
return JavaArray<Char>.CreateArgumentState (value, synchronize, (list, copy) => {
604605
var a = copy
@@ -609,7 +610,7 @@ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState
609610
});
610611
}
611612

612-
public override void DestroyGenericArgumentState (IList<Char> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
613+
public override void DestroyGenericArgumentState ([AllowNull]IList<Char> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
613614
{
614615
JavaArray<Char>.DestroyArgumentState<JavaCharArray> (value, ref state, synchronize);
615616
}
@@ -774,7 +775,7 @@ public override IList<Int16> CreateGenericValue (ref JniObjectReference referenc
774775
(ref JniObjectReference h, JniObjectReferenceOptions o) => new JavaInt16Array (ref h, o));
775776
}
776777

777-
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IList<Int16> value, ParameterAttributes synchronize)
778+
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull]IList<Int16> value, ParameterAttributes synchronize)
778779
{
779780
return JavaArray<Int16>.CreateArgumentState (value, synchronize, (list, copy) => {
780781
var a = copy
@@ -785,7 +786,7 @@ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState
785786
});
786787
}
787788

788-
public override void DestroyGenericArgumentState (IList<Int16> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
789+
public override void DestroyGenericArgumentState ([AllowNull]IList<Int16> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
789790
{
790791
JavaArray<Int16>.DestroyArgumentState<JavaInt16Array> (value, ref state, synchronize);
791792
}
@@ -950,7 +951,7 @@ public override IList<Int32> CreateGenericValue (ref JniObjectReference referenc
950951
(ref JniObjectReference h, JniObjectReferenceOptions o) => new JavaInt32Array (ref h, o));
951952
}
952953

953-
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IList<Int32> value, ParameterAttributes synchronize)
954+
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull]IList<Int32> value, ParameterAttributes synchronize)
954955
{
955956
return JavaArray<Int32>.CreateArgumentState (value, synchronize, (list, copy) => {
956957
var a = copy
@@ -961,7 +962,7 @@ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState
961962
});
962963
}
963964

964-
public override void DestroyGenericArgumentState (IList<Int32> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
965+
public override void DestroyGenericArgumentState ([AllowNull]IList<Int32> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
965966
{
966967
JavaArray<Int32>.DestroyArgumentState<JavaInt32Array> (value, ref state, synchronize);
967968
}
@@ -1126,7 +1127,7 @@ public override IList<Int64> CreateGenericValue (ref JniObjectReference referenc
11261127
(ref JniObjectReference h, JniObjectReferenceOptions o) => new JavaInt64Array (ref h, o));
11271128
}
11281129

1129-
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IList<Int64> value, ParameterAttributes synchronize)
1130+
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull]IList<Int64> value, ParameterAttributes synchronize)
11301131
{
11311132
return JavaArray<Int64>.CreateArgumentState (value, synchronize, (list, copy) => {
11321133
var a = copy
@@ -1137,7 +1138,7 @@ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState
11371138
});
11381139
}
11391140

1140-
public override void DestroyGenericArgumentState (IList<Int64> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
1141+
public override void DestroyGenericArgumentState ([AllowNull]IList<Int64> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
11411142
{
11421143
JavaArray<Int64>.DestroyArgumentState<JavaInt64Array> (value, ref state, synchronize);
11431144
}
@@ -1302,7 +1303,7 @@ public override IList<Single> CreateGenericValue (ref JniObjectReference referen
13021303
(ref JniObjectReference h, JniObjectReferenceOptions o) => new JavaSingleArray (ref h, o));
13031304
}
13041305

1305-
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IList<Single> value, ParameterAttributes synchronize)
1306+
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull]IList<Single> value, ParameterAttributes synchronize)
13061307
{
13071308
return JavaArray<Single>.CreateArgumentState (value, synchronize, (list, copy) => {
13081309
var a = copy
@@ -1313,7 +1314,7 @@ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState
13131314
});
13141315
}
13151316

1316-
public override void DestroyGenericArgumentState (IList<Single> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
1317+
public override void DestroyGenericArgumentState ([AllowNull]IList<Single> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
13171318
{
13181319
JavaArray<Single>.DestroyArgumentState<JavaSingleArray> (value, ref state, synchronize);
13191320
}
@@ -1478,7 +1479,7 @@ public override IList<Double> CreateGenericValue (ref JniObjectReference referen
14781479
(ref JniObjectReference h, JniObjectReferenceOptions o) => new JavaDoubleArray (ref h, o));
14791480
}
14801481

1481-
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState (IList<Double> value, ParameterAttributes synchronize)
1482+
public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState ([MaybeNull]IList<Double> value, ParameterAttributes synchronize)
14821483
{
14831484
return JavaArray<Double>.CreateArgumentState (value, synchronize, (list, copy) => {
14841485
var a = copy
@@ -1489,7 +1490,7 @@ public override JniValueMarshalerState CreateGenericObjectReferenceArgumentState
14891490
});
14901491
}
14911492

1492-
public override void DestroyGenericArgumentState (IList<Double> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
1493+
public override void DestroyGenericArgumentState ([AllowNull]IList<Double> value, ref JniValueMarshalerState state, ParameterAttributes synchronize)
14931494
{
14941495
JavaArray<Double>.DestroyArgumentState<JavaDoubleArray> (value, ref state, synchronize);
14951496
}

0 commit comments

Comments
 (0)