1 /* valasourcereference.vala
3 * Copyright (C) 2006-2008 Jürg Billeter
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library 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 GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Jürg Billeter <j@bitron.ch>
26 * Represents a reference to a location in a source file.
28 public class Vala
.SourceReference
{
30 * The source file to be referenced.
32 public weak SourceFile file
{ get; set; }
35 * The first line number of the referenced source code.
37 public int first_line
{ get; set; }
40 * The first column number of the referenced source code.
42 public int first_column
{ get; set; }
45 * The last line number of the referenced source code.
47 public int last_line
{ get; set; }
50 * The last column number of the referenced source code.
52 public int last_column
{ get; set; }
55 * The text describing the referenced source code.
57 public string comment
{ get; set; }
60 * Creates a new source reference.
62 * @param file a source file
63 * @param first_line first line number
64 * @param first_column first column number
65 * @param last_line last line number
66 * @param last_column last column number
67 * @return newly created source reference
69 public SourceReference (SourceFile _file
, int _first_line
= 0, int _first_column
= 0, int _last_line
= 0, int _last_column
= 0) {
71 first_line
= _first_line
;
72 first_column
= _first_column
;
73 last_line
= _last_line
;
74 last_column
= _last_column
;
78 * Creates a new commented source reference.
80 * @param file a source file
81 * @param first_line first line number
82 * @param first_column first column number
83 * @param last_line last line number
84 * @param last_column last column number
85 * @param comment code comment
86 * @return newly created source reference
88 public SourceReference
.with_comment (SourceFile _file
, int _first_line
, int _first_column
, int _last_line
, int _last_column
, string? _comment
) {
90 first_line
= _first_line
;
91 first_column
= _first_column
;
92 last_line
= _last_line
;
93 last_column
= _last_column
;
98 * Returns a string representation of this source reference.
100 * @return human-readable string
102 public string to_string () {
103 return ("%s:%d.%d-%d.%d".printf (file
.get_relative_filename (), first_line
, first_column
, last_line
, last_column
));