Skip to content

Commit 39f1744

Browse files
atsushienojonpryor
authored andcommitted
[generator] remove extraneous warnings on missing methods for api-versions check. (#114)
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. Additionally, provide the missing ApiSince information for nested types.
1 parent 65a0157 commit 39f1744

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

tools/generator/ApiVersionsSupport.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,25 @@ public interface IApiAvailability
2020
int ApiAvailableSince { get; set; }
2121
}
2222

23-
public static void AssignApiLevels (IList<GenBase> gens, string apiVersionsXml, string currentApiLevelString)
23+
static IEnumerable<GenBase> FlattenGens (IEnumerable<GenBase> gens)
2424
{
25-
int dummy;
26-
int currentApiLevel = int.TryParse (currentApiLevelString, out dummy) ? dummy : int.MaxValue;
25+
foreach (var g in gens) {
26+
yield return g;
27+
foreach (var nt in FlattenGens (g.NestedTypes))
28+
yield return nt;
29+
}
30+
}
2731

32+
public static void AssignApiLevels (IList<GenBase> gens, string apiVersionsXml)
33+
{
34+
var flattenGens = FlattenGens (gens);
2835
var versions = new ApiVersionsProvider ();
2936
versions.Parse (apiVersionsXml);
3037
foreach (var type in versions.Versions.Values) {
31-
var matchedGens = gens.Where (g => g.JavaName == type.Name);
38+
var matchedGens = flattenGens.Where (g => g.JavaName == type.Name);
3239
if (!matchedGens.Any ())
40+
// There are known missing types, and it's going to be too noisy to report missing ones here.
41+
// That task should be done elsewhere.
3342
continue;
3443
foreach (var gen in matchedGens)
3544
gen.ApiAvailableSince = type.Since;
@@ -38,9 +47,6 @@ public static void AssignApiLevels (IList<GenBase> gens, string apiVersionsXml,
3847
// it might be moved to the corresponding class.
3948
if (genf != null)
4049
genf.ApiAvailableSince = field.Since > 0 ? field.Since : type.Since;
41-
// commenting out this, because there are too many enum-mapped fields (removed).
42-
//else
43-
// Console.Error.WriteLine ("!!!!! In type {0}, field {1} not found.", type.Name, field.Name);
4450
}
4551
Func<Method,ApiVersionsProvider.Definition,bool> methodMatch =
4652
(m, method) => m.JavaName == method.MethodName && m.JniSignature == method.Name.Substring (method.MethodName.Length);
@@ -52,9 +58,6 @@ public static void AssignApiLevels (IList<GenBase> gens, string apiVersionsXml,
5258
matchedGens.SelectMany (g => GetAllMethods (g)).FirstOrDefault (m => methodMatch (m, method));
5359
if (genm != null)
5460
genm.ApiAvailableSince = method.Since > 0 ? method.Since : type.Since;
55-
// there are several "missing" stuff from android.test packages (unbound yet).
56-
else if (!type.Name.StartsWith ("android.test") && method.Since <= currentApiLevel)
57-
Report.Warning (0, Report.WarningAnnotationsProvider, " api-versions.xml mensions type {0}, methodbase {1}, but not found.", type.Name, method.Name);
5861
}
5962
}
6063
}

tools/generator/CodeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ static void Run (CodeGeneratorOptions options, DirectoryAssemblyResolver resolve
318318
Validate (gens, opt);
319319

320320
if (api_versions_xml != null)
321-
ApiVersionsSupport.AssignApiLevels (gens, api_versions_xml, api_level);
321+
ApiVersionsSupport.AssignApiLevels (gens, api_versions_xml);
322322

323323
foreach (GenBase gen in gens)
324324
gen.FillProperties ();

0 commit comments

Comments
 (0)