gnodet opened a new pull request, #11402:
URL: https://github.com/apache/maven/pull/11402
## Problem
The `XMLStreamReader.getLocation()` method returns the position **after**
the start tag has been parsed (after the `>` character), which is
counterintuitive for users who expect locations to point to where the tag
begins (at the `<` character).
This makes error messages and debugging more difficult as the reported
location doesn't match the intuitive expectation of where an element starts in
the XML file.
## Solution
This PR adds a helper method `getStartTagColumnNumber()` that calculates the
approximate start position by:
- Computing the length of the opening tag including:
- The `<` character
- Element name (with namespace prefix if present)
- All attributes (names, values, quotes, spaces)
- The closing `>` character
- Subtracting this length from the current column position to estimate the
`<` position
## Changes
### Modified Files
1. **src/mdo/reader-stax.vm**
- Added `getStartTagColumnNumber()` helper method
- Updated all `InputLocation.of()` calls to use the adjusted column number
- Fixed location capture for properties to occur before `nextText()`
moves the parser
2.
**impl/maven-support/src/test/java/org/apache/maven/model/v4/MavenStaxReaderTest.java**
- Added `testLocationReportingForElements()` - tests regular elements
- Added `testLocationReportingForAttributes()` - tests elements with
attributes
- Added `testLocationReportingForListElements()` - tests list elements
(modules)
## Testing
All tests pass successfully:
- ✅ 10 tests in MavenStaxReaderTest
- ✅ Location reporting now points to correct line numbers
- ✅ Column numbers provide reasonable approximation of tag start position
- ✅ Works correctly for nested elements, lists, and properties
## Benefits
- More intuitive location information for error reporting
- Better debugging experience
- Locations now match user expectations of where XML elements begin
---
Pull Request opened by [Augment Code](https://www.augmentcode.com/) with
guidance from the PR author
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]