[gnome-builder/wip/beniofel/vala-codestyle: 2/2] Vala: use a consistent coding style
- From: Ben Iofel <beniofel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/beniofel/vala-codestyle: 2/2] Vala: use a consistent coding style
- Date: Fri, 15 Jan 2016 17:03:47 +0000 (UTC)
commit b7d1e453283134404d6d9ab3fd17cf4437a8a308
Author: Ben Iofel <iofelben gmail com>
Date: Thu Jan 14 18:55:24 2016 -0500
Vala: use a consistent coding style
plugins/vala-pack/ide-vala-completion-item.vala | 53 +++++++---------
.../vala-pack/ide-vala-completion-provider.vala | 35 +++++------
plugins/vala-pack/ide-vala-completion.vala | 38 +++++------
.../vala-pack/ide-vala-diagnostic-provider.vala | 13 +---
plugins/vala-pack/ide-vala-diagnostics.vala | 16 ++---
plugins/vala-pack/ide-vala-indenter.vala | 61 ++++++++----------
plugins/vala-pack/ide-vala-index.vala | 57 ++++++-----------
plugins/vala-pack/ide-vala-locator.vala | 45 ++++++++-----
plugins/vala-pack/ide-vala-service.vala | 11 +--
plugins/vala-pack/ide-vala-source-file.vala | 29 +++------
plugins/vala-pack/ide-vala-symbol-resolver.vala | 68 +++++++++++---------
plugins/vala-pack/ide-vala-symbol-tree.vala | 58 +++++++----------
12 files changed, 212 insertions(+), 272 deletions(-)
---
diff --git a/plugins/vala-pack/ide-vala-completion-item.vala b/plugins/vala-pack/ide-vala-completion-item.vala
index c48e556..7309633 100644
--- a/plugins/vala-pack/ide-vala-completion-item.vala
+++ b/plugins/vala-pack/ide-vala-completion-item.vala
@@ -16,14 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-using GLib;
using Gtk;
using Vala;
-namespace Ide
-{
- public class ValaCompletionItem: Ide.CompletionItem, Gtk.SourceCompletionProposal
- {
+namespace Ide {
+ public class ValaCompletionItem: Ide.CompletionItem, Gtk.SourceCompletionProposal {
static uint hash_seed;
internal Vala.Symbol symbol;
@@ -34,8 +31,7 @@ namespace Ide
hash_seed = "IdeValaCompletionItem".hash ();
}
- public ValaCompletionItem (Vala.Symbol symbol, Ide.ValaCompletionProvider provider)
- {
+ public ValaCompletionItem (Vala.Symbol symbol, Ide.ValaCompletionProvider provider) {
this.symbol = symbol;
this.provider = provider;
@@ -46,44 +42,42 @@ namespace Ide
this.build_label ();
}
- public unowned string? get_icon_name ()
- {
- if (symbol is Vala.LocalVariable)
+ public unowned string? get_icon_name () {
+ if (symbol is Vala.LocalVariable) {
return "lang-variable-symbolic";
- else if (symbol is Vala.Field)
+ } else if (symbol is Vala.Field) {
return "struct-field-symbolic";
- else if (symbol is Vala.Subroutine)
+ } else if (symbol is Vala.Subroutine) {
return "lang-function-symbolic";
- else if (symbol is Vala.Namespace)
+ } else if (symbol is Vala.Namespace) {
return "lang-include-symbolic";
- else if (symbol is Vala.MemberAccess)
+ } else if (symbol is Vala.MemberAccess) {
return "struct-field-symbolic";
- else if (symbol is Vala.Property)
+ } else if (symbol is Vala.Property) {
return "struct-field-symbolic";
- else if (symbol is Vala.Struct)
+ } else if (symbol is Vala.Struct) {
return "lang-struct-symbolic";
- else if (symbol is Vala.Class)
+ } else if (symbol is Vala.Class) {
return "lang-class-symbolic";
- else if (symbol is Vala.Enum)
+ } else if (symbol is Vala.Enum) {
return "lang-enum-symbolic";
- else if (symbol is Vala.EnumValue)
+ } else if (symbol is Vala.EnumValue) {
return "lang-enum-value-symbolic";
- else if (symbol is Vala.Delegate)
+ } else if (symbol is Vala.Delegate) {
return "lang-typedef-symbolic";
+ }
return null;
}
- public override bool match (string query, string casefold)
- {
+ public override bool match (string query, string casefold) {
uint priority = 0;
bool result = Ide.CompletionItem.fuzzy_match (this.symbol.name, casefold, out
priority);
this.set_priority (priority);
return result;
}
- public void build_label ()
- {
+ public void build_label () {
GLib.StringBuilder str = new GLib.StringBuilder ();
if (this.symbol is Vala.Method) {
@@ -108,10 +102,11 @@ namespace Ide
break;
}
- if (param.direction == ParameterDirection.OUT)
+ if (param.direction == ParameterDirection.OUT) {
str.append ("out ");
- else if (param.direction == ParameterDirection.REF)
+ } else if (param.direction == ParameterDirection.REF) {
str.append ("ref ");
+ }
str.append_printf ("%s, ", param.variable_type.to_qualified_string
(method.owner));
}
@@ -137,8 +132,7 @@ namespace Ide
return this.label;
}
- public string get_text ()
- {
+ public string get_text () {
return this.symbol.name;
}
@@ -150,8 +144,7 @@ namespace Ide
return null;
}
- public uint hash ()
- {
+ public uint hash () {
return this.symbol.name.hash () ^ hash_seed;
}
}
diff --git a/plugins/vala-pack/ide-vala-completion-provider.vala
b/plugins/vala-pack/ide-vala-completion-provider.vala
index 62646ee..0f820bb 100644
--- a/plugins/vala-pack/ide-vala-completion-provider.vala
+++ b/plugins/vala-pack/ide-vala-completion-provider.vala
@@ -16,23 +16,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-using GLib;
-using Ide;
using Vala;
-namespace Ide
-{
- public class ValaCompletionProvider: Ide.Object,
- Gtk.SourceCompletionProvider,
- Ide.CompletionProvider
- {
+namespace Ide {
+ public class ValaCompletionProvider : Ide.Object,
+ Gtk.SourceCompletionProvider,
+ Ide.CompletionProvider {
internal string? query;
int line = -1;
int column = -1;
Ide.CompletionResults? results;
- public void populate (Gtk.SourceCompletionContext context)
- {
+ public void populate (Gtk.SourceCompletionContext context) {
Gtk.TextIter iter;
Gtk.TextIter begin;
@@ -89,25 +84,26 @@ namespace Ide
cancellable,
out res_line,
out res_column);
- if (res_line > 0 && res_column > 0) {
+ if (res_line > 0 && res_column > 0) {
this.line = res_line - 1;
this.column = res_column - 1;
}
Idle.add (() => {
- if (!cancellable.is_cancelled ())
+ if (!cancellable.is_cancelled ()) {
this.results.present (this, context);
+ }
return false;
});
});
}
- public bool match (Gtk.SourceCompletionContext context)
- {
+ public bool match (Gtk.SourceCompletionContext context) {
Gtk.TextIter iter;
- if (!context.get_iter (out iter))
+ if (!context.get_iter (out iter)) {
return false;
+ }
var buffer = iter.get_buffer () as Ide.Buffer;
@@ -120,12 +116,14 @@ namespace Ide
* whitespace.
*/
if (context.activation != Gtk.SourceCompletionActivation.USER_REQUESTED) {
- if (iter.starts_line () || !iter.backward_char () || iter.get_char ().isspace
())
+ if (iter.starts_line () || !iter.backward_char () || iter.get_char ().isspace
()) {
return false;
+ }
}
- if (Ide.CompletionProvider.context_in_comment (context))
+ if (Ide.CompletionProvider.context_in_comment (context)) {
return false;
+ }
return true;
}
@@ -134,8 +132,7 @@ namespace Ide
return "Vala";
}
- public int get_priority ()
- {
+ public int get_priority () {
return 200;
}
}
diff --git a/plugins/vala-pack/ide-vala-completion.vala b/plugins/vala-pack/ide-vala-completion.vala
index f7c98b1..b47efb0 100644
--- a/plugins/vala-pack/ide-vala-completion.vala
+++ b/plugins/vala-pack/ide-vala-completion.vala
@@ -19,14 +19,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-using GLib;
using Gtk;
using Vala;
-namespace Ide
-{
- public class ValaCompletion: GLib.Object
- {
+namespace Ide {
+ public class ValaCompletion : GLib.Object {
static Regex member_access;
static Regex member_access_split;
static Regex function_call;
@@ -49,22 +46,21 @@ namespace Ide
public ValaCompletion (Vala.CodeContext context,
Vala.SourceLocation location,
string current_text,
- Vala.Block? nearest)
- {
+ Vala.Block? nearest) {
this.context = context;
this.location = location;
this.current_text = current_text;
this.nearest = nearest;
}
- public GLib.List<Vala.Symbol>? run (ref Vala.SourceLocation start_pos)
- {
+ public GLib.List<Vala.Symbol>? run (ref Vala.SourceLocation start_pos) {
MatchInfo match_info;
- if (!member_access.match (current_text, 0, out match_info))
+ if (!member_access.match (current_text, 0, out match_info)) {
return null;
- else if (match_info.fetch(0).length < 2)
+ } else if (match_info.fetch(0).length < 2) {
return null;
+ }
start_pos.line = this.location.line;
start_pos.column = this.location.column - (int)match_info.fetch (2).length;
@@ -79,12 +75,12 @@ namespace Ide
return syms;
}
- GLib.List<Vala.Symbol> lookup_symbol (Vala.Expression? inner, string name, bool prefix_match,
Vala.Block? block)
- {
+ GLib.List<Vala.Symbol> lookup_symbol (Vala.Expression? inner, string name, bool prefix_match,
Vala.Block? block) {
var matching_symbols = new GLib.List<Vala.Symbol> ();
- if (block == null)
+ if (block == null) {
return matching_symbols;
+ }
if (inner == null) {
for (var sym = (Vala.Symbol) block; sym != null; sym = sym.parent_symbol) {
@@ -95,12 +91,13 @@ namespace Ide
matching_symbols.concat (symbol_lookup_inherited
(ns.namespace_symbol, name, prefix_match));
}
} else if (inner.symbol_reference != null) {
- matching_symbols.concat (symbol_lookup_inherited
(inner.symbol_reference, name, prefix_match));
+ matching_symbols.concat (symbol_lookup_inherited (inner.symbol_reference,
name, prefix_match));
} else if (inner is Vala.MemberAccess) {
var inner_ma = (Vala.MemberAccess) inner;
var matching = lookup_symbol (inner_ma.inner, inner_ma.member_name, false,
block);
- if (matching != null)
+ if (matching != null) {
matching_symbols.concat (symbol_lookup_inherited (matching.data,
name, prefix_match));
+ }
} else if (inner is Vala.MethodCall) {
var inner_inv = (Vala.MethodCall) inner;
var inner_ma = inner_inv.call as Vala.MemberAccess;
@@ -117,13 +114,13 @@ namespace Ide
GLib.List<Vala.Symbol> symbol_lookup_inherited (Vala.Symbol? sym,
string name,
bool prefix_match,
- bool invocation = false)
- {
+ bool invocation = false) {
GLib.List<Vala.Symbol> result = null;
// This may happen if we cannot find all the needed packages
- if (sym == null)
+ if (sym == null) {
return result;
+ }
var symbol_table = sym.scope.get_symbol_table ();
@@ -168,8 +165,7 @@ namespace Ide
return result;
}
- Vala.Expression construct_member_access (string[] names)
- {
+ Vala.Expression construct_member_access (string[] names) {
Vala.Expression expr = null;
for (var i = 0; names[i] != null; i++) {
diff --git a/plugins/vala-pack/ide-vala-diagnostic-provider.vala
b/plugins/vala-pack/ide-vala-diagnostic-provider.vala
index 5a66032..9d727e1 100644
--- a/plugins/vala-pack/ide-vala-diagnostic-provider.vala
+++ b/plugins/vala-pack/ide-vala-diagnostic-provider.vala
@@ -16,18 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-using GLib;
-using Ide;
using Vala;
-namespace Ide
-{
- public class ValaDiagnosticProvider: Ide.Object, Ide.DiagnosticProvider
- {
- public async Ide.Diagnostics? diagnose_async (Ide.File file,
- GLib.Cancellable? cancellable)
- throws GLib.Error
- {
+namespace Ide {
+ public class ValaDiagnosticProvider : Ide.Object, Ide.DiagnosticProvider {
+ public async Ide.Diagnostics? diagnose_async (Ide.File file, Cancellable? cancellable) throws
GLib.Error {
var context = this.get_context ();
var service = (Ide.ValaService)context.get_service_typed (typeof (Ide.ValaService));
yield service.index.parse_file (file.file, context.unsaved_files, cancellable);
diff --git a/plugins/vala-pack/ide-vala-diagnostics.vala b/plugins/vala-pack/ide-vala-diagnostics.vala
index 42daadf..58217ab 100644
--- a/plugins/vala-pack/ide-vala-diagnostics.vala
+++ b/plugins/vala-pack/ide-vala-diagnostics.vala
@@ -16,25 +16,21 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-using GLib;
using Vala;
-namespace Ide
-{
- public class ValaDiagnostics: Vala.Report
- {
- public void clear ()
- {
+namespace Ide {
+ public class ValaDiagnostics : Vala.Report {
+ public void clear () {
this.errors = 0;
this.warnings = 0;
}
void add (Vala.SourceReference? source_reference,
string message,
- Ide.DiagnosticSeverity severity)
- {
- if (source_reference == null)
+ Ide.DiagnosticSeverity severity) {
+ if (source_reference == null) {
return;
+ }
if (source_reference.file is Ide.ValaSourceFile) {
var file = (Ide.ValaSourceFile)source_reference.file;
diff --git a/plugins/vala-pack/ide-vala-indenter.vala b/plugins/vala-pack/ide-vala-indenter.vala
index 95e29d5..cf6b176 100644
--- a/plugins/vala-pack/ide-vala-indenter.vala
+++ b/plugins/vala-pack/ide-vala-indenter.vala
@@ -17,14 +17,10 @@
*/
using Gtk;
-using Ide;
-
-namespace Ide
-{
- public class ValaIndenter: Ide.Object, Ide.Indenter
- {
- public bool is_trigger (Gdk.EventKey evkey)
- {
+
+namespace Ide {
+ public class ValaIndenter : Ide.Object, Ide.Indenter {
+ public bool is_trigger (Gdk.EventKey evkey) {
switch (evkey.keyval) {
/* newline indents */
@@ -45,8 +41,7 @@ namespace Ide
Gtk.TextIter begin,
Gtk.TextIter end,
out int cursor_offset,
- Gdk.EventKey evkey)
- {
+ Gdk.EventKey evkey) {
Gtk.SourceView source_view = (text_view as Gtk.SourceView);
bool was_newline = is_newline_keyval (evkey.keyval);
Gtk.TextIter copy = end;
@@ -69,32 +64,33 @@ namespace Ide
}
}
- if (was_newline)
+ if (was_newline) {
return indent_comment (text_view, copy);
+ }
}
if (is_newline_in_braces (copy)) {
string prefix = copy_indent (text_view, copy);
string indent;
- if (source_view.insert_spaces_instead_of_tabs)
+ if (source_view.insert_spaces_instead_of_tabs) {
indent = " ";
- else
+ } else {
indent = "\t";
+ }
cursor_offset = -prefix.length - 1;
return (prefix + indent + "\n" + prefix);
}
- if (was_newline)
+ if (was_newline) {
return copy_indent (text_view, copy);
+ }
return null;
}
- string? copy_indent (Gtk.TextView text_view,
- Gtk.TextIter iter)
- {
+ string? copy_indent (Gtk.TextView text_view, Gtk.TextIter iter) {
Gtk.TextIter begin = iter;
Gtk.TextIter end;
@@ -108,48 +104,47 @@ namespace Ide
return begin.get_slice (end);
}
- string get_line_text (Gtk.TextIter iter)
- {
+ string get_line_text (Gtk.TextIter iter) {
Gtk.TextIter begin = iter;
Gtk.TextIter end = iter;
begin.set_line_offset (0);
- if (!end.ends_line ())
+ if (!end.ends_line ()) {
end.forward_to_line_end ();
+ }
return begin.get_slice (end);
}
- string? indent_comment (Gtk.TextView text_view,
- Gtk.TextIter iter)
- {
+ string? indent_comment (Gtk.TextView text_view, Gtk.TextIter iter) {
string line = get_line_text (iter).strip ();
/* continue with another single line comment */
- if (line.has_prefix ("//"))
+ if (line.has_prefix ("//")) {
return copy_indent (text_view, iter) + "// ";
+ }
/* comment is closed, copy indent, possibly trimming extra space */
if (line.has_suffix ("*/")) {
if (line.has_prefix ("*")) {
var str = new GLib.StringBuilder (copy_indent (text_view, iter));
- if (str.str.has_suffix (" "))
+ if (str.str.has_suffix (" ")) {
str.truncate (str.len - 1);
+ }
return str.str;
}
}
- if (line.has_prefix ("/*") && !line.has_suffix ("*/"))
+ if (line.has_prefix ("/*") && !line.has_suffix ("*/")) {
return copy_indent (text_view, iter) + " * ";
- else if (line.has_prefix ("*"))
+ } else if (line.has_prefix ("*")) {
return copy_indent (text_view, iter) + "* ";
+ }
return copy_indent (text_view, iter);
}
- bool in_comment (Gtk.TextView text_view,
- Gtk.TextIter iter)
- {
+ bool in_comment (Gtk.TextView text_view, Gtk.TextIter iter) {
Gtk.SourceBuffer buffer = text_view.buffer as Gtk.SourceBuffer;
Gtk.TextIter copy = iter;
@@ -158,8 +153,7 @@ namespace Ide
return buffer.iter_has_context_class (copy, "comment");
}
- bool is_newline_keyval (uint keyval)
- {
+ bool is_newline_keyval (uint keyval) {
switch (keyval) {
case Gdk.Key.Return:
case Gdk.Key.KP_Enter:
@@ -170,8 +164,7 @@ namespace Ide
}
}
- bool is_newline_in_braces (Gtk.TextIter iter)
- {
+ bool is_newline_in_braces (Gtk.TextIter iter) {
Gtk.TextIter prev = iter;
Gtk.TextIter next = iter;
diff --git a/plugins/vala-pack/ide-vala-index.vala b/plugins/vala-pack/ide-vala-index.vala
index 2640b56..64facf3 100644
--- a/plugins/vala-pack/ide-vala-index.vala
+++ b/plugins/vala-pack/ide-vala-index.vala
@@ -24,23 +24,18 @@
* Ide.Service (via Ide.ValaService) to keep an index-per-project.
*/
-using GLib;
using Gtk;
-using Ide;
using Vala;
-namespace Ide
-{
- public class ValaIndex: GLib.Object
- {
+namespace Ide {
+ public class ValaIndex : GLib.Object {
Vala.CodeContext code_context;
Vala.Parser parser;
HashMap<GLib.File,Ide.ValaSourceFile> source_files;
Ide.ValaDiagnostics report;
- public ValaIndex ()
- {
- this.source_files = new HashMap<GLib.File,Ide.ValaSourceFile> (GLib.File.hash,
(GLib.EqualFunc)GLib.File.equal);
+ public ValaIndex () {
+ this.source_files = new HashMap<GLib.File, Ide.ValaSourceFile> (GLib.File.hash,
(GLib.EqualFunc)GLib.File.equal);
this.code_context = new Vala.CodeContext ();
@@ -109,8 +104,7 @@ namespace Ide
Vala.CodeContext.pop ();
}
- void add_file (GLib.File file)
- {
+ void add_file (GLib.File file) {
var path = file.get_path ();
if (path == null)
return;
@@ -121,14 +115,13 @@ namespace Ide
this.source_files [file] = source_file;
}
- public async void add_files (ArrayList<GLib.File> files,
- GLib.Cancellable? cancellable)
- {
+ public async void add_files (ArrayList<GLib.File> files, GLib.Cancellable? cancellable) {
Ide.ThreadPool.push (Ide.ThreadPoolKind.COMPILER, () => {
lock (this.code_context) {
Vala.CodeContext.push (this.code_context);
- foreach (var file in files)
+ foreach (var file in files) {
this.add_file (file);
+ }
Vala.CodeContext.pop ();
GLib.Idle.add(add_files.callback);
}
@@ -139,9 +132,7 @@ namespace Ide
public async bool parse_file (GLib.File file,
Ide.UnsavedFiles? unsaved_files,
- GLib.Cancellable? cancellable)
- throws GLib.Error
- {
+ GLib.Cancellable? cancellable) throws GLib.Error {
GLib.GenericArray<UnsavedFile>? unsaved_files_copy = null;
if (unsaved_files != null) {
@@ -153,8 +144,9 @@ namespace Ide
lock (this.code_context) {
Vala.CodeContext.push (this.code_context);
- if (!this.source_files.contains (file))
+ if (!this.source_files.contains (file)) {
this.add_file (file);
+ }
this.apply_unsaved_files (unsaved_files_copy);
this.reparse ();
@@ -180,8 +172,7 @@ namespace Ide
Ide.ValaCompletionProvider provider,
GLib.Cancellable? cancellable,
out int result_line,
- out int result_column)
- {
+ out int result_column) {
var unsaved_files_copy = unsaved_files.to_array ();
var result = new Ide.CompletionResults (provider.query);
@@ -212,9 +203,7 @@ namespace Ide
return result;
}
- public async Ide.Diagnostics? get_diagnostics (GLib.File file,
- GLib.Cancellable? cancellable = null)
- {
+ public async Ide.Diagnostics? get_diagnostics (GLib.File file, Cancellable? cancellable =
null) {
Ide.Diagnostics? diagnostics = null;
Ide.ThreadPool.push (Ide.ThreadPoolKind.COMPILER, () => {
@@ -235,8 +224,7 @@ namespace Ide
return diagnostics;
}
- void apply_unsaved_files (GLib.GenericArray<Ide.UnsavedFile> unsaved_files)
- {
+ void apply_unsaved_files (GLib.GenericArray<Ide.UnsavedFile> unsaved_files) {
foreach (var source_file in this.code_context.get_source_files ()) {
if ((source_file.file_type == Vala.SourceFileType.SOURCE) &&
(source_file is Ide.ValaSourceFile)) {
@@ -245,8 +233,7 @@ namespace Ide
}
}
- void reparse ()
- {
+ void reparse () {
this.report.clear ();
foreach (var source_file in this.code_context.get_source_files ()) {
@@ -267,8 +254,7 @@ namespace Ide
string line_text,
Vala.Symbol? nearest,
Ide.CompletionResults results,
- Ide.ValaCompletionProvider provider)
- {
+ Ide.ValaCompletionProvider provider) {
var block = nearest as Vala.Block;
Vala.SourceLocation cursor = Vala.SourceLocation (null, line, column);
@@ -280,16 +266,16 @@ namespace Ide
var list = completion.run (ref cursor);
foreach (var symbol in list) {
- if (symbol.name != null && symbol.name[0] != '\0')
+ if (symbol.name != null && symbol.name[0] != '\0') {
results.take_proposal (new Ide.ValaCompletionItem (symbol, provider));
+ }
}
line = cursor.line;
column = cursor.column;
}
- public async Vala.Symbol? find_symbol_at (GLib.File file, int line, int column)
- {
+ public async Vala.Symbol? find_symbol_at (GLib.File file, int line, int column) {
Vala.Symbol? symbol = null;
/*
@@ -323,10 +309,7 @@ namespace Ide
return symbol;
}
- public async Ide.SymbolTree? get_symbol_tree (GLib.File file,
- GLib.Cancellable? cancellable)
- throws GLib.Error
- {
+ public async Ide.SymbolTree? get_symbol_tree (GLib.File file, Cancellable? cancellable)
throws GLib.Error {
Ide.SymbolTree? ret = null;
Ide.ThreadPool.push (Ide.ThreadPoolKind.COMPILER, () => {
diff --git a/plugins/vala-pack/ide-vala-locator.vala b/plugins/vala-pack/ide-vala-locator.vala
index 84a84b1..124065e 100644
--- a/plugins/vala-pack/ide-vala-locator.vala
+++ b/plugins/vala-pack/ide-vala-locator.vala
@@ -18,7 +18,7 @@
/* Finds the innermost block containing the given location */
namespace Ide {
- public class ValaLocator: Vala.CodeVisitor {
+ public class ValaLocator : Vala.CodeVisitor {
struct Location {
int line;
int column;
@@ -36,10 +36,11 @@ namespace Ide {
}
public bool before (Location other) {
- if (line > other.line)
+ if (line > other.line) {
return false;
- else if (line == other.line && column > other.column)
+ } else if (line == other.line && column > other.column) {
return false;
+ }
return true;
}
}
@@ -57,25 +58,27 @@ namespace Ide {
}
bool update_location (Vala.Symbol s) {
- if (!location.inside (s.source_reference))
+ if (!location.inside (s.source_reference)) {
return false;
+ }
var begin = Location (s.source_reference.begin.line, s.source_reference.begin.column);
var end = Location (s.source_reference.end.line, s.source_reference.end.column);
if (innermost == null || (innermost_begin.before(begin) &&
end.before(innermost_end))) {
- innermost = s;
- innermost_begin = begin;
- innermost_end = end;
- return true;
+ innermost = s;
+ innermost_begin = begin;
+ innermost_end = end;
+ return true;
}
return false;
}
public override void visit_block (Vala.Block b) {
- if (update_location (b))
+ if (update_location (b)) {
b.accept_children(this);
+ }
}
public override void visit_namespace (Vala.Namespace ns) {
@@ -84,29 +87,34 @@ namespace Ide {
}
public override void visit_class (Vala.Class cl) {
/* the location of a class contains only its declaration, not its content */
- if (update_location (cl))
+ if (update_location (cl)) {
return;
+ }
cl.accept_children(this);
}
public override void visit_struct (Vala.Struct st) {
- if (update_location (st))
+ if (update_location (st)) {
return;
+ }
st.accept_children(this);
}
public override void visit_interface (Vala.Interface iface) {
- if (update_location (iface))
+ if (update_location (iface)) {
return;
+ }
iface.accept_children(this);
}
public override void visit_method (Vala.Method m) {
- if (update_location (m))
+ if (update_location (m)) {
return;
+ }
m.accept_children(this);
}
public override void visit_creation_method (Vala.CreationMethod m) {
- if (update_location (m))
+ if (update_location (m)) {
return;
+ }
m.accept_children(this);
}
public override void visit_property (Vala.Property prop) {
@@ -161,8 +169,9 @@ namespace Ide {
variable.accept_children (this);
}
public override void visit_end_full_expression (Vala.Expression expr) {
- if (expr is Vala.LambdaExpression)
+ if (expr is Vala.LambdaExpression) {
visit_method ((expr as Vala.LambdaExpression).method);
+ }
if (expr is Vala.MethodCall) {
foreach (Vala.Expression e in (expr as Vala.MethodCall).get_argument_list()) {
visit_expression (e);
@@ -170,11 +179,13 @@ namespace Ide {
}
}
public override void visit_expression (Vala.Expression expr) {
- if (expr is Vala.LambdaExpression)
+ if (expr is Vala.LambdaExpression) {
visit_method ((expr as Vala.LambdaExpression).method);
+ }
if (expr is Vala.MethodCall) {
- foreach (Vala.Expression e in (expr as Vala.MethodCall).get_argument_list())
+ foreach (Vala.Expression e in (expr as Vala.MethodCall).get_argument_list()) {
visit_expression (e);
+ }
}
}
}
diff --git a/plugins/vala-pack/ide-vala-service.vala b/plugins/vala-pack/ide-vala-service.vala
index 8bba1c0..29e5bfe 100644
--- a/plugins/vala-pack/ide-vala-service.vala
+++ b/plugins/vala-pack/ide-vala-service.vala
@@ -16,14 +16,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-using GLib;
-using Ide;
using Vala;
-namespace Ide
-{
- public class ValaService: Ide.Object, Ide.Service
- {
+namespace Ide {
+ public class ValaService : Ide.Object, Ide.Service {
Ide.ValaIndex _index;
construct {
@@ -58,8 +54,7 @@ namespace Ide
public void load_directory (GLib.File directory,
GLib.Cancellable? cancellable,
- ArrayList<GLib.File> files)
- {
+ ArrayList<GLib.File> files) {
try {
var enumerator = directory.enumerate_children
(FileAttribute.STANDARD_NAME+","+FileAttribute.STANDARD_TYPE, 0, cancellable);
var directories = new ArrayList<GLib.File> ();
diff --git a/plugins/vala-pack/ide-vala-source-file.vala b/plugins/vala-pack/ide-vala-source-file.vala
index 2a62294..996e9ad 100644
--- a/plugins/vala-pack/ide-vala-source-file.vala
+++ b/plugins/vala-pack/ide-vala-source-file.vala
@@ -36,14 +36,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-using GLib;
-using Ide;
using Vala;
-namespace Ide
-{
- public class ValaSourceFile: Vala.SourceFile
- {
+namespace Ide {
+ public class ValaSourceFile : Vala.SourceFile {
ArrayList<Ide.Diagnostic> diagnostics;
internal Ide.File file;
@@ -51,8 +47,7 @@ namespace Ide
Vala.SourceFileType type,
string filename,
string? content,
- bool cmdline)
- {
+ bool cmdline) {
base (context, type, filename, content, cmdline);
this.file = new Ide.File (null, GLib.File.new_for_path (filename));
@@ -64,13 +59,11 @@ namespace Ide
public bool dirty { get; set; }
- public GLib.File get_file ()
- {
+ public GLib.File get_file () {
return this.file.file;
}
- public void reset ()
- {
+ public void reset () {
this.diagnostics.clear ();
/* Copy the node list since we will be mutating while iterating */
@@ -99,8 +92,7 @@ namespace Ide
this.dirty = true;
}
- public void sync (GenericArray<Ide.UnsavedFile> unsaved_files)
- {
+ public void sync (GenericArray<Ide.UnsavedFile> unsaved_files) {
var gfile = this.file.file;
unsaved_files.foreach((unsaved_file) => {
if (unsaved_file.get_file ().equal (gfile)) {
@@ -117,8 +109,7 @@ namespace Ide
public void report (Vala.SourceReference source_reference,
string message,
- Ide.DiagnosticSeverity severity)
- {
+ Ide.DiagnosticSeverity severity) {
var begin = new Ide.SourceLocation (this.file,
source_reference.begin.line - 1,
source_reference.begin.column - 1,
@@ -133,8 +124,7 @@ namespace Ide
this.diagnostics.add (diag);
}
- public Ide.Diagnostics? diagnose ()
- {
+ public Ide.Diagnostics? diagnose () {
var ar = new GLib.GenericArray<Ide.Diagnostic> ();
foreach (var diag in this.diagnostics) {
ar.add (diag);
@@ -142,8 +132,7 @@ namespace Ide
return new Ide.Diagnostics (ar);
}
- void add_default_namespace ()
- {
+ void add_default_namespace () {
this.current_using_directives = new ArrayList<Vala.UsingDirective> ();
var unres = new Vala.UnresolvedSymbol (null, "GLib");
diff --git a/plugins/vala-pack/ide-vala-symbol-resolver.vala b/plugins/vala-pack/ide-vala-symbol-resolver.vala
index 200714a..0ac2efd 100644
--- a/plugins/vala-pack/ide-vala-symbol-resolver.vala
+++ b/plugins/vala-pack/ide-vala-symbol-resolver.vala
@@ -16,18 +16,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-using GLib;
-using Ide;
using Vala;
-namespace Ide
-{
- public class ValaSymbolResolver: Ide.Object, Ide.SymbolResolver
- {
+namespace Ide {
+ public class ValaSymbolResolver : Ide.Object, Ide.SymbolResolver {
public async Ide.SymbolTree? get_symbol_tree_async (GLib.File file,
- GLib.Cancellable? cancellable)
- throws GLib.Error
- {
+ Cancellable? cancellable) throws
GLib.Error {
var context = this.get_context ();
var service = (Ide.ValaService)context.get_service_typed (typeof (Ide.ValaService));
var index = service.index;
@@ -37,9 +31,7 @@ namespace Ide
}
public async Ide.Symbol? lookup_symbol_async (Ide.SourceLocation location,
- GLib.Cancellable? cancellable)
- throws GLib.Error
- {
+ Cancellable? cancellable) throws GLib.Error {
var context = this.get_context ();
var service = (Ide.ValaService)context.get_service_typed (typeof (Ide.ValaService));
var index = service.index;
@@ -51,29 +43,39 @@ namespace Ide
if (symbol != null) {
var kind = Ide.SymbolKind.NONE;
- if (symbol is Vala.Class) kind = Ide.SymbolKind.CLASS;
- else if (symbol is Vala.Subroutine) {
- if (symbol.is_instance_member ())
+ if (symbol is Vala.Class) {
+ kind = Ide.SymbolKind.CLASS;
+ } else if (symbol is Vala.Subroutine) {
+ if (symbol.is_instance_member ()) {
kind = Ide.SymbolKind.METHOD;
- else
+ } else {
kind = Ide.SymbolKind.FUNCTION;
+ }
+ } else if (symbol is Vala.Struct) {
+ kind = Ide.SymbolKind.STRUCT;
+ } else if (symbol is Vala.Field) {
+ kind = Ide.SymbolKind.FIELD;
+ } else if (symbol is Vala.Enum) {
+ kind = Ide.SymbolKind.ENUM;
+ } else if (symbol is Vala.EnumValue) {
+ kind = Ide.SymbolKind.ENUM_VALUE;
+ } else if (symbol is Vala.Variable) {
+ kind = Ide.SymbolKind.VARIABLE;
}
- else if (symbol is Vala.Struct) kind = Ide.SymbolKind.STRUCT;
- else if (symbol is Vala.Field) kind = Ide.SymbolKind.FIELD;
- else if (symbol is Vala.Enum) kind = Ide.SymbolKind.ENUM;
- else if (symbol is Vala.EnumValue) kind = Ide.SymbolKind.ENUM_VALUE;
- else if (symbol is Vala.Variable) kind = Ide.SymbolKind.VARIABLE;
var flags = Ide.SymbolFlags.NONE;
- if (symbol.is_instance_member ())
+ if (symbol.is_instance_member ()) {
flags |= Ide.SymbolFlags.IS_MEMBER;
+ }
var binding = get_member_binding (symbol);
- if (binding != null && binding == Vala.MemberBinding.STATIC)
+ if (binding != null && binding == Vala.MemberBinding.STATIC) {
flags |= Ide.SymbolFlags.IS_STATIC;
+ }
- if (symbol.deprecated)
+ if (symbol.deprecated) {
flags |= Ide.SymbolFlags.IS_DEPRECATED;
+ }
var source_reference = symbol.source_reference;
@@ -90,18 +92,22 @@ namespace Ide
}
// a member binding is Instance, Class, or Static
- private Vala.MemberBinding? get_member_binding (Vala.Symbol sym)
- {
- if (sym is Vala.Constructor)
+ private Vala.MemberBinding? get_member_binding (Vala.Symbol sym) {
+ if (sym is Vala.Constructor) {
return ((Vala.Constructor)sym).binding;
- if (sym is Vala.Destructor)
+ }
+ if (sym is Vala.Destructor) {
return ((Vala.Destructor)sym).binding;
- if (sym is Vala.Field)
+ }
+ if (sym is Vala.Field) {
return ((Vala.Field)sym).binding;
- if (sym is Vala.Method)
+ }
+ if (sym is Vala.Method) {
return ((Vala.Method)sym).binding;
- if (sym is Vala.Property)
+ }
+ if (sym is Vala.Property) {
return ((Vala.Property)sym).binding;
+ }
return null;
}
}
diff --git a/plugins/vala-pack/ide-vala-symbol-tree.vala b/plugins/vala-pack/ide-vala-symbol-tree.vala
index 272f12f..83b918b 100644
--- a/plugins/vala-pack/ide-vala-symbol-tree.vala
+++ b/plugins/vala-pack/ide-vala-symbol-tree.vala
@@ -16,19 +16,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-using GLib;
-using Ide;
using Vala;
-namespace Ide
-{
- public class ValaSymbolTreeVisitor: Vala.CodeVisitor
- {
+namespace Ide {
+ public class ValaSymbolTreeVisitor : Vala.CodeVisitor {
HashMap<Vala.CodeNode?,ArrayList<Vala.CodeNode>> table;
GLib.Queue<ArrayList<Vala.CodeNode>> queue;
- public ValaSymbolTreeVisitor ()
- {
+ public ValaSymbolTreeVisitor () {
this.table = new HashMap<Vala.CodeNode?,ArrayList<Vala.CodeNode>> ();
this.queue = new GLib.Queue<ArrayList<Vala.CodeNode>> ();
@@ -37,13 +32,11 @@ namespace Ide
this.queue.push_head (root);
}
- public Ide.SymbolTree? build_tree ()
- {
+ public Ide.SymbolTree? build_tree () {
return new Ide.ValaSymbolTree (this.table);
}
- void visit_generic (Vala.CodeNode node)
- {
+ void visit_generic (Vala.CodeNode node) {
var current = this.queue.peek_head ();
current.add (node);
@@ -72,19 +65,16 @@ namespace Ide
public override void visit_source_file (Vala.SourceFile source_file) {
source_file.accept_children (this); }
}
- public class ValaSymbolTree : GLib.Object, Ide.SymbolTree
- {
+ public class ValaSymbolTree : GLib.Object, Ide.SymbolTree {
HashMap<Vala.CodeNode?,ArrayList<Vala.CodeNode>> table;
- public ValaSymbolTree (HashMap<Vala.CodeNode?,ArrayList<Vala.CodeNode>> table)
- {
+ public ValaSymbolTree (HashMap<Vala.CodeNode?,ArrayList<Vala.CodeNode>> table) {
this.table = table;
debug ("Tree created with %u rows", table.size);
}
- ArrayList<Vala.CodeNode>? find (Ide.SymbolNode? node)
- {
+ ArrayList<Vala.CodeNode>? find (Ide.SymbolNode? node) {
Ide.ValaSymbolNode? symbol_node = (Ide.ValaSymbolNode)node;
Vala.CodeNode? key = null;
@@ -97,53 +87,51 @@ namespace Ide
return this.table [key];
}
- public uint get_n_children (Ide.SymbolNode? node)
- {
+ public uint get_n_children (Ide.SymbolNode? node) {
var list = find (node);
- if (list == null)
+ if (list == null) {
debug ("Failed to find child! %p", node);
- else
+ } else {
debug ("node has %u children.", list.size);
+ }
return list != null ? list.size : 0;
}
- public Ide.SymbolNode? get_nth_child (Ide.SymbolNode? node, uint nth)
- {
+ public Ide.SymbolNode? get_nth_child (Ide.SymbolNode? node, uint nth) {
var list = find (node);
- if (list != null && list.size > nth)
+ if (list != null && list.size > nth) {
return new Ide.ValaSymbolNode (list [(int)nth]);
+ }
return null;
}
}
- public class ValaSymbolNode : Ide.SymbolNode
- {
+ public class ValaSymbolNode : Ide.SymbolNode {
public Vala.CodeNode? node;
- public ValaSymbolNode (Vala.CodeNode node)
- {
+ public ValaSymbolNode (Vala.CodeNode node) {
this.node = node;
this.name = (node as Vala.Symbol).name;
this.kind = Ide.SymbolKind.NONE;
this.flags = Ide.SymbolFlags.NONE;
- if (node is Vala.Method)
+ if (node is Vala.Method) {
this.kind = Ide.SymbolKind.FUNCTION;
- else if (node is Vala.Class)
+ } else if (node is Vala.Class) {
this.kind = Ide.SymbolKind.CLASS;
- else if (node is Vala.Struct)
+ } else if (node is Vala.Struct) {
this.kind = Ide.SymbolKind.STRUCT;
- else if (node is Vala.Property)
+ } else if (node is Vala.Property) {
this.kind = Ide.SymbolKind.FIELD;
+ }
}
- public override Ide.SourceLocation? get_location ()
- {
+ public override Ide.SourceLocation? get_location () {
var source_reference = this.node.source_reference;
var file = (source_reference.file as Ide.ValaSourceFile).file;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]