using Valadoc.Importer;
public class Valadoc.Api.Package : Node {
+
/**
* Specifies whether this package is a dependency
*/
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}
*/
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);
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);
}
}
}
+ public Attribute? get_attribute (string name) {
+ if (attributes != null) {
+ foreach (Attribute att in attributes) {
+ if (att.name == name) {
+ return att;
+ }
+ }
+ }
+
+ return null;
+ }
+
/**
* {@inheritDoc}
*/
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;
- 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");
}
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);
}
}
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");
}
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});