View Javadoc
1   /*
2    Licensed to the Apache Software Foundation (ASF) under one
3    or more contributor license agreements.  See the NOTICE file
4    distributed with this work for additional information
5    regarding copyright ownership.  The ASF licenses this file
6    to you under the Apache License, Version 2.0 (the
7    "License"); you may not use this file except in compliance
8    with the License.  You may obtain a copy of the License at
9    
10       http://www.apache.org/licenses/LICENSE-2.0
11   
12   Unless required by applicable law or agreed to in writing,
13   software distributed under the License is distributed on an
14   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   KIND, either express or implied.  See the License for the
16   specific language governing permissions and limitations
17   under the License.
18   =================== DO NOT EDIT THIS FILE ====================
19   Generated by Modello 2.4.0,
20   any modifications will be overwritten.
21   ==============================================================
22   */
23  
24  package org.apache.maven.model;
25  
26  /**
27   * Class InputLocation.
28   * 
29   * @version $Revision$ $Date$
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       //- Class/Member Variables -/
38      //--------------------------/
39  
40      /**
41       * The one-based line number. The value will be non-positive if
42       * unknown.
43       */
44      private int lineNumber = -1;
45  
46      /**
47       * The one-based column number. The value will be non-positive
48       * if unknown.
49       */
50      private int columnNumber = -1;
51  
52      /**
53       * Field source.
54       */
55      private InputSource source;
56  
57      /**
58       * Field locations.
59       */
60      private java.util.Map<Object, InputLocation> locations;
61  
62      /**
63       * Field location.
64       */
65      private InputLocation location;
66  
67  
68        //----------------/
69       //- Constructors -/
70      //----------------/
71  
72      public InputLocation(int lineNumber, int columnNumber)
73      {
74          this.lineNumber = lineNumber;
75          this.columnNumber = columnNumber;
76      } //-- org.apache.maven.model.InputLocation(int, int)
77  
78      public InputLocation(int lineNumber, int columnNumber, InputSource source)
79      {
80          this.lineNumber = lineNumber;
81          this.columnNumber = columnNumber;
82          this.source = source;
83      } //-- org.apache.maven.model.InputLocation(int, int, InputSource)
84  
85  
86        //-----------/
87       //- Methods -/
88      //-----------/
89  
90      /**
91       * Method clone.
92       * 
93       * @return InputLocation
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     } //-- InputLocation clone()
114 
115     /**
116      * Get the one-based column number. The value will be
117      * non-positive if unknown.
118      * 
119      * @return int
120      */
121     public int getColumnNumber()
122     {
123         return this.columnNumber;
124     } //-- int getColumnNumber()
125 
126     /**
127      * Get the one-based line number. The value will be
128      * non-positive if unknown.
129      * 
130      * @return int
131      */
132     public int getLineNumber()
133     {
134         return this.lineNumber;
135     } //-- int getLineNumber()
136 
137     /**
138      * 
139      * 
140      * @param key a key object.
141      * @return InputLocation
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     } //-- InputLocation getLocation( Object )
164 
165     /**
166      * 
167      * 
168      * @return Map
169      */
170     public java.util.Map<Object, InputLocation> getLocations()
171     {
172         return locations;
173     } //-- java.util.Map<Object, InputLocation> getLocations()
174 
175     /**
176      * 
177      * 
178      * @param key a key object.
179      * @param location a location object.
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     } //-- void setLocation( Object, InputLocation )
204 
205     /**
206      * 
207      * 
208      * @param key a key object.
209      * @param location a location object.
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     } //-- void setOtherLocation( Object, InputLocation )
222 
223     /**
224      * 
225      * 
226      * @param key a key object.
227      * @return InputLocation
228      */
229     private InputLocation getOtherLocation( Object key )
230     {
231         return ( locations != null ) ? locations.get( key ) : null;
232     } //-- InputLocation getOtherLocation( Object )
233 
234     /**
235      * Get the source field.
236      * 
237      * @return InputSource
238      */
239     public InputSource getSource()
240     {
241         return this.source;
242     } //-- InputSource getSource()
243 
244     /**
245      * Method merge.
246      * 
247      * @param target a target object.
248      * @param sourceDominant a sourceDominant object.
249      * @param source a source object.
250      * @return InputLocation
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     } //-- InputLocation merge( InputLocation, InputLocation, boolean )
287 
288     /**
289      * Method merge.
290      * 
291      * @param target a target object.
292      * @param indices a indices object.
293      * @param source a source object.
294      * @return InputLocation
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     } //-- InputLocation merge( InputLocation, InputLocation, java.util.Collection )
343 
344     /**
345      * 
346      * 
347      * @param locations a locations object.
348      */
349     public void setLocations( java.util.Map<Object, InputLocation> locations )
350     {
351         this.locations = locations;
352     } //-- void setLocations( java.util.Map )
353 
354 
355       //-----------------/
356      //- Inner Classes -/
357     //-----------------/
358 
359     /**
360      * Class StringFormatter.
361      * 
362      * @version $Revision$ $Date$
363      */
364     public abstract static class StringFormatter
365     {
366 
367           //-----------/
368          //- Methods -/
369         //-----------/
370 
371         /**
372          * Method toString.
373          * 
374          * @param location a location object.
375          * @return String
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 }