public static void AssignApiLevels(IList <GenBase> gens, string apiVersionsXml, string currentApiLevelString)
        {
            int dummy;
            int currentApiLevel = int.TryParse(currentApiLevelString, out dummy) ? dummy : int.MaxValue;

            var versions = new ApiVersionsProvider();

            versions.Parse(apiVersionsXml);
            foreach (var type in versions.Versions.Values)
            {
                var matchedGens = gens.Where(g => g.JavaName == type.Name);
                if (!matchedGens.Any())
                {
                    continue;
                }
                foreach (var gen in matchedGens)
                {
                    gen.ApiAvailableSince = type.Since;
                }
                foreach (var field in type.Fields)
                {
                    var genf = matchedGens.SelectMany(g => g.Fields).FirstOrDefault(f => f.JavaName == field.Name);
                    // 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);
                Func <Ctor, ApiVersionsProvider.Definition, bool> ctorMatch =
                    (m, method) => m.JniSignature == method.Name.Substring(method.MethodName.Length);
                foreach (var method in type.Methods)
                {
                    var genm = method.MethodName == "<init>" ?
                               (MethodBase)matchedGens.OfType <ClassGen> ().SelectMany(g => g.Ctors).FirstOrDefault(m => ctorMatch(m, method)) :
                               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);
                    }
                }
            }
        }
Example #2
0
        public static void AssignApiLevels(IList <GenBase> gens, string apiVersionsXml)
        {
            var flattenGens = FlattenGens(gens).ToLookup(g => g.JavaName);
            var versions    = new ApiVersionsProvider();

            versions.Parse(apiVersionsXml);
            foreach (var type in versions.Versions.Values)
            {
                var matchedGens = flattenGens [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;
                }
                foreach (var field in type.Fields)
                {
                    var genf = matchedGens.SelectMany(g => g.Fields).FirstOrDefault(f => f.JavaName == field.Name);
                    // it might be moved to the corresponding class.
                    if (genf != null)
                    {
                        genf.ApiAvailableSince = field.Since > 0 ? field.Since : type.Since;
                    }
                }
                Func <Method, ApiVersionsProvider.Definition, bool> methodMatch =
                    (m, method) => m.JavaName == method.MethodName && m.JniSignature == method.Name.Substring(method.MethodName.Length);
                Func <Ctor, ApiVersionsProvider.Definition, bool> ctorMatch =
                    (m, method) => m.JniSignature == method.Name.Substring(method.MethodName.Length);
                foreach (var method in type.Methods)
                {
                    var genm = method.MethodName == "<init>" ?
                               (MethodBase)matchedGens.OfType <ClassGen> ().SelectMany(g => g.Ctors).FirstOrDefault(m => ctorMatch(m, method)) :
                               matchedGens.SelectMany(g => GetAllMethods(g)).FirstOrDefault(m => methodMatch(m, method));
                    if (genm != null)
                    {
                        genm.ApiAvailableSince = method.Since > 0 ? method.Since : type.Since;
                    }
                }
            }
        }