1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.apache.maven.model;
25
26
27
28
29
30
31 @SuppressWarnings( "all" )
32 public final class InputLocation
33 implements java.io.Serializable, java.lang.Cloneable, org.apache.maven.model.InputLocationTracker
34 {
35
36
37
38
39
40
41
42
43
44 private int lineNumber = -1;
45
46
47
48
49
50 private int columnNumber = -1;
51
52
53
54
55 private InputSource source;
56
57
58
59
60 private java.util.Map<Object, InputLocation> locations;
61
62
63
64
65 private InputLocation location;
66
67
68
69
70
71
72 public InputLocation(int lineNumber, int columnNumber)
73 {
74 this.lineNumber = lineNumber;
75 this.columnNumber = columnNumber;
76 }
77
78 public InputLocation(int lineNumber, int columnNumber, InputSource source)
79 {
80 this.lineNumber = lineNumber;
81 this.columnNumber = columnNumber;
82 this.source = source;
83 }
84
85
86
87
88
89
90
91
92
93
94
95 public InputLocation clone()
96 {
97 try
98 {
99 InputLocation copy = (InputLocation) super.clone();
100
101 if ( copy.locations != null )
102 {
103 copy.locations = new java.util.LinkedHashMap( copy.locations );
104 }
105
106 return copy;
107 }
108 catch ( java.lang.Exception ex )
109 {
110 throw (java.lang.RuntimeException) new java.lang.UnsupportedOperationException( getClass().getName()
111 + " does not support clone()" ).initCause( ex );
112 }
113 }
114
115
116
117
118
119
120
121 public int getColumnNumber()
122 {
123 return this.columnNumber;
124 }
125
126
127
128
129
130
131
132 public int getLineNumber()
133 {
134 return this.lineNumber;
135 }
136
137
138
139
140
141
142
143 public InputLocation getLocation( Object key )
144 {
145 if ( key instanceof String )
146 {
147 switch ( ( String ) key )
148 {
149 case "" :
150 {
151 return this.location;
152 }
153 default :
154 {
155 return getOtherLocation( key );
156 }
157 }
158 }
159 else
160 {
161 return getOtherLocation( key );
162 }
163 }
164
165
166
167
168
169
170 public java.util.Map<Object, InputLocation> getLocations()
171 {
172 return locations;
173 }
174
175
176
177
178
179
180
181 public void setLocation( Object key, InputLocation location )
182 {
183 if ( key instanceof String )
184 {
185 switch ( ( String ) key )
186 {
187 case "" :
188 {
189 this.location = location;
190 return;
191 }
192 default :
193 {
194 setOtherLocation( key, location );
195 return;
196 }
197 }
198 }
199 else
200 {
201 setOtherLocation( key, location );
202 }
203 }
204
205
206
207
208
209
210
211 public void setOtherLocation( Object key, InputLocation location )
212 {
213 if ( location != null )
214 {
215 if ( this.locations == null )
216 {
217 this.locations = new java.util.LinkedHashMap<Object, InputLocation>();
218 }
219 this.locations.put( key, location );
220 }
221 }
222
223
224
225
226
227
228
229 private InputLocation getOtherLocation( Object key )
230 {
231 return ( locations != null ) ? locations.get( key ) : null;
232 }
233
234
235
236
237
238
239 public InputSource getSource()
240 {
241 return this.source;
242 }
243
244
245
246
247
248
249
250
251
252 public static InputLocation merge( InputLocation target, InputLocation source, boolean sourceDominant )
253 {
254 if ( source == null )
255 {
256 return target;
257 }
258 else if ( target == null )
259 {
260 return source;
261 }
262
263 InputLocation result =
264 new InputLocation( target.getLineNumber(), target.getColumnNumber(), target.getSource() );
265
266 java.util.Map<Object, InputLocation> locations;
267 java.util.Map<Object, InputLocation> sourceLocations = source.getLocations();
268 java.util.Map<Object, InputLocation> targetLocations = target.getLocations();
269 if ( sourceLocations == null )
270 {
271 locations = targetLocations;
272 }
273 else if ( targetLocations == null )
274 {
275 locations = sourceLocations;
276 }
277 else
278 {
279 locations = new java.util.LinkedHashMap();
280 locations.putAll( sourceDominant ? targetLocations : sourceLocations );
281 locations.putAll( sourceDominant ? sourceLocations : targetLocations );
282 }
283 result.setLocations( locations );
284
285 return result;
286 }
287
288
289
290
291
292
293
294
295
296 public static InputLocation merge( InputLocation target, InputLocation source, java.util.Collection<Integer> indices )
297 {
298 if ( source == null )
299 {
300 return target;
301 }
302 else if ( target == null )
303 {
304 return source;
305 }
306
307 InputLocation result =
308 new InputLocation( target.getLineNumber(), target.getColumnNumber(), target.getSource() );
309
310 java.util.Map<Object, InputLocation> locations;
311 java.util.Map<Object, InputLocation> sourceLocations = source.getLocations();
312 java.util.Map<Object, InputLocation> targetLocations = target.getLocations();
313 if ( sourceLocations == null )
314 {
315 locations = targetLocations;
316 }
317 else if ( targetLocations == null )
318 {
319 locations = sourceLocations;
320 }
321 else
322 {
323 locations = new java.util.LinkedHashMap<Object, InputLocation>();
324 for ( java.util.Iterator<Integer> it = indices.iterator(); it.hasNext(); )
325 {
326 InputLocation location;
327 Integer index = it.next();
328 if ( index.intValue() < 0 )
329 {
330 location = sourceLocations.get(Integer.valueOf(~index.intValue()));
331 }
332 else
333 {
334 location = targetLocations.get( index );
335 }
336 locations.put(Integer.valueOf(locations.size()), location);
337 }
338 }
339 result.setLocations( locations );
340
341 return result;
342 }
343
344
345
346
347
348
349 public void setLocations( java.util.Map<Object, InputLocation> locations )
350 {
351 this.locations = locations;
352 }
353
354
355
356
357
358
359
360
361
362
363
364 public abstract static class StringFormatter
365 {
366
367
368
369
370
371
372
373
374
375
376
377 public abstract String toString( InputLocation location );
378
379 }
380
381
382
383
384 @Override
385 public String toString()
386 {
387 return getLineNumber() + " : " + getColumnNumber() + ", " + getSource();
388 }
389
390
391 }