[gnome-builder] diagnostics: add helpers to compare diagnostics



commit 46edf030a1679336b608bd75a3ef26a32a43138c
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jun 27 00:53:35 2016 -0700

    diagnostics: add helpers to compare diagnostics

 libide/diagnostics/ide-diagnostic.c      |   21 +++++++++++++++++++++
 libide/diagnostics/ide-diagnostic.h      |    2 ++
 libide/diagnostics/ide-source-location.c |   21 +++++++++++++++++++++
 libide/diagnostics/ide-source-location.h |   24 +++++++++++++-----------
 libide/files/ide-file.c                  |   16 ++++++++++++++++
 libide/files/ide-file.h                  |    2 ++
 6 files changed, 75 insertions(+), 11 deletions(-)
---
diff --git a/libide/diagnostics/ide-diagnostic.c b/libide/diagnostics/ide-diagnostic.c
index ee93332..8be7f71 100644
--- a/libide/diagnostics/ide-diagnostic.c
+++ b/libide/diagnostics/ide-diagnostic.c
@@ -322,3 +322,24 @@ ide_diagnostic_get_fixit (IdeDiagnostic *self,
 
   return g_ptr_array_index (self->fixits, index);
 }
+
+gint
+ide_diagnostic_compare (const IdeDiagnostic *a,
+                        const IdeDiagnostic *b)
+{
+  gint ret;
+
+  g_assert (a != NULL);
+  g_assert (b != NULL);
+
+  if (0 != (ret = (gint)a->severity - (gint)b->severity))
+    return ret;
+
+  if (a->location && b->location)
+    {
+      if (0 != (ret = ide_source_location_compare (a->location, b->location)))
+        return ret;
+    }
+
+  return g_strcmp0 (a->text, b->text);
+}
diff --git a/libide/diagnostics/ide-diagnostic.h b/libide/diagnostics/ide-diagnostic.h
index 7f5b5e7..54503ab 100644
--- a/libide/diagnostics/ide-diagnostic.h
+++ b/libide/diagnostics/ide-diagnostic.h
@@ -58,6 +58,8 @@ void                   ide_diagnostic_take_fixit           (IdeDiagnostic
                                                             IdeFixit              *fixit);
 void                   ide_diagnostic_take_range           (IdeDiagnostic         *self,
                                                             IdeSourceRange        *range);
+gint                   ide_diagnostic_compare              (const IdeDiagnostic   *a,
+                                                            const IdeDiagnostic   *b);
 
 const gchar           *ide_diagnostic_severity_to_string   (IdeDiagnosticSeverity severity);
 
diff --git a/libide/diagnostics/ide-source-location.c b/libide/diagnostics/ide-source-location.c
index 4a14699..2804b78 100644
--- a/libide/diagnostics/ide-source-location.c
+++ b/libide/diagnostics/ide-source-location.c
@@ -190,3 +190,24 @@ ide_source_location_get_uri (IdeSourceLocation *self)
 
   return ret;
 }
+
+gint
+ide_source_location_compare (const IdeSourceLocation *a,
+                             const IdeSourceLocation *b)
+{
+  gint ret;
+
+  g_assert (a != NULL);
+  g_assert (b != NULL);
+
+  if (a->file && b->file)
+    {
+      if (0 != (ret = ide_file_compare (a->file, b->file)))
+        return ret;
+    }
+
+  if (0 != (ret = (gint)a->line - (gint)b->line))
+    return ret;
+
+  return (gint)a->line_offset - (gint)b->line_offset;
+}
diff --git a/libide/diagnostics/ide-source-location.h b/libide/diagnostics/ide-source-location.h
index 3fae79d..ab56e18 100644
--- a/libide/diagnostics/ide-source-location.h
+++ b/libide/diagnostics/ide-source-location.h
@@ -28,17 +28,19 @@ G_BEGIN_DECLS
 #define IDE_TYPE_SOURCE_LOCATION (ide_source_location_get_type())
 
 GType              ide_source_location_get_type        (void);
-IdeSourceLocation *ide_source_location_ref             (IdeSourceLocation *self);
-void               ide_source_location_unref           (IdeSourceLocation *self);
-IdeSourceLocation *ide_source_location_new             (IdeFile           *file,
-                                                        guint              line,
-                                                        guint              line_offset,
-                                                        guint              offset);
-guint              ide_source_location_get_line        (IdeSourceLocation *self);
-guint              ide_source_location_get_line_offset (IdeSourceLocation *self);
-guint              ide_source_location_get_offset      (IdeSourceLocation *self);
-IdeFile           *ide_source_location_get_file        (IdeSourceLocation *self);
-IdeUri            *ide_source_location_get_uri         (IdeSourceLocation *self);
+IdeSourceLocation *ide_source_location_ref             (IdeSourceLocation       *self);
+void               ide_source_location_unref           (IdeSourceLocation       *self);
+IdeSourceLocation *ide_source_location_new             (IdeFile                 *file,
+                                                        guint                    line,
+                                                        guint                    line_offset,
+                                                        guint                    offset);
+guint              ide_source_location_get_line        (IdeSourceLocation       *self);
+guint              ide_source_location_get_line_offset (IdeSourceLocation       *self);
+guint              ide_source_location_get_offset      (IdeSourceLocation       *self);
+IdeFile           *ide_source_location_get_file        (IdeSourceLocation       *self);
+IdeUri            *ide_source_location_get_uri         (IdeSourceLocation       *self);
+gint               ide_source_location_compare         (const IdeSourceLocation *a,
+                                                        const IdeSourceLocation *b);
 
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (IdeSourceLocation, ide_source_location_unref)
 
diff --git a/libide/files/ide-file.c b/libide/files/ide-file.c
index 9d1da8b..febc522 100644
--- a/libide/files/ide-file.c
+++ b/libide/files/ide-file.c
@@ -689,3 +689,19 @@ ide_file_new_for_path (IdeContext  *context,
 
   return ret;
 }
+
+gint
+ide_file_compare (const IdeFile *a,
+                  const IdeFile *b)
+{
+  g_autofree gchar *filea = NULL;
+  g_autofree gchar *fileb = NULL;
+
+  g_assert (a != NULL);
+  g_assert (b != NULL);
+
+  filea = g_file_get_uri (a->file);
+  fileb = g_file_get_uri (b->file);
+
+  return g_strcmp0 (filea, fileb);
+}
diff --git a/libide/files/ide-file.h b/libide/files/ide-file.h
index 6b9ee62..0f6b1cb 100644
--- a/libide/files/ide-file.h
+++ b/libide/files/ide-file.h
@@ -55,6 +55,8 @@ void               ide_file_find_other_async     (IdeFile              *self,
 IdeFile           *ide_file_find_other_finish    (IdeFile              *self,
                                                   GAsyncResult         *result,
                                                   GError              **error);
+gint               ide_file_compare              (const IdeFile        *a,
+                                                  const IdeFile        *b);
 
 
 G_END_DECLS


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