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