Line data Source code
1 : /* valasourcereference.vala
2 : *
3 : * Copyright (C) 2006-2012 Jürg Billeter
4 : *
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.
9 :
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.
14 :
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
18 : *
19 : * Author:
20 : * Jürg Billeter <j@bitron.ch>
21 : */
22 :
23 : using GLib;
24 :
25 : /**
26 : * Represents a reference to a location in a source file.
27 : */
28 357896477 : public class Vala.SourceReference {
29 : /**
30 : * The source file to be referenced.
31 : */
32 189453349 : public weak SourceFile file { get; set; }
33 :
34 : /**
35 : * The begin of the referenced source code.
36 : */
37 102399046 : public SourceLocation begin { get; set; }
38 :
39 : /**
40 : * The end of the referenced source code.
41 : */
42 102882880 : public SourceLocation end { get; set; }
43 :
44 204544124 : public List<UsingDirective> using_directives { get; private set; }
45 :
46 : /**
47 : * Creates a new source reference.
48 : *
49 : * @param _file a source file
50 : * @param begin the begin of the referenced source code
51 : * @param end the end of the referenced source code
52 : * @return newly created source reference
53 : */
54 306801087 : public SourceReference (SourceFile _file, SourceLocation begin, SourceLocation end) {
55 102267029 : file = _file;
56 102267029 : this.begin = begin;
57 102267029 : this.end = end;
58 102267029 : using_directives = file.current_using_directives;
59 : }
60 :
61 : /**
62 : * Checks if given source location is part of this source reference.
63 : *
64 : * @param location a source location
65 : * @return whether this source location is part of this
66 : */
67 0 : public bool contains (SourceLocation location) {
68 0 : if (location.line > begin.line && location.line < end.line) {
69 0 : return true;
70 0 : } else if (location.line == begin.line && location.line == end.line) {
71 0 : return location.column >= begin.column && location.column <= end.column;
72 0 : } else if (location.line == begin.line) {
73 0 : return location.column >= begin.column;
74 0 : } else if (location.line == end.line) {
75 0 : return location.column <= end.column;
76 : } else {
77 0 : return false;
78 : }
79 : }
80 :
81 : /**
82 : * Returns a string representation of this source reference.
83 : *
84 : * @return human-readable string
85 : */
86 748 : public string to_string () {
87 748 : return ("%s:%d:%d-%d:%d".printf (file.get_relative_filename (), begin.line, begin.column, end.line, end.column));
88 : }
89 : }
|