Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions tools/generator/ApiVersionsSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,25 @@ public interface IApiAvailability
int ApiAvailableSince { get; set; }
}

public static void AssignApiLevels (IList<GenBase> gens, string apiVersionsXml, string currentApiLevelString)
static IEnumerable<GenBase> FlattenGens (IEnumerable<GenBase> 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<GenBase> 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;
Expand All @@ -38,9 +47,6 @@ public static void AssignApiLevels (IList<GenBase> 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<Method,ApiVersionsProvider.Definition,bool> methodMatch =
(m, method) => m.JavaName == method.MethodName && m.JniSignature == method.Name.Substring (method.MethodName.Length);
Expand All @@ -52,9 +58,6 @@ public static void AssignApiLevels (IList<GenBase> 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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tools/generator/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down