[vala/switch-to-gir: 24/34] girparser: Report unused metadata information



commit 73c38e1fd29eeec09df5381b36a049ad82b1e895
Author: Luca Bruno <lucabru src gnome org>
Date:   Sun Aug 29 15:11:02 2010 +0200

    girparser: Report unused metadata information

 vala/valagirparser.vala |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index e78f169..a8a6e07 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -591,6 +591,8 @@ public class Vala.GirParser : CodeVisitor {
 		next ();
 		parse_repository ();
 
+		report_unused_metadata (metadata);
+
 		reader = null;
 		this.current_source_file = null;
 	}
@@ -2317,6 +2319,34 @@ public class Vala.GirParser : CodeVisitor {
 		return c;
 	}
 
+	/* Reporting */
+	void report_unused_metadata (Metadata metadata) {
+		if (metadata == Metadata.empty) {
+			return;
+		}
+
+		if (metadata.args.size == 0 && metadata.children.size == 0) {
+			Report.warning (metadata.source_reference, "empty metadata");
+			return;
+		}
+
+		foreach (var arg_type in metadata.args.get_keys ()) {
+			var arg = metadata.args[arg_type];
+			if (!arg.used) {
+				// if metadata is used and argument is not, then it's a unexpected argument
+				Report.warning (arg.source_reference, "argument never used");
+			}
+		}
+
+		foreach (var child in metadata.children) {
+			if (!child.used) {
+				Report.warning (child.source_reference, "metadata never used");
+			} else {
+				report_unused_metadata (child);
+			}
+		}
+	}
+
 	/* Post-parsing */
 
 	void resolve_gir_symbols () {



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