Compute the end position of multi-line token only once

Description

Currently, we have different components in the java analyzer that compute the end position of a token, and each time in a different way (SonarComponents, InternalSyntaxToken, SyntaxHighlighterVisitor):

  • the majority does not support tokens on multiple lines

  • some support tokens on multiple lines but the result is not consistent with others

The improvement is:

  • compute only once the end position (line, column) of a token and expose its value on the SyntaxToken public API

  • try to be more explicit in the code about columns. Currently, SyntaxToken#column() start at 0 instead of 1 and there's often a mess of "+ 1" or "- 1" around. SonarJava's developers should be encouraged to always use the column number (starting at 1, the only one understood by our users) and should have access to the column offset (starting at 0, used for external integration like sonar-plugin-api) without computation.

Activity

Show:

Michael Gumowski August 30, 2021 at 3:35 PM

LGTM!

Fixed
Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Components

Fix versions

Priority

Sentry

Created August 26, 2021 at 12:25 PM
Updated October 16, 2024 at 2:08 PM
Resolved September 3, 2021 at 11:03 AM