[gnome-builder/wip/slaf/xml-pack] xml-pack: add accessors to IdeXmlPosition



commit e85da38d03818cf7cc4fe4ea8df336ee57de7870
Author: Sebastien Lafargue <slafargue gnome org>
Date:   Wed May 17 11:16:29 2017 +0200

    xml-pack: add accessors to IdeXmlPosition
    
    We add siblings getters but IdeXmlAnnalysis too
    because for completion we need the root node
    and the schemas list.
    
    Be able to ref the analysis is also need to keep
    the nodes tree arround when matching the tree and
    the schema.

 plugins/xml-pack/ide-xml-position.c |   64 ++++++++++++++++++++++++++++++++++-
 plugins/xml-pack/ide-xml-position.h |   31 ++++++++++------
 2 files changed, 82 insertions(+), 13 deletions(-)
---
diff --git a/plugins/xml-pack/ide-xml-position.c b/plugins/xml-pack/ide-xml-position.c
index fd23266..32c2666 100644
--- a/plugins/xml-pack/ide-xml-position.c
+++ b/plugins/xml-pack/ide-xml-position.c
@@ -31,7 +31,7 @@ ide_xml_position_new (IdeXmlSymbolNode   *node,
   self = g_slice_new0 (IdeXmlPosition);
   self->ref_count = 1;
 
-  self->node = node;
+  self->node = g_object_ref (node);
   self->kind = kind;
 
   return self;
@@ -57,6 +57,13 @@ ide_xml_position_free (IdeXmlPosition *self)
   g_assert (self);
   g_assert_cmpint (self->ref_count, ==, 0);
 
+  if (self->analysis != NULL)
+    ide_xml_analysis_unref (self->analysis);
+
+  g_clear_object (&self->node);
+  g_clear_object (&self->previous_sibling_node);
+  g_clear_object (&self->next_sibling_node);
+
   g_slice_free (IdeXmlPosition, self);
 }
 
@@ -81,11 +88,50 @@ ide_xml_position_unref (IdeXmlPosition *self)
     ide_xml_position_free (self);
 }
 
+IdeXmlAnalysis *
+ide_xml_position_get_analysis (IdeXmlPosition *self)
+{
+  g_return_val_if_fail (self, NULL);
+
+  return self->analysis;
+}
+
+void
+ide_xml_position_set_analysis (IdeXmlPosition *self,
+                               IdeXmlAnalysis *analysis)
+{
+  g_return_if_fail (self);
+
+  self->analysis = ide_xml_analysis_ref (analysis);
+}
+
+IdeXmlSymbolNode *
+ide_xml_position_get_next_sibling (IdeXmlPosition *self)
+{
+  g_return_val_if_fail (self, NULL);
+
+  return self->next_sibling_node;
+}
+
+IdeXmlSymbolNode *
+ide_xml_position_get_previous_sibling (IdeXmlPosition *self)
+{
+  g_return_val_if_fail (self, NULL);
+
+  return self->previous_sibling_node;
+}
+
 void
 ide_xml_position_set_siblings    (IdeXmlPosition   *self,
                                   IdeXmlSymbolNode *previous_sibling_node,
                                   IdeXmlSymbolNode *next_sibling_node)
 {
+  if (previous_sibling_node != NULL)
+    g_object_ref (previous_sibling_node);
+
+  if (next_sibling_node != NULL)
+    g_object_ref (next_sibling_node);
+
   self->previous_sibling_node = previous_sibling_node;
   self->next_sibling_node = next_sibling_node;
 }
@@ -165,3 +211,19 @@ ide_xml_position_print (IdeXmlPosition *self)
         }
     }
 }
+
+IdeXmlSymbolNode *
+ide_xml_position_get_node (IdeXmlPosition *self)
+{
+  g_return_val_if_fail (self, NULL);
+
+  return self->node;
+}
+
+IdeXmlPositionKind
+ide_xml_position_get_kind (IdeXmlPosition *self)
+{
+  g_return_val_if_fail (self, IDE_XML_POSITION_KIND_UNKNOW);
+
+  return self->kind;
+}
diff --git a/plugins/xml-pack/ide-xml-position.h b/plugins/xml-pack/ide-xml-position.h
index e323985..22e7524 100644
--- a/plugins/xml-pack/ide-xml-position.h
+++ b/plugins/xml-pack/ide-xml-position.h
@@ -22,6 +22,7 @@
 #include <glib-object.h>
 
 #include "ide-xml-types.h"
+#include "ide-xml-analysis.h"
 #include "ide-xml-symbol-node.h"
 
 G_BEGIN_DECLS
@@ -32,7 +33,7 @@ typedef struct _IdeXmlPosition IdeXmlPosition;
 
 struct _IdeXmlPosition
 {
-  IdeXmlSymbolNode   *root_node;
+  IdeXmlAnalysis     *analysis;
   IdeXmlSymbolNode   *node;
   IdeXmlSymbolNode   *previous_sibling_node;
   IdeXmlSymbolNode   *next_sibling_node;
@@ -41,18 +42,24 @@ struct _IdeXmlPosition
   guint               ref_count;
 };
 
-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);
+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);
+IdeXmlAnalysis     *ide_xml_position_get_analysis         (IdeXmlPosition     *self);
+IdeXmlPositionKind  ide_xml_position_get_kind             (IdeXmlPosition     *self);
+IdeXmlSymbolNode   *ide_xml_position_get_next_sibling     (IdeXmlPosition     *self);
+IdeXmlSymbolNode   *ide_xml_position_get_node             (IdeXmlPosition     *self);
+IdeXmlSymbolNode   *ide_xml_position_get_previous_sibling (IdeXmlPosition     *self);
+void                ide_xml_position_set_analysis         (IdeXmlPosition     *self,
+                                                           IdeXmlAnalysis     *analysis);
+void                ide_xml_position_set_siblings         (IdeXmlPosition     *self,
+                                                           IdeXmlSymbolNode   *previous_sibling_node,
+                                                           IdeXmlSymbolNode   *next_sibling_node);
 
-void                ide_xml_position_set_siblings (IdeXmlPosition     *self,
-                                                   IdeXmlSymbolNode   *previous_sibling_node,
-                                                   IdeXmlSymbolNode   *next_sibling_node);
-
-void                ide_xml_position_print        (IdeXmlPosition     *self);
-const gchar        *ide_xml_position_kind_get_str (IdeXmlPositionKind  kind);
+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]