[gxml/gxml-0.10: 1/3] Micro API Changes to fix valadoc generation
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gxml/gxml-0.10: 1/3] Micro API Changes to fix valadoc generation
- Date: Mon, 1 Aug 2016 19:45:19 +0000 (UTC)
commit 5b6477f94cd50701bc0ad0a56150e2ae4f6b5f57
Author: Daniel Espinosa <esodan gmail com>
Date: Mon Jun 6 13:12:15 2016 -0500
Micro API Changes to fix valadoc generation
* While generating valadoc.org documentation, errors where reported.
In order to fix them, some changes were introduced, like API changes
* GXml.last_error is a legacy field maked public for some reason,
in 0.10.1 this is replaced by GXml.get_last_error() and GXml.set_last_error()
in order to avoid fields in namespaces.
gxml/TDocument.vala | 96 +++++++++++++++++++++--------------------
gxml/libxml-DomException.vala | 5 ++-
test/GXmlTest.vala | 8 ++--
3 files changed, 57 insertions(+), 52 deletions(-)
---
diff --git a/gxml/TDocument.vala b/gxml/TDocument.vala
index 4ea255d..5bdca0a 100644
--- a/gxml/TDocument.vala
+++ b/gxml/TDocument.vala
@@ -23,6 +23,25 @@ using Gee;
using Xml;
/**
+ * Delegate function to control parsing of XML documents. Return {@link TDocumentReadType.NEXT}
+ * to skip all children nodes of current {@link GXml.Node}; {@link TDocumentReadType.CONTINUE}
+ * continue parsing nodes or {@link TDocumentReadType.STOP} to stop reading.
+ *
+ * While you get the current {@link Xml.TextReader} used in parsing, you can control
+ * next action to take depending on current node.
+ */
+public delegate GXml.TDocumentReadType GXml.TDocumentReadTypeFunc (GXml.Node node, TextReader tr);
+
+
+ /**
+ * Enum for {@link Xml.TextReader} flag on parsing.
+ */
+ public enum GXml.TDocumentReadType {
+ NEXT,
+ CONTINUE,
+ STOP
+ }
+/**
* Class implemeting {@link GXml.Document} interface, not tied to libxml-2.0 library.
*
* This class use {@link Xml.TextWriter} to write down XML documents using
@@ -33,7 +52,7 @@ public class GXml.TDocument : GXml.TNode, GXml.Document
protected Gee.ArrayList<GXml.Node> _namespaces;
protected Gee.ArrayList<GXml.Node> _children;
private GXml.Element _root = null;
- private ReadTypeFunc _readtype_func = null;
+ private TDocumentReadTypeFunc _readtype_func = null;
construct {
_name = "#document";
@@ -68,28 +87,28 @@ public class GXml.TDocument : GXml.TNode, GXml.Document
}
- public TDocument.from_path_with_readtype_func (string path, ReadTypeFunc func) {
+ public TDocument.from_path_with_readtype_func (string path, TDocumentReadTypeFunc func) {
this.file = GLib.File.new_for_path (path);
if (!file.query_exists ()) return;
try { read_doc (this, file, func); } catch {}
}
- public TDocument.from_uri_with_readtype_func (string uri, ReadTypeFunc func) {
+ public TDocument.from_uri_with_readtype_func (string uri, TDocumentReadTypeFunc func) {
this.from_file_with_readtype_func (File.new_for_uri (uri), func);
}
- public TDocument.from_file_with_readtype_func (GLib.File file, ReadTypeFunc func) {
+ public TDocument.from_file_with_readtype_func (GLib.File file, TDocumentReadTypeFunc func) {
if (!file.query_exists ()) return;
try { read_doc (this, file, func); } catch {}
this.file = file;
}
- public TDocument.from_stream_with_readtype_func (GLib.InputStream stream, ReadTypeFunc func) {
+ public TDocument.from_stream_with_readtype_func (GLib.InputStream stream, TDocumentReadTypeFunc func) {
try { read_doc_stream (this, stream, func); } catch {}
}
- public TDocument.from_string_with_readtype_func (string str, ReadTypeFunc func) {
+ public TDocument.from_string_with_readtype_func (string str, TDocumentReadTypeFunc func) {
var minput = new GLib.MemoryInputStream ();
minput.add_data ((uint8[]) str.dup (), null);
TDocument.from_stream_with_readtype_func (minput, func);
@@ -450,27 +469,10 @@ public class GXml.TDocument : GXml.TNode, GXml.Document
return str;
}
/**
- * Enum for {@link Xml.TextReader} flag on parsing.
- */
- public enum ReadType {
- NEXT,
- CONTINUE,
- STOP
- }
- /**
- * Delegate function to control parsing of XML documents. Return {@link ReadType.NEXT}
- * to skip all children nodes of current {@link GXml.Node}; {@link ReadType.CONTINUE}
- * continue parsing nodes or {@link ReadType.STOP} to stop reading.
- *
- * While you get the current {@link Xml.TextReader} used in parsing, you can control
- * next action to take depending on current node.
- */
- public delegate ReadType ReadTypeFunc (GXml.Node node, TextReader tr);
- /**
* Read a {@link GXml.Document} from a {@link GLib.File}, parsing is controller
- * using {@link ReadTypeFunc}, if null it parse all nodes.
+ * using {@link TDocumentReadTypeFunc}, if null it parse all nodes.
*/
- public static void read_doc (GXml.Document doc, GLib.File file, ReadTypeFunc? rtfunc = null) throws
GLib.Error {
+ public static void read_doc (GXml.Document doc, GLib.File file, TDocumentReadTypeFunc? rtfunc = null)
throws GLib.Error {
if (!file.query_exists ())
throw new GXml.DocumentError.INVALID_FILE (_("File doesn't exist"));
read_doc_stream (doc, file.read (), rtfunc);
@@ -478,7 +480,7 @@ public class GXml.TDocument : GXml.TNode, GXml.Document
/**
* Reads document from {@link GLib.InputStream} objects.
*/
- public static void read_doc_stream (GXml.Document doc, GLib.InputStream istream, ReadTypeFunc? rtfunc =
null) {
+ public static void read_doc_stream (GXml.Document doc, GLib.InputStream istream, TDocumentReadTypeFunc?
rtfunc = null) {
var b = new MemoryOutputStream.resizable ();
b.splice (istream, 0);
#if DEBUG
@@ -486,24 +488,24 @@ public class GXml.TDocument : GXml.TNode, GXml.Document
#endif
var tr = new TextReader.for_memory ((char[]) b.data, (int) b.get_data_size (), "/gxml_memory");
GXml.Node current = null;
- while (read_node (doc, tr, rtfunc) == ReadType.CONTINUE);
+ while (read_node (doc, tr, rtfunc) == TDocumentReadType.CONTINUE);
}
/**
* Parse current node in {@link Xml.TextReader}.
*
* Returns: a {@link GXml.Node} respresenting current parsed one.
*/
- public static ReadType read_node (GXml.Node node,
+ public static TDocumentReadType read_node (GXml.Node node,
Xml.TextReader tr,
- ReadTypeFunc? rntfunc = null) throws GLib.Error {
+ TDocumentReadTypeFunc? rntfunc = null) throws GLib.Error {
GXml.Node n = null;
string prefix, nsuri;
- ReadType rt = ReadType.CONTINUE;
+ TDocumentReadType rt = TDocumentReadType.CONTINUE;
if (rntfunc != null) rt = rntfunc (node, tr);
- if (rt == ReadType.CONTINUE)
- if (tr.read () != 1) return ReadType.STOP;
- if (rt == ReadType.NEXT)
- if (tr.next () != 1) return ReadType.STOP;
+ if (rt == TDocumentReadType.CONTINUE)
+ if (tr.read () != 1) return TDocumentReadType.STOP;
+ if (rt == TDocumentReadType.NEXT)
+ if (tr.next () != 1) return TDocumentReadType.STOP;
var t = tr.node_type ();
#if DEBUG
GLib.message ("ReadNode: Current Node:"+node.name);
@@ -513,7 +515,7 @@ public class GXml.TDocument : GXml.TNode, GXml.Document
#if DEBUG
GLib.message ("Type NONE");
#endif
- if (tr.read () != 1) return ReadType.STOP;
+ if (tr.read () != 1) return TDocumentReadType.STOP;
break;
case Xml.ReaderType.ELEMENT:
bool isempty = (tr.is_empty_element () == 1);
@@ -522,15 +524,15 @@ public class GXml.TDocument : GXml.TNode, GXml.Document
GLib.message ("ReadNode: Element: "+tr.const_local_name ());
#endif
n = node.document.create_element (tr.const_local_name ());
- ReadType nrt = ReadType.CONTINUE;
+ TDocumentReadType nrt = TDocumentReadType.CONTINUE;
if (rntfunc != null) nrt = rntfunc (n, tr);
- if (nrt == ReadType.NEXT) {
+ if (nrt == TDocumentReadType.NEXT) {
if (isempty) {
- return ReadType.CONTINUE;
+ return TDocumentReadType.CONTINUE;
}
var cont = true;
while (cont) {
- if (tr.read () != 1) return ReadType.STOP;
+ if (tr.read () != 1) return TDocumentReadType.STOP;
t = tr.node_type ();
if (t == Xml.ReaderType.END_ELEMENT) {
if (tr.const_local_name () == n.name) {
@@ -538,11 +540,11 @@ public class GXml.TDocument : GXml.TNode, GXml.Document
}
}
}
- return ReadType.CONTINUE;
+ return TDocumentReadType.CONTINUE;
}
- if (nrt == ReadType.STOP) {
+ if (nrt == TDocumentReadType.STOP) {
tr.close ();
- return ReadType.STOP;
+ return TDocumentReadType.STOP;
}
node.children.add (n);
#if DEBUG
@@ -607,8 +609,8 @@ public class GXml.TDocument : GXml.TNode, GXml.Document
}
}
}
- if (isempty) return ReadType.CONTINUE;
- while (read_node (n, tr, rntfunc) == ReadType.CONTINUE);
+ if (isempty) return TDocumentReadType.CONTINUE;
+ while (read_node (n, tr, rntfunc) == TDocumentReadType.CONTINUE);
#if DEBUG
GLib.message ("Current Document: "+node.document.to_string ());
#endif
@@ -699,18 +701,18 @@ public class GXml.TDocument : GXml.TNode, GXml.Document
#if DEBUG
GLib.message ("Type END_ELEMENT");
#endif
- return ReadType.STOP;
+ return TDocumentReadType.STOP;
case Xml.ReaderType.END_ENTITY:
#if DEBUG
GLib.message ("Type END_ENTITY");
#endif
- return ReadType.STOP;
+ return TDocumentReadType.STOP;
case Xml.ReaderType.XML_DECLARATION:
#if DEBUG
GLib.message ("Type XML_DECLARATION");
#endif
break;
}
- return ReadType.CONTINUE;
+ return TDocumentReadType.CONTINUE;
}
}
diff --git a/gxml/libxml-DomException.vala b/gxml/libxml-DomException.vala
index 3ac99bc..883f8a6 100644
--- a/gxml/libxml-DomException.vala
+++ b/gxml/libxml-DomException.vala
@@ -26,7 +26,10 @@ namespace GXml {
/**
* Last error exception for DOM.
*/
- public static DomException last_error = DomException.NONE;
+ private static DomException last_error = DomException.NONE;
+
+ public static DomException dom_get_last_error () { return last_error; }
+ public static void dom_set_last_error (DomException exc) { last_error = exc; }
/**
* Log DOM exception warnings.
diff --git a/test/GXmlTest.vala b/test/GXmlTest.vala
index b2a7646..2d75f70 100644
--- a/test/GXmlTest.vala
+++ b/test/GXmlTest.vala
@@ -29,14 +29,14 @@ class GXmlTest {
}
internal static void test_error (GXml.DomException expected) {
- if (expected != GXml.last_error) {
- stderr.printf ("Expected last error [%s] but found [%s]", expected.to_string (),
GXml.last_error.to_string ());
- Test.message ("Expected last error [%s] but found [%s]", expected.to_string (),
GXml.last_error.to_string ());
+ if (expected != GXml.dom_get_last_error ()) {
+ stderr.printf ("Expected last error [%s] but found [%s]", expected.to_string (),
GXml.dom_get_last_error ().to_string ());
+ Test.message ("Expected last error [%s] but found [%s]", expected.to_string (),
GXml.dom_get_last_error ().to_string ());
Test.fail ();
}
// clear it
- GXml.last_error = DomException.NONE;
+ GXml.dom_set_last_error (DomException.NONE);
}
public static int main (string[] args) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]