Skip to content

Commit 0eaa47e

Browse files
authored
[Java.Interop.Tools.JavaCallableWrappers] NRT Support (#1012)
Context: 3226a4b Context: 7068f4b Enable [C# 8 Nullable Reference Types][0] for `Java.Interop.Tools.JavaCallableWrappers.dll`. [0]: https://docs.microsoft.com/en-us/dotnet/csharp/nullable-references
1 parent 45fe392 commit 0eaa47e

File tree

11 files changed

+146
-108
lines changed

11 files changed

+146
-108
lines changed

src/Java.Interop.NamingCustomAttributes/Android.Runtime/RegisterAttribute.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#nullable enable
2+
13
using System;
24

35
using Mono.Cecil;
@@ -10,9 +12,9 @@ namespace Android.Runtime {
1012
#endif // !JCW_ONLY_TYPE_NAMES
1113
sealed class RegisterAttribute : Attribute, Java.Interop.IJniNameProviderAttribute {
1214

13-
string connector;
15+
string? connector;
1416
string name;
15-
string signature;
17+
string? signature;
1618

1719
public RegisterAttribute (string name)
1820
{
@@ -26,22 +28,22 @@ public RegisterAttribute (string name, string signature, string connector)
2628
this.signature = signature;
2729
}
2830
#if HAVE_CECIL
29-
public RegisterAttribute (string name, CustomAttribute originAttribute)
31+
public RegisterAttribute (string name, CustomAttribute? originAttribute)
3032
: this (name)
3133
{
3234
OriginAttribute = originAttribute;
3335
}
3436

35-
public RegisterAttribute (string name, string signature, string connector, CustomAttribute originAttribute)
37+
public RegisterAttribute (string name, string signature, string connector, CustomAttribute? originAttribute)
3638
: this (name, signature, connector)
3739
{
3840
OriginAttribute = originAttribute;
3941
}
4042

41-
public CustomAttribute OriginAttribute { get; }
43+
public CustomAttribute? OriginAttribute { get; }
4244
#endif // HAVE_CECIL
4345

44-
public string Connector {
46+
public string? Connector {
4547
get { return connector; }
4648
set { connector = value; }
4749
}
@@ -51,7 +53,7 @@ public string Name {
5153
set { name = value; }
5254
}
5355

54-
public string Signature {
56+
public string? Signature {
5557
get { return signature; }
5658
set { signature = value; }
5759
}

src/Java.Interop.NamingCustomAttributes/Java.Interop/ExportAttribute.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#nullable enable
2+
13
using System;
24

35
namespace Java.Interop {
@@ -15,15 +17,15 @@ public ExportAttribute ()
1517
{
1618
}
1719

18-
public ExportAttribute (string name)
20+
public ExportAttribute (string? name)
1921
{
2022
Name = name;
2123
}
2224

23-
public string Name {get; private set;}
24-
public string SuperArgumentsString {get; set;}
25-
public Type [] Throws {get; set;}
26-
internal string [] ThrownNames {get; set;} // msbuild internal use
25+
public string? Name {get; private set;}
26+
public string? SuperArgumentsString {get; set;}
27+
public Type []? Throws {get; set;}
28+
internal string []? ThrownNames {get; set;} // msbuild internal use
2729
}
2830
}
2931

src/Java.Interop.Tools.Diagnostics/Java.Interop.Tools.Diagnostics/Diagnostic.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ namespace Java.Interop.Tools.Diagnostics {
148148
//
149149

150150
public static class Diagnostic {
151-
public static void Error (int code, SequencePoint location, string message, params object[] args)
151+
public static void Error (int code, SequencePoint? location, string message, params object[] args)
152152
{
153153
throw new XamarinAndroidException (code, message, args) {
154154
Location = location,

src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
66
<LangVersion>8.0</LangVersion>
7+
<Nullable>enable</Nullable>
78
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
89
<SignAssembly>true</SignAssembly>
910
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>

src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/IdentifierValidator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public static class IdentifierValidator
3131
// We use [^ ...] to detect any character that is NOT a match.
3232
static Regex validIdentifier = new Regex ($"[^{Identifier}]", RegexOptions.Compiled);
3333

34-
public static string CreateValidIdentifier (string identifier, bool useEncodedReplacements = false)
34+
public static string CreateValidIdentifier (string? identifier, bool useEncodedReplacements = false)
3535
{
36-
if (string.IsNullOrWhiteSpace (identifier)) return string.Empty;
36+
if (identifier == null || string.IsNullOrWhiteSpace (identifier)) return string.Empty;
3737

3838
var normalizedIdentifier = identifier.Normalize ();
3939

0 commit comments

Comments
 (0)