|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| package koala.dynamicjava.tree; |
|
66 |
| |
|
67 |
| import java.io.*; |
|
68 |
| |
|
69 |
| import edu.rice.cs.plt.object.ObjectUtil; |
|
70 |
| import edu.rice.cs.plt.tuple.Option; |
|
71 |
| |
|
72 |
| |
|
73 |
| public final class SourceInfo implements Comparable<SourceInfo> { |
|
74 |
| |
|
75 |
| public interface Wrapper { |
|
76 |
| SourceInfo getSourceInfo(); |
|
77 |
| } |
|
78 |
| |
|
79 |
| public static final SourceInfo NONE = new SourceInfo(Option.<File>none(), 0, 0, 0, 0); |
|
80 |
| |
|
81 |
1848
| public static SourceInfo point(File f, int line, int column) {
|
|
82 |
1848
| return new SourceInfo(Option.wrap(f), line, column, line, column);
|
|
83 |
| } |
|
84 |
| |
|
85 |
9284
| public static SourceInfo range(File f, int startLine, int startColumn, int endLine, int endColumn) {
|
|
86 |
9284
| return new SourceInfo(Option.wrap(f), startLine, startColumn, endLine, endColumn);
|
|
87 |
| } |
|
88 |
| |
|
89 |
4733
| public static SourceInfo extend(SourceInfo si, int endLine, int endColumn) {
|
|
90 |
4733
| return new SourceInfo(si._file, si._startLine, si._startColumn, endLine, endColumn);
|
|
91 |
| } |
|
92 |
| |
|
93 |
4733
| public static SourceInfo extend(Wrapper wrapper, int endLine, int endColumn) {
|
|
94 |
4733
| return extend(wrapper.getSourceInfo(), endLine, endColumn);
|
|
95 |
| } |
|
96 |
| |
|
97 |
1074
| public static SourceInfo prepend(int startLine, int startColumn, SourceInfo si) {
|
|
98 |
1074
| return new SourceInfo(si._file, startLine, startColumn, si._endLine, si._endColumn);
|
|
99 |
| } |
|
100 |
| |
|
101 |
1074
| public static SourceInfo prepend(int startLine, int startColumn, Wrapper wrapper) {
|
|
102 |
1074
| return prepend(startLine, startColumn, wrapper.getSourceInfo());
|
|
103 |
| } |
|
104 |
| |
|
105 |
1513
| public static SourceInfo span(SourceInfo first, SourceInfo second) {
|
|
106 |
1513
| assert ObjectUtil.equal(first._file, second._file);
|
|
107 |
1513
| return new SourceInfo(first._file, first._startLine, first._startColumn, second._endLine, second._endColumn);
|
|
108 |
| } |
|
109 |
| |
|
110 |
0
| public static SourceInfo span(SourceInfo first, Wrapper second) {
|
|
111 |
0
| return span(first, second.getSourceInfo());
|
|
112 |
| } |
|
113 |
| |
|
114 |
0
| public static SourceInfo span(Wrapper first, SourceInfo second) {
|
|
115 |
0
| return span(first.getSourceInfo(), second);
|
|
116 |
| } |
|
117 |
| |
|
118 |
1509
| public static SourceInfo span(Wrapper first, Wrapper second) {
|
|
119 |
1509
| return span(first.getSourceInfo(), second.getSourceInfo());
|
|
120 |
| } |
|
121 |
| |
|
122 |
| |
|
123 |
| |
|
124 |
| |
|
125 |
| private final Option<File> _file; |
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
| |
|
130 |
| private final int _startLine; |
|
131 |
| |
|
132 |
| |
|
133 |
| |
|
134 |
| |
|
135 |
| private final int _startColumn; |
|
136 |
| |
|
137 |
| |
|
138 |
| |
|
139 |
| |
|
140 |
| private final int _endLine; |
|
141 |
| |
|
142 |
| |
|
143 |
| |
|
144 |
| |
|
145 |
| private final int _endColumn; |
|
146 |
| |
|
147 |
18455
| private SourceInfo(Option<File> file, int startLine, int startColumn, int endLine, int endColumn) {
|
|
148 |
18455
| _file = file;
|
|
149 |
18455
| _startLine = startLine;
|
|
150 |
18455
| _startColumn = startColumn;
|
|
151 |
18455
| _endLine = endLine;
|
|
152 |
18455
| _endColumn = endColumn;
|
|
153 |
| } |
|
154 |
| |
|
155 |
| |
|
156 |
0
| public File getFile() { return _file.unwrap(null); }
|
|
157 |
| |
|
158 |
| |
|
159 |
0
| public String getFilename() { return _file.isNone() ? "(no file)" : _file.unwrap().getPath(); }
|
|
160 |
| |
|
161 |
0
| public int getStartLine() { return _startLine; }
|
|
162 |
0
| public int getStartColumn() { return _startColumn; }
|
|
163 |
0
| public int getEndLine() { return _endLine; }
|
|
164 |
0
| public int getEndColumn() { return _endColumn; }
|
|
165 |
| |
|
166 |
| |
|
167 |
| |
|
168 |
| |
|
169 |
| |
|
170 |
| |
|
171 |
| |
|
172 |
0
| public String toString() {
|
|
173 |
0
| return "[" + getFilename() + ": " +
|
|
174 |
| "(" + _startLine + "," + _startColumn + ")-" + |
|
175 |
| "(" + _endLine + "," + _endColumn + ")]"; |
|
176 |
| } |
|
177 |
| |
|
178 |
| |
|
179 |
| |
|
180 |
| |
|
181 |
| |
|
182 |
| |
|
183 |
| |
|
184 |
| |
|
185 |
| |
|
186 |
0
| @Override public boolean equals(Object obj) {
|
|
187 |
0
| if (obj == null || obj.getClass() != this.getClass()) {
|
|
188 |
0
| return false;
|
|
189 |
| } |
|
190 |
| else { |
|
191 |
0
| SourceInfo casted = (SourceInfo) obj;
|
|
192 |
0
| return
|
|
193 |
| this._file.equals(casted._file) && |
|
194 |
| this._startLine == casted._startLine && |
|
195 |
| this._startColumn == casted._startColumn && |
|
196 |
| this._endLine == casted._endLine && |
|
197 |
| this._endColumn == casted._endColumn; |
|
198 |
| } |
|
199 |
| } |
|
200 |
| |
|
201 |
0
| @Override public int hashCode() {
|
|
202 |
0
| return ObjectUtil.hash(getClass(), _file, _startLine, _startColumn, _endLine, _endColumn);
|
|
203 |
| } |
|
204 |
| |
|
205 |
0
| public int compareTo(SourceInfo that) {
|
|
206 |
0
| int result = Option.<File>comparator().compare(this._file, that._file);
|
|
207 |
0
| if (result == 0) {
|
|
208 |
0
| result = ObjectUtil.compare(this._startLine, that._startLine,
|
|
209 |
| this._startColumn, that._startColumn, |
|
210 |
| this._endLine, that._endLine, |
|
211 |
| this._endColumn, that._endColumn); |
|
212 |
| } |
|
213 |
0
| return result;
|
|
214 |
| } |
|
215 |
| |
|
216 |
| } |