[gnome-builder/wip/slaf/xml-pack: 237/254] xml-pack: rework the IdeXmlPosition
- From: Sébastien Lafargue <slafargue src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/slaf/xml-pack: 237/254] xml-pack: rework the IdeXmlPosition
- Date: Thu, 13 Jul 2017 09:09:07 +0000 (UTC)
commit cd74fcf080ea3b398ad204e5b93e5a70e23525fa
Author: Sebastien Lafargue <slafargue gnome org>
Date: Sat Jun 3 12:33:10 2017 +0200
xml-pack: rework the IdeXmlPosition
plugins/xml-pack/ide-xml-position.c | 76 ++++++++++++++++++++++++++++-------
plugins/xml-pack/ide-xml-position.h | 7 +++-
2 files changed, 67 insertions(+), 16 deletions(-)
---
diff --git a/plugins/xml-pack/ide-xml-position.c b/plugins/xml-pack/ide-xml-position.c
index 32c2666..ca421be 100644
--- a/plugins/xml-pack/ide-xml-position.c
+++ b/plugins/xml-pack/ide-xml-position.c
@@ -31,8 +31,9 @@ ide_xml_position_new (IdeXmlSymbolNode *node,
self = g_slice_new0 (IdeXmlPosition);
self->ref_count = 1;
- self->node = g_object_ref (node);
+ self->node = (IDE_IS_XML_SYMBOL_NODE (node)) ? g_object_ref (node) : NULL;
self->kind = kind;
+ self->child_pos = -1;
return self;
}
@@ -48,6 +49,17 @@ ide_xml_position_copy (IdeXmlPosition *self)
copy = ide_xml_position_new (self->node,
self->kind);
+ if (self->analysis != NULL)
+ copy->analysis = ide_xml_analysis_ref (self->analysis);
+
+ if (self->next_sibling_node != NULL)
+ copy->next_sibling_node = g_object_ref (self->next_sibling_node);
+
+ if (self->previous_sibling_node != NULL)
+ copy->previous_sibling_node = g_object_ref (self->previous_sibling_node);
+
+ copy->child_pos = self->child_pos;
+
return copy;
}
@@ -155,14 +167,6 @@ ide_xml_position_kind_get_str (IdeXmlPositionKind kind)
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;
@@ -180,23 +184,49 @@ ide_xml_position_print (IdeXmlPosition *self)
const gchar *p_sibling_str;
const gchar *n_sibling_str;
const gchar *kind_str;
+ IdeXmlSymbolNode *parent_node;
+ gint n_children;
p_sibling_str = (self->previous_sibling_node == NULL) ?
- "None" :
+ "none" :
ide_xml_symbol_node_get_element_name (self->previous_sibling_node);
n_sibling_str = (self->next_sibling_node == NULL) ?
- "None" :
+ "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,
+ parent_node = ide_xml_symbol_node_get_parent (self->node);
+ printf ("POSITION: parent: %s node: %s kind:%s",
+ (parent_node != NULL) ? ide_xml_symbol_node_get_element_name (parent_node) : "none",
+ (self->node != NULL) ? ide_xml_symbol_node_get_element_name (self->node) : "none",
kind_str);
+ if (self->child_pos != -1)
+ {
+ printf (" (between %s and %s)", p_sibling_str, n_sibling_str);
+ n_children = ide_xml_symbol_node_get_n_direct_children (self->node);
+ if (self->child_pos == 0)
+ {
+ if (n_children == 1)
+ printf (" pos: |0\n");
+ else
+ printf (" pos: |0..%d\n", n_children - 1);
+ }
+ else if (self->child_pos == (n_children + 1))
+ {
+ if (n_children == 1)
+ printf (" pos: 0|\n");
+ else
+ printf (" pos: 0..%d|\n", n_children - 1);
+ }
+ else
+ printf (" pos: %d|%d\n", self->child_pos - 1, self->child_pos);
+ }
+ else
+ printf ("\n");
+
if (self->node != NULL)
{
const gchar **attributes_names;
@@ -227,3 +257,19 @@ ide_xml_position_get_kind (IdeXmlPosition *self)
return self->kind;
}
+
+gint
+ide_xml_position_get_child_pos (IdeXmlPosition *self)
+{
+ g_return_val_if_fail (self, -1);
+
+ return self->child_pos;
+}
+
+void ide_xml_position_set_child_pos (IdeXmlPosition *self,
+ gint child_pos)
+{
+ g_return_if_fail (self);
+
+ self->child_pos = child_pos;
+}
diff --git a/plugins/xml-pack/ide-xml-position.h b/plugins/xml-pack/ide-xml-position.h
index 22e7524..a2320ca 100644
--- a/plugins/xml-pack/ide-xml-position.h
+++ b/plugins/xml-pack/ide-xml-position.h
@@ -38,22 +38,27 @@ struct _IdeXmlPosition
IdeXmlSymbolNode *previous_sibling_node;
IdeXmlSymbolNode *next_sibling_node;
IdeXmlPositionKind kind;
+ gint child_pos;
guint ref_count;
};
-IdeXmlPosition *ide_xml_position_new (IdeXmlSymbolNode *self,
+IdeXmlPosition *ide_xml_position_new (IdeXmlSymbolNode *node,
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);
+gint ide_xml_position_get_child_pos (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_parent_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_child_pos (IdeXmlPosition *self,
+ gint child_pos);
void ide_xml_position_set_siblings (IdeXmlPosition *self,
IdeXmlSymbolNode *previous_sibling_node,
IdeXmlSymbolNode *next_sibling_node);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]