[valadoc] drivers: fix namespace comment selection



commit 66586932bbd0d85f1868d0e382da843398c34665
Author: Florian Brosch <flo brosch gmail com>
Date:   Fri Aug 10 22:02:03 2012 +0200

    drivers: fix namespace comment selection

 src/driver/0.10.x/treebuilder.vala                 |   13 ++++++++++---
 src/driver/0.12.x/treebuilder.vala                 |    9 ++++++---
 src/driver/0.14.x/treebuilder.vala                 |    9 ++++++---
 src/driver/0.16.x/treebuilder.vala                 |    7 +++++--
 src/driver/0.18.x/treebuilder.vala                 |    9 ++++++---
 src/libvaladoc/api/sourcefile.vala                 |    8 +++++++-
 .../importer/girdocumentationimporter.vala         |    2 +-
 7 files changed, 41 insertions(+), 16 deletions(-)
---
diff --git a/src/driver/0.10.x/treebuilder.vala b/src/driver/0.10.x/treebuilder.vala
index 2b37981..163fe86 100644
--- a/src/driver/0.10.x/treebuilder.vala
+++ b/src/driver/0.10.x/treebuilder.vala
@@ -70,7 +70,11 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
 			this.package = package;
 		}
 
-		public Namespace get_namespace (Vala.Namespace vns, SourceFile? file) {
+		private bool is_source_file (Vala.SourceFile file) {
+			return (file.filename.has_suffix (".vala") || file.filename.has_suffix (".gs"));
+		}
+
+		public Namespace get_namespace (Vala.Namespace vns, SourceFile file) {
 			Namespace? ns = namespaces.get (vns);
 			if (ns != null) {
 				return ns;
@@ -80,7 +84,10 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
 			SourceComment? comment = null;
 			if (vns.source_reference != null) {
 				foreach (Vala.Comment c in vns.get_comments()) {
-					if (c.source_reference.file == vns.source_reference.file) {
+					if (c.source_reference.file == file.data ||
+						(is_source_file (c.source_reference.file)
+						 && is_source_file ((Vala.SourceFile) file.data))
+					) {
 						Vala.SourceReference pos = c.source_reference;
 						comment = new SourceComment (c.content, file, pos.first_line, pos.first_column, pos.last_line, pos.last_column);
 						break;
@@ -271,7 +278,7 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
 	}
 
 	private SourceFile register_source_file (PackageMetaData meta_data, Vala.SourceFile source_file) {
-		SourceFile file = new SourceFile (meta_data.package, source_file.get_relative_filename (), source_file.get_csource_filename ());
+		SourceFile file = new SourceFile (meta_data.package, source_file.get_relative_filename (), source_file.get_csource_filename (), source_file);
 		files.set (source_file, file);
 
 		meta_data.register_source_file (source_file);
diff --git a/src/driver/0.12.x/treebuilder.vala b/src/driver/0.12.x/treebuilder.vala
index f41b10c..95be543 100644
--- a/src/driver/0.12.x/treebuilder.vala
+++ b/src/driver/0.12.x/treebuilder.vala
@@ -70,7 +70,7 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
 			this.package = package;
 		}
 
-		public Namespace get_namespace (Vala.Namespace vns, SourceFile? file) {
+		public Namespace get_namespace (Vala.Namespace vns, SourceFile file) {
 			Namespace? ns = namespaces.get (vns);
 			if (ns != null) {
 				return ns;
@@ -80,7 +80,10 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
 			SourceComment? comment = null;
 			if (vns.source_reference != null) {
 				foreach (Vala.Comment c in vns.get_comments()) {
-					if (c.source_reference.file == vns.source_reference.file) {
+					if (c.source_reference.file == file.data ||
+						(c.source_reference.file.file_type == Vala.SourceFileType.SOURCE
+						 && ((Vala.SourceFile) file.data).file_type == Vala.SourceFileType.SOURCE)
+					) {
 						Vala.SourceReference pos = c.source_reference;
 						comment = new SourceComment (c.content, file, pos.first_line, pos.first_column, pos.last_line, pos.last_column);
 						break;
@@ -277,7 +280,7 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
 	}
 
 	private SourceFile register_source_file (PackageMetaData meta_data, Vala.SourceFile source_file) {
-		SourceFile file = new SourceFile (meta_data.package, source_file.get_relative_filename (), source_file.get_csource_filename ());
+		SourceFile file = new SourceFile (meta_data.package, source_file.get_relative_filename (), source_file.get_csource_filename (), source_file);
 		files.set (source_file, file);
 
 		meta_data.register_source_file (source_file);
diff --git a/src/driver/0.14.x/treebuilder.vala b/src/driver/0.14.x/treebuilder.vala
index 422b296..8f4ff5e 100644
--- a/src/driver/0.14.x/treebuilder.vala
+++ b/src/driver/0.14.x/treebuilder.vala
@@ -70,7 +70,7 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
 			this.package = package;
 		}
 
-		public Namespace get_namespace (Vala.Namespace vns, SourceFile? file) {
+		public Namespace get_namespace (Vala.Namespace vns, SourceFile file) {
 			Namespace? ns = namespaces.get (vns);
 			if (ns != null) {
 				return ns;
@@ -80,7 +80,10 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
 			SourceComment? comment = null;
 			if (vns.source_reference != null) {
 				foreach (Vala.Comment c in vns.get_comments()) {
-					if (c.source_reference.file == vns.source_reference.file) {
+					if (c.source_reference.file == file.data ||
+						(c.source_reference.file.file_type == Vala.SourceFileType.SOURCE
+						 && ((Vala.SourceFile) file.data).file_type == Vala.SourceFileType.SOURCE)
+					) {
 						Vala.SourceReference pos = c.source_reference;
 						comment = new SourceComment (c.content, file, pos.first_line, pos.first_column, pos.last_line, pos.last_column);
 						break;
@@ -403,7 +406,7 @@ message ("--%s--", symbol.name);
 	}
 
 	private SourceFile register_source_file (PackageMetaData meta_data, Vala.SourceFile source_file) {
-		SourceFile file = new SourceFile (meta_data.package, source_file.get_relative_filename (), source_file.get_csource_filename ());
+		SourceFile file = new SourceFile (meta_data.package, source_file.get_relative_filename (), source_file.get_csource_filename (), source_file);
 		files.set (source_file, file);
 
 		meta_data.register_source_file (source_file);
diff --git a/src/driver/0.16.x/treebuilder.vala b/src/driver/0.16.x/treebuilder.vala
index 30008c3..93a5510 100644
--- a/src/driver/0.16.x/treebuilder.vala
+++ b/src/driver/0.16.x/treebuilder.vala
@@ -80,7 +80,10 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
 			SourceComment? comment = null;
 			if (vns.source_reference != null) {
 				foreach (Vala.Comment c in vns.get_comments()) {
-					if (c.source_reference.file == vns.source_reference.file) {
+					if (c.source_reference.file == file.data ||
+						(c.source_reference.file.file_type == Vala.SourceFileType.SOURCE
+						 && ((Vala.SourceFile) file.data).file_type == Vala.SourceFileType.SOURCE)
+					) {
 						Vala.SourceReference pos = c.source_reference;
 #if ! VALA_0_15_0
 						if (c is Vala.GirComment) {
@@ -358,7 +361,7 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
 	}
 
 	private SourceFile register_source_file (PackageMetaData meta_data, Vala.SourceFile source_file) {
-		SourceFile file = new SourceFile (meta_data.package, source_file.get_relative_filename (), source_file.get_csource_filename ());
+		SourceFile file = new SourceFile (meta_data.package, source_file.get_relative_filename (), source_file.get_csource_filename (), source_file);
 		files.set (source_file, file);
 
 		meta_data.register_source_file (source_file);
diff --git a/src/driver/0.18.x/treebuilder.vala b/src/driver/0.18.x/treebuilder.vala
index 68e0f05..c8fd7e2 100644
--- a/src/driver/0.18.x/treebuilder.vala
+++ b/src/driver/0.18.x/treebuilder.vala
@@ -70,7 +70,7 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
 			this.package = package;
 		}
 
-		public Namespace get_namespace (Vala.Namespace vns, SourceFile? file) {
+		public Namespace get_namespace (Vala.Namespace vns, SourceFile file) {
 			Namespace? ns = namespaces.get (vns);
 			if (ns != null) {
 				return ns;
@@ -80,7 +80,10 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
 			SourceComment? comment = null;
 			if (vns.source_reference != null) {
 				foreach (Vala.Comment c in vns.get_comments()) {
-					if (c.source_reference.file == vns.source_reference.file) {
+					if (c.source_reference.file == file.data ||
+						(c.source_reference.file.file_type == Vala.SourceFileType.SOURCE
+						 && ((Vala.SourceFile) file.data).file_type == Vala.SourceFileType.SOURCE)
+					) {
 						Vala.SourceReference pos = c.source_reference;
 						if (c is Vala.GirComment) {
 #if VALA_0_17_0
@@ -371,7 +374,7 @@ public class Valadoc.Drivers.TreeBuilder : Vala.CodeVisitor {
 	}
 
 	private SourceFile register_source_file (PackageMetaData meta_data, Vala.SourceFile source_file) {
-		SourceFile file = new SourceFile (meta_data.package, source_file.get_relative_filename (), source_file.get_csource_filename ());
+		SourceFile file = new SourceFile (meta_data.package, source_file.get_relative_filename (), source_file.get_csource_filename (), source_file);
 		files.set (source_file, file);
 
 		meta_data.register_source_file (source_file);
diff --git a/src/libvaladoc/api/sourcefile.vala b/src/libvaladoc/api/sourcefile.vala
index 09b821f..8cb1d96 100644
--- a/src/libvaladoc/api/sourcefile.vala
+++ b/src/libvaladoc/api/sourcefile.vala
@@ -43,10 +43,16 @@ public class Valadoc.Api.SourceFile : Object {
 		return Path.get_basename (relative_path);
 	}
 
-	public SourceFile (Package package, string relative_path, string? relative_c_path) {
+	public void* data {
+		private set;
+		get;
+	}
+
+	public SourceFile (Package package, string relative_path, string? relative_c_path, void* data) {
 		this.relative_c_path = relative_c_path;
 		this.relative_path = relative_path;
 		this.package = package;
+		this.data = data;
 	}
 }
 
diff --git a/src/libvaladoc/importer/girdocumentationimporter.vala b/src/libvaladoc/importer/girdocumentationimporter.vala
index d097e26..6319475 100644
--- a/src/libvaladoc/importer/girdocumentationimporter.vala
+++ b/src/libvaladoc/importer/girdocumentationimporter.vala
@@ -61,7 +61,7 @@ public class Valadoc.Importer.GirDocumentationImporter : DocumentationImporter {
 	}
 
 	public override void process (string source_file) {
-		this.file = new Api.SourceFile (new Api.Package (Path.get_basename (source_file), true, null), source_file, null);
+		this.file = new Api.SourceFile (new Api.Package (Path.get_basename (source_file), true, null), source_file, null, null);
 		this.reader = new MarkupReader (source_file, reporter);
 
 		// xml prolog



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