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