/* ide-vala-indenter.c generated by valac 0.30.0, the Vala compiler
 * generated from ide-vala-indenter.vala, do not modify */

/* ide-vala-indenter.vala
 *
 * Copyright (C) 2015 Christian Hergert <christian@hergert.me>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <glib.h>
#include <glib-object.h>
#include <ide.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
#include <gtksourceview/gtksource.h>


#define IDE_TYPE_VALA_INDENTER (ide_vala_indenter_get_type ())
#define IDE_VALA_INDENTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDE_TYPE_VALA_INDENTER, IdeValaIndenter))
#define IDE_VALA_INDENTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IDE_TYPE_VALA_INDENTER, IdeValaIndenterClass))
#define IDE_IS_VALA_INDENTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDE_TYPE_VALA_INDENTER))
#define IDE_IS_VALA_INDENTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IDE_TYPE_VALA_INDENTER))
#define IDE_VALA_INDENTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IDE_TYPE_VALA_INDENTER, IdeValaIndenterClass))

typedef struct _IdeValaIndenter IdeValaIndenter;
typedef struct _IdeValaIndenterClass IdeValaIndenterClass;
typedef struct _IdeValaIndenterPrivate IdeValaIndenterPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))

struct _IdeValaIndenter {
	IdeObject parent_instance;
	IdeValaIndenterPrivate * priv;
};

struct _IdeValaIndenterClass {
	IdeObjectClass parent_class;
};


static gpointer ide_vala_indenter_parent_class = NULL;
static IdeIndenterInterface* ide_vala_indenter_ide_indenter_parent_iface = NULL;
static GType ide_vala_indenter_type_id = 0;

GType ide_vala_indenter_get_type (void) G_GNUC_CONST;
GType ide_vala_indenter_register_type (GTypeModule * module);
enum  {
	IDE_VALA_INDENTER_DUMMY_PROPERTY
};
static gboolean ide_vala_indenter_real_is_trigger (IdeIndenter* base, GdkEventKey* evkey);
static gchar* ide_vala_indenter_real_format (IdeIndenter* base, GtkTextView* text_view, GtkTextIter* begin, GtkTextIter* end, gint* cursor_offset, GdkEventKey* evkey);
static gboolean ide_vala_indenter_is_newline_keyval (IdeValaIndenter* self, guint keyval);
static gboolean ide_vala_indenter_in_comment (IdeValaIndenter* self, GtkTextView* text_view, GtkTextIter* iter);
static gchar* ide_vala_indenter_indent_comment (IdeValaIndenter* self, GtkTextView* text_view, GtkTextIter* iter);
static gboolean ide_vala_indenter_is_newline_in_braces (IdeValaIndenter* self, GtkTextIter* iter);
static gchar* ide_vala_indenter_copy_indent (IdeValaIndenter* self, GtkTextView* text_view, GtkTextIter* iter);
static gchar* ide_vala_indenter_get_line_text (IdeValaIndenter* self, GtkTextIter* iter);
IdeValaIndenter* ide_vala_indenter_new (void);
IdeValaIndenter* ide_vala_indenter_construct (GType object_type);


static gboolean ide_vala_indenter_real_is_trigger (IdeIndenter* base, GdkEventKey* evkey) {
	IdeValaIndenter * self;
	gboolean result = FALSE;
	GdkEventKey* _tmp0_ = NULL;
	guint _tmp1_ = 0U;
	self = (IdeValaIndenter*) base;
	g_return_val_if_fail (evkey != NULL, FALSE);
	_tmp0_ = evkey;
	_tmp1_ = _tmp0_->keyval;
	switch (_tmp1_) {
		case GDK_KEY_Return:
		case GDK_KEY_KP_Enter:
		{
			result = TRUE;
			return result;
		}
		case GDK_KEY_slash:
		{
			result = TRUE;
			return result;
		}
		default:
		{
			result = FALSE;
			return result;
		}
	}
}


static gpointer _g_object_ref0 (gpointer self) {
	return self ? g_object_ref (self) : NULL;
}


static gchar* ide_vala_indenter_real_format (IdeIndenter* base, GtkTextView* text_view, GtkTextIter* begin, GtkTextIter* end, gint* cursor_offset, GdkEventKey* evkey) {
	IdeValaIndenter * self;
	gint _vala_cursor_offset = 0;
	gchar* result = NULL;
	GtkSourceView* source_view = NULL;
	GtkTextView* _tmp0_ = NULL;
	GtkSourceView* _tmp1_ = NULL;
	gboolean was_newline = FALSE;
	GdkEventKey* _tmp2_ = NULL;
	guint _tmp3_ = 0U;
	gboolean _tmp4_ = FALSE;
	GtkTextIter copy = {0};
	GtkTextIter _tmp5_ = {0};
	GtkTextView* _tmp6_ = NULL;
	GtkTextIter _tmp7_ = {0};
	gboolean _tmp8_ = FALSE;
	GtkTextIter _tmp23_ = {0};
	gboolean _tmp24_ = FALSE;
	gboolean _tmp45_ = FALSE;
	self = (IdeValaIndenter*) base;
	g_return_val_if_fail (text_view != NULL, NULL);
	g_return_val_if_fail (begin != NULL, NULL);
	g_return_val_if_fail (end != NULL, NULL);
	g_return_val_if_fail (evkey != NULL, NULL);
	_tmp0_ = text_view;
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp0_, gtk_source_view_get_type ()) ? ((GtkSourceView*) _tmp0_) : NULL);
	source_view = _tmp1_;
	_tmp2_ = evkey;
	_tmp3_ = _tmp2_->keyval;
	_tmp4_ = ide_vala_indenter_is_newline_keyval (self, _tmp3_);
	was_newline = _tmp4_;
	_tmp5_ = *end;
	copy = _tmp5_;
	_vala_cursor_offset = 0;
	gtk_text_iter_backward_char (&copy);
	_tmp6_ = text_view;
	_tmp7_ = copy;
	_tmp8_ = ide_vala_indenter_in_comment (self, _tmp6_, &_tmp7_);
	if (_tmp8_) {
		gunichar _tmp9_ = 0U;
		gboolean _tmp19_ = FALSE;
		_tmp9_ = gtk_text_iter_get_char (&copy);
		if (_tmp9_ == ((gunichar) '/')) {
			GtkTextIter close = {0};
			GtkTextIter _tmp10_ = {0};
			gboolean _tmp11_ = FALSE;
			gboolean _tmp12_ = FALSE;
			gboolean _tmp13_ = FALSE;
			gboolean _tmp14_ = FALSE;
			_tmp10_ = copy;
			close = _tmp10_;
			_tmp14_ = gtk_text_iter_backward_char (&close);
			if (_tmp14_) {
				gunichar _tmp15_ = 0U;
				_tmp15_ = gtk_text_iter_get_char (&close);
				_tmp13_ = _tmp15_ == ((gunichar) ' ');
			} else {
				_tmp13_ = FALSE;
			}
			if (_tmp13_) {
				gboolean _tmp16_ = FALSE;
				_tmp16_ = gtk_text_iter_backward_char (&close);
				_tmp12_ = _tmp16_;
			} else {
				_tmp12_ = FALSE;
			}
			if (_tmp12_) {
				gunichar _tmp17_ = 0U;
				_tmp17_ = gtk_text_iter_get_char (&close);
				_tmp11_ = _tmp17_ == ((gunichar) '*');
			} else {
				_tmp11_ = FALSE;
			}
			if (_tmp11_) {
				gchar* _tmp18_ = NULL;
				gtk_text_iter_backward_char (begin);
				gtk_text_iter_backward_char (begin);
				_tmp18_ = g_strdup ("/");
				result = _tmp18_;
				_g_object_unref0 (source_view);
				if (cursor_offset) {
					*cursor_offset = _vala_cursor_offset;
				}
				return result;
			}
		}
		_tmp19_ = was_newline;
		if (_tmp19_) {
			GtkTextView* _tmp20_ = NULL;
			GtkTextIter _tmp21_ = {0};
			gchar* _tmp22_ = NULL;
			_tmp20_ = text_view;
			_tmp21_ = copy;
			_tmp22_ = ide_vala_indenter_indent_comment (self, _tmp20_, &_tmp21_);
			result = _tmp22_;
			_g_object_unref0 (source_view);
			if (cursor_offset) {
				*cursor_offset = _vala_cursor_offset;
			}
			return result;
		}
	}
	_tmp23_ = copy;
	_tmp24_ = ide_vala_indenter_is_newline_in_braces (self, &_tmp23_);
	if (_tmp24_) {
		gchar* prefix = NULL;
		GtkTextView* _tmp25_ = NULL;
		GtkTextIter _tmp26_ = {0};
		gchar* _tmp27_ = NULL;
		gchar* indent = NULL;
		GtkSourceView* _tmp28_ = NULL;
		gboolean _tmp29_ = FALSE;
		gboolean _tmp30_ = FALSE;
		const gchar* _tmp33_ = NULL;
		gint _tmp34_ = 0;
		gint _tmp35_ = 0;
		const gchar* _tmp36_ = NULL;
		const gchar* _tmp37_ = NULL;
		gchar* _tmp38_ = NULL;
		gchar* _tmp39_ = NULL;
		gchar* _tmp40_ = NULL;
		gchar* _tmp41_ = NULL;
		const gchar* _tmp42_ = NULL;
		gchar* _tmp43_ = NULL;
		gchar* _tmp44_ = NULL;
		_tmp25_ = text_view;
		_tmp26_ = copy;
		_tmp27_ = ide_vala_indenter_copy_indent (self, _tmp25_, &_tmp26_);
		prefix = _tmp27_;
		_tmp28_ = source_view;
		_tmp29_ = gtk_source_view_get_insert_spaces_instead_of_tabs (_tmp28_);
		_tmp30_ = _tmp29_;
		if (_tmp30_) {
			gchar* _tmp31_ = NULL;
			_tmp31_ = g_strdup ("    ");
			_g_free0 (indent);
			indent = _tmp31_;
		} else {
			gchar* _tmp32_ = NULL;
			_tmp32_ = g_strdup ("\t");
			_g_free0 (indent);
			indent = _tmp32_;
		}
		_tmp33_ = prefix;
		_tmp34_ = strlen (_tmp33_);
		_tmp35_ = _tmp34_;
		_vala_cursor_offset = (-_tmp35_) - 1;
		_tmp36_ = prefix;
		_tmp37_ = indent;
		_tmp38_ = g_strconcat (_tmp36_, _tmp37_, NULL);
		_tmp39_ = _tmp38_;
		_tmp40_ = g_strconcat (_tmp39_, "\n", NULL);
		_tmp41_ = _tmp40_;
		_tmp42_ = prefix;
		_tmp43_ = g_strconcat (_tmp41_, _tmp42_, NULL);
		_tmp44_ = _tmp43_;
		_g_free0 (_tmp41_);
		_g_free0 (_tmp39_);
		result = _tmp44_;
		_g_free0 (indent);
		_g_free0 (prefix);
		_g_object_unref0 (source_view);
		if (cursor_offset) {
			*cursor_offset = _vala_cursor_offset;
		}
		return result;
	}
	_tmp45_ = was_newline;
	if (_tmp45_) {
		GtkTextView* _tmp46_ = NULL;
		GtkTextIter _tmp47_ = {0};
		gchar* _tmp48_ = NULL;
		_tmp46_ = text_view;
		_tmp47_ = copy;
		_tmp48_ = ide_vala_indenter_copy_indent (self, _tmp46_, &_tmp47_);
		result = _tmp48_;
		_g_object_unref0 (source_view);
		if (cursor_offset) {
			*cursor_offset = _vala_cursor_offset;
		}
		return result;
	}
	result = NULL;
	_g_object_unref0 (source_view);
	if (cursor_offset) {
		*cursor_offset = _vala_cursor_offset;
	}
	return result;
}


static gchar* ide_vala_indenter_copy_indent (IdeValaIndenter* self, GtkTextView* text_view, GtkTextIter* iter) {
	gchar* result = NULL;
	GtkTextIter begin = {0};
	GtkTextIter _tmp0_ = {0};
	GtkTextIter end = {0};
	GtkTextIter _tmp1_ = {0};
	GtkTextIter _tmp8_ = {0};
	gchar* _tmp9_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (text_view != NULL, NULL);
	g_return_val_if_fail (iter != NULL, NULL);
	_tmp0_ = *iter;
	begin = _tmp0_;
	gtk_text_iter_set_line_offset (&begin, 0);
	_tmp1_ = begin;
	end = _tmp1_;
	while (TRUE) {
		gboolean _tmp2_ = FALSE;
		gboolean _tmp3_ = FALSE;
		gboolean _tmp4_ = FALSE;
		_tmp4_ = gtk_text_iter_ends_line (&end);
		if (!_tmp4_) {
			gunichar _tmp5_ = 0U;
			gboolean _tmp6_ = FALSE;
			_tmp5_ = gtk_text_iter_get_char (&end);
			_tmp6_ = g_unichar_isspace (_tmp5_);
			_tmp3_ = _tmp6_;
		} else {
			_tmp3_ = FALSE;
		}
		if (_tmp3_) {
			gboolean _tmp7_ = FALSE;
			_tmp7_ = gtk_text_iter_forward_char (&end);
			_tmp2_ = _tmp7_;
		} else {
			_tmp2_ = FALSE;
		}
		if (!_tmp2_) {
			break;
		}
	}
	_tmp8_ = end;
	_tmp9_ = gtk_text_iter_get_slice (&begin, &_tmp8_);
	result = _tmp9_;
	return result;
}


static gchar* ide_vala_indenter_get_line_text (IdeValaIndenter* self, GtkTextIter* iter) {
	gchar* result = NULL;
	GtkTextIter begin = {0};
	GtkTextIter _tmp0_ = {0};
	GtkTextIter end = {0};
	GtkTextIter _tmp1_ = {0};
	gboolean _tmp2_ = FALSE;
	GtkTextIter _tmp3_ = {0};
	gchar* _tmp4_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (iter != NULL, NULL);
	_tmp0_ = *iter;
	begin = _tmp0_;
	_tmp1_ = *iter;
	end = _tmp1_;
	gtk_text_iter_set_line_offset (&begin, 0);
	_tmp2_ = gtk_text_iter_ends_line (&end);
	if (!_tmp2_) {
		gtk_text_iter_forward_to_line_end (&end);
	}
	_tmp3_ = end;
	_tmp4_ = gtk_text_iter_get_slice (&begin, &_tmp3_);
	result = _tmp4_;
	return result;
}


static gchar* string_strip (const gchar* self) {
	gchar* result = NULL;
	gchar* _result_ = NULL;
	gchar* _tmp0_ = NULL;
	const gchar* _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	_tmp1_ = _result_;
	g_strstrip (_tmp1_);
	result = _result_;
	return result;
}


static gchar* ide_vala_indenter_indent_comment (IdeValaIndenter* self, GtkTextView* text_view, GtkTextIter* iter) {
	gchar* result = NULL;
	gchar* line = NULL;
	GtkTextIter _tmp0_ = {0};
	gchar* _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	gchar* _tmp4_ = NULL;
	const gchar* _tmp5_ = NULL;
	gboolean _tmp6_ = FALSE;
	const gchar* _tmp13_ = NULL;
	gboolean _tmp14_ = FALSE;
	gboolean _tmp32_ = FALSE;
	const gchar* _tmp33_ = NULL;
	gboolean _tmp34_ = FALSE;
	GtkTextView* _tmp51_ = NULL;
	GtkTextIter _tmp52_ = {0};
	gchar* _tmp53_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (text_view != NULL, NULL);
	g_return_val_if_fail (iter != NULL, NULL);
	_tmp0_ = *iter;
	_tmp1_ = ide_vala_indenter_get_line_text (self, &_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = string_strip (_tmp2_);
	_tmp4_ = _tmp3_;
	_g_free0 (_tmp2_);
	line = _tmp4_;
	_tmp5_ = line;
	_tmp6_ = g_str_has_prefix (_tmp5_, "//");
	if (_tmp6_) {
		GtkTextView* _tmp7_ = NULL;
		GtkTextIter _tmp8_ = {0};
		gchar* _tmp9_ = NULL;
		gchar* _tmp10_ = NULL;
		gchar* _tmp11_ = NULL;
		gchar* _tmp12_ = NULL;
		_tmp7_ = text_view;
		_tmp8_ = *iter;
		_tmp9_ = ide_vala_indenter_copy_indent (self, _tmp7_, &_tmp8_);
		_tmp10_ = _tmp9_;
		_tmp11_ = g_strconcat (_tmp10_, "// ", NULL);
		_tmp12_ = _tmp11_;
		_g_free0 (_tmp10_);
		result = _tmp12_;
		_g_free0 (line);
		return result;
	}
	_tmp13_ = line;
	_tmp14_ = g_str_has_suffix (_tmp13_, "*/");
	if (_tmp14_) {
		const gchar* _tmp15_ = NULL;
		gboolean _tmp16_ = FALSE;
		_tmp15_ = line;
		_tmp16_ = g_str_has_prefix (_tmp15_, "*");
		if (_tmp16_) {
			GString* str = NULL;
			GtkTextView* _tmp17_ = NULL;
			GtkTextIter _tmp18_ = {0};
			gchar* _tmp19_ = NULL;
			gchar* _tmp20_ = NULL;
			GString* _tmp21_ = NULL;
			GString* _tmp22_ = NULL;
			GString* _tmp23_ = NULL;
			const gchar* _tmp24_ = NULL;
			gboolean _tmp25_ = FALSE;
			GString* _tmp29_ = NULL;
			const gchar* _tmp30_ = NULL;
			gchar* _tmp31_ = NULL;
			_tmp17_ = text_view;
			_tmp18_ = *iter;
			_tmp19_ = ide_vala_indenter_copy_indent (self, _tmp17_, &_tmp18_);
			_tmp20_ = _tmp19_;
			_tmp21_ = g_string_new (_tmp20_);
			_tmp22_ = _tmp21_;
			_g_free0 (_tmp20_);
			str = _tmp22_;
			_tmp23_ = str;
			_tmp24_ = _tmp23_->str;
			_tmp25_ = g_str_has_suffix (_tmp24_, " ");
			if (_tmp25_) {
				GString* _tmp26_ = NULL;
				GString* _tmp27_ = NULL;
				gssize _tmp28_ = 0L;
				_tmp26_ = str;
				_tmp27_ = str;
				_tmp28_ = _tmp27_->len;
				g_string_truncate (_tmp26_, (gsize) (_tmp28_ - 1));
			}
			_tmp29_ = str;
			_tmp30_ = _tmp29_->str;
			_tmp31_ = g_strdup (_tmp30_);
			result = _tmp31_;
			_g_string_free0 (str);
			_g_free0 (line);
			return result;
		}
	}
	_tmp33_ = line;
	_tmp34_ = g_str_has_prefix (_tmp33_, "/*");
	if (_tmp34_) {
		const gchar* _tmp35_ = NULL;
		gboolean _tmp36_ = FALSE;
		_tmp35_ = line;
		_tmp36_ = g_str_has_suffix (_tmp35_, "*/");
		_tmp32_ = !_tmp36_;
	} else {
		_tmp32_ = FALSE;
	}
	if (_tmp32_) {
		GtkTextView* _tmp37_ = NULL;
		GtkTextIter _tmp38_ = {0};
		gchar* _tmp39_ = NULL;
		gchar* _tmp40_ = NULL;
		gchar* _tmp41_ = NULL;
		gchar* _tmp42_ = NULL;
		_tmp37_ = text_view;
		_tmp38_ = *iter;
		_tmp39_ = ide_vala_indenter_copy_indent (self, _tmp37_, &_tmp38_);
		_tmp40_ = _tmp39_;
		_tmp41_ = g_strconcat (_tmp40_, " * ", NULL);
		_tmp42_ = _tmp41_;
		_g_free0 (_tmp40_);
		result = _tmp42_;
		_g_free0 (line);
		return result;
	} else {
		const gchar* _tmp43_ = NULL;
		gboolean _tmp44_ = FALSE;
		_tmp43_ = line;
		_tmp44_ = g_str_has_prefix (_tmp43_, "*");
		if (_tmp44_) {
			GtkTextView* _tmp45_ = NULL;
			GtkTextIter _tmp46_ = {0};
			gchar* _tmp47_ = NULL;
			gchar* _tmp48_ = NULL;
			gchar* _tmp49_ = NULL;
			gchar* _tmp50_ = NULL;
			_tmp45_ = text_view;
			_tmp46_ = *iter;
			_tmp47_ = ide_vala_indenter_copy_indent (self, _tmp45_, &_tmp46_);
			_tmp48_ = _tmp47_;
			_tmp49_ = g_strconcat (_tmp48_, "* ", NULL);
			_tmp50_ = _tmp49_;
			_g_free0 (_tmp48_);
			result = _tmp50_;
			_g_free0 (line);
			return result;
		}
	}
	_tmp51_ = text_view;
	_tmp52_ = *iter;
	_tmp53_ = ide_vala_indenter_copy_indent (self, _tmp51_, &_tmp52_);
	result = _tmp53_;
	_g_free0 (line);
	return result;
}


static gboolean ide_vala_indenter_in_comment (IdeValaIndenter* self, GtkTextView* text_view, GtkTextIter* iter) {
	gboolean result = FALSE;
	GtkSourceBuffer* buffer = NULL;
	GtkTextView* _tmp0_ = NULL;
	GtkTextBuffer* _tmp1_ = NULL;
	GtkTextBuffer* _tmp2_ = NULL;
	GtkSourceBuffer* _tmp3_ = NULL;
	GtkTextIter copy = {0};
	GtkTextIter _tmp4_ = {0};
	GtkTextIter _tmp5_ = {0};
	gboolean _tmp6_ = FALSE;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (text_view != NULL, FALSE);
	g_return_val_if_fail (iter != NULL, FALSE);
	_tmp0_ = text_view;
	_tmp1_ = gtk_text_view_get_buffer (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp2_, gtk_source_buffer_get_type ()) ? ((GtkSourceBuffer*) _tmp2_) : NULL);
	buffer = _tmp3_;
	_tmp4_ = *iter;
	copy = _tmp4_;
	gtk_text_iter_backward_char (&copy);
	_tmp5_ = copy;
	_tmp6_ = gtk_source_buffer_iter_has_context_class (buffer, &_tmp5_, "comment");
	result = _tmp6_;
	_g_object_unref0 (buffer);
	return result;
}


static gboolean ide_vala_indenter_is_newline_keyval (IdeValaIndenter* self, guint keyval) {
	gboolean result = FALSE;
	guint _tmp0_ = 0U;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = keyval;
	switch (_tmp0_) {
		case GDK_KEY_Return:
		case GDK_KEY_KP_Enter:
		{
			result = TRUE;
			return result;
		}
		default:
		{
			result = FALSE;
			return result;
		}
	}
}


static gboolean ide_vala_indenter_is_newline_in_braces (IdeValaIndenter* self, GtkTextIter* iter) {
	gboolean result = FALSE;
	GtkTextIter prev = {0};
	GtkTextIter _tmp0_ = {0};
	GtkTextIter next = {0};
	GtkTextIter _tmp1_ = {0};
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gunichar _tmp4_ = 0U;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (iter != NULL, FALSE);
	_tmp0_ = *iter;
	prev = _tmp0_;
	_tmp1_ = *iter;
	next = _tmp1_;
	gtk_text_iter_backward_char (&prev);
	gtk_text_iter_forward_char (&next);
	_tmp4_ = gtk_text_iter_get_char (&prev);
	if (_tmp4_ == ((gunichar) '{')) {
		gunichar _tmp5_ = 0U;
		_tmp5_ = gtk_text_iter_get_char (iter);
		_tmp3_ = _tmp5_ == ((gunichar) '\n');
	} else {
		_tmp3_ = FALSE;
	}
	if (_tmp3_) {
		gunichar _tmp6_ = 0U;
		_tmp6_ = gtk_text_iter_get_char (&next);
		_tmp2_ = _tmp6_ == ((gunichar) '}');
	} else {
		_tmp2_ = FALSE;
	}
	result = _tmp2_;
	return result;
}


IdeValaIndenter* ide_vala_indenter_construct (GType object_type) {
	IdeValaIndenter * self = NULL;
	self = (IdeValaIndenter*) g_object_new (object_type, NULL);
	return self;
}


IdeValaIndenter* ide_vala_indenter_new (void) {
	return ide_vala_indenter_construct (IDE_TYPE_VALA_INDENTER);
}


static void ide_vala_indenter_class_init (IdeValaIndenterClass * klass) {
	ide_vala_indenter_parent_class = g_type_class_peek_parent (klass);
}


static void ide_vala_indenter_ide_indenter_interface_init (IdeIndenterInterface * iface) {
	ide_vala_indenter_ide_indenter_parent_iface = g_type_interface_peek_parent (iface);
	iface->is_trigger = (gboolean (*)(IdeIndenter*, GdkEventKey*)) ide_vala_indenter_real_is_trigger;
	iface->format = (gchar* (*)(IdeIndenter*, GtkTextView*, GtkTextIter*, GtkTextIter*, gint*, GdkEventKey*)) ide_vala_indenter_real_format;
	iface->set_context = (void (*)(IdeIndenter*, IdeContext*)) ide_object_set_context;
	iface->set_context = (void (*) (IdeIndenter *, IdeContext*)) ide_object_set_context;
}


static void ide_vala_indenter_instance_init (IdeValaIndenter * self) {
}


GType ide_vala_indenter_get_type (void) {
	return ide_vala_indenter_type_id;
}


GType ide_vala_indenter_register_type (GTypeModule * module) {
	static const GTypeInfo g_define_type_info = { sizeof (IdeValaIndenterClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ide_vala_indenter_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (IdeValaIndenter), 0, (GInstanceInitFunc) ide_vala_indenter_instance_init, NULL };
	static const GInterfaceInfo ide_indenter_info = { (GInterfaceInitFunc) ide_vala_indenter_ide_indenter_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	ide_vala_indenter_type_id = g_type_module_register_type (module, ide_object_get_type (), "IdeValaIndenter", &g_define_type_info, 0);
	g_type_module_add_interface (module, ide_vala_indenter_type_id, ide_indenter_get_type (), &ide_indenter_info);
	return ide_vala_indenter_type_id;
}



