Updated Spanish translation
[anjuta.git] / plugins / language-support-js / import-symbol.c
blob1b33c7a60fbfb411ca37ec7d1fc3120ac7b651a0
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 Copyright (C) 2009 Maxim Ermilov <zaspire@rambler.ru>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "ijs-symbol.h"
21 #include "import-symbol.h"
22 #include "util.h"
23 #include "gi-symbol.h"
24 #include "dir-symbol.h"
26 static void import_symbol_interface_init (IJsSymbolIface *iface);
27 static GList* import_symbol_get_arg_list (IJsSymbol *obj);
28 static gint import_symbol_get_base_type (IJsSymbol *obj);
29 static GList* import_symbol_get_func_ret_type (IJsSymbol *obj);
30 static IJsSymbol* import_symbol_get_member (IJsSymbol *obj, const gchar * name);
31 static const gchar * import_symbol_get_name (IJsSymbol *obj);
32 static GList* import_symbol_list_member (IJsSymbol *obj);
34 typedef struct _ImportSymbolPrivate ImportSymbolPrivate;
35 struct _ImportSymbolPrivate
37 GList *member;
38 GList *dirs;
41 #define IMPORT_SYMBOL_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), IMPORT_TYPE_SYMBOL, ImportSymbolPrivate))
43 G_DEFINE_TYPE_WITH_CODE (ImportSymbol, import_symbol, G_TYPE_OBJECT,
44 G_IMPLEMENT_INTERFACE (IJS_TYPE_SYMBOL,
45 import_symbol_interface_init));
47 static void
48 import_symbol_init (ImportSymbol *object)
50 ImportSymbolPrivate *priv = IMPORT_SYMBOL_PRIVATE(object);
51 priv->member = NULL;
52 priv->dirs = NULL;
55 static void
56 import_symbol_finalize (GObject *object)
58 ImportSymbolPrivate *priv = IMPORT_SYMBOL_PRIVATE(object);
60 g_list_foreach (priv->member, (GFunc)g_object_unref, NULL);
61 g_list_foreach (priv->dirs, (GFunc)g_object_unref, NULL);
62 g_list_free (priv->member);
63 g_list_free (priv->dirs);
64 G_OBJECT_CLASS (import_symbol_parent_class)->finalize (object);
67 static void
68 import_symbol_class_init (ImportSymbolClass *klass)
70 GObjectClass* object_class = G_OBJECT_CLASS (klass);
71 /*GObjectClass* parent_class = G_OBJECT_CLASS (klass);*/
73 g_type_class_add_private (klass, sizeof (ImportSymbolPrivate));
75 object_class->finalize = import_symbol_finalize;
79 ImportSymbol*
80 import_symbol_new ()
82 ImportSymbol* ret = IMPORT_SYMBOL (g_object_new (IMPORT_TYPE_SYMBOL, NULL));
83 ImportSymbolPrivate *priv = IMPORT_SYMBOL_PRIVATE(ret);
85 priv->member = g_list_append (NULL, gi_symbol_new ());
86 priv->dirs = NULL;
88 return ret;
91 static void
92 import_symbol_interface_init (IJsSymbolIface *iface)
94 iface->get_arg_list = import_symbol_get_arg_list;
95 iface->get_base_type = import_symbol_get_base_type;
96 iface->get_func_ret_type = import_symbol_get_func_ret_type;
98 iface->get_member = import_symbol_get_member;
99 iface->get_name = import_symbol_get_name;
100 iface->list_member = import_symbol_list_member;
103 static void
104 post_init (ImportSymbol *symbol)
106 ImportSymbolPrivate *priv = IMPORT_SYMBOL_PRIVATE (symbol);
107 GList *paths = get_import_include_paths ();
109 GList *i;
110 for (i = priv->dirs; i; )
112 GList *k;
113 gchar *path = dir_symbol_get_path (DIR_SYMBOL (i->data));
114 gboolean has_path = FALSE;
115 g_assert (path != NULL);
116 for (k = paths; k; k = g_list_next (k))
118 if (g_strcmp0 (path, (gchar*)k->data) != 0)
119 continue;
120 has_path = TRUE;
121 paths = g_list_delete_link (paths, k);
122 break;
124 if (!has_path)
126 k = g_list_next (i);
127 g_object_unref (i->data);
128 priv->dirs = g_list_remove_link (priv->dirs, i);
129 i = k;
131 else
132 i = g_list_next (i);
133 g_free (path);
135 for (i = paths; i; i = g_list_next (i))
137 gchar *path = (gchar*)i->data;
138 g_assert (path != NULL);
139 DirSymbol *sym = dir_symbol_new (path);
140 if (sym)
141 priv->dirs = g_list_append (priv->dirs, sym);
143 g_list_foreach (paths, (GFunc)g_free, NULL);
144 g_list_free (paths);
147 static GList*
148 import_symbol_get_arg_list (IJsSymbol *obj)
150 g_assert_not_reached ();
151 return NULL;
154 static gint
155 import_symbol_get_base_type (IJsSymbol *obj)
157 return BASE_CLASS;
160 static GList*
161 import_symbol_get_func_ret_type (IJsSymbol *obj)
163 g_assert_not_reached ();
164 return NULL;
167 static IJsSymbol*
168 import_symbol_get_member (IJsSymbol *obj, const gchar * name)
170 ImportSymbol* self = IMPORT_SYMBOL (obj);
171 ImportSymbolPrivate *priv = IMPORT_SYMBOL_PRIVATE(self);
173 GList *i;
175 post_init (self);
177 for (i = priv->member; i; i = g_list_next (i))
179 IJsSymbol *t = IJS_SYMBOL (i->data);
180 if (g_strcmp0 (name, ijs_symbol_get_name (t)) == 0 )
182 g_object_ref (t);
183 return t;
186 for (i = priv->dirs; i; i = g_list_next (i))
188 IJsSymbol *t = IJS_SYMBOL (i->data);
189 IJsSymbol* ret = ijs_symbol_get_member (t, name);
190 if (!ret)
191 continue;
192 g_object_ref (ret);
193 return ret;
195 return NULL;
198 static const gchar *
199 import_symbol_get_name (IJsSymbol *obj)
201 return "imports";
204 static GList*
205 import_symbol_list_member (IJsSymbol *obj)
207 ImportSymbol* self = IMPORT_SYMBOL (obj);
208 ImportSymbolPrivate *priv = IMPORT_SYMBOL_PRIVATE(self);
210 GList *i;
211 GList *ret = NULL;
213 post_init (self);
215 for (i = priv->member; i; i = g_list_next (i))
217 IJsSymbol *t = IJS_SYMBOL (i->data);
218 ret = g_list_append (ret, g_strdup (ijs_symbol_get_name (t)));
220 for (i = priv->dirs; i; i = g_list_next (i))
222 IJsSymbol *t = IJS_SYMBOL (i->data);
223 ret = g_list_concat (ret, ijs_symbol_list_member (t));
225 return ret;