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
48
49 public InputLocation(int lineNumber, int columnNumber)
50 {
51 this.lineNumber = lineNumber;
52 this.columnNumber = columnNumber;
53 }
54
55 public InputLocation(int lineNumber, int columnNumber, InputSource source)
56 {
57 this.lineNumber = lineNumber;
58 this.columnNumber = columnNumber;
59 this.source = source;
60 }
61
62
63
64
65
66
67
68
69
70
71
72 public InputLocation clone()
73 {
74 try
75 {
76 InputLocation copy = (InputLocation) super.clone();
77
78 if ( copy.locations != null )
79 {
80 copy.locations = new java.util.LinkedHashMap( copy.locations );
81 }
82
83 return copy;
84 }
85 catch ( java.lang.Exception ex )
86 {
87 throw (java.lang.RuntimeException) new java.lang.UnsupportedOperationException( getClass().getName()
88 + " does not support clone()" ).initCause( ex );
89 }
90 }
91
92
93
94
95
96
97
98 public int getColumnNumber()
99 {
100 return this.columnNumber;
101 }
102
103
104
105
106
107
108
109 public int getLineNumber()
110 {
111 return this.lineNumber;
112 }
113
114
115
116
117
118
119
120 public InputLocation getLocation( Object key )
121 {
122 return ( locations != null ) ? locations.get( key ) : null;
123 }
124
125
126
127
128
129
130 public java.util.Map<Object, InputLocation> getLocations()
131 {
132 return locations;
133 }
134
135
136
137
138
139
140 public InputSource getSource()
141 {
142 return this.source;
143 }
144
145
146
147
148
149
150
151
152
153 public static InputLocation merge( InputLocation target, InputLocation source, boolean sourceDominant )
154 {
155 if ( source == null )
156 {
157 return target;
158 }
159 else if ( target == null )
160 {
161 return source;
162 }
163
164 InputLocation result =
165 new InputLocation( target.getLineNumber(), target.getColumnNumber(), target.getSource() );
166
167 java.util.Map<Object, InputLocation> locations;
168 java.util.Map<Object, InputLocation> sourceLocations = source.getLocations();
169 java.util.Map<Object, InputLocation> targetLocations = target.getLocations();
170 if ( sourceLocations == null )
171 {
172 locations = targetLocations;
173 }
174 else if ( targetLocations == null )
175 {
176 locations = sourceLocations;
177 }
178 else
179 {
180 locations = new java.util.LinkedHashMap();
181 locations.putAll( sourceDominant ? targetLocations : sourceLocations );
182 locations.putAll( sourceDominant ? sourceLocations : targetLocations );
183 }
184 result.setLocations( locations );
185
186 return result;
187 }
188
189
190
191
192
193
194
195
196
197 public static InputLocation merge( InputLocation target, InputLocation source, java.util.Collection<Integer> indices )
198 {
199 if ( source == null )
200 {
201 return target;
202 }
203 else if ( target == null )
204 {
205 return source;
206 }
207
208 InputLocation result =
209 new InputLocation( target.getLineNumber(), target.getColumnNumber(), target.getSource() );
210
211 java.util.Map<Object, InputLocation> locations;
212 java.util.Map<Object, InputLocation> sourceLocations = source.getLocations();
213 java.util.Map<Object, InputLocation> targetLocations = target.getLocations();
214 if ( sourceLocations == null )
215 {
216 locations = targetLocations;
217 }
218 else if ( targetLocations == null )
219 {
220 locations = sourceLocations;
221 }
222 else
223 {
224 locations = new java.util.LinkedHashMap<Object, InputLocation>();
225 for ( java.util.Iterator<Integer> it = indices.iterator(); it.hasNext(); )
226 {
227 InputLocation location;
228 Integer index = it.next();
229 if ( index.intValue() < 0 )
230 {
231 location = sourceLocations.get( Integer.valueOf( ~index.intValue() ) );
232 }
233 else
234 {
235 location = targetLocations.get( index );
236 }
237 locations.put( Integer.valueOf( locations.size() ), location );
238 }
239 }
240 result.setLocations( locations );
241
242 return result;
243 }
244
245
246
247
248
249
250
251 public void setLocation( Object key, InputLocation location )
252 {
253 if ( location != null )
254 {
255 if ( this.locations == null )
256 {
257 this.locations = new java.util.LinkedHashMap<Object, InputLocation>();
258 }
259 this.locations.put( key, location );
260 }
261 }
262
263
264
265
266
267
268 public void setLocations( java.util.Map<Object, InputLocation> locations )
269 {
270 this.locations = locations;
271 }
272
273
274
275
276 @Override
277 public String toString()
278 {
279 return getLineNumber() + " : " + getColumnNumber() + ", " + getSource();
280 }
281
282
283 }