예제 #1
0
        void FixOldConstants(StreamWriter sw)
        {
            foreach (var pair in remove_nodes)
            {
                var enu = pair.Key;

                string package, type, member;
                ParseJniMember(enu, out package, out type, out member);

                if (pair.Value != null)
                {
                    sw.WriteLine("  <attr path=\"/api/package[@name='{0}']/{3}[@name='{1}']/field[@name='{2}']\" name=\"type\">{4}</attr>",
                                 package, type, member, enu.StartsWith("I:") ? "interface" : "class", pair.Value);
                    sw.WriteLine("  <attr path=\"/api/package[@name='{0}']/{3}[@name='{1}']/field[@name='{2}']\" name=\"deprecated\">This constant will be removed in the future version. Use {4} enum directly instead of this field.</attr>",
                                 package, type, member, enu.StartsWith("I:") ? "interface" : "class", pair.Value);
                    sw.WriteLine("  <attr path=\"/api/package[@name='{0}']/{3}[@name='{1}']/field[@name='{2}']\" name=\"deprecated-error\">true</attr>",
                                 package, type, member, enu.StartsWith("I:") ? "interface" : "class", pair.Value);
                    continue;
                }
                try {
                    sw.WriteLine("  <remove-node path=\"/api/package[@name='{0}']/{3}[@name='{1}']/field[@name='{2}']\" />",
                                 package, type, member, enu.StartsWith("I:") ? "interface" : "class");
                } catch (Exception ex) {
                    Report.LogCodedError(Report.ErrorFailedToRemoveConstants, ex, enu);
                    throw;
                }
            }
        }
예제 #2
0
 //  <remove-node path="/api/package[@name='java.lang']/class[@name='Float']/field[@name='MAX_VALUE']" />
 void RemoveOldConstants(StreamWriter sw)
 {
     foreach (var e in remove_nodes)
     {
         string enu = e.Key;
         string package, type, member;
         ParseJniMember(enu, out package, out type, out member);
         try {
             sw.WriteLine("  <remove-node path=\"/api/package[@name='{0}']/{3}[@name='{1}']/field[@name='{2}']\" />",
                          package, type, member, enu.StartsWith("I:") ? "interface" : "class");
         } catch (Exception ex) {
             Report.LogCodedError(Report.ErrorFailedToRemoveConstants, ex, enu);
             throw;
         }
     }
 }
예제 #3
0
        public List <GenBase> Parse(XDocument doc, IEnumerable <string> fixups, string apiLevel, int productVersion)
        {
            if (doc == null)
            {
                return(null);
            }
            try {
                var apiFixup = new ApiFixup(doc);
                apiFixup.Process(from fixup in fixups select Load(fixup), apiLevel, productVersion);
                ApiSource = apiFixup.ApiSource;
            } catch (XmlException ex) {
                // BG4200
                Report.LogCodedError(Report.ErrorFailedToProcessMetadata, ex.Message);
                return(null);
            }

            var root = doc.Root;

            if ((root == null) || !root.HasElements)
            {
                Report.LogCodedWarning(0, Report.WarningNoPackageElements);
                return(null);
            }

            List <GenBase> gens = new List <GenBase> ();

            foreach (var elem in root.Elements())
            {
                switch (elem.Name.LocalName)
                {
                case "package":
                    gens.AddRange(ParsePackage(elem));
                    break;

                case "enum":
                    ISymbol sym = new EnumSymbol(elem.XGetAttribute("name"));
                    opt.SymbolTable.AddType(elem.XGetAttribute("name"), sym);
                    continue;

                default:
                    Report.LogCodedWarning(0, Report.WarningUnexpectedRootChildNode, elem.Name.ToString());
                    break;
                }
            }

            return(gens);
        }
예제 #4
0
        internal List <ApiTransform> ParseMethodMappings(TextReader source, int filter_version)
        {
            var list = new List <ApiTransform> ();

            if (source == null)
            {
                return(list);
            }

            string s;
            bool   preserveTypeMode = false;

            while ((s = source.ReadLine()) != null)
            {
                if (s.Trim() == "---- PRESERVE TYPE MODE ----")
                {
                    preserveTypeMode = true;
                }

                if (s.Length == 0 || s.StartsWith("//", StringComparison.Ordinal))
                {
                    continue;
                }
                var items = s.Split(',');
                int ver;
                if (filter_version > 0 && int.TryParse(items [0], out ver) && filter_version < ver)
                {
                    continue;
                }
                try {
                    list.Add(new ApiTransform(preserveTypeMode, items));
                } catch (Exception ex) {
                    Report.LogCodedError(Report.ErrorFailedToProcessEnumMap, ex, s);
                    throw;
                }
            }

            return(list);
        }
예제 #5
0
        public string GetOutputName(string type)
        {
            // Handle a few special cases
            if (type == "System.Void")
            {
                return("void");
            }
            if (type.StartsWith("params "))
            {
                return("params " + GetOutputName(type.Substring("params ".Length)));
            }
            if (type.StartsWith("global::"))
            {
                Report.LogCodedError(Report.ErrorUnexpectedGlobal);
            }
            if (!UseGlobal)
            {
                return(type);
            }

            // Add "global::" in front of types
            return(ParsedType.Parse(type).ToString(UseGlobal));
        }
예제 #6
0
        void Process(XDocument meta_doc, string apiLevelString, int productVersion)
        {
            int apiLevel = 0;

            int.TryParse(apiLevelString, out apiLevel);

            var      metadataChildren = meta_doc.XPathSelectElements("/metadata/*");
            string   prev_path        = null;
            XElement attr_last_cache  = null;

            foreach (var metaitem in metadataChildren)
            {
                if (ShouldSkip(metaitem, apiLevel, productVersion))
                {
                    continue;
                }
                if (!ShouldApply(metaitem))
                {
                    continue;
                }
                string path = metaitem.XGetAttribute("path");
                if (path != prev_path)
                {
                    attr_last_cache = null;
                }
                prev_path = path;

                switch (metaitem.Name.LocalName)
                {
                case "remove-node":
                    try {
                        var nodes = api_doc.XPathSelectElements(path).ToArray();
                        if (nodes.Any())
                        {
                            foreach (var node in nodes)
                            {
                                node.Remove();
                            }
                        }
                        else
                        {
                            // BG8A00
                            Report.LogCodedWarning(0, Report.WarningRemoveNodeMatchedNoNodes, null, metaitem, $"<remove-node path=\"{path}\" />");
                        }
                    } catch (XPathException e) {
                        // BG4301
                        Report.LogCodedError(Report.ErrorRemoveNodeInvalidXPath, e, metaitem, path);
                    }
                    break;

                case "add-node":
                    try {
                        var nodes = api_doc.XPathSelectElements(path);
                        if (!nodes.Any())
                        {
                            // BG8A01
                            Report.LogCodedWarning(0, Report.WarningAddNodeMatchedNoNodes, null, metaitem, $"<add-node path=\"{path}\" />");
                        }
                        else
                        {
                            foreach (var node in nodes)
                            {
                                node.Add(metaitem.Nodes());
                            }
                        }
                    } catch (XPathException e) {
                        // BG4302
                        Report.LogCodedError(Report.ErrorAddNodeInvalidXPath, e, metaitem, path);
                    }
                    break;

                case "change-node":
                    try {
                        var  nodes   = api_doc.XPathSelectElements(path);
                        bool matched = false;
                        foreach (var node in nodes)
                        {
                            var newChild = new XElement(metaitem.Value);
                            newChild.Add(node.Attributes());
                            newChild.Add(node.Nodes());
                            node.ReplaceWith(newChild);
                            matched = true;
                        }

                        if (!matched)
                        {
                            // BG8A03
                            Report.LogCodedWarning(0, Report.WarningChangeNodeTypeMatchedNoNodes, null, metaitem, $"<change-node-type path=\"{path}\" />");
                        }
                    } catch (XPathException e) {
                        // BG4303
                        Report.LogCodedError(Report.ErrorChangeNodeInvalidXPath, e, metaitem, path);
                    }
                    break;

                case "attr":
                    try {
                        string attr_name = metaitem.XGetAttribute("name");
                        if (string.IsNullOrEmpty(attr_name))
                        {
                            // BG4307
                            Report.LogCodedError(Report.ErrorMissingAttrName, null, metaitem, path);
                        }
                        var nodes        = attr_last_cache != null ? new XElement [] { attr_last_cache } : api_doc.XPathSelectElements(path);
                        int attr_matched = 0;
                        foreach (var n in nodes)
                        {
                            n.SetAttributeValue(attr_name, metaitem.Value);
                            attr_matched++;
                        }
                        if (attr_matched == 0)
                        {
                            // BG8A04
                            Report.LogCodedWarning(0, Report.WarningAttrMatchedNoNodes, null, metaitem, $"<attr path=\"{path}\" />");
                        }
                        if (attr_matched != 1)
                        {
                            attr_last_cache = null;
                        }
                    } catch (XPathException e) {
                        // BG4304
                        Report.LogCodedError(Report.ErrorAttrInvalidXPath, e, metaitem, path);
                    }
                    break;

                case "move-node":
                    try {
                        string parent  = metaitem.Value;
                        var    parents = api_doc.XPathSelectElements(parent);
                        bool   matched = false;
                        foreach (var parent_node in parents)
                        {
                            var nodes = parent_node.XPathSelectElements(path).ToArray();
                            foreach (var node in nodes)
                            {
                                node.Remove();
                            }
                            parent_node.Add(nodes);
                            matched = true;
                        }
                        if (!matched)
                        {
                            // BG8A05
                            Report.LogCodedWarning(0, Report.WarningMoveNodeMatchedNoNodes, null, metaitem, $"<move-node path=\"{path}\" />");
                        }
                    } catch (XPathException e) {
                        // BG4305
                        Report.LogCodedError(Report.ErrorMoveNodeInvalidXPath, e, metaitem, path);
                    }
                    break;

                case "remove-attr":
                    try {
                        string name    = metaitem.XGetAttribute("name");
                        var    nodes   = api_doc.XPathSelectElements(path);
                        bool   matched = false;

                        foreach (var node in nodes)
                        {
                            node.RemoveAttributes();
                            matched = true;
                        }

                        if (!matched)
                        {
                            // BG8A06
                            Report.LogCodedWarning(0, Report.WarningRemoveAttrMatchedNoNodes, null, metaitem, $"<remove-attr path=\"{path}\" />");
                        }
                    } catch (XPathException e) {
                        // BG4306
                        Report.LogCodedError(Report.ErrorRemoveAttrInvalidXPath, e, metaitem, path);
                    }
                    break;
                }
            }
        }