[vala] codewriter: Factorize writing type parameters in write_type_parameters



commit 790b2f4cac56ddf162088c63b331d1ea1dcca33a
Author: Luca Bruno <lucabru src gnome org>
Date:   Wed Aug 17 09:12:13 2011 +0200

    codewriter: Factorize writing type parameters in write_type_parameters

 vala/valacodewriter.vala |   76 ++++++++++++----------------------------------
 1 files changed, 20 insertions(+), 56 deletions(-)
---
diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala
index 922134f..3a849e0 100644
--- a/vala/valacodewriter.vala
+++ b/vala/valacodewriter.vala
@@ -201,20 +201,7 @@ public class Vala.CodeWriter : CodeVisitor {
 		write_string ("class ");
 		write_identifier (cl.name);
 
-		var type_params = cl.get_type_parameters ();
-		if (type_params.size > 0) {
-			write_string ("<");
-			bool first = true;
-			foreach (TypeParameter type_param in type_params) {
-				if (first) {
-					first = false;
-				} else {
-					write_string (",");
-				}
-				write_identifier (type_param.name);
-			}
-			write_string (">");
-		}
+		write_type_parameters (cl.get_type_parameters ());
 
 		var base_types = cl.get_base_types ();
 		if (base_types.size > 0) {
@@ -342,20 +329,7 @@ public class Vala.CodeWriter : CodeVisitor {
 		write_string ("interface ");
 		write_identifier (iface.name);
 
-		var type_params = iface.get_type_parameters ();
-		if (type_params.size > 0) {
-			write_string ("<");
-			bool first = true;
-			foreach (TypeParameter type_param in type_params) {
-				if (first) {
-					first = false;
-				} else {
-					write_string (",");
-				}
-				write_identifier (type_param.name);
-			}
-			write_string (">");
-		}
+		write_type_parameters (iface.get_type_parameters ());
 
 		var prerequisites = iface.get_prerequisites ();
 		if (prerequisites.size > 0) {
@@ -645,20 +619,7 @@ public class Vala.CodeWriter : CodeVisitor {
 		write_string (" ");
 		write_identifier (cb.name);
 
-		var type_params = cb.get_type_parameters ();
-		if (type_params.size > 0) {
-			write_string ("<");
-			bool first = true;
-			foreach (TypeParameter type_param in type_params) {
-				if (first) {
-					first = false;
-				} else {
-					write_string (",");
-				}
-				write_identifier (type_param.name);
-			}
-			write_string (">");
-		}
+		write_type_parameters (cb.get_type_parameters ());
 
 		write_string (" ");
 		
@@ -737,20 +698,7 @@ public class Vala.CodeWriter : CodeVisitor {
 
 			write_identifier (m.name);
 
-			var type_params = m.get_type_parameters ();
-			if (type_params.size > 0) {
-				write_string ("<");
-				bool first = true;
-				foreach (TypeParameter type_param in type_params) {
-					if (first) {
-						first = false;
-					} else {
-						write_string (",");
-					}
-					write_identifier (type_param.name);
-				}
-				write_string (">");
-			}
+			write_type_parameters (m.get_type_parameters ());
 
 			write_string (" ");
 		}
@@ -1629,6 +1577,22 @@ public class Vala.CodeWriter : CodeVisitor {
 			write_string (" private");
 		}
 	}
+
+	void write_type_parameters (List<TypeParameter> type_params) {
+		if (type_params.size > 0) {
+			write_string ("<");
+			bool first = true;
+			foreach (TypeParameter type_param in type_params) {
+				if (first) {
+					first = false;
+				} else {
+					write_string (",");
+				}
+				write_identifier (type_param.name);
+			}
+			write_string (">");
+		}
+	}
 }
 
 public enum Vala.CodeWriterType {



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