[valadoc] libvaladoc: Add support for attributes
- From: Florian Brosch <flobrosch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [valadoc] libvaladoc: Add support for attributes
- Date: Fri, 12 Aug 2011 22:40:05 +0000 (UTC)
commit 847ecc21e6e86d1c365d43843c3eab516f35c81b
Author: Florian Brosch <flo brosch gmail com>
Date: Thu Aug 11 02:01:43 2011 +0200
libvaladoc: Add support for attributes
src/libvaladoc/Makefile.am | 2 +
src/libvaladoc/api/attribute.vala | 97 ++++++++++++++++++++
src/libvaladoc/api/attributeargument.vala | 141 +++++++++++++++++++++++++++++
src/libvaladoc/api/signaturebuilder.vala | 13 +++
src/libvaladoc/api/symbol.vala | 17 ++++
src/libvaladoc/html/basicdoclet.vala | 13 +++
6 files changed, 283 insertions(+), 0 deletions(-)
---
diff --git a/src/libvaladoc/Makefile.am b/src/libvaladoc/Makefile.am
index 4b92591..aa9e01d 100755
--- a/src/libvaladoc/Makefile.am
+++ b/src/libvaladoc/Makefile.am
@@ -41,6 +41,8 @@ libvaladoc_la_VALASOURCES = \
importer/valadocdocumentationimporterscanner.vala \
api/symbolaccessibility.vala \
api/sourcecomment.vala \
+ api/attributeargument.vala \
+ api/attribute.vala \
api/array.vala \
api/class.vala \
api/constant.vala \
diff --git a/src/libvaladoc/api/attribute.vala b/src/libvaladoc/api/attribute.vala
new file mode 100644
index 0000000..1d31894
--- /dev/null
+++ b/src/libvaladoc/api/attribute.vala
@@ -0,0 +1,97 @@
+/* attribute.vala
+ *
+ * Copyright (C) 2011 Florian Brosch
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Florian Brosch <flo brosch gmail com>
+ */
+
+using Valadoc.Content;
+using Gee;
+
+
+public class Valadoc.Api.Attribute : Item {
+ private ArrayList<AttributeArgument> args = new ArrayList<AttributeArgument> ();
+ private SourceFile file;
+
+ public string name {
+ private set;
+ get;
+ }
+
+ public Attribute (Node parent, SourceFile file, string name, void* data) {
+ base (data);
+
+ this.parent = parent;
+ this.name = name;
+ this.file = file;
+ }
+
+ public AttributeArgument add_boolean (string name, bool value, void* data = null) {
+ AttributeArgument arg = new AttributeArgument.boolean (this, file, name, value, data);
+ args.add (arg);
+ return arg;
+ }
+
+ public AttributeArgument add_integer (string name, int value, void* data = null) {
+ AttributeArgument arg = new AttributeArgument.integer (this, file, name, value, data);
+ args.add (arg);
+ return arg;
+ }
+
+ public AttributeArgument add_double (string name, double value, void* data = null) {
+ AttributeArgument arg = new AttributeArgument.double (this, file, name, value, data);
+ args.add (arg);
+ return arg;
+ }
+
+ public AttributeArgument add_string (string name, string value, void* data = null) {
+ AttributeArgument arg = new AttributeArgument.string (this, file, name, value, data);
+ args.add (arg);
+ return arg;
+ }
+
+ public SourceFile get_source_file () {
+ return file;
+ }
+
+ protected override Inline build_signature () {
+ SignatureBuilder builder = new SignatureBuilder ();
+
+ builder.append_attribute ("[");
+ builder.append_type_name (name);
+
+ if (args.size > 0) {
+ builder.append_attribute ("(");
+ bool first = true;
+
+ foreach (AttributeArgument arg in args) {
+ if (first == false) {
+ builder.append_attribute (", ");
+ }
+ builder.append_content (arg.signature);
+ first = false;
+ }
+ builder.append_attribute (")");
+ }
+
+ builder.append_attribute ("]");
+
+ return builder.get ();
+ }
+}
+
diff --git a/src/libvaladoc/api/attributeargument.vala b/src/libvaladoc/api/attributeargument.vala
new file mode 100644
index 0000000..a15fb3d
--- /dev/null
+++ b/src/libvaladoc/api/attributeargument.vala
@@ -0,0 +1,141 @@
+/* attributeargument.vala
+ *
+ * Copyright (C) 2011 Florian Brosch
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Florian Brosch <flo brosch gmail com>
+ */
+
+
+using Valadoc.Content;
+using Gee;
+
+
+
+public class Valadoc.Api.AttributeArgument : Item {
+ public enum Type {
+ BOOLEAN,
+ INTEGER,
+ DOUBLE,
+ STRING
+ }
+
+ private SourceFile file;
+
+ public string name {
+ private set;
+ get;
+ }
+
+ public AttributeArgument.Type argument_type {
+ private set;
+ get;
+ }
+
+ public string value {
+ private set;
+ get;
+ }
+
+ public AttributeArgument.boolean (Attribute parent, SourceFile file, string name, bool value, void* data) {
+ this (parent, file, name, Type.BOOLEAN, value.to_string (), data);
+ }
+
+ public AttributeArgument.integer (Attribute parent, SourceFile file, string name, int value, void* data) {
+ this (parent, file, name, Type.INTEGER, value.to_string (), data);
+ }
+
+ public AttributeArgument.double (Attribute parent, SourceFile file, string name, double value, void* data) {
+ this (parent, file, name, Type.DOUBLE, value.to_string (), data);
+ }
+
+ public AttributeArgument.string (Attribute parent, SourceFile file, string name, string value, void* data) {
+ this (parent, file, name, Type.STRING, value, data);
+ }
+
+ private AttributeArgument (Attribute parent, SourceFile file, string name, Type type, string value, void* data) {
+ base (data);
+
+ this.argument_type = type;
+ this.parent = parent;
+ this.value = value;
+ this.file = file;
+ this.name = name;
+ }
+
+ public SourceFile get_source_file () {
+ return file;
+ }
+
+ public bool get_value_as_boolean () {
+ assert (argument_type == Type.BOOLEAN);
+
+ bool tmp;
+
+ if (bool.try_parse (value, out tmp)) {
+ return tmp;
+ }
+
+ assert_not_reached ();
+ }
+
+ public int get_value_as_integer () {
+ assert (argument_type == Type.INTEGER);
+
+ double tmp;
+
+ if (global::double.try_parse (value, out tmp) && tmp >= int.MIN && tmp <= int.MAX) {
+ return (int) tmp;
+ }
+
+ assert_not_reached ();
+ }
+
+ public double get_value_as_double () {
+ assert (argument_type == Type.DOUBLE);
+
+ double tmp;
+
+ if (global::double.try_parse (value, out tmp)) {
+ return tmp;
+ }
+
+ assert_not_reached ();
+ }
+
+ public string get_value_as_string () {
+ assert (argument_type == Type.STRING);
+
+ return value;
+ }
+
+ protected override Inline build_signature () {
+ 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);
+ }
+
+ return builder.get ();
+ }
+}
diff --git a/src/libvaladoc/api/signaturebuilder.vala b/src/libvaladoc/api/signaturebuilder.vala
index f589a0b..22a73aa 100755
--- a/src/libvaladoc/api/signaturebuilder.vala
+++ b/src/libvaladoc/api/signaturebuilder.vala
@@ -59,6 +59,19 @@ public class Valadoc.Api.SignatureBuilder {
}
/**
+ * Adds text onto the end of the builder.
+ *
+ * @param literal a string
+ * @param spaced add a space at the front of the string if necessary
+ * @return this
+ */
+ public SignatureBuilder append_attribute (string text, bool spaced = true) {
+ string content = (last_appended != null && spaced ? " " : "") + text;
+ append_text (content);
+ return this;
+ }
+
+ /**
* Adds highlighted text onto the end of the builder.
*
* @param literal a string
diff --git a/src/libvaladoc/api/symbol.vala b/src/libvaladoc/api/symbol.vala
index 260a5d3..3309921 100755
--- a/src/libvaladoc/api/symbol.vala
+++ b/src/libvaladoc/api/symbol.vala
@@ -27,6 +27,7 @@ using Gee;
* Represents a node in the symbol tree.
*/
public abstract class Valadoc.Api.Symbol : Node {
+ private ArrayList<Attribute> attributes;
public Symbol (Node parent, SourceFile file, string? name, SymbolAccessibility accessibility, void* data) {
base (parent, file, name, data);
@@ -34,6 +35,22 @@ public abstract class Valadoc.Api.Symbol : Node {
this.accessibility = accessibility;
}
+ public void add_attribute (Attribute att) {
+ if (attributes == null) {
+ attributes = new ArrayList<Attribute> ();
+ }
+
+ attributes.add (att);
+ }
+
+ public Collection<Attribute> get_attributes () {
+ if (attributes == null) {
+ return Collection<Attribute>.empty<Attribute> ();
+ } else {
+ return attributes;
+ }
+ }
+
/**
* { inheritDoc}
*/
diff --git a/src/libvaladoc/html/basicdoclet.vala b/src/libvaladoc/html/basicdoclet.vala
index d04d39e..c862278 100755
--- a/src/libvaladoc/html/basicdoclet.vala
+++ b/src/libvaladoc/html/basicdoclet.vala
@@ -382,6 +382,16 @@ public abstract class Valadoc.Html.BasicDoclet : Api.Visitor, Doclet {
writer.end_tag ("div");
}
+ private void write_attributes (Api.Symbol element, Api.Node? pos) {
+ writer.set_wrap (false);
+ _renderer.set_container (pos);
+ foreach (Attribute att in element.get_attributes ()) {
+ _renderer.render (att.signature);
+ writer.simple_tag ("br");
+ }
+ writer.set_wrap (true);
+ }
+
private void write_signature (Api.Node element , Api.Node? pos) {
writer.set_wrap (false);
_renderer.set_container (pos);
@@ -518,6 +528,9 @@ public abstract class Valadoc.Html.BasicDoclet : Api.Visitor, Doclet {
this.write_image_block (node);
writer.start_tag ("h2", {"class", css_title}).text ("Description:").end_tag ("h2");
writer.start_tag ("div", {"class", css_code_definition});
+ if (node is Symbol) {
+ this.write_attributes ((Symbol) node, node);
+ }
this.write_signature (node, node);
writer.end_tag ("div");
this.write_documentation (node, node);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]