Package org.apache.maven.api.toolchain
Class InputLocation
java.lang.Object
org.apache.maven.api.toolchain.InputLocation
- All Implemented Interfaces:
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 Summary
Modifier and TypeMethodDescriptionintGets the one-based column number where this element is located in the source file.Gets the parent InputLocation where this InputLocation may have been imported from.intGets the one-based line number where this element is located in the source file.getLocation(Object key) Gets the InputLocation for a specific nested element key.Gets the map of nested element locations within this location.Gets the input source where this location originates from.static InputLocationmerge(InputLocation target, InputLocation source, boolean sourceDominant) Merges thesourcelocation into thetargetlocation.static InputLocationmerge(InputLocation target, InputLocation source, Collection<Integer> indices) Merges thesourcelocation into thetargetlocation.static InputLocationof()Creates an empty InputLocation with no line/column information.static InputLocationof(int lineNumber, int columnNumber) Creates an InputLocation with the specified line and column numbers.static InputLocationof(int lineNumber, int columnNumber, InputSource source) Creates an InputLocation with the specified line number, column number, and source.static InputLocationof(int lineNumber, int columnNumber, InputSource source, Object selfLocationKey) Creates an InputLocation with the specified line number, column number, source, and a self-location key.static InputLocationof(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.toString()
-
Method Details
-
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
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
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 fromselfLocationKey- 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 fromlocations- 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
Gets the input source where this location originates from.- Returns:
- the input source, or null if unknown
-
getLocation
Gets the InputLocation for a specific nested element key.- Specified by:
getLocationin interfaceInputLocationTracker- Parameters:
key- the key to look up- Returns:
- the InputLocation for the specified key, or null if not found
-
getLocations
Gets the map of nested element locations within this location.- Returns:
- an immutable map of keys to InputLocation instances for nested elements
-
getImportedFrom
Gets the parent InputLocation where this InputLocation may have been imported from. Can returnnull.- Specified by:
getImportedFromin interfaceInputLocationTracker- Returns:
- InputLocation
- Since:
- 4.0.0
-
merge
public static InputLocation merge(InputLocation target, InputLocation source, boolean sourceDominant) Merges thesourcelocation into thetargetlocation.- Parameters:
target- the target locationsource- the source locationsourceDominant- the boolean indicating ofsourceis dominant compared totarget- Returns:
- the merged location
-
merge
public static InputLocation merge(InputLocation target, InputLocation source, Collection<Integer> indices) Merges thesourcelocation into thetargetlocation. This method is used when the locations refer to lists and also merges the indices.- Parameters:
target- the target locationsource- the source locationindices- the list of integers for the indices- Returns:
- the merged location
-
toString
-