[vala] GIR writer: Generate annotations on all elements



commit 272f24bfa19ee7be735dd2a5feacc1ea02d111ad
Author: Didier 'Ptitjes <ptitjes free fr>
Date:   Sun Mar 22 16:34:29 2009 +0100

    GIR writer: Generate annotations on all elements
    
    Signed-off-by: Didier 'Ptitjes <ptitjes free fr>
---
 gobject/valagirwriter.vala |   53 +++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 52 insertions(+), 1 deletions(-)

diff --git a/gobject/valagirwriter.vala b/gobject/valagirwriter.vala
index 2f6a1e3..5918d06 100644
--- a/gobject/valagirwriter.vala
+++ b/gobject/valagirwriter.vala
@@ -114,6 +114,8 @@ public class Vala.GIRWriter : CodeVisitor {
 		stream.printf ("<namespace name=\"%s\" version=\"1.0\">\n", ns.name);
 		indent++;
 
+		write_annotations (ns);
+
 		ns.accept_children (this);
 
 		indent--;
@@ -165,6 +167,8 @@ public class Vala.GIRWriter : CodeVisitor {
 				stream.printf ("</implements>\n");
 			}
 
+			write_annotations (cl);
+
 			cl.accept_children (this);
 
 			indent--;
@@ -193,6 +197,8 @@ public class Vala.GIRWriter : CodeVisitor {
 			stream.printf (">\n");
 			indent++;
 
+			write_annotations (cl);
+
 			cl.accept_children (this);
 
 			indent--;
@@ -215,6 +221,8 @@ public class Vala.GIRWriter : CodeVisitor {
 		stream.printf (">\n");
 		indent++;
 
+		write_annotations (st);
+
 		st.accept_children (this);
 
 		indent--;
@@ -264,6 +272,8 @@ public class Vala.GIRWriter : CodeVisitor {
 			stream.printf ("</requires>\n");
 		}
 
+		write_annotations (iface);
+
 		iface.accept_children (this);
 
 		indent--;
@@ -303,6 +313,8 @@ public class Vala.GIRWriter : CodeVisitor {
 		stream.printf (">\n");
 		indent++;
 
+		write_annotations (en);
+
 		enum_value = 0;
 		en.accept_children (this);
 
@@ -338,7 +350,11 @@ public class Vala.GIRWriter : CodeVisitor {
 		stream.printf ("<errordomain name=\"%s\"", edomain.name);
 		stream.printf (" get-quark=\"%squark\"", edomain.get_lower_case_cprefix ());
 		stream.printf (" codes=\"%s\"", edomain.name);
-		stream.printf ("/>\n");
+		stream.printf (">\n");
+
+		write_annotations (edomain);
+
+		stream.printf ("</errordomain>\n");
 
 		write_indent ();
 		stream.printf ("<enumeration name=\"%s\"", edomain.name);
@@ -409,6 +425,8 @@ public class Vala.GIRWriter : CodeVisitor {
 		stream.printf (">\n");
 		indent++;
 
+		write_annotations (f);
+
 		write_type (f.field_type);
 
 		indent--;
@@ -470,6 +488,8 @@ public class Vala.GIRWriter : CodeVisitor {
 			stream.printf (">\n");
 			indent++;
 
+			write_annotations (param);
+
 			write_type (param.parameter_type);
 
 			indent--;
@@ -500,6 +520,8 @@ public class Vala.GIRWriter : CodeVisitor {
 		stream.printf (">\n");
 		indent++;
 
+		write_annotations (cb);
+
 		write_params (cb.get_parameters ());
 
 		write_return_type (cb.return_type);
@@ -548,6 +570,8 @@ public class Vala.GIRWriter : CodeVisitor {
 		stream.printf (">\n");
 		indent++;
 
+		write_annotations (m);
+
 		DataType instance_type = null;
 		if (instance) {
 			instance_type = CCodeBaseModule.get_data_type_for_symbol ((TypeSymbol) m.parent_symbol);
@@ -579,6 +603,8 @@ public class Vala.GIRWriter : CodeVisitor {
 		stream.printf (">\n");
 		indent++;
 
+		write_annotations (m);
+
 		write_params (m.get_parameters ());
 
 		var datatype = CCodeBaseModule.get_data_type_for_symbol ((TypeSymbol) m.parent_symbol);
@@ -612,6 +638,8 @@ public class Vala.GIRWriter : CodeVisitor {
 		stream.printf (">\n");
 		indent++;
 
+		write_annotations (prop);
+
 		write_type (prop.property_type);
 
 		indent--;
@@ -629,6 +657,8 @@ public class Vala.GIRWriter : CodeVisitor {
 		stream.printf (">\n");
 		indent++;
 
+		write_annotations (sig);
+
 		write_params (sig.get_parameters ());
 
 		write_return_type (sig.return_type);
@@ -721,6 +751,23 @@ public class Vala.GIRWriter : CodeVisitor {
 		}
 	}
 
+	private void write_annotations (CodeNode node) {
+		foreach (Attribute attr in node.attributes) {
+			string name = camel_case_to_canonical (attr.name);
+			foreach (string arg_name in attr.args.get_keys ()) {
+				var arg = attr.args.get (arg_name);
+
+				string value = literal_expression_to_value_string ((Literal) arg);
+
+				if (value != null) {
+					write_indent ();
+					stream.printf ("<annotation key=\"%s.%s\" value=\"%s\"/>\n",
+						name, camel_case_to_canonical (arg_name), value);
+				}
+			}
+		}
+	}
+
 	private string gi_type_name (TypeSymbol type_symbol) {
 		return vala_to_gi_type_name (type_symbol.get_full_name());
 	}
@@ -784,6 +831,10 @@ public class Vala.GIRWriter : CodeVisitor {
 			.replace ("\"", "&quot;");
 	}
 
+	private string camel_case_to_canonical (string name) {
+		return Symbol.camel_case_to_lower_case (name).replace ("_", "-");
+	}
+
 	private bool check_accessibility (Symbol sym) {
 		if (sym.access == SymbolAccessibility.PUBLIC ||
 		    sym.access == SymbolAccessibility.PROTECTED) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]