]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Add support for the Version tag that replaces the Deprecated tag
authorCorentin Noël <corentin@elementary.io>
Wed, 15 Feb 2017 00:39:38 +0000 (01:39 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 21 Feb 2017 08:17:53 +0000 (09:17 +0100)
https://bugzilla.gnome.org/show_bug.cgi?id=778640

src/doclets/gtkdoc/generator.vala
src/driver/0.32.x/treebuilder.vala
src/driver/0.34.x/treebuilder.vala
src/driver/0.36.x/treebuilder.vala
src/libvaladoc/api/symbol.vala
src/libvaladoc/html/basicdoclet.vala
src/libvaladoc/taglets/tagletdeprecated.vala

index 98c1d259695e83eab1ad9437c1cd4154de4e63a7..6aba0a691aaaca3990d426708bf9854648d26dbd 100644 (file)
@@ -1336,13 +1336,24 @@ It is important that your <link linkend=\"GValue\"><type>GValue</type></link> ho
 
        private void process_attributes (Symbol sym, GComment gcomment) {
                // Handle the ‘Deprecated’ attribute.
-               var deprecated_attribute = sym.get_attribute ("Deprecated");
+               if (sym.is_deprecated) {
+                       Attribute? version;
+                       Attribute? deprecated;
+                       AttributeArgument? deprecated_since;
+                       AttributeArgument? replacement;
+                       if ((version = sym.get_attribute ("Version")) != null) {
+                               deprecated_since = version.get_argument ("deprecated_since");
+                               replacement = version.get_argument ("replacement");
+                       } else if ((deprecated = sym.get_attribute ("Deprecated")) != null) {
+                               deprecated_since = deprecated.get_argument ("since");
+                               replacement = deprecated.get_argument ("replacement");
+                       } else {
+                               assert_not_reached ();
+                       }
 
-               if (deprecated_attribute != null) {
-                       var _since = deprecated_attribute.get_argument ("since");
                        string? since = null;
-                       if (_since != null) {
-                               since = _since.value;
+                       if (deprecated_since != null) {
+                               since = deprecated_since.value;
 
                                // Strip surrounding quotation marks.
                                if (since.has_prefix ("\"")) {
@@ -1353,7 +1364,6 @@ It is important that your <link linkend=\"GValue\"><type>GValue</type></link> ho
                                }
                        }
 
-                       var replacement = deprecated_attribute.get_argument ("replacement");
                        string? replacement_symbol_name = null;
                        Api.Node? replacement_symbol = null;
 
index 59e019ad5c24a14b59e22737b5dc761f1a8ea4ca..5b9c5ea9b0b1f449c754c5d2b7443d8c79bd27f9 100644 (file)
@@ -248,16 +248,33 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
                                Attribute new_attribute = new Attribute (parent, parent.get_source_file (), att.name, att);
                                new_attribute.add_boolean ("has_target", false, att);
                                parent.add_attribute (new_attribute);
-                       } else if (att.name == "Deprecated") {
+                       } else if (att.name == "Version") {
                                Attribute new_attribute = new Attribute (parent, parent.get_source_file (), att.name, att);
+                               if ((tmp = att.args.get ("deprecated")) != null) {
+                                       new_attribute.add_boolean ("deprecated", bool.parse (tmp), att);
+                               }
+                               if ((tmp = att.args.get ("since")) != null) {
+                                       new_attribute.add_string ("since", tmp, att);
+                               }
+                               if ((tmp = att.args.get ("deprecated_since")) != null) {
+                                       new_attribute.add_string ("deprecated_since", tmp, att);
+                                       if (att.args.get ("deprecated") == null) {
+                                               new_attribute.add_boolean ("deprecated", true, att);
+                                       }
+                               }
+                               if ((tmp = att.args.get ("replacement")) != null) {
+                                       new_attribute.add_string ("replacement", tmp, att);
+                               }
                                parent.add_attribute (new_attribute);
+                       } else if (att.name == "Deprecated") {
+                               Attribute new_attribute = new Attribute (parent, parent.get_source_file (), att.name, att);
                                if ((tmp = att.args.get ("since")) != null) {
                                        new_attribute.add_string ("since", tmp, att);
                                }
-
                                if ((tmp = att.args.get ("replacement")) != null) {
                                        new_attribute.add_string ("replacement", tmp, att);
                                }
+                               parent.add_attribute (new_attribute);
                        } else if (att.name in attributes) {
                                Attribute new_attribute = new Attribute (parent, parent.get_source_file (), att.name, att);
                                parent.add_attribute (new_attribute);
index cbdadae89e0f04061bcbf15238ffb7691cb4524e..9931efd15e2b31e95740b7d617b5214500528fe4 100644 (file)
@@ -248,16 +248,33 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
                                Attribute new_attribute = new Attribute (parent, parent.get_source_file (), att.name, att);
                                new_attribute.add_boolean ("has_target", false, att);
                                parent.add_attribute (new_attribute);
-                       } else if (att.name == "Deprecated") {
+                       } else if (att.name == "Version") {
                                Attribute new_attribute = new Attribute (parent, parent.get_source_file (), att.name, att);
+                               if ((tmp = att.args.get ("deprecated")) != null) {
+                                       new_attribute.add_boolean ("deprecated", bool.parse (tmp), att);
+                               }
+                               if ((tmp = att.args.get ("since")) != null) {
+                                       new_attribute.add_string ("since", tmp, att);
+                               }
+                               if ((tmp = att.args.get ("deprecated_since")) != null) {
+                                       new_attribute.add_string ("deprecated_since", tmp, att);
+                                       if (att.args.get ("deprecated") == null) {
+                                               new_attribute.add_boolean ("deprecated", true, att);
+                                       }
+                               }
+                               if ((tmp = att.args.get ("replacement")) != null) {
+                                       new_attribute.add_string ("replacement", tmp, att);
+                               }
                                parent.add_attribute (new_attribute);
+                       } else if (att.name == "Deprecated") {
+                               Attribute new_attribute = new Attribute (parent, parent.get_source_file (), att.name, att);
                                if ((tmp = att.args.get ("since")) != null) {
                                        new_attribute.add_string ("since", tmp, att);
                                }
-
                                if ((tmp = att.args.get ("replacement")) != null) {
                                        new_attribute.add_string ("replacement", tmp, att);
                                }
+                               parent.add_attribute (new_attribute);
                        } else if (att.name in attributes) {
                                Attribute new_attribute = new Attribute (parent, parent.get_source_file (), att.name, att);
                                parent.add_attribute (new_attribute);
index 46c4b255d0e3e753b69b80a7d32af416b8de9039..aebf2726e57d4fa73824dbefb8d3c8bbfdcf231d 100644 (file)
@@ -248,16 +248,33 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
                                Attribute new_attribute = new Attribute (parent, parent.get_source_file (), att.name, att);
                                new_attribute.add_boolean ("has_target", false, att);
                                parent.add_attribute (new_attribute);
-                       } else if (att.name == "Deprecated") {
+                       } else if (att.name == "Version") {
                                Attribute new_attribute = new Attribute (parent, parent.get_source_file (), att.name, att);
+                               if ((tmp = att.args.get ("deprecated")) != null) {
+                                       new_attribute.add_boolean ("deprecated", bool.parse (tmp), att);
+                               }
+                               if ((tmp = att.args.get ("since")) != null) {
+                                       new_attribute.add_string ("since", tmp, att);
+                               }
+                               if ((tmp = att.args.get ("deprecated_since")) != null) {
+                                       new_attribute.add_string ("deprecated_since", tmp, att);
+                                       if (att.args.get ("deprecated") == null) {
+                                               new_attribute.add_boolean ("deprecated", true, att);
+                                       }
+                               }
+                               if ((tmp = att.args.get ("replacement")) != null) {
+                                       new_attribute.add_string ("replacement", tmp, att);
+                               }
                                parent.add_attribute (new_attribute);
+                       } else if (att.name == "Deprecated") {
+                               Attribute new_attribute = new Attribute (parent, parent.get_source_file (), att.name, att);
                                if ((tmp = att.args.get ("since")) != null) {
                                        new_attribute.add_string ("since", tmp, att);
                                }
-
                                if ((tmp = att.args.get ("replacement")) != null) {
                                        new_attribute.add_string ("replacement", tmp, att);
                                }
+                               parent.add_attribute (new_attribute);
                        } else if (att.name in attributes) {
                                Attribute new_attribute = new Attribute (parent, parent.get_source_file (), att.name, att);
                                parent.add_attribute (new_attribute);
index e4520b387913a1d4348316dd03d0159bc603a4ab..aec2bdd753b13a0a133e3449469815bf6dc60e88 100644 (file)
@@ -49,9 +49,18 @@ public abstract class Valadoc.Api.Symbol : Node {
                }
 
                // register deprecated symbols:
-               if (att.name == "Deprecated") {
+               if (att.name == "Version") {
+                       AttributeArgument? deprecated = att.get_argument ("deprecated");
+                       AttributeArgument? version = att.get_argument ("deprecated_since");
+                       if ((deprecated != null && deprecated.get_value_as_boolean ()) || version != null) {
+                               string? version_str = (version != null) ? version.get_value_as_string () : null;
+
+                               package.register_deprecated_symbol (this, version_str);
+                               is_deprecated = true;
+                       }
+               } else if (att.name == "Deprecated") {
                        AttributeArgument? version = att.get_argument ("version");
-                       string? version_str = (version == null)? null : version.get_value_as_string ();
+                       string? version_str = (version != null) ? version.get_value_as_string () : null;
 
                        package.register_deprecated_symbol (this, version_str);
                        is_deprecated = true;
index 66ab3e05339466f2b956ef9c54ea31b409dc1a52..f770bc2076a00e6b777425768333179216b174dc 100644 (file)
@@ -459,10 +459,10 @@ public abstract class Valadoc.Html.BasicDoclet : Api.Visitor, Doclet {
 
        private void write_documentation (Api.Node element , Api.Node? pos) {
                Content.Comment? doctree = element.documentation;
-               Attribute? deprecated = (element is Symbol)? ((Symbol) element).get_attribute ("Deprecated") : null;
+               bool is_deprecated = (element is Symbol && ((Symbol) element).is_deprecated);
 
                // avoid empty divs
-               if (doctree == null && deprecated == null) {
+               if (doctree == null && !is_deprecated) {
                        return;
                }
 
@@ -471,9 +471,21 @@ public abstract class Valadoc.Html.BasicDoclet : Api.Visitor, Doclet {
                _renderer.set_owner (element);
 
                // deprecation warning:
-               if (deprecated != null) {
-                       AttributeArgument? replacement = deprecated.get_argument ("replacement");
-                       AttributeArgument? version = deprecated.get_argument ("version");
+               if (is_deprecated) {
+                       Symbol symbol = (Symbol) element;
+                       Attribute? version;
+                       Attribute? deprecated;
+                       AttributeArgument? replacement;
+                       AttributeArgument? since;
+                       if ((version = symbol.get_attribute ("Version")) != null) {
+                               replacement = version.get_argument ("replacement");
+                               since = version.get_argument ("deprecated_since");
+                       } else if ((deprecated = symbol.get_attribute ("Deprecated")) != null) {
+                               replacement = deprecated.get_argument ("replacement");
+                               since = deprecated.get_argument ("version");
+                       } else {
+                               assert_not_reached ();
+                       }
 
                        writer.start_tag ("p");
                        writer.start_tag ("b");
@@ -481,8 +493,8 @@ public abstract class Valadoc.Html.BasicDoclet : Api.Visitor, Doclet {
                        writer.end_tag ("b");
                        writer.text (" %s is deprecated".printf (element.name));
 
-                       if (version != null) {
-                               writer.text (" since %s".printf (version.get_value_as_string ()));
+                       if (since != null) {
+                               writer.text (" since %s".printf (since.get_value_as_string ()));
                        }
 
                        writer.text (".");
index 82c01f8b559bb4b707d01993ecc6bc084d82ac13..c77457935b6d95e1a99ad553bf620e7e79d2f319 100644 (file)
@@ -35,7 +35,7 @@ public class Valadoc.Taglets.Deprecated : BlockContent, Taglet, Block {
        {
                base.check (api_root, container, file_path, reporter, settings);
                reporter.simple_warning ("%s: %s: @deprecated".printf (file_path, container.get_full_name ()),
-                                                                "@deprecated is deprecated. Use [Deprecated]");
+                                                                "@deprecated is deprecated. Use [Version (deprecated = true)]");
        }
 
        public override void accept (ContentVisitor visitor) {