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 19:45:33 GMT, Jonathan Gibbons <jjg at openjdk.org> wrote:

>> Regex sounds simple and robust. However, I thought we could concoct a more idiomatic compiler solution, using trees, start and end diagnostic positions, and also line numbers.
>> 
>> So, if a comment tree start and end position are on the same line that is also the first line of the file, we don't output the warning. Can we do that?
>
> 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.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/21923#discussion_r1833311736


More information about the compiler-dev mailing list