]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
libvaladoc/html: Mark deprecated symbols
authorFlorian Brosch <flo.brosch@gmail.com>
Fri, 12 Aug 2011 00:32:51 +0000 (02:32 +0200)
committerFlorian Brosch <flo.brosch@gmail.com>
Fri, 12 Aug 2011 00:32:51 +0000 (02:32 +0200)
icons/devhelpstyle.css
icons/style.css
icons/wikistyle.css
src/libvaladoc/api/attribute.vala
src/libvaladoc/api/attributeargument.vala
src/libvaladoc/api/package.vala
src/libvaladoc/api/symbol.vala
src/libvaladoc/html/basicdoclet.vala

index 19392d11243bba71a90b1953eafb7f39a1caf5d3..fa181e22297aff6b4bf84f762d3708938dc3e9b2 100644 (file)
@@ -530,3 +530,6 @@ ul.no_bullet li {
 .package_note {
 }
 
+.deprecated {
+       text-decoration:line-through;
+}
index 04564176080595204ac6ae1d4d23c2722f6297a0..e556fbd6d4d6b9816baab4b39ebe9e03681fc0fc 100644 (file)
@@ -542,3 +542,6 @@ ul.no_bullet li {
 .package_note {
 }
 
+.deprecated {
+       text-decoration:line-through;
+}
index 9c878ce09f9705f21229b3343fb2129528b3844b..56ca6bc73a24469c098b2e58931088877ed06736 100644 (file)
@@ -495,3 +495,6 @@ ul.no_bullet li {
        color: #ff01ff;
 }
 
+.deprecated {
+       text-decoration:line-through;
+}
index 1d31894d38480554a60e2b5fa236fcce788e1abe..04fac9b18fa4d67aaada8edc5d99237a3065a4da 100644 (file)
@@ -41,6 +41,18 @@ public class Valadoc.Api.Attribute : Item {
                this.file = file;
        }
 
+       public AttributeArgument? get_argument (string name) {
+               if (args != null) {
+                       foreach (AttributeArgument arg in args) {
+                               if (arg.name == name) {
+                                       return arg;
+                               }
+                       }
+               }
+
+               return null;
+       }
+
        public AttributeArgument add_boolean (string name, bool value, void* data = null) {
                AttributeArgument arg = new AttributeArgument.boolean (this, file, name, value, data);
                args.add (arg);
index a15fb3d2348a4e1b81fee9856bae0abc7f74dbeb..7bcd0c6d881e603daef6a57efe4adeb2d2440016 100644 (file)
@@ -127,14 +127,8 @@ public class Valadoc.Api.AttributeArgument : Item {
                SignatureBuilder builder = new SignatureBuilder ();
 
                builder.append_attribute (name);
-
                builder.append_attribute ("=");
-
-               if (argument_type == Type.STRING) {
-                       builder.append_literal ("\"" + value + "\"");
-               } else {
-                       builder.append_literal (value);
-               }
+               builder.append_literal (value);
 
                return builder.get ();
        }
index 6656b4810d0ecf89ceda9b61ddd9e8e9f2432088..85be9bd8356a4ab7fad78c578523422edaeb0dce 100755 (executable)
@@ -25,6 +25,7 @@ using Valadoc.Content;
 using Valadoc.Importer;
 
 public class Valadoc.Api.Package : Node {
+
        /**
         * Specifies whether this package is a dependency
         */
@@ -79,6 +80,51 @@ public class Valadoc.Api.Package : Node {
                this.parent = null;
        }
 
+       // <version, symbols>
+       private HashMap<string?, ArrayList<Symbol>> deprecated;
+
+       internal void register_deprecated_symbol (Symbol symbol, string? version) {
+               if (deprecated == null) {
+                       // some libgee-versions do not like nullable strings
+
+                       EqualFunc<string?> str_eq0 = (a, b) => { 
+                               if (a == null && b == null) {
+                                       return true;
+                               } else if (a == null || b == null) {
+                                       return false;
+                               }
+
+                               return a == b;
+                       };
+
+                       HashFunc<string?> str_hash0 = (a) => {
+                               if (a == null) {
+                                       return 0;
+                               }
+
+                               return a.hash ();
+                       };
+
+                       deprecated = new HashMap<string?, ArrayList<Symbol>> (str_hash0, str_eq0);
+               }
+
+               ArrayList<Symbol> list = deprecated.get (version);
+               if (list == null) {
+                       list = new ArrayList<Symbol> ();
+                       deprecated.set (version, list);
+               }
+
+               list.add (symbol);
+       }
+
+       public Map<string?, Collection<Symbol>> get_deprecated_symbols () {
+               if (deprecated == null) {
+                       return Map<string?, Collection<Symbol>>.empty<string?, Collection<Symbol>> ();
+               }
+
+               return deprecated;
+       }
+
        /**
         * {@inheritDoc}
         */
index 33099215306d61da16e7c4d6c3722e363ead4f88..54f887d6f98812af8b0f58080d7e9c674d6ce0c0 100755 (executable)
@@ -29,6 +29,12 @@ using Gee;
 public abstract class Valadoc.Api.Symbol : Node {
        private ArrayList<Attribute> attributes;
 
+       public bool is_deprecated {
+               default = false;
+               private set;
+               get;
+       }
+
        public Symbol (Node parent, SourceFile file, string? name, SymbolAccessibility accessibility, void* data) {
                base (parent, file, name, data);
 
@@ -40,6 +46,15 @@ public abstract class Valadoc.Api.Symbol : Node {
                        attributes = new ArrayList<Attribute> ();
                }
 
+               // register deprecated symbols:
+               if (att.name == "Deprecated") {
+                       AttributeArgument? version = att.get_argument ("version");
+                       string? version_str = (version == null)? null : version.get_value_as_string ();
+
+                       package.register_deprecated_symbol (this, version_str);
+                       is_deprecated = true;
+               }
+
                attributes.add (att);
        }
 
@@ -51,6 +66,18 @@ public abstract class Valadoc.Api.Symbol : Node {
                }
        }
 
+       public Attribute? get_attribute (string name) {
+               if (attributes != null) {
+                       foreach (Attribute att in attributes) {
+                               if (att.name == name) {
+                                       return att;
+                               }
+                       }
+               }
+
+               return null;
+       }
+
        /**
         * {@inheritDoc}
         */
index c8622787c91da061935521a504db6f12a66b28c6..f624bf52c6a0354fd66ad1fc770145b9f2a202f8 100755 (executable)
@@ -94,6 +94,7 @@ public abstract class Valadoc.Html.BasicDoclet : Api.Visitor, Doclet {
        private const string css_style_navigation = "site_navigation";
        private const string css_style_content = "site_content";
        private const string css_style_body = "site_body";
+       private const string css_deprecated = "deprecated";
 
        public virtual void process (Settings settings, Api.Tree tree, ErrorReporter reporter) {
                this.settings = settings;
@@ -126,15 +127,31 @@ public abstract class Valadoc.Html.BasicDoclet : Api.Visitor, Doclet {
 
 
 
-       protected void write_navi_entry_html_template (string style, string content) {
+       protected void write_navi_entry_html_template (string style, string content, bool is_deprecated) {
                writer.start_tag ("li", {"class", style});
-               writer.text (content);
+
+               if (is_deprecated) {
+                       writer.start_tag ("span", {"class", css_deprecated});
+                       writer.text (content);
+                       writer.end_tag ("span");
+               } else {
+                       writer.text (content);
+               }
+
                writer.end_tag ("li");
        }
 
-       protected void write_navi_entry_html_template_with_link (string style, string link, string content) {
+       protected void write_navi_entry_html_template_with_link (string style, string link, string content, bool is_deprecated) {
                writer.start_tag ("li", {"class", style});
-               writer.link (link, content);
+
+               if (is_deprecated) {
+                       writer.start_tag ("span", {"class", css_deprecated});
+                       writer.link (link, content);
+                       writer.end_tag ("span");
+               } else {
+                       writer.link (link, content);
+               }
+
                writer.end_tag ("li");
        }
 
@@ -149,10 +166,12 @@ public abstract class Valadoc.Html.BasicDoclet : Api.Visitor, Doclet {
                        name = (tmp == null)? "Global Namespace" : tmp;
                }
 
+               bool is_deprecated = element is Symbol && ((Symbol) element).is_deprecated;
+
                if (link == true) {
-                       this.write_navi_entry_html_template_with_link (style, this.get_link (element, pos), name);
+                       this.write_navi_entry_html_template_with_link (style, this.get_link (element, pos), name, is_deprecated);
                } else {
-                       this.write_navi_entry_html_template (style, name);
+                       this.write_navi_entry_html_template (style, name, is_deprecated);
                }
        }
 
@@ -370,14 +389,54 @@ public abstract class Valadoc.Html.BasicDoclet : Api.Visitor, Doclet {
 
        private void write_documentation (Api.Node element , Api.Node? pos) {
                Content.Comment? doctree = element.documentation;
-               if (doctree == null) {
+               Attribute? deprecated = (element is Symbol)? ((Symbol) element).get_attribute ("Deprecated") : null;
+
+               // avoid empty divs
+               if (doctree == null && deprecated == null) {
                        return;
                }
 
+
                writer.start_tag ("div", {"class", css_description});
 
-               _renderer.set_container (pos);
-               _renderer.render (doctree);
+               // deprecation warning:
+               if (deprecated != null) {
+                       AttributeArgument? replacement = deprecated.get_argument ("replacement");
+                       AttributeArgument? version = deprecated.get_argument ("version");
+
+                       writer.start_tag ("p");
+                       writer.start_tag ("b");
+                       writer.text ("Warning:");
+                       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 ()));
+                       }
+
+                       writer.text (".");
+
+                       if (replacement != null) {
+                               string replacement_name = replacement.get_value_as_string ();
+                               Api.Node? replacement_node = tree.search_symbol_str (pos, replacement_name.substring (1, replacement_name.length - 2));
+
+                               writer.text (" Use ");
+                               if (replacement_node == null) {
+                                       writer.text (replacement_name);
+                               } else {
+                                       string css = cssresolver.resolve (replacement_node);
+                                       writer.link (get_link (replacement_node, pos), replacement_node.get_full_name (), css);
+                               }
+                               writer.text (".");
+                       }
+
+                       writer.end_tag ("p");
+               }
+
+               if (doctree != null) {
+                       _renderer.set_container (pos);
+                       _renderer.render (doctree);
+               }
 
                writer.end_tag ("div");
        }
@@ -655,12 +714,24 @@ public abstract class Valadoc.Html.BasicDoclet : Api.Visitor, Doclet {
                        foreach (Api.Node child in children) {
                                writer.start_tag ("li", {"class", cssresolver.resolve (child)});
                                if (is_internal_node (child)) {
-                                       writer.link (get_link (child, container), child.name);
+                                       if (child is Symbol && ((Symbol) child).is_deprecated) {
+                                               writer.start_tag ("span", {"class", css_deprecated});
+                                               writer.link (get_link (child, container), child.name);
+                                               writer.end_tag ("span");
+                                       } else {
+                                               writer.link (get_link (child, container), child.name);
+                                       }
                                        writer.text (" - ");
                                        write_brief_description (child, container);
                                } else {
                                        writer.start_tag ("span", {"class", css_leaf_code_definition});
-                                       write_signature (child, container);
+                                       if (child is Symbol && ((Symbol) child).is_deprecated) {
+                                               writer.start_tag ("span", {"class", css_deprecated});
+                                               write_signature (child, container);
+                                               writer.end_tag ("span");
+                                       } else {
+                                               write_signature (child, container);
+                                       }
                                        writer.end_tag ("span");
 
                                        writer.start_tag ("div", {"class", css_leaf_brief_description});