[gnome-builder/wip/slaf/xml-pack: 215/254] xml-pack: add debug functions to IdeXmlPosition



commit f555419aa4d22706aa918d89c10d07b41f029c74
Author: Sebastien Lafargue <slafargue gnome org>
Date:   Sun May 14 22:41:10 2017 +0200

    xml-pack: add debug functions to IdeXmlPosition

 plugins/xml-pack/ide-xml-position.c |   75 +++++++++++++++++++++++++++++++++++
 plugins/xml-pack/ide-xml-position.h |   12 ++++--
 2 files changed, 83 insertions(+), 4 deletions(-)
---
diff --git a/plugins/xml-pack/ide-xml-position.c b/plugins/xml-pack/ide-xml-position.c
index 55d1fe9..819f206 100644
--- a/plugins/xml-pack/ide-xml-position.c
+++ b/plugins/xml-pack/ide-xml-position.c
@@ -73,3 +73,78 @@ ide_xml_position_unref (IdeXmlPosition *self)
   if (g_atomic_int_dec_and_test (&self->ref_count))
     ide_xml_position_free (self);
 }
+const gchar *
+ide_xml_position_kind_get_str (IdeXmlPositionKind kind)
+{
+  const gchar *kind_str;
+
+  switch (kind)
+    {
+    case IDE_XML_POSITION_KIND_UNKNOW:
+      kind_str = "unknow";
+      break;
+
+    case IDE_XML_POSITION_KIND_IN_START_TAG:
+      kind_str = "in start";
+      break;
+
+    case IDE_XML_POSITION_KIND_IN_END_TAG:
+      kind_str = "in end";
+      break;
+
+    case IDE_XML_POSITION_KIND_BEFORE:
+      kind_str = "before";
+      break;
+
+    case IDE_XML_POSITION_KIND_AFTER:
+      kind_str = "after";
+      break;
+
+    case IDE_XML_POSITION_KIND_IN_CONTENT:
+      kind_str = "in content";
+      break;
+
+    default:
+      g_assert_not_reached ();
+    }
+
+  return kind_str;
+}
+
+void
+ide_xml_position_print (IdeXmlPosition *self)
+{
+  const gchar *p_sibling_str;
+  const gchar *n_sibling_str;
+  const gchar *kind_str;
+
+  p_sibling_str = (self->previous_sibling_node == NULL) ?
+    "None" :
+    ide_xml_symbol_node_get_element_name (self->previous_sibling_node);
+
+  n_sibling_str = (self->next_sibling_node == NULL) ?
+    "None" :
+    ide_xml_symbol_node_get_element_name (self->next_sibling_node);
+
+  kind_str = ide_xml_position_kind_get_str (self->kind);
+
+  printf ("node: %s (between %s and %s) kind:%s\n",
+          ide_xml_symbol_node_get_element_name (self->node),
+          p_sibling_str,
+          n_sibling_str,
+          kind_str);
+
+  if (self->node != NULL)
+    {
+      const gchar **attributes_names;
+
+      if (NULL != (attributes_names = ide_xml_symbol_node_get_attributes_names (self->node)))
+        {
+          while (attributes_names [0] != NULL)
+            {
+              printf ("attr:%s\n", *attributes_names);
+              ++attributes_names;
+            }
+        }
+    }
+}
diff --git a/plugins/xml-pack/ide-xml-position.h b/plugins/xml-pack/ide-xml-position.h
index d021d9e..8b6eda3 100644
--- a/plugins/xml-pack/ide-xml-position.h
+++ b/plugins/xml-pack/ide-xml-position.h
@@ -40,10 +40,14 @@ struct _IdeXmlPosition
   guint               ref_count;
 };
 
-IdeXmlPosition     *ide_xml_position_new   (void);
-IdeXmlPosition     *ide_xml_position_copy  (IdeXmlPosition *self);
-IdeXmlPosition     *ide_xml_position_ref   (IdeXmlPosition *self);
-void                ide_xml_position_unref (IdeXmlPosition *self);
+IdeXmlPosition     *ide_xml_position_new          (IdeXmlSymbolNode   *self,
+                                                   IdeXmlPositionKind  kind);
+IdeXmlPosition     *ide_xml_position_copy         (IdeXmlPosition     *self);
+IdeXmlPosition     *ide_xml_position_ref          (IdeXmlPosition     *self);
+void                ide_xml_position_unref        (IdeXmlPosition     *self);
+
+void                ide_xml_position_print        (IdeXmlPosition     *self);
+const gchar        *ide_xml_position_kind_get_str (IdeXmlPositionKind  kind);
 
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (IdeXmlPosition, ide_xml_position_unref)
 


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