From dac5f96646a8edef5cf10da9bcbad774ef8b8e9c Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Tue, 3 Jan 2023 12:07:23 -0600 Subject: [PATCH 1/4] [Java.Interop.Tools.JavaCallableWrappers] fix more places to use TypeDefinitionCache Reviewing code in `JavaCallableWrapperGenerator`, I found places we weren't using the supplied `TypeDefinitionCache` or `IMetadataResolver`. Thus we appeared to be calling `TypeReference.Resolve()` potentially on the same types. For example, `dotnet trace` output of an incremental build of a `dotnet new maui` project: 41.65ms xamarin.android.cecil!Mono.Cecil.TypeReference.Resolve() I created a new `TypeDefinitionRocks.ResolveCached()` method to be used everywhere instead. Resulting with: 23.89ms xamarin.android.cecil!Mono.Cecil.TypeReference.Resolve() Additionally, I updated to places to use plain `foreach` loops instead of System.Linq. Before: 1.03s xamarin.android.build.tasks!Xamarin.Android.Tasks.GenerateJavaStubs.RunTask() After: 944.48ms xamarin.android.build.tasks!Xamarin.Android.Tasks.GenerateJavaStubs.RunTask() I think this likely saves about ~50ms off incremental builds of a `dotnet new maui` project. --- .../TypeDefinitionRocks.cs | 13 ++-- .../JavaCallableWrapperGenerator.cs | 75 ++++++++++--------- .../JavaNativeTypeManager.cs | 17 ++--- 3 files changed, 51 insertions(+), 54 deletions(-) diff --git a/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs b/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs index 1bb282d19..c436a6d5f 100644 --- a/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs +++ b/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs @@ -7,6 +7,9 @@ namespace Java.Interop.Tools.Cecil { public static class TypeDefinitionRocks { + public static TypeDefinition ResolveCached (this TypeReference type, IMetadataResolver? resolver) => + resolver != null ? resolver.Resolve (type) : type.Resolve (); + [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] public static TypeDefinition? GetBaseType (this TypeDefinition type) => GetBaseType (type, resolver: null); @@ -19,9 +22,7 @@ public static class TypeDefinitionRocks { var bt = type.BaseType; if (bt == null) return null; - if (resolver != null) - return resolver.Resolve (bt); - return bt.Resolve (); + return bt.ResolveCached (resolver); } [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] @@ -68,7 +69,7 @@ public static bool IsAssignableFrom (this TypeReference type, TypeReference c, I { if (type.FullName == c.FullName) return true; - var d = (resolver?.Resolve (c)) ?? c.Resolve (); + var d = c.ResolveCached (resolver); if (d == null) return false; foreach (var t in d.GetTypeAndBaseTypes (resolver)) { @@ -127,7 +128,7 @@ public static string GetPartialAssemblyName (this TypeReference type, TypeDefini public static string GetPartialAssemblyName (this TypeReference type, IMetadataResolver? resolver) { - TypeDefinition? def = (resolver?.Resolve (type)) ?? type.Resolve (); + TypeDefinition? def = type.ResolveCached (resolver); return (def ?? type).Module.Assembly.Name.Name; } @@ -156,7 +157,7 @@ public static string GetAssemblyQualifiedName (this TypeReference type, TypeDefi public static string GetAssemblyQualifiedName (this TypeReference type, IMetadataResolver? resolver) { - TypeDefinition? def = (resolver?.Resolve (type)) ?? type.Resolve (); + TypeDefinition? def = type.ResolveCached(resolver); return string.Format ("{0}, {1}", // Cecil likes to use '/' as the nested type separator, while // Reflection uses '+' as the nested type separator. Use Reflection. diff --git a/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaCallableWrapperGenerator.cs b/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaCallableWrapperGenerator.cs index d102d57a6..14752be62 100644 --- a/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaCallableWrapperGenerator.cs +++ b/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaCallableWrapperGenerator.cs @@ -41,7 +41,7 @@ public JavaFieldInfo (MethodDefinition method, string fieldName, IMetadataResolv ?? throw new ArgumentException ($"Could not get JNI signature for method `{method.Name}`", nameof (method)); IsStatic = method.IsStatic; Access = method.Attributes & MethodAttributes.MemberAccessMask; - Annotations = GetAnnotationsString ("\t", method.CustomAttributes); + Annotations = GetAnnotationsString ("\t", method.CustomAttributes, resolver); } public MethodAttributes Access { get; private set; } @@ -175,20 +175,23 @@ void AddNestedTypes (TypeDefinition type) } } - foreach (MethodDefinition imethod in type.Interfaces.Select (ifaceInfo => ifaceInfo.InterfaceType) - .Select (r => { - var d = r.Resolve (); - if (d == null) - Diagnostic.Error (4204, - LookupSource (type), - Localization.Resources.JavaCallableWrappers_XA4204, - r.FullName); - return d; - }) - .Where (d => d != null && GetTypeRegistrationAttributes (d).Any ()) - .SelectMany (d => d!.Methods) - .Where (m => !m.IsStatic)) { - AddMethod (imethod, imethod); + foreach (InterfaceImplementation ifaceInfo in type.Interfaces) { + var typeReference = ifaceInfo.InterfaceType; + var typeDefinition = typeReference.ResolveCached (resolver); + if (typeDefinition == null) { + Diagnostic.Error (4204, + LookupSource (type), + Localization.Resources.JavaCallableWrappers_XA4204, + typeReference.FullName); + continue; + } + if (!GetTypeRegistrationAttributes (typeDefinition).Any ()) + continue; + foreach (MethodDefinition imethod in typeDefinition.Methods) { + if (imethod.IsStatic) + continue; + AddMethod (imethod, imethod); + } } var ctorTypes = new List () { @@ -303,7 +306,7 @@ void AddConstructor (MethodDefinition ctor, TypeDefinition type, string? outerTy if (rattr != null) { if (ctors.Any (c => c.JniSignature == rattr.Signature)) return; - ctors.Add (new Signature (ctor, rattr, managedParameters, outerType)); + ctors.Add (new Signature (ctor, rattr, managedParameters, outerType, cache)); curCtors.Add (ctor); return; } @@ -473,7 +476,7 @@ void AddMethod (MethodDefinition? registeredMethod, MethodDefinition implemented Diagnostic.Error (4217, LookupSource (implementedMethod), Localization.Resources.JavaCallableWrappers_XA4217, attr.Name); bool shouldBeDynamicallyRegistered = methodClassifier?.ShouldBeDynamicallyRegistered (type, registeredMethod, implementedMethod, attr.OriginAttribute) ?? true; - var msig = new Signature (implementedMethod, attr, shouldBeDynamicallyRegistered); + var msig = new Signature (implementedMethod, attr, cache, shouldBeDynamicallyRegistered); if (!registeredMethod.IsConstructor && !methods.Any (m => m.Name == msig.Name && m.Params == msig.Params)) methods.Add (msig); } @@ -601,17 +604,17 @@ public void Generate (string outputPath) } } - static string GetAnnotationsString (string indent, IEnumerable atts) + static string GetAnnotationsString (string indent, IEnumerable atts, IMetadataResolver? resolver) { var sw = new StringWriter (); - WriteAnnotations (indent, sw, atts); + WriteAnnotations (indent, sw, atts, resolver); return sw.ToString (); } - static void WriteAnnotations (string indent, TextWriter sw, IEnumerable atts) + static void WriteAnnotations (string indent, TextWriter sw, IEnumerable atts, IMetadataResolver? resolver) { foreach (var ca in atts) { - var catype = ca.AttributeType.Resolve (); + var catype = ca.AttributeType.ResolveCached (resolver); var tca = catype.CustomAttributes.FirstOrDefault (a => a.AttributeType.FullName == "Android.Runtime.AnnotationAttribute"); if (tca != null) { sw.Write (indent); @@ -655,7 +658,7 @@ void GenerateHeader (TextWriter sw) sw.WriteLine (); // class annotations. - WriteAnnotations ("", sw, type.CustomAttributes); + WriteAnnotations ("", sw, type.CustomAttributes, cache); sw.WriteLine ("public " + (type.IsAbstract ? "abstract " : "") + "class " + name); @@ -673,15 +676,13 @@ void GenerateHeader (TextWriter sw) sw.Write ("mono.android.IGCUserPeer"); break; } - IEnumerable ifaces = type.Interfaces.Select (ifaceInfo => ifaceInfo.InterfaceType) - .Select (r => r.Resolve ()) - .Where (d => GetTypeRegistrationAttributes (d).Any ()); - if (ifaces.Any ()) { - foreach (TypeDefinition iface in ifaces) { - sw.WriteLine (","); - sw.Write ("\t\t"); - sw.Write (GetJavaTypeName (iface, cache)); - } + foreach (var ifaceInfo in type.Interfaces) { + var iface = ifaceInfo.InterfaceType.ResolveCached (cache); + if (!GetTypeRegistrationAttributes (iface).Any ()) + continue; + sw.WriteLine (","); + sw.Write ("\t\t"); + sw.Write (GetJavaTypeName (iface, cache)); } sw.WriteLine (); sw.WriteLine ("{"); @@ -811,7 +812,7 @@ static string GetJavaAccess (MethodAttributes access) static string GetJavaTypeName (TypeReference r, IMetadataResolver cache) { - TypeDefinition d = r.Resolve (); + TypeDefinition d = cache.Resolve (r); string? jniName = JavaNativeTypeManager.ToJniName (d, cache); if (jniName == null) { Diagnostic.Error (4201, Localization.Resources.JavaCallableWrappers_XA4201, r.FullName); @@ -827,12 +828,12 @@ bool CannotRegisterInStaticConstructor (TypeDefinition type) class Signature { - public Signature (MethodDefinition method, RegisterAttribute register, bool shouldBeDynamicallyRegistered = true) : this (method, register, null, null, shouldBeDynamicallyRegistered) {} + public Signature (MethodDefinition method, RegisterAttribute register, IMetadataResolver cache, bool shouldBeDynamicallyRegistered = true) : this (method, register, null, null, cache, shouldBeDynamicallyRegistered) {} - public Signature (MethodDefinition method, RegisterAttribute register, string? managedParameters, string? outerType, bool shouldBeDynamicallyRegistered = true) + public Signature (MethodDefinition method, RegisterAttribute register, string? managedParameters, string? outerType, IMetadataResolver cache, bool shouldBeDynamicallyRegistered = true) : this (register.Name, register.Signature, register.Connector, managedParameters, outerType, null) { - Annotations = JavaCallableWrapperGenerator.GetAnnotationsString ("\t", method.CustomAttributes); + Annotations = JavaCallableWrapperGenerator.GetAnnotationsString ("\t", method.CustomAttributes, cache); IsDynamicallyRegistered = shouldBeDynamicallyRegistered; } @@ -844,10 +845,10 @@ public Signature (MethodDefinition method, ExportAttribute export, IMetadataReso JavaAccess = JavaCallableWrapperGenerator.GetJavaAccess (method.Attributes & MethodAttributes.MemberAccessMask); ThrownTypeNames = export.ThrownNames; JavaNameOverride = export.Name; - Annotations = JavaCallableWrapperGenerator.GetAnnotationsString ("\t", method.CustomAttributes); + Annotations = JavaCallableWrapperGenerator.GetAnnotationsString ("\t", method.CustomAttributes, cache); } - public Signature (MethodDefinition method, ExportFieldAttribute exportField, IMetadataResolver? cache) + public Signature (MethodDefinition method, ExportFieldAttribute exportField, IMetadataResolver cache) : this (method.Name, GetJniSignature (method, cache), "__export__", null, null, null) { if (method.HasParameters) diff --git a/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs b/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs index 24370f719..5366462e5 100644 --- a/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs +++ b/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs @@ -473,7 +473,7 @@ public static bool IsInstrumentation (TypeDefinition type, IMetadataResolver? re internal static string? GetJniTypeName (TypeReference typeRef, ExportParameterKind exportKind, IMetadataResolver? cache) { - return GetJniTypeName (typeRef, exportKind, t => t.Resolve (), t => { + return GetJniTypeName (typeRef, exportKind, t => t.ResolveCached (cache), t => { TypeReference etype; int rank = GetArrayInfo (typeRef, out etype); return new KeyValuePair (rank,etype); @@ -525,7 +525,7 @@ public static string ToJniName (TypeDefinition type, IMetadataResolver? resolver throw new ArgumentNullException ("type"); if (type.IsValueType) - return GetPrimitiveClass (type); + return GetPrimitiveClass (type, cache); if (type.FullName == "System.String") return "java/lang/String"; @@ -554,7 +554,7 @@ public static string ToJniName (TypeDefinition type, IMetadataResolver? resolver static string? ToJniNameFromAttributesForInterop (TypeDefinition type, IMetadataResolver? resolver) { var attr = type.CustomAttributes.FirstOrDefault (a => - Resolve (resolver, a.AttributeType) + a.AttributeType.ResolveCached (resolver) .FullName == "Java.Interop.JniTypeSignatureAttribute"); if (attr == null) { return null; @@ -604,17 +604,12 @@ static bool IsIJniNameProviderAttribute (CustomAttribute attr, IMetadataResolver return true; // Slow path resolves the type, looking for IJniNameProviderAttribute - var attributeType = Resolve (resolver, attr.AttributeType); + var attributeType = attr.AttributeType.ResolveCached (resolver); if (!attributeType.HasInterfaces) return false; return attributeType.Interfaces.Any (it => it.InterfaceType.FullName == typeof (IJniNameProviderAttribute).FullName); } - static TypeDefinition Resolve (IMetadataResolver? resolver, TypeReference typeReference) => - resolver?.Resolve (typeReference) ?? - typeReference.Resolve () ?? - throw new InvalidOperationException (); - public static int GetArrayInfo (Mono.Cecil.TypeReference type, out Mono.Cecil.TypeReference elementType) { elementType = type; @@ -626,10 +621,10 @@ 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, IMetadataResolver? cache) { if (type.IsEnum) - return GetPrimitiveClass (type.Fields.First (f => f.IsSpecialName).FieldType.Resolve ()); + return GetPrimitiveClass (type.Fields.First (f => f.IsSpecialName).FieldType.ResolveCached (cache), cache); if (type.FullName == "System.Byte") return "B"; if (type.FullName == "System.Char") From f3979e9f8b47f3cbbafce65aacffc8ad1e4f0733 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Wed, 4 Jan 2023 14:29:30 -0600 Subject: [PATCH 2/4] APIs now *require* `TypeDefinitionCache` Any place we had: TypeDefinitionCache? IMetadataResolver? These no longer allow nulls, and so overloads that use `Obsolete` now emit errors instead of warnings: [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] public static MethodDefinition GetBaseDefinition (this MethodDefinition method) => GetBaseDefinition (method, resolver: null!); This results in 3 compiler errors in xamarin-android: src\Xamarin.Android.Build.Tasks\Mono.Android\ApplicationAttribute.Partial.cs(65,11): error CS0619: 'TypeDefinitionRocks.IsSubclassOf(TypeDefinition, string)' is obsolete: 'Use the TypeDefinitionCache overload for better performance.' src\Xamarin.Android.Build.Tasks\Mono.Android\ApplicationAttribute.Partial.cs(268,12): error CS0619: 'JavaNativeTypeManager.ToJniName(TypeDefinition)' is obsolete: 'Use the TypeDefinitionCache overload for better performance.' src\Xamarin.Android.Build.Tasks\Utilities\ManifestDocumentElement.cs(28,11): error CS0619: 'JavaNativeTypeManager.ToJniName(TypeDefinition)' is obsolete: 'Use the TypeDefinitionCache overload for better performance.' After these changes, it appears we will improve the performance further of apps that use: * `ApplicationAttribute.BackupAgent` * `ApplicationAttribute.Name` * `AndroidManifest.xml` attributes that take a `System.Type` values The full scope of changes required in xamarin/xamarin-android will be: https://github.com/xamarin/xamarin-android/compare/main...jonathanpeppers:JavaInteropBreakingChanges Additionally, this found a couple places in `generator` where changes were needed. --- .../MethodDefinitionRocks.cs | 38 ++++---- .../TypeDefinitionRocks.cs | 63 +++++++------- .../JavaCallableWrapperGenerator.cs | 30 +++---- .../JavaTypeScanner.cs | 10 +-- .../Adapters/ManagedApiImporter.cs | 14 +-- .../JavaNativeTypeManager.cs | 86 +++++++++---------- tools/generator/CodeGenerator.cs | 2 +- .../JavaTypeResolutionFixups.cs | 8 +- 8 files changed, 129 insertions(+), 122 deletions(-) diff --git a/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/MethodDefinitionRocks.cs b/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/MethodDefinitionRocks.cs index 9b9ae0974..2b73e6177 100644 --- a/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/MethodDefinitionRocks.cs +++ b/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/MethodDefinitionRocks.cs @@ -9,14 +9,14 @@ namespace Java.Interop.Tools.Cecil { public static class MethodDefinitionRocks { - [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] + [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] public static MethodDefinition GetBaseDefinition (this MethodDefinition method) => - GetBaseDefinition (method, resolver: null); + GetBaseDefinition (method, resolver: null!); - public static MethodDefinition GetBaseDefinition (this MethodDefinition method, TypeDefinitionCache? cache) => - GetBaseDefinition (method, (IMetadataResolver?) cache); + public static MethodDefinition GetBaseDefinition (this MethodDefinition method, TypeDefinitionCache cache) => + GetBaseDefinition (method, (IMetadataResolver) cache); - public static MethodDefinition GetBaseDefinition (this MethodDefinition method, IMetadataResolver? resolver) + public static MethodDefinition GetBaseDefinition (this MethodDefinition method, IMetadataResolver resolver) { if (method.IsStatic || method.IsNewSlot || !method.IsVirtual) return method; @@ -34,14 +34,14 @@ public static MethodDefinition GetBaseDefinition (this MethodDefinition method, return method; } - [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] + [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] public static IEnumerable GetOverriddenMethods (MethodDefinition method, bool inherit) => - GetOverriddenMethods (method, inherit, resolver: null); + GetOverriddenMethods (method, inherit, resolver: null!); - public static IEnumerable GetOverriddenMethods (MethodDefinition method, bool inherit, TypeDefinitionCache? cache) => - GetOverriddenMethods (method, inherit, (IMetadataResolver?) cache); + public static IEnumerable GetOverriddenMethods (MethodDefinition method, bool inherit, TypeDefinitionCache cache) => + GetOverriddenMethods (method, inherit, (IMetadataResolver) cache); - public static IEnumerable GetOverriddenMethods (MethodDefinition method, bool inherit, IMetadataResolver? resolver) + public static IEnumerable GetOverriddenMethods (MethodDefinition method, bool inherit, IMetadataResolver resolver) { yield return method; if (inherit) { @@ -53,14 +53,14 @@ public static IEnumerable GetOverriddenMethods (MethodDefiniti } } - [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] + [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] public static bool AreParametersCompatibleWith (this Collection a, Collection b) => - AreParametersCompatibleWith (a, b, resolver: null); + AreParametersCompatibleWith (a, b, resolver: null!); - public static bool AreParametersCompatibleWith (this Collection a, Collection b, TypeDefinitionCache? cache) => - AreParametersCompatibleWith (a, b, (IMetadataResolver?) cache); + public static bool AreParametersCompatibleWith (this Collection a, Collection b, TypeDefinitionCache cache) => + AreParametersCompatibleWith (a, b, (IMetadataResolver) cache); - public static bool AreParametersCompatibleWith (this Collection a, Collection b, IMetadataResolver? resolver) + public static bool AreParametersCompatibleWith (this Collection a, Collection b, IMetadataResolver resolver) { if (a.Count != b.Count) return false; @@ -75,7 +75,7 @@ public static bool AreParametersCompatibleWith (this Collection + static TypeDefinition ResolveCached (this TypeReference type, IMetadataResolver? resolver) => resolver != null ? resolver.Resolve (type) : type.Resolve (); - [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] + [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] public static TypeDefinition? GetBaseType (this TypeDefinition type) => - GetBaseType (type, resolver: null); + GetBaseType (type, resolver: null!); - public static TypeDefinition? GetBaseType (this TypeDefinition type, TypeDefinitionCache? cache) => - GetBaseType (type, (IMetadataResolver?) cache); + public static TypeDefinition? GetBaseType (this TypeDefinition type, TypeDefinitionCache cache) => + GetBaseType (type, (IMetadataResolver) cache); - public static TypeDefinition? GetBaseType (this TypeDefinition type, IMetadataResolver? resolver) + public static TypeDefinition? GetBaseType (this TypeDefinition type, IMetadataResolver resolver) { var bt = type.BaseType; if (bt == null) @@ -25,14 +24,14 @@ public static TypeDefinition ResolveCached (this TypeReference type, IMetadataRe return bt.ResolveCached (resolver); } - [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] + [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] public static IEnumerable GetTypeAndBaseTypes (this TypeDefinition type) => - GetTypeAndBaseTypes (type, resolver: null); + GetTypeAndBaseTypes (type, resolver: null!); - public static IEnumerable GetTypeAndBaseTypes (this TypeDefinition type, TypeDefinitionCache? cache) => - GetTypeAndBaseTypes (type, (IMetadataResolver?) cache); + public static IEnumerable GetTypeAndBaseTypes (this TypeDefinition type, TypeDefinitionCache cache) => + GetTypeAndBaseTypes (type, (IMetadataResolver) cache); - public static IEnumerable GetTypeAndBaseTypes (this TypeDefinition type, IMetadataResolver? resolver) + public static IEnumerable GetTypeAndBaseTypes (this TypeDefinition type, IMetadataResolver resolver) { TypeDefinition? t = type; @@ -42,14 +41,14 @@ public static IEnumerable GetTypeAndBaseTypes (this TypeDefiniti } } - [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] + [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] public static IEnumerable GetBaseTypes (this TypeDefinition type) => - GetBaseTypes (type, resolver: null); + GetBaseTypes (type, resolver: null!); - public static IEnumerable GetBaseTypes (this TypeDefinition type, TypeDefinitionCache? cache) => - GetBaseTypes (type, (IMetadataResolver?) cache); + public static IEnumerable GetBaseTypes (this TypeDefinition type, TypeDefinitionCache cache) => + GetBaseTypes (type, (IMetadataResolver) cache); - public static IEnumerable GetBaseTypes (this TypeDefinition type, IMetadataResolver? resolver) + public static IEnumerable GetBaseTypes (this TypeDefinition type, IMetadataResolver resolver) { TypeDefinition? t = type; @@ -58,14 +57,14 @@ public static IEnumerable GetBaseTypes (this TypeDefinition type } } - [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] + [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] public static bool IsAssignableFrom (this TypeReference type, TypeReference c) => - IsAssignableFrom (type, c, resolver: null); + IsAssignableFrom (type, c, resolver: null!); - public static bool IsAssignableFrom (this TypeReference type, TypeReference c, TypeDefinitionCache? cache) => - IsAssignableFrom (type, c, (IMetadataResolver?) cache); + public static bool IsAssignableFrom (this TypeReference type, TypeReference c, TypeDefinitionCache cache) => + IsAssignableFrom (type, c, (IMetadataResolver) cache); - public static bool IsAssignableFrom (this TypeReference type, TypeReference c, IMetadataResolver? resolver) + public static bool IsAssignableFrom (this TypeReference type, TypeReference c, IMetadataResolver resolver) { if (type.FullName == c.FullName) return true; @@ -84,13 +83,13 @@ public static bool IsAssignableFrom (this TypeReference type, TypeReference c, I return false; } - [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] + [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] public static bool IsSubclassOf (this TypeDefinition type, string typeName) => - IsSubclassOf (type, typeName, resolver: null); + IsSubclassOf (type, typeName, resolver: null!); - public static bool IsSubclassOf (this TypeDefinition type, string typeName, TypeDefinitionCache? cache) => - IsSubclassOf (type, typeName, (IMetadataResolver?) cache); - public static bool IsSubclassOf (this TypeDefinition type, string typeName, IMetadataResolver? resolver) + public static bool IsSubclassOf (this TypeDefinition type, string typeName, TypeDefinitionCache cache) => + IsSubclassOf (type, typeName, (IMetadataResolver) cache); + public static bool IsSubclassOf (this TypeDefinition type, string typeName, IMetadataResolver resolver) { foreach (var t in type.GetTypeAndBaseTypes (resolver)) { if (t.FullName == typeName) { @@ -100,14 +99,14 @@ public static bool IsSubclassOf (this TypeDefinition type, string typeName, IMet return false; } - [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] + [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] public static bool ImplementsInterface (this TypeDefinition type, string interfaceName) => - ImplementsInterface (type, interfaceName, resolver: null); + ImplementsInterface (type, interfaceName, resolver: null!); - public static bool ImplementsInterface (this TypeDefinition type, string interfaceName, TypeDefinitionCache? cache) => - ImplementsInterface (type, interfaceName, (IMetadataResolver?) cache); + public static bool ImplementsInterface (this TypeDefinition type, string interfaceName, TypeDefinitionCache cache) => + ImplementsInterface (type, interfaceName, (IMetadataResolver) cache); - public static bool ImplementsInterface (this TypeDefinition type, string interfaceName, IMetadataResolver? resolver) + public static bool ImplementsInterface (this TypeDefinition type, string interfaceName, IMetadataResolver resolver) { foreach (var t in type.GetTypeAndBaseTypes (resolver)) { foreach (var i in t.Interfaces) { diff --git a/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaCallableWrapperGenerator.cs b/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaCallableWrapperGenerator.cs index 14752be62..abb409984 100644 --- a/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaCallableWrapperGenerator.cs +++ b/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaCallableWrapperGenerator.cs @@ -33,7 +33,7 @@ public abstract class JavaCallableMethodClassifier public class JavaCallableWrapperGenerator { class JavaFieldInfo { - public JavaFieldInfo (MethodDefinition method, string fieldName, IMetadataResolver? resolver) + public JavaFieldInfo (MethodDefinition method, string fieldName, IMetadataResolver resolver) { this.FieldName = fieldName; InitializerName = method.Name; @@ -69,25 +69,25 @@ public string GetJavaAccess () readonly IMetadataResolver cache; readonly JavaCallableMethodClassifier? methodClassifier; - [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] + [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] public JavaCallableWrapperGenerator (TypeDefinition type, Action log) - : this (type, log, resolver: null, methodClassifier: null) + : this (type, log, resolver: null!, methodClassifier: null) { } - public JavaCallableWrapperGenerator (TypeDefinition type, Action log, TypeDefinitionCache? cache) - : this (type, log, (IMetadataResolver?) cache, methodClassifier: null) + public JavaCallableWrapperGenerator (TypeDefinition type, Action log, TypeDefinitionCache cache) + : this (type, log, (IMetadataResolver) cache, methodClassifier: null) { } - public JavaCallableWrapperGenerator (TypeDefinition type, Action log, TypeDefinitionCache? cache, JavaCallableMethodClassifier? methodClassifier) - : this (type, log, (IMetadataResolver?) cache, methodClassifier) + public JavaCallableWrapperGenerator (TypeDefinition type, Action log, TypeDefinitionCache cache, JavaCallableMethodClassifier? methodClassifier) + : this (type, log, (IMetadataResolver) cache, methodClassifier) { } - public JavaCallableWrapperGenerator (TypeDefinition type, Action log, IMetadataResolver? resolver) + public JavaCallableWrapperGenerator (TypeDefinition type, Action log, IMetadataResolver resolver) : this (type, log, resolver, methodClassifier: null) { } - public JavaCallableWrapperGenerator (TypeDefinition type, Action log, IMetadataResolver? resolver, JavaCallableMethodClassifier? methodClassifier) + public JavaCallableWrapperGenerator (TypeDefinition type, Action log, IMetadataResolver resolver, JavaCallableMethodClassifier? methodClassifier) : this (type, null, log, resolver, methodClassifier) { AddNestedTypes (type); @@ -133,7 +133,7 @@ void AddNestedTypes (TypeDefinition type) HasExport |= children.Any (t => t.HasExport); } - JavaCallableWrapperGenerator (TypeDefinition type, string? outerType, Action log, IMetadataResolver? resolver, JavaCallableMethodClassifier? methodClassifier = null) + JavaCallableWrapperGenerator (TypeDefinition type, string? outerType, Action log, IMetadataResolver resolver, JavaCallableMethodClassifier? methodClassifier = null) { this.methodClassifier = methodClassifier; this.type = type; @@ -177,7 +177,7 @@ void AddNestedTypes (TypeDefinition type) foreach (InterfaceImplementation ifaceInfo in type.Interfaces) { var typeReference = ifaceInfo.InterfaceType; - var typeDefinition = typeReference.ResolveCached (resolver); + var typeDefinition = cache.Resolve (typeReference); if (typeDefinition == null) { Diagnostic.Error (4204, LookupSource (type), @@ -604,17 +604,17 @@ public void Generate (string outputPath) } } - static string GetAnnotationsString (string indent, IEnumerable atts, IMetadataResolver? resolver) + static string GetAnnotationsString (string indent, IEnumerable atts, IMetadataResolver resolver) { var sw = new StringWriter (); WriteAnnotations (indent, sw, atts, resolver); return sw.ToString (); } - static void WriteAnnotations (string indent, TextWriter sw, IEnumerable atts, IMetadataResolver? resolver) + static void WriteAnnotations (string indent, TextWriter sw, IEnumerable atts, IMetadataResolver resolver) { foreach (var ca in atts) { - var catype = ca.AttributeType.ResolveCached (resolver); + var catype = resolver.Resolve (ca.AttributeType); var tca = catype.CustomAttributes.FirstOrDefault (a => a.AttributeType.FullName == "Android.Runtime.AnnotationAttribute"); if (tca != null) { sw.Write (indent); @@ -677,7 +677,7 @@ void GenerateHeader (TextWriter sw) break; } foreach (var ifaceInfo in type.Interfaces) { - var iface = ifaceInfo.InterfaceType.ResolveCached (cache); + var iface = cache.Resolve(ifaceInfo.InterfaceType); if (!GetTypeRegistrationAttributes (iface).Any ()) continue; sw.WriteLine (","); diff --git a/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaTypeScanner.cs b/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaTypeScanner.cs index 77cab0cb4..9f080ce0a 100644 --- a/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaTypeScanner.cs +++ b/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaTypeScanner.cs @@ -76,14 +76,14 @@ void AddJavaTypes (List javaTypes, TypeDefinition type) AddJavaTypes (javaTypes, nested); } - [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] + [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] public static bool ShouldSkipJavaCallableWrapperGeneration (TypeDefinition type) => - ShouldSkipJavaCallableWrapperGeneration (type, resolver: null); + ShouldSkipJavaCallableWrapperGeneration (type, resolver: null!); - public static bool ShouldSkipJavaCallableWrapperGeneration (TypeDefinition type, TypeDefinitionCache? cache) => - ShouldSkipJavaCallableWrapperGeneration (type, (IMetadataResolver?) cache); + public static bool ShouldSkipJavaCallableWrapperGeneration (TypeDefinition type, TypeDefinitionCache cache) => + ShouldSkipJavaCallableWrapperGeneration (type, (IMetadataResolver) cache); - public static bool ShouldSkipJavaCallableWrapperGeneration (TypeDefinition type, IMetadataResolver? resolver) + public static bool ShouldSkipJavaCallableWrapperGeneration (TypeDefinition type, IMetadataResolver resolver) { if (JavaNativeTypeManager.IsNonStaticInnerClass (type, resolver)) return true; diff --git a/src/Java.Interop.Tools.JavaTypeSystem/Adapters/ManagedApiImporter.cs b/src/Java.Interop.Tools.JavaTypeSystem/Adapters/ManagedApiImporter.cs index e48e5dc53..a2463a4ab 100644 --- a/src/Java.Interop.Tools.JavaTypeSystem/Adapters/ManagedApiImporter.cs +++ b/src/Java.Interop.Tools.JavaTypeSystem/Adapters/ManagedApiImporter.cs @@ -10,13 +10,17 @@ namespace Java.Interop.Tools.JavaTypeSystem { public static class ManagedApiImporter { - public static JavaTypeCollection Parse (AssemblyDefinition assembly, JavaTypeCollection collection) + [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] + public static JavaTypeCollection Parse (AssemblyDefinition assembly, JavaTypeCollection collection) => + Parse (assembly, collection, resolver: null!); + + public static JavaTypeCollection Parse (AssemblyDefinition assembly, JavaTypeCollection collection, TypeDefinitionCache resolver) { var types_to_add = new List (); foreach (var md in assembly.Modules) foreach (var td in md.Types) { - if (!ShouldSkipType (td) && ParseType (td, collection) is JavaTypeModel type) + if (!ShouldSkipType (td, resolver) && ParseType (td, collection) is JavaTypeModel type) types_to_add.Add (type); } @@ -219,7 +223,7 @@ static void AddReferenceTypeRecursive (JavaTypeModel type, JavaTypeCollection co AddReferenceTypeRecursive (nested, collection); } - static bool ShouldSkipType (TypeDefinition type) + static bool ShouldSkipType (TypeDefinition type, TypeDefinitionCache cache) { // We want to use Java's collection types instead of our managed adapter. // eg: 'Java.Util.ArrayList' over 'Android.Runtime.JavaList' @@ -240,13 +244,13 @@ static bool ShouldSkipType (TypeDefinition type) ? type.Module.GetType (type.FullName.Substring (0, type.FullName.IndexOf ('`'))) : null; - if (ShouldSkipGeneric (type, non_generic_type, null)) + if (ShouldSkipGeneric (type, non_generic_type, cache)) return true; return false; } - static bool ShouldSkipGeneric (TypeDefinition? a, TypeDefinition? b, TypeDefinitionCache? cache) + static bool ShouldSkipGeneric (TypeDefinition? a, TypeDefinition? b, TypeDefinitionCache cache) { if (a == null || b == null) return false; diff --git a/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs b/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs index 5366462e5..32648db39 100644 --- a/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs +++ b/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs @@ -414,39 +414,39 @@ internal static ExportParameterAttribute ToExportParameterAttribute (CustomAttri return new ExportParameterAttribute ((ExportParameterKind)attr.ConstructorArguments [0].Value); } - [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] + [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] public static bool IsApplication (TypeDefinition type) => - IsApplication (type, resolver: null); + IsApplication (type, resolver: null!); - public static bool IsApplication (TypeDefinition type, TypeDefinitionCache? cache) => - IsApplication (type, (IMetadataResolver?) cache); + public static bool IsApplication (TypeDefinition type, TypeDefinitionCache cache) => + IsApplication (type, (IMetadataResolver) cache); - public static bool IsApplication (TypeDefinition type, IMetadataResolver? resolver) + public static bool IsApplication (TypeDefinition type, IMetadataResolver resolver) { return type.GetBaseTypes (resolver).Any (b => b.FullName == "Android.App.Application"); } - [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] + [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] public static bool IsInstrumentation (TypeDefinition type) => - IsInstrumentation (type, resolver: null); + IsInstrumentation (type, resolver: null!); - public static bool IsInstrumentation (TypeDefinition type, TypeDefinitionCache? cache) => - IsInstrumentation (type, (IMetadataResolver?) cache); + public static bool IsInstrumentation (TypeDefinition type, TypeDefinitionCache cache) => + IsInstrumentation (type, (IMetadataResolver) cache); - public static bool IsInstrumentation (TypeDefinition type, IMetadataResolver? resolver) + public static bool IsInstrumentation (TypeDefinition type, IMetadataResolver resolver) { return type.GetBaseTypes (resolver).Any (b => b.FullName == "Android.App.Instrumentation"); } // moved from JavaTypeInfo - [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] + [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] public static string? GetJniSignature (MethodDefinition method) => - GetJniSignature (method, resolver: null); + GetJniSignature (method, resolver: null!); - public static string? GetJniSignature (MethodDefinition method, TypeDefinitionCache? cache) => - GetJniSignature (method, (IMetadataResolver?) cache); + public static string? GetJniSignature (MethodDefinition method, TypeDefinitionCache cache) => + GetJniSignature (method, (IMetadataResolver) cache); - public static string? GetJniSignature (MethodDefinition method, IMetadataResolver? resolver) + public static string? GetJniSignature (MethodDefinition method, IMetadataResolver resolver) { return GetJniSignature ( method.Parameters, @@ -459,35 +459,35 @@ public static bool IsInstrumentation (TypeDefinition type, IMetadataResolver? re } // moved from JavaTypeInfo - [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] + [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] public static string? GetJniTypeName (TypeReference typeRef) => - GetJniTypeName (typeRef, resolver: null); + GetJniTypeName (typeRef, resolver: null!); - public static string? GetJniTypeName (TypeReference typeRef, TypeDefinitionCache? cache) => - GetJniTypeName (typeRef, (IMetadataResolver?) cache); + public static string? GetJniTypeName (TypeReference typeRef, TypeDefinitionCache cache) => + GetJniTypeName (typeRef, (IMetadataResolver) cache); - public static string? GetJniTypeName (TypeReference typeRef, IMetadataResolver? resolver) + public static string? GetJniTypeName (TypeReference typeRef, IMetadataResolver resolver) { return GetJniTypeName (typeRef, ExportParameterKind.Unspecified, resolver); } - internal static string? GetJniTypeName (TypeReference typeRef, ExportParameterKind exportKind, IMetadataResolver? cache) + internal static string? GetJniTypeName (TypeReference typeRef, ExportParameterKind exportKind, IMetadataResolver cache) { - return GetJniTypeName (typeRef, exportKind, t => t.ResolveCached (cache), t => { + return GetJniTypeName (typeRef, exportKind, t => cache.Resolve (t), t => { TypeReference etype; int rank = GetArrayInfo (typeRef, out etype); return new KeyValuePair (rank,etype); }, t => t.FullName, (t, k) => ToJniName (t, k, cache)); } - [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] + [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] public static string ToCompatJniName (TypeDefinition type) => - ToCompatJniName (type, resolver: null); + ToCompatJniName (type, resolver: null!); - public static string ToCompatJniName (TypeDefinition type, TypeDefinitionCache? cache) => - ToCompatJniName (type, (IMetadataResolver?) cache); + public static string ToCompatJniName (TypeDefinition type, TypeDefinitionCache cache) => + ToCompatJniName (type, (IMetadataResolver) cache); - public static string ToCompatJniName (TypeDefinition type, IMetadataResolver? resolver) + public static string ToCompatJniName (TypeDefinition type, IMetadataResolver resolver) { return ToJniName ( type: type, @@ -505,21 +505,21 @@ static string ToCompatPackageName (TypeDefinition type) } // Keep in sync with ToJniNameFromAttributes(Type) and ToJniName(Type) - [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] + [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] public static string ToJniName (TypeDefinition type) => - ToJniName (type, resolver: null); + ToJniName (type, resolver: null!); - public static string ToJniName (TypeDefinition type, TypeDefinitionCache? cache) => - ToJniName (type, (IMetadataResolver?) cache); + public static string ToJniName (TypeDefinition type, TypeDefinitionCache cache) => + ToJniName (type, (IMetadataResolver) cache); - public static string ToJniName (TypeDefinition type, IMetadataResolver? resolver) + public static string ToJniName (TypeDefinition type, IMetadataResolver resolver) { var x = ToJniName (type, ExportParameterKind.Unspecified, resolver) ?? "java/lang/Object"; return x; } - static string? ToJniName (TypeDefinition type, ExportParameterKind exportKind, IMetadataResolver? cache) + static string? ToJniName (TypeDefinition type, ExportParameterKind exportKind, IMetadataResolver cache) { if (type == null) throw new ArgumentNullException ("type"); @@ -545,16 +545,16 @@ public static string ToJniName (TypeDefinition type, IMetadataResolver? resolver ); } - static string? ToJniNameFromAttributes (TypeDefinition type, IMetadataResolver? resolver) + static string? ToJniNameFromAttributes (TypeDefinition type, IMetadataResolver resolver) { return ToJniNameFromAttributesForAndroid (type, resolver) ?? ToJniNameFromAttributesForInterop (type, resolver); } - static string? ToJniNameFromAttributesForInterop (TypeDefinition type, IMetadataResolver? resolver) + static string? ToJniNameFromAttributesForInterop (TypeDefinition type, IMetadataResolver resolver) { var attr = type.CustomAttributes.FirstOrDefault (a => - a.AttributeType.ResolveCached (resolver) + resolver.Resolve (a.AttributeType) .FullName == "Java.Interop.JniTypeSignatureAttribute"); if (attr == null) { return null; @@ -565,7 +565,7 @@ public static string ToJniName (TypeDefinition type, IMetadataResolver? resolver return (string) carg.Value; } - static string? ToJniNameFromAttributesForAndroid (TypeDefinition type, IMetadataResolver? resolver) + static string? ToJniNameFromAttributesForAndroid (TypeDefinition type, IMetadataResolver resolver) { if (!type.HasCustomAttributes) return null; @@ -597,14 +597,14 @@ public static string ToJniName (TypeDefinition type, IMetadataResolver? resolver "Android.Runtime.RegisterAttribute", }; - static bool IsIJniNameProviderAttribute (CustomAttribute attr, IMetadataResolver? resolver) + static bool IsIJniNameProviderAttribute (CustomAttribute attr, IMetadataResolver resolver) { // Fast path for a list of known IJniNameProviderAttribute implementations if (KnownIJniNameProviders.Contains (attr.AttributeType.FullName)) return true; // Slow path resolves the type, looking for IJniNameProviderAttribute - var attributeType = attr.AttributeType.ResolveCached (resolver); + var attributeType = resolver.Resolve (attr.AttributeType); if (!attributeType.HasInterfaces) return false; return attributeType.Interfaces.Any (it => it.InterfaceType.FullName == typeof (IJniNameProviderAttribute).FullName); @@ -621,10 +621,10 @@ public static int GetArrayInfo (Mono.Cecil.TypeReference type, out Mono.Cecil.Ty return rank; } - static string? GetPrimitiveClass (Mono.Cecil.TypeDefinition type, IMetadataResolver? cache) + static string? GetPrimitiveClass (Mono.Cecil.TypeDefinition type, IMetadataResolver cache) { if (type.IsEnum) - return GetPrimitiveClass (type.Fields.First (f => f.IsSpecialName).FieldType.ResolveCached (cache), cache); + return GetPrimitiveClass (cache.Resolve (type.Fields.First (f => f.IsSpecialName).FieldType), cache); if (type.FullName == "System.Byte") return "B"; if (type.FullName == "System.Char") @@ -707,7 +707,7 @@ static string ToJniName (T type, Func decl, Func name, Func< } #if HAVE_CECIL - internal static bool IsNonStaticInnerClass (TypeDefinition? type, IMetadataResolver? cache) + internal static bool IsNonStaticInnerClass (TypeDefinition? type, IMetadataResolver cache) { if (type == null) return false; @@ -721,7 +721,7 @@ internal static bool IsNonStaticInnerClass (TypeDefinition? type, IMetadataResol .Any (ctor => ctor.Parameters.Any (p => p.Name == "__self")); } - static IEnumerable GetBaseConstructors (TypeDefinition type, IMetadataResolver? cache) + static IEnumerable GetBaseConstructors (TypeDefinition type, IMetadataResolver cache) { var baseType = type.GetBaseTypes (cache).FirstOrDefault (t => t.GetCustomAttributes (typeof (RegisterAttribute)).Any ()); if (baseType != null) diff --git a/tools/generator/CodeGenerator.cs b/tools/generator/CodeGenerator.cs index 753f05138..150e93382 100644 --- a/tools/generator/CodeGenerator.cs +++ b/tools/generator/CodeGenerator.cs @@ -110,7 +110,7 @@ static void Run (CodeGeneratorOptions options, DirectoryAssemblyResolver resolve // Resolve types using Java.Interop.Tools.JavaTypeSystem if (is_classparse && !options.UseLegacyJavaResolver) { var output_xml = api_xml_adjuster_output ?? Path.Combine (Path.GetDirectoryName (filename), Path.GetFileName (filename) + ".adjusted"); - JavaTypeResolutionFixups.Fixup (filename, output_xml, resolver, references.Distinct ().ToArray ()); + JavaTypeResolutionFixups.Fixup (filename, output_xml, resolver, references.Distinct ().ToArray (), resolverCache); if (only_xml_adjuster) return; diff --git a/tools/generator/Java.Interop.Tools.Generator.Transformation/JavaTypeResolutionFixups.cs b/tools/generator/Java.Interop.Tools.Generator.Transformation/JavaTypeResolutionFixups.cs index 648475fce..63af7c0b2 100644 --- a/tools/generator/Java.Interop.Tools.Generator.Transformation/JavaTypeResolutionFixups.cs +++ b/tools/generator/Java.Interop.Tools.Generator.Transformation/JavaTypeResolutionFixups.cs @@ -9,9 +9,13 @@ namespace generator { public static class JavaTypeResolutionFixups { + [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] + public static void Fixup (string xmlFile, string outputXmlFile, DirectoryAssemblyResolver resolver, string [] references) => + Fixup(xmlFile, outputXmlFile, resolver, references, cache: null!); + // This fixup ensures all referenced Java types can be resolved, and // removes types and members that rely on unresolvable Java types. - public static void Fixup (string xmlFile, string outputXmlFile, DirectoryAssemblyResolver resolver, string [] references) + public static void Fixup (string xmlFile, string outputXmlFile, DirectoryAssemblyResolver resolver, string [] references, TypeDefinitionCache cache) { // Parse api.xml var type_collection = JavaXmlApiImporter.Parse (xmlFile); @@ -21,7 +25,7 @@ public static void Fixup (string xmlFile, string outputXmlFile, DirectoryAssembl Report.Verbose (0, "Resolving assembly for Java type resolution: '{0}'.", reference); var assembly = resolver.Load (reference); - ManagedApiImporter.Parse (assembly, type_collection); + ManagedApiImporter.Parse (assembly, type_collection, cache); } // Run the type resolution pass From a8a8d9eac5c1a316c9e95342795ef1bfa65605b8 Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Wed, 4 Jan 2023 14:48:38 -0600 Subject: [PATCH 3/4] Actually throw `NotSupportedException` --- .../MethodDefinitionRocks.cs | 9 +++------ .../TypeDefinitionRocks.cs | 18 ++++++------------ .../JavaCallableWrapperGenerator.cs | 4 +--- .../JavaTypeScanner.cs | 5 ++--- .../Adapters/ManagedApiImporter.cs | 3 +-- .../JavaNativeTypeManager.cs | 18 ++++++------------ .../JavaTypeResolutionFixups.cs | 3 +-- 7 files changed, 20 insertions(+), 40 deletions(-) diff --git a/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/MethodDefinitionRocks.cs b/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/MethodDefinitionRocks.cs index 2b73e6177..cdbdcaf02 100644 --- a/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/MethodDefinitionRocks.cs +++ b/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/MethodDefinitionRocks.cs @@ -10,8 +10,7 @@ namespace Java.Interop.Tools.Cecil { public static class MethodDefinitionRocks { [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] - public static MethodDefinition GetBaseDefinition (this MethodDefinition method) => - GetBaseDefinition (method, resolver: null!); + public static MethodDefinition GetBaseDefinition (this MethodDefinition method) => throw new NotSupportedException (); public static MethodDefinition GetBaseDefinition (this MethodDefinition method, TypeDefinitionCache cache) => GetBaseDefinition (method, (IMetadataResolver) cache); @@ -35,8 +34,7 @@ public static MethodDefinition GetBaseDefinition (this MethodDefinition method, } [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] - public static IEnumerable GetOverriddenMethods (MethodDefinition method, bool inherit) => - GetOverriddenMethods (method, inherit, resolver: null!); + public static IEnumerable GetOverriddenMethods (MethodDefinition method, bool inherit) => throw new NotSupportedException (); public static IEnumerable GetOverriddenMethods (MethodDefinition method, bool inherit, TypeDefinitionCache cache) => GetOverriddenMethods (method, inherit, (IMetadataResolver) cache); @@ -54,8 +52,7 @@ public static IEnumerable GetOverriddenMethods (MethodDefiniti } [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] - public static bool AreParametersCompatibleWith (this Collection a, Collection b) => - AreParametersCompatibleWith (a, b, resolver: null!); + public static bool AreParametersCompatibleWith (this Collection a, Collection b) => throw new NotSupportedException (); public static bool AreParametersCompatibleWith (this Collection a, Collection b, TypeDefinitionCache cache) => AreParametersCompatibleWith (a, b, (IMetadataResolver) cache); diff --git a/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs b/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs index 5402fc6a1..a9d893f8c 100644 --- a/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs +++ b/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs @@ -10,8 +10,7 @@ static TypeDefinition ResolveCached (this TypeReference type, IMetadataResolver? resolver != null ? resolver.Resolve (type) : type.Resolve (); [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] - public static TypeDefinition? GetBaseType (this TypeDefinition type) => - GetBaseType (type, resolver: null!); + public static TypeDefinition? GetBaseType (this TypeDefinition type) => throw new NotSupportedException (); public static TypeDefinition? GetBaseType (this TypeDefinition type, TypeDefinitionCache cache) => GetBaseType (type, (IMetadataResolver) cache); @@ -25,8 +24,7 @@ static TypeDefinition ResolveCached (this TypeReference type, IMetadataResolver? } [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] - public static IEnumerable GetTypeAndBaseTypes (this TypeDefinition type) => - GetTypeAndBaseTypes (type, resolver: null!); + public static IEnumerable GetTypeAndBaseTypes (this TypeDefinition type) => throw new NotSupportedException (); public static IEnumerable GetTypeAndBaseTypes (this TypeDefinition type, TypeDefinitionCache cache) => GetTypeAndBaseTypes (type, (IMetadataResolver) cache); @@ -42,8 +40,7 @@ public static IEnumerable GetTypeAndBaseTypes (this TypeDefiniti } [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] - public static IEnumerable GetBaseTypes (this TypeDefinition type) => - GetBaseTypes (type, resolver: null!); + public static IEnumerable GetBaseTypes (this TypeDefinition type) => throw new NotSupportedException(); public static IEnumerable GetBaseTypes (this TypeDefinition type, TypeDefinitionCache cache) => GetBaseTypes (type, (IMetadataResolver) cache); @@ -58,8 +55,7 @@ public static IEnumerable GetBaseTypes (this TypeDefinition type } [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] - public static bool IsAssignableFrom (this TypeReference type, TypeReference c) => - IsAssignableFrom (type, c, resolver: null!); + public static bool IsAssignableFrom (this TypeReference type, TypeReference c) => throw new NotSupportedException (); public static bool IsAssignableFrom (this TypeReference type, TypeReference c, TypeDefinitionCache cache) => IsAssignableFrom (type, c, (IMetadataResolver) cache); @@ -84,8 +80,7 @@ public static bool IsAssignableFrom (this TypeReference type, TypeReference c, I } [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] - public static bool IsSubclassOf (this TypeDefinition type, string typeName) => - IsSubclassOf (type, typeName, resolver: null!); + public static bool IsSubclassOf (this TypeDefinition type, string typeName) => throw new NotSupportedException (); public static bool IsSubclassOf (this TypeDefinition type, string typeName, TypeDefinitionCache cache) => IsSubclassOf (type, typeName, (IMetadataResolver) cache); @@ -100,8 +95,7 @@ public static bool IsSubclassOf (this TypeDefinition type, string typeName, IMet } [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] - public static bool ImplementsInterface (this TypeDefinition type, string interfaceName) => - ImplementsInterface (type, interfaceName, resolver: null!); + public static bool ImplementsInterface (this TypeDefinition type, string interfaceName) => throw new NotSupportedException (); public static bool ImplementsInterface (this TypeDefinition type, string interfaceName, TypeDefinitionCache cache) => ImplementsInterface (type, interfaceName, (IMetadataResolver) cache); diff --git a/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaCallableWrapperGenerator.cs b/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaCallableWrapperGenerator.cs index abb409984..cd489d00d 100644 --- a/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaCallableWrapperGenerator.cs +++ b/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaCallableWrapperGenerator.cs @@ -70,9 +70,7 @@ public string GetJavaAccess () readonly JavaCallableMethodClassifier? methodClassifier; [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] - public JavaCallableWrapperGenerator (TypeDefinition type, Action log) - : this (type, log, resolver: null!, methodClassifier: null) - { } + public JavaCallableWrapperGenerator (TypeDefinition type, Action log) => throw new NotSupportedException (); public JavaCallableWrapperGenerator (TypeDefinition type, Action log, TypeDefinitionCache cache) : this (type, log, (IMetadataResolver) cache, methodClassifier: null) diff --git a/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaTypeScanner.cs b/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaTypeScanner.cs index 9f080ce0a..97f2222ea 100644 --- a/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaTypeScanner.cs +++ b/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/JavaTypeScanner.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -77,8 +77,7 @@ void AddJavaTypes (List javaTypes, TypeDefinition type) } [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] - public static bool ShouldSkipJavaCallableWrapperGeneration (TypeDefinition type) => - ShouldSkipJavaCallableWrapperGeneration (type, resolver: null!); + public static bool ShouldSkipJavaCallableWrapperGeneration (TypeDefinition type) => throw new NotSupportedException (); public static bool ShouldSkipJavaCallableWrapperGeneration (TypeDefinition type, TypeDefinitionCache cache) => ShouldSkipJavaCallableWrapperGeneration (type, (IMetadataResolver) cache); diff --git a/src/Java.Interop.Tools.JavaTypeSystem/Adapters/ManagedApiImporter.cs b/src/Java.Interop.Tools.JavaTypeSystem/Adapters/ManagedApiImporter.cs index a2463a4ab..aa7dfc541 100644 --- a/src/Java.Interop.Tools.JavaTypeSystem/Adapters/ManagedApiImporter.cs +++ b/src/Java.Interop.Tools.JavaTypeSystem/Adapters/ManagedApiImporter.cs @@ -11,8 +11,7 @@ namespace Java.Interop.Tools.JavaTypeSystem public static class ManagedApiImporter { [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] - public static JavaTypeCollection Parse (AssemblyDefinition assembly, JavaTypeCollection collection) => - Parse (assembly, collection, resolver: null!); + public static JavaTypeCollection Parse (AssemblyDefinition assembly, JavaTypeCollection collection) => throw new NotSupportedException (); public static JavaTypeCollection Parse (AssemblyDefinition assembly, JavaTypeCollection collection, TypeDefinitionCache resolver) { diff --git a/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs b/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs index 32648db39..14f6c42c9 100644 --- a/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs +++ b/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs @@ -415,8 +415,7 @@ internal static ExportParameterAttribute ToExportParameterAttribute (CustomAttri } [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] - public static bool IsApplication (TypeDefinition type) => - IsApplication (type, resolver: null!); + public static bool IsApplication (TypeDefinition type) => throw new NotSupportedException (); public static bool IsApplication (TypeDefinition type, TypeDefinitionCache cache) => IsApplication (type, (IMetadataResolver) cache); @@ -427,8 +426,7 @@ public static bool IsApplication (TypeDefinition type, IMetadataResolver resolve } [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] - public static bool IsInstrumentation (TypeDefinition type) => - IsInstrumentation (type, resolver: null!); + public static bool IsInstrumentation (TypeDefinition type) => throw new NotSupportedException (); public static bool IsInstrumentation (TypeDefinition type, TypeDefinitionCache cache) => IsInstrumentation (type, (IMetadataResolver) cache); @@ -440,8 +438,7 @@ public static bool IsInstrumentation (TypeDefinition type, IMetadataResolver res // moved from JavaTypeInfo [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] - public static string? GetJniSignature (MethodDefinition method) => - GetJniSignature (method, resolver: null!); + public static string? GetJniSignature (MethodDefinition method) => throw new NotSupportedException (); public static string? GetJniSignature (MethodDefinition method, TypeDefinitionCache cache) => GetJniSignature (method, (IMetadataResolver) cache); @@ -460,8 +457,7 @@ public static bool IsInstrumentation (TypeDefinition type, IMetadataResolver res // moved from JavaTypeInfo [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] - public static string? GetJniTypeName (TypeReference typeRef) => - GetJniTypeName (typeRef, resolver: null!); + public static string? GetJniTypeName (TypeReference typeRef) => throw new NotSupportedException (); public static string? GetJniTypeName (TypeReference typeRef, TypeDefinitionCache cache) => GetJniTypeName (typeRef, (IMetadataResolver) cache); @@ -481,8 +477,7 @@ public static bool IsInstrumentation (TypeDefinition type, IMetadataResolver res } [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] - public static string ToCompatJniName (TypeDefinition type) => - ToCompatJniName (type, resolver: null!); + public static string ToCompatJniName (TypeDefinition type) => throw new NotSupportedException (); public static string ToCompatJniName (TypeDefinition type, TypeDefinitionCache cache) => ToCompatJniName (type, (IMetadataResolver) cache); @@ -506,8 +501,7 @@ static string ToCompatPackageName (TypeDefinition type) // Keep in sync with ToJniNameFromAttributes(Type) and ToJniName(Type) [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] - public static string ToJniName (TypeDefinition type) => - ToJniName (type, resolver: null!); + public static string ToJniName (TypeDefinition type) => throw new NotSupportedException (); public static string ToJniName (TypeDefinition type, TypeDefinitionCache cache) => ToJniName (type, (IMetadataResolver) cache); diff --git a/tools/generator/Java.Interop.Tools.Generator.Transformation/JavaTypeResolutionFixups.cs b/tools/generator/Java.Interop.Tools.Generator.Transformation/JavaTypeResolutionFixups.cs index 63af7c0b2..71b0c2b0b 100644 --- a/tools/generator/Java.Interop.Tools.Generator.Transformation/JavaTypeResolutionFixups.cs +++ b/tools/generator/Java.Interop.Tools.Generator.Transformation/JavaTypeResolutionFixups.cs @@ -10,8 +10,7 @@ namespace generator public static class JavaTypeResolutionFixups { [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] - public static void Fixup (string xmlFile, string outputXmlFile, DirectoryAssemblyResolver resolver, string [] references) => - Fixup(xmlFile, outputXmlFile, resolver, references, cache: null!); + public static void Fixup (string xmlFile, string outputXmlFile, DirectoryAssemblyResolver resolver, string [] references) => throw new NotSupportedException (); // This fixup ensures all referenced Java types can be resolved, and // removes types and members that rely on unresolvable Java types. From 1bf920d35043e67b1ba9c588de7f4109b4d1c46a Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Thu, 5 Jan 2023 08:57:00 -0600 Subject: [PATCH 4/4] Address feedback, fix more places to require TypeDefinitionCache --- .../TypeDefinitionRocks.cs | 43 ++++++++----------- .../JavaNativeTypeManager.cs | 11 +++-- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs b/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs index a9d893f8c..f4a2d82bc 100644 --- a/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs +++ b/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/TypeDefinitionRocks.cs @@ -6,8 +6,6 @@ namespace Java.Interop.Tools.Cecil { public static class TypeDefinitionRocks { - static TypeDefinition ResolveCached (this TypeReference type, IMetadataResolver? resolver) => - resolver != null ? resolver.Resolve (type) : type.Resolve (); [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] public static TypeDefinition? GetBaseType (this TypeDefinition type) => throw new NotSupportedException (); @@ -20,7 +18,7 @@ static TypeDefinition ResolveCached (this TypeReference type, IMetadataResolver? var bt = type.BaseType; if (bt == null) return null; - return bt.ResolveCached (resolver); + return resolver.Resolve (bt); } [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] @@ -64,7 +62,7 @@ public static bool IsAssignableFrom (this TypeReference type, TypeReference c, I { if (type.FullName == c.FullName) return true; - var d = c.ResolveCached (resolver); + var d = resolver.Resolve (c); if (d == null) return false; foreach (var t in d.GetTypeAndBaseTypes (resolver)) { @@ -112,27 +110,25 @@ public static bool ImplementsInterface (this TypeDefinition type, string interfa return false; } - [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] - public static string GetPartialAssemblyName (this TypeReference type) => - GetPartialAssemblyName (type, resolver: null); + [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] + public static string GetPartialAssemblyName (this TypeReference type) => throw new NotSupportedException (); - public static string GetPartialAssemblyName (this TypeReference type, TypeDefinitionCache? cache) => - GetPartialAssemblyName (type, (IMetadataResolver?) cache); + public static string GetPartialAssemblyName (this TypeReference type, TypeDefinitionCache cache) => + GetPartialAssemblyName (type, (IMetadataResolver) cache); - public static string GetPartialAssemblyName (this TypeReference type, IMetadataResolver? resolver) + public static string GetPartialAssemblyName (this TypeReference type, IMetadataResolver resolver) { - TypeDefinition? def = type.ResolveCached (resolver); + TypeDefinition? def = resolver.Resolve (type); return (def ?? type).Module.Assembly.Name.Name; } - [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] - public static string GetPartialAssemblyQualifiedName (this TypeReference type) => - GetPartialAssemblyQualifiedName (type, resolver: null); + [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] + public static string GetPartialAssemblyQualifiedName (this TypeReference type) => throw new NotSupportedException (); - public static string GetPartialAssemblyQualifiedName (this TypeReference type, TypeDefinitionCache? cache) => - GetPartialAssemblyQualifiedName (type, (IMetadataResolver?) cache); + public static string GetPartialAssemblyQualifiedName (this TypeReference type, TypeDefinitionCache cache) => + GetPartialAssemblyQualifiedName (type, (IMetadataResolver) cache); - public static string GetPartialAssemblyQualifiedName (this TypeReference type, IMetadataResolver? resolver) + public static string GetPartialAssemblyQualifiedName (this TypeReference type, IMetadataResolver resolver) { return string.Format ("{0}, {1}", // Cecil likes to use '/' as the nested type separator, while @@ -141,16 +137,15 @@ public static string GetPartialAssemblyQualifiedName (this TypeReference type, I type.GetPartialAssemblyName (resolver)); } - [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] - public static string GetAssemblyQualifiedName (this TypeReference type) => - GetAssemblyQualifiedName (type, resolver: null); + [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] + public static string GetAssemblyQualifiedName (this TypeReference type) => throw new NotSupportedException (); - public static string GetAssemblyQualifiedName (this TypeReference type, TypeDefinitionCache? cache) => - GetAssemblyQualifiedName (type, (IMetadataResolver?) cache); + public static string GetAssemblyQualifiedName (this TypeReference type, TypeDefinitionCache cache) => + GetAssemblyQualifiedName (type, (IMetadataResolver) cache); - public static string GetAssemblyQualifiedName (this TypeReference type, IMetadataResolver? resolver) + public static string GetAssemblyQualifiedName (this TypeReference type, IMetadataResolver resolver) { - TypeDefinition? def = type.ResolveCached(resolver); + TypeDefinition? def = resolver.Resolve (type); return string.Format ("{0}, {1}", // Cecil likes to use '/' as the nested type separator, while // Reflection uses '+' as the nested type separator. Use Reflection. diff --git a/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs b/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs index 14f6c42c9..a8bba4531 100644 --- a/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs +++ b/src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs @@ -638,14 +638,13 @@ public static int GetArrayInfo (Mono.Cecil.TypeReference type, out Mono.Cecil.Ty return null; } - [Obsolete ("Use the TypeDefinitionCache overload for better performance.")] - public static string GetPackageName (TypeDefinition type) => - GetPackageName (type, resolver: null); + [Obsolete ("Use the TypeDefinitionCache overload for better performance.", error: true)] + public static string GetPackageName (TypeDefinition type) => throw new NotSupportedException (); - public static string GetPackageName (TypeDefinition type, TypeDefinitionCache? cache) => - GetPackageName (type, (IMetadataResolver?) cache); + public static string GetPackageName (TypeDefinition type, TypeDefinitionCache cache) => + GetPackageName (type, (IMetadataResolver) cache); - public static string GetPackageName (TypeDefinition type, IMetadataResolver? resolver) + public static string GetPackageName (TypeDefinition type, IMetadataResolver resolver) { if (IsPackageNamePreservedForAssembly (type.GetPartialAssemblyName (resolver))) return type.Namespace.ToLowerInvariant ();