Class InputLocation

java.lang.Object
org.apache.maven.api.toolchain.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. The class supports nested location tracking through a locations map that can contain InputLocation instances for child elements.

InputLocation instances are immutable and can be safely shared across threads. Factory methods are provided for convenient creation of instances with different combinations of location information.

Since:
4.0.0
See Also:
  • Method Details

    • of

      public static InputLocation of()
      Creates an empty InputLocation with no line/column information. This is a singleton instance representing an unknown or unspecified location.
      Returns:
      an empty InputLocation instance
    • 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
    • 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
    • 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
    • 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
    • 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
    • getImportedFrom

      public InputLocation getImportedFrom()
      Gets the parent InputLocation where this InputLocation may have been imported from. Can return null.
      Specified by:
      getImportedFrom in interface InputLocationTracker
      Returns:
      InputLocation
      Since:
      4.0.0
    • 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
    • toString

      public String toString()
      Overrides:
      toString in class Object