RFR: 8341907: javac -Xlint should ignore /// on first line of source file [v2]
Jonathan Gibbons
jjg at openjdk.org
Thu Nov 7 20:17:43 UTC 2024
On Thu, 7 Nov 2024 20:13:03 GMT, Jonathan Gibbons <jjg at openjdk.org> wrote:
>> Computing line numbers is a relatively expensive operation, because the internal coordinates are character-offset based. That being said, there is a bunch of caching going on under the covers, and, the check can be guarded by the additional (proposed) check that the check is only suppressed if the comment begins at offset 0.
>
> Generally, the method you want is `DiagnosticSource.getLineNumber(int pos)`, which means you need a `DiagnosticSource` object. `JavacParser` (that is, this class) has a `Log log` member, and `[Abstract]Log` provides `currentSource()`, so to get the line number for a position it should be possible to use something like `log.currentSource().getLineNumber(pos)`, assuming that the current source is set up correctly at the time you need it.
> So, if a comment tree start and end position are on the same line that is also the first line of the file
The end position will always be after the start position, so you only need check if the line number of the end position of the comment is line 1. (Line numbers are 1-based.)
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/21923#discussion_r1833313690
More information about the compiler-dev
mailing list