View Javadoc
1   // =================== DO NOT EDIT THIS FILE ====================
2   // Generated by Modello 1.11,
3   // any modifications will be overwritten.
4   // ==============================================================
5   
6   package org.apache.maven.model;
7   
8   /**
9    * Class InputLocation.
10   * 
11   * @version $Revision$ $Date$
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       //- Class/Member Variables -/
20      //--------------------------/
21  
22      /**
23       * The one-based line number. The value will be non-positive if
24       * unknown.
25       */
26      private int lineNumber = -1;
27  
28      /**
29       * The one-based column number. The value will be non-positive
30       * if unknown.
31       */
32      private int columnNumber = -1;
33  
34      /**
35       * Field source.
36       */
37      private InputSource source;
38  
39      /**
40       * Field locations.
41       */
42      private java.util.Map<Object, InputLocation> locations;
43  
44      /**
45       * Field location.
46       */
47      private InputLocation location;
48  
49  
50        //----------------/
51       //- Constructors -/
52      //----------------/
53  
54      public InputLocation(int lineNumber, int columnNumber)
55      {
56          this.lineNumber = lineNumber;
57          this.columnNumber = columnNumber;
58      } //-- org.apache.maven.model.InputLocation(int, int)
59  
60      public InputLocation(int lineNumber, int columnNumber, InputSource source)
61      {
62          this.lineNumber = lineNumber;
63          this.columnNumber = columnNumber;
64          this.source = source;
65      } //-- org.apache.maven.model.InputLocation(int, int, InputSource)
66  
67  
68        //-----------/
69       //- Methods -/
70      //-----------/
71  
72      /**
73       * Method clone.
74       * 
75       * @return InputLocation
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      } //-- InputLocation clone()
96  
97      /**
98       * Get the one-based column number. The value will be
99       * non-positive if unknown.
100      * 
101      * @return int
102      */
103     public int getColumnNumber()
104     {
105         return this.columnNumber;
106     } //-- int getColumnNumber()
107 
108     /**
109      * Get the one-based line number. The value will be
110      * non-positive if unknown.
111      * 
112      * @return int
113      */
114     public int getLineNumber()
115     {
116         return this.lineNumber;
117     } //-- int getLineNumber()
118 
119     /**
120      * 
121      * 
122      * @param key
123      * @return InputLocation
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     } //-- InputLocation getLocation( Object )
146 
147     /**
148      * 
149      * 
150      * @return Map
151      */
152     public java.util.Map<Object, InputLocation> getLocations()
153     {
154         return locations;
155     } //-- java.util.Map<Object, InputLocation> getLocations()
156 
157     /**
158      * 
159      * 
160      * @param key
161      * @param location
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     } //-- void setLocation( Object, InputLocation )
186 
187     /**
188      * 
189      * 
190      * @param key
191      * @param location
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     } //-- void setOtherLocation( Object, InputLocation )
204 
205     /**
206      * 
207      * 
208      * @param key
209      * @return InputLocation
210      */
211     private InputLocation getOtherLocation( Object key )
212     {
213         return ( locations != null ) ? locations.get( key ) : null;
214     } //-- InputLocation getOtherLocation( Object )
215 
216     /**
217      * Get the source field.
218      * 
219      * @return InputSource
220      */
221     public InputSource getSource()
222     {
223         return this.source;
224     } //-- InputSource getSource()
225 
226     /**
227      * Method merge.
228      * 
229      * @param target
230      * @param sourceDominant
231      * @param source
232      * @return InputLocation
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     } //-- InputLocation merge( InputLocation, InputLocation, boolean )
269 
270     /**
271      * Method merge.
272      * 
273      * @param target
274      * @param indices
275      * @param source
276      * @return InputLocation
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     } //-- InputLocation merge( InputLocation, InputLocation, java.util.Collection )
325 
326     /**
327      * 
328      * 
329      * @param locations
330      */
331     public void setLocations( java.util.Map<Object, InputLocation> locations )
332     {
333         this.locations = locations;
334     } //-- void setLocations( java.util.Map )
335 
336 
337       //-----------------/
338      //- Inner Classes -/
339     //-----------------/
340 
341     /**
342      * Class StringFormatter.
343      * 
344      * @version $Revision$ $Date$
345      */
346     public abstract static class StringFormatter
347     {
348 
349           //-----------/
350          //- Methods -/
351         //-----------/
352 
353         /**
354          * Method toString.
355          * 
356          * @param location
357          * @return String
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 }