Class InputLocation

java.lang.Object
org.apache.maven.api.settings.InputLocation
All Implemented Interfaces:
Serializable, InputLocationTracker

public final class InputLocation extends Object implements Serializable, InputLocationTracker
Represents the location of an element within a model source file.

This class tracks the line and column numbers of elements in source files like POM files. It's used for error reporting and debugging to help identify where specific model elements are defined in the source files.

Note: Starting with Maven 4.0.0, it is recommended to use the static factory methods of(...) instead of constructors. The constructors are deprecated and will be removed in a future version.

Since:
4.0.0
See Also:
  • Constructor Details

    • InputLocation

      @Deprecated public InputLocation(InputSource source)
      Deprecated.
      since 4.0.0-rc-6, use of(InputSource) instead
      Creates an InputLocation with only a source, no line/column information. The line and column numbers will be set to -1 (unknown).
      Parameters:
      source - the input source where this location originates from
    • InputLocation

      @Deprecated public InputLocation(int lineNumber, int columnNumber)
      Deprecated.
      since 4.0.0-rc-6, use of(int, int) instead
      Creates an InputLocation with line and column numbers but no source.
      Parameters:
      lineNumber - the line number in the source file (1-based)
      columnNumber - the column number in the source file (1-based)
    • InputLocation

      @Deprecated public InputLocation(int lineNumber, int columnNumber, InputSource source)
      Deprecated.
      since 4.0.0-rc-6, use of(int, int, InputSource) instead
      Creates an InputLocation with line number, column number, and source.
      Parameters:
      lineNumber - the line number in the source file (1-based)
      columnNumber - the column number in the source file (1-based)
      source - the input source where this location originates from
    • InputLocation

      @Deprecated public InputLocation(int lineNumber, int columnNumber, InputSource source, Object selfLocationKey)
      Deprecated.
      since 4.0.0-rc-6, use of(int, int, InputSource, Object) instead
      Creates an InputLocation with line number, column number, source, and a self-location key.
      Parameters:
      lineNumber - the line number in the source file (1-based)
      columnNumber - the column number in the source file (1-based)
      source - the input source where this location originates from
      selfLocationKey - the key to map this location to itself in the locations map
    • InputLocation

      @Deprecated public InputLocation(int lineNumber, int columnNumber, InputSource source, Map<Object, InputLocation> locations)
      Deprecated.
      since 4.0.0-rc-6, use of(int, int, InputSource, Map) instead
      Creates an InputLocation with line number, column number, source, and a complete locations map.
      Parameters:
      lineNumber - the line number in the source file (1-based)
      columnNumber - the column number in the source file (1-based)
      source - the input source where this location originates from
      locations - a map of keys to InputLocation instances for nested elements
  • Method Details

    • of

      public static InputLocation of(InputSource source)
      Creates an InputLocation with the specified source.
      Parameters:
      source - the input source
      Returns:
      a new InputLocation instance
      Since:
      4.0.0
    • of

      public static InputLocation of(int lineNumber, int columnNumber)
      Creates an InputLocation with the specified line and column numbers. The source and locations map will be null.
      Parameters:
      lineNumber - the line number in the source file (1-based)
      columnNumber - the column number in the source file (1-based)
      Returns:
      a new InputLocation instance
      Since:
      4.0.0
    • of

      public static InputLocation of(int lineNumber, int columnNumber, InputSource source)
      Creates an InputLocation with the specified line number, column number, and source. The locations map will be empty.
      Parameters:
      lineNumber - the line number in the source file (1-based)
      columnNumber - the column number in the source file (1-based)
      source - the input source where this location originates from
      Returns:
      a new InputLocation instance
      Since:
      4.0.0
    • of

      public static InputLocation of(int lineNumber, int columnNumber, InputSource source, Object selfLocationKey)
      Creates an InputLocation with the specified line number, column number, source, and a self-location key. The locations map will contain a single entry mapping the selfLocationKey to this location.
      Parameters:
      lineNumber - the line number in the source file (1-based)
      columnNumber - the column number in the source file (1-based)
      source - the input source where this location originates from
      selfLocationKey - the key to map this location to itself in the locations map
      Returns:
      a new InputLocation instance
      Since:
      4.0.0
    • of

      public static InputLocation of(int lineNumber, int columnNumber, InputSource source, Map<Object, InputLocation> locations)
      Creates an InputLocation with the specified line number, column number, source, and a complete locations map. This is typically used when merging or combining location information from multiple sources.
      Parameters:
      lineNumber - the line number in the source file (1-based)
      columnNumber - the column number in the source file (1-based)
      source - the input source where this location originates from
      locations - a map of keys to InputLocation instances for nested elements
      Returns:
      a new InputLocation instance
      Since:
      4.0.0
    • getLineNumber

      public int getLineNumber()
      Gets the one-based line number where this element is located in the source file.
      Returns:
      the line number, or -1 if unknown
    • getColumnNumber

      public int getColumnNumber()
      Gets the one-based column number where this element is located in the source file.
      Returns:
      the column number, or -1 if unknown
    • getSource

      public InputSource getSource()
      Gets the input source where this location originates from.
      Returns:
      the input source, or null if unknown
    • getLocation

      public InputLocation getLocation(Object key)
      Gets the InputLocation for a specific nested element key.
      Specified by:
      getLocation in interface InputLocationTracker
      Parameters:
      key - the key to look up
      Returns:
      the InputLocation for the specified key, or null if not found
    • getLocations

      public Map<Object, InputLocation> getLocations()
      Gets the map of nested element locations within this location.
      Returns:
      an immutable map of keys to InputLocation instances for nested elements
    • merge

      public static InputLocation merge(InputLocation target, InputLocation source, boolean sourceDominant)
      Merges the source location into the target location.
      Parameters:
      target - the target location
      source - the source location
      sourceDominant - the boolean indicating of source is dominant compared to target
      Returns:
      the merged location
    • merge

      public static InputLocation merge(InputLocation target, InputLocation source, Collection<Integer> indices)
      Merges the source location into the target location. This method is used when the locations refer to lists and also merges the indices.
      Parameters:
      target - the target location
      source - the source location
      indices - the list of integers for the indices
      Returns:
      the merged location