Skip to content
This repository was archived by the owner on Jul 6, 2026. It is now read-only.

Commit 3f6cf72

Browse files
authored
[.Localization, .Cecil, .Diagnostics, .Generator] $(Nullable)=enable (#746)
Update `Java.Interop.Localization.dll`, `Java.Interop.Tools.Cecil.dll`, `Java.Interop.Tools.Diagnostics.dll`, and `Java.Interop.Tools.Generator.dll` so that C# 8 [Nullable Reference Types][0] are used. [0]: https://docs.microsoft.com/dotnet/csharp/nullable-references
1 parent 2f62ffd commit 3f6cf72

11 files changed

Lines changed: 105 additions & 61 deletions

File tree

‎src/Java.Interop.Localization/Java.Interop.Localization.csproj‎

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

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5+
<LangVersion>8.0</LangVersion>
6+
<Nullable>enable</Nullable>
7+
<DefineConstants>INTERNAL_NULLABLE_ATTRIBUTES</DefineConstants>
58
</PropertyGroup>
69

710
<ItemGroup>
@@ -16,6 +19,10 @@
1619
</Compile>
1720
</ItemGroup>
1821

22+
<ItemGroup>
23+
<CompileInclude="..\utils\NullableAttributes.cs" />
24+
</ItemGroup>
25+
1926
<ItemGroup>
2027
<EmbeddedResourceUpdate="Resources.resx">
2128
<Generator>PublicResXFileCodeGenerator</Generator>

‎src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil.csproj‎

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

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5+
<LangVersion>8.0</LangVersion>
6+
<Nullable>enable</Nullable>
7+
<DefineConstants>INTERNAL_NULLABLE_ATTRIBUTES</DefineConstants>
58
</PropertyGroup>
69

710
<ImportProject="..\..\build-tools\scripts\cecil.projitems" />
@@ -10,6 +13,10 @@
1013
<OutputPath>$(ToolOutputFullPath)</OutputPath>
1114
</PropertyGroup>
1215

16+
<ItemGroup>
17+
<CompileInclude="..\utils\NullableAttributes.cs" />
18+
</ItemGroup>
19+
1320
<ItemGroup>
1421
<ProjectReferenceInclude="..\Java.Interop.Localization\Java.Interop.Localization.csproj" />
1522
<ProjectReferenceInclude="..\Java.Interop.Tools.Diagnostics\Java.Interop.Tools.Diagnostics.csproj" />

‎src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs‎

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class DirectoryAssemblyResolver : IAssemblyResolver {
6161

6262
publicICollection<string>SearchDirectories{get;privateset;}
6363

64-
Dictionary<string,AssemblyDefinition>cache;
64+
Dictionary<string,AssemblyDefinition?>cache;
6565
boolloadDebugSymbols;
6666
Action<TraceLevel,string>logger;
6767

@@ -71,18 +71,18 @@ public class DirectoryAssemblyResolver : IAssemblyResolver {
7171
};
7272

7373
[Obsolete("Use DirectoryAssemblyResolver(Action<TraceLevel, string>, bool, ReaderParameters)")]
74-
publicDirectoryAssemblyResolver(Action<string,object[]>logWarnings,boolloadDebugSymbols,ReaderParametersloadReaderParameters=null)
74+
publicDirectoryAssemblyResolver(Action<string,object[]>logWarnings,boolloadDebugSymbols,ReaderParameters?loadReaderParameters=null)
7575
:this((TraceLevellevel,stringvalue)=>logWarnings?.Invoke("{0}",new[]{value}),loadDebugSymbols,loadReaderParameters)
7676
{
7777
if(logWarnings==null)
7878
thrownewArgumentNullException(nameof(logWarnings));
7979
}
8080

81-
publicDirectoryAssemblyResolver(Action<TraceLevel,string>logger,boolloadDebugSymbols,ReaderParametersloadReaderParameters=null)
81+
publicDirectoryAssemblyResolver(Action<TraceLevel,string>logger,boolloadDebugSymbols,ReaderParameters?loadReaderParameters=null)
8282
{
8383
if(logger==null)
8484
thrownewArgumentNullException(nameof(logger));
85-
cache=newDictionary<string,AssemblyDefinition>();
85+
cache=newDictionary<string,AssemblyDefinition?>();
8686
this.loadDebugSymbols=loadDebugSymbols;
8787
this.logger=logger;
8888
SearchDirectories=newList<string>();
@@ -100,14 +100,14 @@ protected virtual void Dispose (bool disposing)
100100
if(!disposing||cache==null)
101101
return;
102102
foreach(vareincache){
103-
e.Value.Dispose();
103+
e.Value?.Dispose();
104104
}
105-
cache=null;
105+
cache.Clear();
106106
}
107107

108-
publicDictionary<string,AssemblyDefinition>ToResolverCache()
108+
publicDictionary<string,AssemblyDefinition?>ToResolverCache()
109109
{
110-
returnnewDictionary<string,AssemblyDefinition>(cache);
110+
returnnewDictionary<string,AssemblyDefinition?>(cache);
111111
}
112112

113113
publicboolAddToCache(AssemblyDefinitionassembly)
@@ -122,12 +122,12 @@ public bool AddToCache (AssemblyDefinition assembly)
122122
returntrue;
123123
}
124124

125-
publicvirtualAssemblyDefinitionLoad(stringfileName,boolforceLoad=false)
125+
publicvirtualAssemblyDefinition?Load(stringfileName,boolforceLoad=false)
126126
{
127127
if(!File.Exists(fileName))
128128
returnnull;
129129

130-
AssemblyDefinitionassembly=null;
130+
AssemblyDefinition?assembly=null;
131131
varname=Path.GetFileNameWithoutExtension(fileName);
132132
if(!forceLoad&&cache.TryGetValue(name,outassembly))
133133
returnassembly;
@@ -181,7 +181,7 @@ public AssemblyDefinition Resolve (string fullName)
181181
returnResolve(fullName,null);
182182
}
183183

184-
publicAssemblyDefinitionResolve(stringfullName,ReaderParametersparameters)
184+
publicAssemblyDefinitionResolve(stringfullName,ReaderParameters?parameters)
185185
{
186186
returnResolve(AssemblyNameReference.Parse(fullName),parameters);
187187
}
@@ -200,7 +200,7 @@ public string FindAssemblyFile (AssemblyNameReference reference)
200200
{
201201
varname=reference.Name;
202202

203-
stringassembly;
203+
string?assembly;
204204
foreach(vardirinSearchDirectories)
205205
if((assembly=SearchDirectory(name,dir))!=null)
206206
returnassembly;
@@ -216,20 +216,24 @@ public string FindAssemblyFile (AssemblyNameReference reference)
216216
name+".dll");
217217
}
218218

219-
publicAssemblyDefinitionResolve(AssemblyNameReferencereference,ReaderParametersparameters)
219+
publicAssemblyDefinitionResolve(AssemblyNameReferencereference,ReaderParameters?parameters)
220220
{
221221
varname=reference.Name;
222222

223-
AssemblyDefinitionassembly;
224-
if(cache.TryGetValue(name,outassembly))
223+
AssemblyDefinition?assembly;
224+
if(cache.TryGetValue(name,outassembly)){
225+
if(assemblyisnull)
226+
throwCreateLoadException(reference);
227+
225228
returnassembly;
229+
}
226230

227-
stringassemblyFile;
228-
AssemblyDefinitioncandidate=null;
231+
string?assemblyFile;
232+
AssemblyDefinition?candidate=null;
229233
foreach(vardirinSearchDirectories){
230234
if((assemblyFile=SearchDirectory(name,dir))!=null){
231235
varloaded=Load(assemblyFile);
232-
if(Array.Equals(loaded.Name.MetadataToken,reference.MetadataToken))
236+
if(Array.Equals(loaded?.Name.MetadataToken,reference.MetadataToken))
233237
returnloaded;
234238
candidate=candidate??loaded;
235239
}
@@ -238,18 +242,23 @@ public AssemblyDefinition Resolve (AssemblyNameReference reference, ReaderParame
238242
if(candidate!=null)
239243
returncandidate;
240244

241-
thrownewSystem.IO.FileNotFoundException(
245+
throwCreateLoadException(reference);
246+
}
247+
248+
staticFileNotFoundExceptionCreateLoadException(AssemblyNameReferencereference)
249+
{
250+
returnnewSystem.IO.FileNotFoundException(
242251
string.Format("Could not load assembly '{0}, Version={1}, Culture={2}, PublicKeyToken={3}'. Perhaps it doesn't exist in the Mono for Android profile?",
243-
name,
244-
reference.Version,
245-
string.IsNullOrEmpty(reference.Culture)?"neutral":reference.Culture,
252+
reference.Name,
253+
reference.Version,
254+
string.IsNullOrEmpty(reference.Culture)?"neutral":reference.Culture,
246255
reference.PublicKeyToken==null
247256
?"null"
248-
:string.Join("",reference.PublicKeyToken.Select(b =>b.ToString("x2")))),
249-
name+".dll");
257+
:string.Join("",reference.PublicKeyToken.Select(b =>b.ToString("x2")))),
258+
reference.Name+".dll");
250259
}
251260

252-
stringSearchDirectory(stringname,stringdirectory)
261+
string?SearchDirectory(stringname,stringdirectory)
253262
{
254263
if(Path.IsPathRooted(name)&&File.Exists(name))
255264
returnname;

‎src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/MethodDefinitionRocks.cs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static class MethodDefinitionRocks
1313
publicstaticMethodDefinitionGetBaseDefinition(thisMethodDefinitionmethod)=>
1414
GetBaseDefinition(method,cache:null);
1515

16-
publicstaticMethodDefinitionGetBaseDefinition(thisMethodDefinitionmethod,TypeDefinitionCachecache)
16+
publicstaticMethodDefinitionGetBaseDefinition(thisMethodDefinitionmethod,TypeDefinitionCache?cache)
1717
{
1818
if(method.IsStatic||method.IsNewSlot||!method.IsVirtual)
1919
returnmethod;
@@ -35,7 +35,7 @@ public static MethodDefinition GetBaseDefinition (this MethodDefinition method,
3535
publicstaticIEnumerable<MethodDefinition>GetOverriddenMethods(MethodDefinitionmethod,boolinherit)=>
3636
GetOverriddenMethods(method,inherit,cache:null);
3737

38-
publicstaticIEnumerable<MethodDefinition>GetOverriddenMethods(MethodDefinitionmethod,boolinherit,TypeDefinitionCachecache)
38+
publicstaticIEnumerable<MethodDefinition>GetOverriddenMethods(MethodDefinitionmethod,boolinherit,TypeDefinitionCache?cache)
3939
{
4040
yieldreturnmethod;
4141
if(inherit){
@@ -51,7 +51,7 @@ public static IEnumerable<MethodDefinition> GetOverriddenMethods (MethodDefiniti
5151
publicstaticboolAreParametersCompatibleWith(thisCollection<ParameterDefinition>a,Collection<ParameterDefinition>b)=>
5252
AreParametersCompatibleWith(a,b,cache:null);
5353

54-
publicstaticboolAreParametersCompatibleWith(thisCollection<ParameterDefinition>a,Collection<ParameterDefinition>b,TypeDefinitionCachecache)
54+
publicstaticboolAreParametersCompatibleWith(thisCollection<ParameterDefinition>a,Collection<ParameterDefinition>b,TypeDefinitionCache?cache)
5555
{
5656
if(a.Count!=b.Count)
5757
returnfalse;
@@ -66,15 +66,15 @@ public static bool AreParametersCompatibleWith (this Collection<ParameterDefinit
6666
returntrue;
6767
}
6868

69-
staticboolIsParameterCompatibleWith(IModifierTypea,IModifierTypeb,TypeDefinitionCachecache)
69+
staticboolIsParameterCompatibleWith(IModifierTypea,IModifierTypeb,TypeDefinitionCache?cache)
7070
{
7171
if(!IsParameterCompatibleWith(a.ModifierType,b.ModifierType,cache))
7272
returnfalse;
7373

7474
returnIsParameterCompatibleWith(a.ElementType,b.ElementType,cache);
7575
}
7676

77-
staticboolIsParameterCompatibleWith(TypeSpecificationa,TypeSpecificationb,TypeDefinitionCachecache)
77+
staticboolIsParameterCompatibleWith(TypeSpecificationa,TypeSpecificationb,TypeDefinitionCache?cache)
7878
{
7979
if(aisGenericInstanceType)
8080
returnIsParameterCompatibleWith((GenericInstanceType)a,(GenericInstanceType)b,cache);
@@ -85,7 +85,7 @@ static bool IsParameterCompatibleWith (TypeSpecification a, TypeSpecification b,
8585
returnIsParameterCompatibleWith(a.ElementType,b.ElementType,cache);
8686
}
8787

88-
staticboolIsParameterCompatibleWith(GenericInstanceTypea,GenericInstanceTypeb,TypeDefinitionCachecache)
88+
staticboolIsParameterCompatibleWith(GenericInstanceTypea,GenericInstanceTypeb,TypeDefinitionCache?cache)
8989
{
9090
if(!IsParameterCompatibleWith(a.ElementType,b.ElementType,cache))
9191
returnfalse;
@@ -103,7 +103,7 @@ static bool IsParameterCompatibleWith (GenericInstanceType a, GenericInstanceTyp
103103
returntrue;
104104
}
105105

106-
staticboolIsParameterCompatibleWith(TypeReferencea,TypeReferenceb,TypeDefinitionCachecache)
106+
staticboolIsParameterCompatibleWith(TypeReferencea,TypeReferenceb,TypeDefinitionCache?cache)
107107
{
108108
if(aisTypeSpecification||bisTypeSpecification){
109109
if(a.GetType()!=b.GetType())

‎src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs‎

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ namespace Java.Interop.Tools.Cecil {
88
publicstaticclassTypeDefinitionRocks{
99

1010
[Obsolete("Use the TypeDefinitionCache overload for better performance.")]
11-
publicstaticTypeDefinitionGetBaseType(thisTypeDefinitiontype)=>
11+
publicstaticTypeDefinition?GetBaseType(thisTypeDefinitiontype)=>
1212
GetBaseType(type,cache:null);
1313

14-
publicstaticTypeDefinitionGetBaseType(thisTypeDefinitiontype,TypeDefinitionCachecache)
14+
publicstaticTypeDefinition?GetBaseType(thisTypeDefinitiontype,TypeDefinitionCache?cache)
1515
{
1616
varbt=type.BaseType;
1717
if(bt==null)
@@ -25,30 +25,34 @@ public static TypeDefinition GetBaseType (this TypeDefinition type, TypeDefiniti
2525
publicstaticIEnumerable<TypeDefinition>GetTypeAndBaseTypes(thisTypeDefinitiontype)=>
2626
GetTypeAndBaseTypes(type,cache:null);
2727

28-
publicstaticIEnumerable<TypeDefinition>GetTypeAndBaseTypes(thisTypeDefinitiontype,TypeDefinitionCachecache)
28+
publicstaticIEnumerable<TypeDefinition>GetTypeAndBaseTypes(thisTypeDefinitiontype,TypeDefinitionCache?cache)
2929
{
30-
while(type!=null){
31-
yieldreturntype;
32-
type=type.GetBaseType(cache);
30+
TypeDefinition?t=type;
31+
32+
while(t!=null){
33+
yieldreturnt;
34+
t=t.GetBaseType(cache);
3335
}
3436
}
3537

3638
[Obsolete("Use the TypeDefinitionCache overload for better performance.")]
3739
publicstaticIEnumerable<TypeDefinition>GetBaseTypes(thisTypeDefinitiontype)=>
3840
GetBaseTypes(type,cache:null);
3941

40-
publicstaticIEnumerable<TypeDefinition>GetBaseTypes(thisTypeDefinitiontype,TypeDefinitionCachecache)
42+
publicstaticIEnumerable<TypeDefinition>GetBaseTypes(thisTypeDefinitiontype,TypeDefinitionCache?cache)
4143
{
42-
while((type=type.GetBaseType(cache))!=null){
43-
yieldreturntype;
44+
TypeDefinition?t=type;
45+
46+
while((t=t.GetBaseType(cache))!=null){
47+
yieldreturnt;
4448
}
4549
}
4650

4751
[Obsolete("Use the TypeDefinitionCache overload for better performance.")]
4852
publicstaticboolIsAssignableFrom(thisTypeReferencetype,TypeReferencec)=>
4953
IsAssignableFrom(type,c,cache:null);
5054

51-
publicstaticboolIsAssignableFrom(thisTypeReferencetype,TypeReferencec,TypeDefinitionCachecache)
55+
publicstaticboolIsAssignableFrom(thisTypeReferencetype,TypeReferencec,TypeDefinitionCache?cache)
5256
{
5357
if(type.FullName==c.FullName)
5458
returntrue;
@@ -71,7 +75,7 @@ public static bool IsAssignableFrom (this TypeReference type, TypeReference c, T
7175
publicstaticboolIsSubclassOf(thisTypeDefinitiontype,stringtypeName)=>
7276
IsSubclassOf(type,typeName,cache:null);
7377

74-
publicstaticboolIsSubclassOf(thisTypeDefinitiontype,stringtypeName,TypeDefinitionCachecache)
78+
publicstaticboolIsSubclassOf(thisTypeDefinitiontype,stringtypeName,TypeDefinitionCache?cache)
7579
{
7680
foreach(vartintype.GetTypeAndBaseTypes(cache)){
7781
if(t.FullName==typeName){
@@ -85,7 +89,7 @@ public static bool IsSubclassOf (this TypeDefinition type, string typeName, Type
8589
publicstaticboolImplementsInterface(thisTypeDefinitiontype,stringinterfaceName)=>
8690
ImplementsInterface(type,interfaceName,cache:null);
8791

88-
publicstaticboolImplementsInterface(thisTypeDefinitiontype,stringinterfaceName,TypeDefinitionCachecache)
92+
publicstaticboolImplementsInterface(thisTypeDefinitiontype,stringinterfaceName,TypeDefinitionCache?cache)
8993
{
9094
foreach(vartintype.GetTypeAndBaseTypes(cache)){
9195
foreach(variint.Interfaces){
@@ -101,7 +105,7 @@ public static bool ImplementsInterface (this TypeDefinition type, string interfa
101105
publicstaticstringGetPartialAssemblyName(thisTypeReferencetype)=>
102106
GetPartialAssemblyName(type,cache:null);
103107

104-
publicstaticstringGetPartialAssemblyName(thisTypeReferencetype,TypeDefinitionCachecache)
108+
publicstaticstringGetPartialAssemblyName(thisTypeReferencetype,TypeDefinitionCache?cache)
105109
{
106110
TypeDefinitiondef=cache!=null?cache.Resolve(type):type.Resolve();
107111
return(def??type).Module.Assembly.Name.Name;
@@ -111,7 +115,7 @@ public static string GetPartialAssemblyName (this TypeReference type, TypeDefini
111115
publicstaticstringGetPartialAssemblyQualifiedName(thisTypeReferencetype)=>
112116
GetPartialAssemblyQualifiedName(type,cache:null);
113117

114-
publicstaticstringGetPartialAssemblyQualifiedName(thisTypeReferencetype,TypeDefinitionCachecache)
118+
publicstaticstringGetPartialAssemblyQualifiedName(thisTypeReferencetype,TypeDefinitionCache?cache)
115119
{
116120
returnstring.Format("{0}, {1}",
117121
// Cecil likes to use '/' as the nested type separator, while
@@ -124,7 +128,7 @@ public static string GetPartialAssemblyQualifiedName (this TypeReference type, T
124128
publicstaticstringGetAssemblyQualifiedName(thisTypeReferencetype)=>
125129
GetAssemblyQualifiedName(type,cache:null);
126130

127-
publicstaticstringGetAssemblyQualifiedName(thisTypeReferencetype,TypeDefinitionCachecache)
131+
publicstaticstringGetAssemblyQualifiedName(thisTypeReferencetype,TypeDefinitionCache?cache)
128132
{
129133
TypeDefinitiondef=cache!=null?cache.Resolve(type):type.Resolve();
130134
returnstring.Format("{0}, {1}",
@@ -134,7 +138,7 @@ public static string GetAssemblyQualifiedName (this TypeReference type, TypeDefi
134138
(def??type).Module.Assembly.Name.FullName);
135139
}
136140

137-
publicstaticTypeDefinitionGetNestedType(thisTypeDefinitiontype,stringname)
141+
publicstaticTypeDefinition?GetNestedType(thisTypeDefinitiontype,stringname)
138142
{
139143
if(type==null)
140144
returnnull;
@@ -147,7 +151,7 @@ public static TypeDefinition GetNestedType (this TypeDefinition type, string nam
147151
}
148152

149153
// Note: this is not recursive, so it will not find nested types.
150-
publicstaticTypeDefinitionFindType(thisModuleDefinitionmodule,stringname)
154+
publicstaticTypeDefinition?FindType(thisModuleDefinitionmodule,stringname)
151155
{
152156
if(module==null)
153157
returnnull;

‎src/Java.Interop.Tools.Diagnostics/Java.Interop.Tools.Diagnostics.csproj‎

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

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5+
<LangVersion>8.0</LangVersion>
6+
<Nullable>enable</Nullable>
7+
<DefineConstants>INTERNAL_NULLABLE_ATTRIBUTES</DefineConstants>
58
</PropertyGroup>
69

710
<ImportProject="..\..\build-tools\scripts\cecil.projitems" />
@@ -10,4 +13,8 @@
1013
<OutputPath>$(ToolOutputFullPath)</OutputPath>
1114
</PropertyGroup>
1215

16+
<ItemGroup>
17+
<CompileInclude="..\utils\NullableAttributes.cs" />
18+
</ItemGroup>
19+
1320
</Project>

0 commit comments

Comments
 (0)