* Luca Bruno <lethalman88@gmail.com>
*/
+public class Gtkdoc.Header {
+ public string name;
+ public string[]? annotations;
+ public string? value;
+ public double pos;
+
+ public Header (string name, string? value = null, double pos = double.MAX) {
+ this.name = name;
+ this.value = value;
+ this.pos = pos;
+ }
+
+ public int cmp (Header header) {
+ if (pos > header.pos) {
+ return 1;
+ } else if (pos < header.pos) {
+ return -1;
+ }
+ return 0;
+ }
+}
+
public class Gtkdoc.GComment {
public string symbol;
public string[] symbol_annotations;
public Gee.List<Header> headers = new Gee.LinkedList<Header> ();
+ public bool short_description;
public string brief_comment;
public string long_comment;
public string returns;
}
}
+ if (short_description && brief_comment != null) {
+ builder.append_printf ("\n * @short_description: %s", commentize (brief_comment));
+ }
+
+ headers.sort ((CompareFunc) Header.cmp);
foreach (var header in headers) {
- builder.append_printf ("\n * %s:", header.name);
+ builder.append_printf ("\n * @%s:", header.name);
if (header.annotations != null && header.annotations.length > 0) {
foreach (var annotation in header.annotations) {
builder.append_printf (" (%s)", annotation);
}
}
- if (brief_comment != null) {
+ if (!short_description && brief_comment != null) {
builder.append_printf ("\n * \n * %s", commentize (brief_comment));
}
if (long_comment != null) {
builder.append (long_comment);
}
+ headers.sort ((CompareFunc) Header.cmp);
if (headers.size > 0 || returns != null) {
builder.append ("""<variablelist role="params">""");
foreach (var header in headers) {
builder.append_printf ("""<varlistentry><term><parameter>%s</parameter> :</term>
<listitem><simpara> %s </simpara></listitem></varlistentry>""",
- header.name.offset (1), header.value);
+ header.name, header.value);
}
if (returns != null) {
builder.append_printf ("""<varlistentry><term><emphasis>Returns</emphasis> :</term>
private DBus.Interface current_dbus_interface;
private DBus.Member current_dbus_member;
+ private Api.Node? current_method_or_delegate {
+ get {
+ if (current_method != null) {
+ return current_method;
+ } else if (current_delegate != null) {
+ return current_delegate;
+ }
+ return null;
+ }
+ }
+
public bool execute (Settings settings, Api.Tree tree) {
this.settings = settings;
tree.accept (this);
}
var gcomment = create_gcomment ("SECTION:%s".printf (get_section (filename)), comment);
- if (gcomment.brief_comment != null) {
- gcomment.headers.insert (0, new Header ("@short_description", gcomment.brief_comment));
- gcomment.brief_comment = null;
- }
+ gcomment.short_description = true;
file_data.section_comment = gcomment;
}
private GComment create_gcomment (string symbol, Comment? comment, string[]? returns_annotations = null, bool is_dbus = false) {
- var converter = new Gtkdoc.CommentConverter ();
+ var converter = new Gtkdoc.CommentConverter (current_method_or_delegate);
+
if (comment != null) {
converter.convert (comment, is_dbus);
}
gcomment.brief_comment = converter.brief_comment;
gcomment.long_comment = converter.long_comment;
- gcomment.headers.add_all (merge_headers (converter.headers, current_headers));
+ gcomment.headers.add_all (merge_headers (converter.parameters, current_headers));
gcomment.versioning.add_all (converter.versioning);
return gcomment;
}
return gcomment;
}
- private Header? add_custom_header (string name, string? comment, string[]? annotations = null) {
+ private Header? add_custom_header (string name, string? comment, string[]? annotations = null, double pos = double.MAX) {
if (comment == null && annotations == null) {
return null;
}
- var header = new Header ("@"+name);
+ var header = new Header (name, comment, pos);
header.annotations = annotations;
- header.value = comment;
current_headers.add (header);
return header;
}
- private void remove_custom_header (string name) {
- var header_name = "@%s".printf (name);
+ private Header? remove_custom_header (string name) {
var it = current_headers.iterator();
while (it.next ()) {
var header = it.@get ();
- if (header.name == header_name) {
+ if (header.name == name) {
it.remove ();
- break;
+ return header;
}
}
+ return null;
}
- private Header? add_header (string name, Comment? comment, string[]? annotations = null) {
+ private Header? add_header (string name, Comment? comment, string[]? annotations = null, double pos = double.MAX) {
if (comment == null && annotations == null) {
return null;
}
- var converter = new Gtkdoc.CommentConverter ();
- var header = new Header ("@"+name);
+ var converter = new Gtkdoc.CommentConverter (current_method_or_delegate);
+ var header = new Header (name);
+ header.pos = pos;
if (comment != null) {
converter.convert (comment);
}
public override void visit_error_domain (Api.ErrorDomain edomain) {
- if (current_method != null || current_delegate != null) {
+ if (current_method_or_delegate != null) {
// method throws error
Header? param_header = null;
foreach (var header in current_headers) {
}
}
if (param_header == null) {
- add_custom_header ("error", "location to store the error occuring, or %NULL to ignore", {"error-domains %s".printf (edomain.get_cname ())});
+ add_custom_header ("error", "location to store the error occuring, or %NULL to ignore", {"error-domains %s".printf (edomain.get_cname ())}, double.MAX-1);
} else {
// assume the only annotation is error-domains
var annotation = param_header.annotations[0];
if (prop.getter != null && !prop.getter.is_private && prop.getter.is_get) {
var gcomment = add_symbol (prop.get_filename(), prop.getter.get_cname ());
- gcomment.headers.add (new Header ("@self", "the %s instance to query".printf (get_docbook_link (prop.parent))));
+ gcomment.headers.add (new Header ("self", "the %s instance to query".printf (get_docbook_link (prop.parent)), 1));
gcomment.returns = "the value of the %s property".printf (get_docbook_link (prop));
}
if (prop.setter != null && !prop.setter.is_private && prop.setter.is_set) {
var gcomment = add_symbol (prop.get_filename(), prop.setter.get_cname ());
- gcomment.headers.insert (0, new Header ("@self", "the %s instance to modify".printf (get_docbook_link (prop.parent))));
- gcomment.headers.add (new Header ("@value", "the new value of the %s property".printf (get_docbook_link (prop))));
+ gcomment.headers.add (new Header ("self", "the %s instance to modify".printf (get_docbook_link (prop.parent)), 1));
+ gcomment.headers.add (new Header ("value", "the new value of the %s property".printf (get_docbook_link (prop)), 2));
}
}
var name = sig.get_cname().replace ("_", "-");
var gcomment = add_comment (sig.get_filename(), "%s::%s".printf (current_cname, name), sig.documentation);
// gtkdoc maps parameters by their ordering, so let's customly add the first parameter
- gcomment.headers.insert (0, new Header ("@%s".printf (to_lower_case (((Api.Node)sig.parent).name)),
- "the %s instance that received the signal".printf (get_docbook_link (sig.parent))));
+ gcomment.headers.insert (0, new Header (to_lower_case (((Api.Node)sig.parent).name),
+ "the %s instance that received the signal".printf (get_docbook_link (sig.parent)), 0.1));
if (current_dbus_interface != null && sig.is_dbus_visible) {
var dbuscomment = create_gcomment (sig.get_dbus_name (), sig.documentation, null, true);
current_dbus_member.comment = dbuscomment;
current_dbus_member = new DBus.Member (m.get_dbus_name ());
}
+ if (!m.is_static && !m.is_constructor) {
+ add_custom_header ("self", "the %s instance".printf (get_docbook_link (m.parent)), null, 0.1);
+ }
+
m.accept_all_children (this);
Header error_header = null;
if (m.is_yields) {
add_custom_header ("_callback_", "callback to call when the request is satisfied", {"scope async"});
add_custom_header ("_user_data_", "the data to pass to @_callback_ function", {"closure"});
- gcomment = add_symbol (m.get_filename(), m.get_cname (), m.documentation);
-
// remove error from here, put that in the _finish function
- var it = gcomment.headers.iterator ();
- while (it.next ()) {
- var header = it.get ();
- if (header.name == "@error") {
- error_header = header;
- it.remove ();
- break;
- }
- }
+ error_header = remove_custom_header ("error");
+ gcomment = add_symbol (m.get_filename(), m.get_cname (), m.documentation);
gcomment.returns = null; // async method has no return value
var see_also = gcomment.see_also; // vala bug
see_also += get_docbook_link (m, false, true);
gcomment = add_symbol (m.get_filename(), m.get_cname (), m.documentation, null, annotations);
}
- if (!m.is_static && !m.is_constructor) {
- gcomment.headers.insert (0, new Header ("@self", "the %s instance".printf (get_docbook_link (m.parent))));
- }
+ remove_custom_header ("self");
if (current_dbus_interface != null && m.is_dbus_visible && !m.is_constructor) {
if (m.return_type != null && m.return_type.data_type != null) {
if (m.is_yields) {
var finish_gcomment = add_symbol (m.get_filename(), m.get_finish_function_cname (), m.documentation);
-
- var iter = finish_gcomment.headers.iterator ();
- while (iter.next ()) {
- // remove parameters from _finish
- if (iter.get().name.has_prefix ("@")) {
- iter.remove ();
- }
- }
+ finish_gcomment.headers.clear ();
if (!m.is_static) {
- finish_gcomment.headers.add (new Header ("@self", "the %s instance".printf (get_docbook_link (m.parent))));
+ finish_gcomment.headers.add (new Header ("self", "the %s instance".printf (get_docbook_link (m.parent))));
}
- finish_gcomment.headers.add (new Header ("@_res_", "a GAsyncResult"));
+ finish_gcomment.headers.add (new Header ("_res_", "a GAsyncResult"));
if (error_header != null) {
finish_gcomment.headers.add (error_header);
}
if (param.parameter_type.data_type is Api.Array) {
annotations += "array length=%s_length1".printf (param.name);
- add_custom_header ("%s_length1".printf (param.name), "length of the @%s array".printf (param.name));
+ add_custom_header ("%s_length1".printf (param.name), "length of the @%s array".printf (param.name),
+ null, get_parameter_pos (current_method_or_delegate, param.name)+0.1);
}
if (get_cname (param.parameter_type.data_type) == "GError") {
// gtkdoc writes arg0, arg1 which is ugly. As a workaround, we always add an header for them.
add_custom_header (param.name, "", null);
} else {
- add_header (param.name, param.documentation, annotations);
+ add_header (param.name, param.documentation, annotations,
+ get_parameter_pos (current_method_or_delegate, param.name));
}
if (param.parameter_type.data_type is Api.Delegate) {
- add_custom_header ("%s_target".printf (param.name), "user data to pass to @%s".printf (param.name), {"allow-none", "closure"});
- add_custom_header ("%s_target_destroy_notify".printf (param.name), "function to call when @%s_target is no longer needed".printf (param.name), {"allow-none"});
+ add_custom_header ("%s_target".printf (param.name), "user data to pass to @%s".printf (param.name),
+ {"allow-none", "closure"}, get_parameter_pos (current_method_or_delegate, param.name)+0.1);
+ add_custom_header ("%s_target_destroy_notify".printf (param.name), "function to call when @%s_target is no longer needed".printf (param.name), {"allow-none"}, get_parameter_pos (current_method_or_delegate, param.name)+0.2);
}
if (current_dbus_member != null) {