]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
libvaladoc: Add support for attributes
authorFlorian Brosch <flo.brosch@gmail.com>
Thu, 11 Aug 2011 00:01:43 +0000 (02:01 +0200)
committerFlorian Brosch <flo.brosch@gmail.com>
Thu, 11 Aug 2011 00:01:43 +0000 (02:01 +0200)
src/libvaladoc/Makefile.am
src/libvaladoc/api/attribute.vala [new file with mode: 0644]
src/libvaladoc/api/attributeargument.vala [new file with mode: 0644]
src/libvaladoc/api/signaturebuilder.vala
src/libvaladoc/api/symbol.vala
src/libvaladoc/html/basicdoclet.vala

index 4b925914d2fa977b6df5984f2b82cf0e1f4fb327..aa9e01da548c66a24e8c72b97d0d99fe9fb88de2 100755 (executable)
@@ -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 (file)
index 0000000..1d31894
--- /dev/null
@@ -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 (file)
index 0000000..a15fb3d
--- /dev/null
@@ -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 ();
+       }
+}
index f589a0b6a12588fb4247dd7aa493be91fb79fa1d..22a73aafc8d9217fbbd70ae2415c69294b5adaa9 100755 (executable)
@@ -58,6 +58,19 @@ public class Valadoc.Api.SignatureBuilder {
                return this;
        }
 
+       /**
+        * 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. 
         *
index 260a5d3b86d59c2f896a3708c5c99b3c4b986621..33099215306d61da16e7c4d6c3722e363ead4f88 100755 (executable)
@@ -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}
         */
index d04d39e80c166637f9fa7f806ae0eb84e83eecd3..c8622787c91da061935521a504db6f12a66b28c6 100755 (executable)
@@ -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);