From 866a1f19ca60a38ab4dc412e5a3e17ce8978f3a2 Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Wed, 11 Jan 2017 13:28:03 +0900 Subject: [PATCH 1/2] [generator] remove extra warnings on missing methods for api-versions check. When we fill [Available (ApiSince = x)] we load api-versions.xml and checks if the mentioned Java member exists. But there are cases that those members should not really exist (e.g. we merge API while we don't for api-versions - we simply can't, there is no per-level api-versions). Missing members should be checked elsewhere, not here, so remove those extraneous (and mostly spurious) warnings. --- tools/generator/ApiVersionsSupport.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tools/generator/ApiVersionsSupport.cs b/tools/generator/ApiVersionsSupport.cs index 20e0f8315..042972ac0 100644 --- a/tools/generator/ApiVersionsSupport.cs +++ b/tools/generator/ApiVersionsSupport.cs @@ -38,9 +38,6 @@ public static void AssignApiLevels (IList gens, string apiVersionsXml, // it might be moved to the corresponding class. if (genf != null) genf.ApiAvailableSince = field.Since > 0 ? field.Since : type.Since; - // commenting out this, because there are too many enum-mapped fields (removed). - //else - // Console.Error.WriteLine ("!!!!! In type {0}, field {1} not found.", type.Name, field.Name); } Func methodMatch = (m, method) => m.JavaName == method.MethodName && m.JniSignature == method.Name.Substring (method.MethodName.Length); @@ -52,9 +49,6 @@ public static void AssignApiLevels (IList gens, string apiVersionsXml, matchedGens.SelectMany (g => GetAllMethods (g)).FirstOrDefault (m => methodMatch (m, method)); if (genm != null) genm.ApiAvailableSince = method.Since > 0 ? method.Since : type.Since; - // there are several "missing" stuff from android.test packages (unbound yet). - else if (!type.Name.StartsWith ("android.test") && method.Since <= currentApiLevel) - Report.Warning (0, Report.WarningAnnotationsProvider, " api-versions.xml mensions type {0}, methodbase {1}, but not found.", type.Name, method.Name); } } } From 06aeba842a9031a16867c407f86360bac4bd112f Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Wed, 11 Jan 2017 19:34:01 +0900 Subject: [PATCH 2/2] [generator] supply missing ApiSince for nested types. GenBase list from CodeGenerator was not flattened and therefore its list did not contain nested types, resulting in that those nested types don't have ApiSince attribute... --- tools/generator/ApiVersionsSupport.cs | 17 +++++++++++++---- tools/generator/CodeGenerator.cs | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tools/generator/ApiVersionsSupport.cs b/tools/generator/ApiVersionsSupport.cs index 042972ac0..7ae5a3e3e 100644 --- a/tools/generator/ApiVersionsSupport.cs +++ b/tools/generator/ApiVersionsSupport.cs @@ -20,16 +20,25 @@ public interface IApiAvailability int ApiAvailableSince { get; set; } } - public static void AssignApiLevels (IList gens, string apiVersionsXml, string currentApiLevelString) + static IEnumerable FlattenGens (IEnumerable gens) { - int dummy; - int currentApiLevel = int.TryParse (currentApiLevelString, out dummy) ? dummy : int.MaxValue; + foreach (var g in gens) { + yield return g; + foreach (var nt in FlattenGens (g.NestedTypes)) + yield return nt; + } + } + public static void AssignApiLevels (IList gens, string apiVersionsXml) + { + var flattenGens = FlattenGens (gens); var versions = new ApiVersionsProvider (); versions.Parse (apiVersionsXml); foreach (var type in versions.Versions.Values) { - var matchedGens = gens.Where (g => g.JavaName == type.Name); + var matchedGens = flattenGens.Where (g => g.JavaName == type.Name); if (!matchedGens.Any ()) + // There are known missing types, and it's going to be too noisy to report missing ones here. + // That task should be done elsewhere. continue; foreach (var gen in matchedGens) gen.ApiAvailableSince = type.Since; diff --git a/tools/generator/CodeGenerator.cs b/tools/generator/CodeGenerator.cs index 8fb650f5f..523c0f9dc 100644 --- a/tools/generator/CodeGenerator.cs +++ b/tools/generator/CodeGenerator.cs @@ -318,7 +318,7 @@ static void Run (CodeGeneratorOptions options, DirectoryAssemblyResolver resolve Validate (gens, opt); if (api_versions_xml != null) - ApiVersionsSupport.AssignApiLevels (gens, api_versions_xml, api_level); + ApiVersionsSupport.AssignApiLevels (gens, api_versions_xml); foreach (GenBase gen in gens) gen.FillProperties ();