RFR: 8350212: Track source end positions of declarations that support @SuppressWarnings [v4]

Maurizio Cimadamore mcimadamore at openjdk.org
Wed Apr 9 08:56:41 UTC 2025


On Tue, 8 Apr 2025 19:51:36 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:

>> This PR is a sub-task split off from [JDK-8224228](https://bugs.openjdk.org/browse/JDK-8224228), which seeks to add `@SuppressWarnings` support for lexical features.
>> 
>> Lexical features don't know about classes, members or symbols, so their source file positions must be matched to the source file character offset range of the innermost containing `JCModuleDecl`, `JCPackageDecl`, `JCClassDecl`, `JCMethodDecl`, or `JCVariableDecl`. That means we need the end positions of all such declarations to be available.
>> 
>> The parser doesn't normally store lexical end positions unless explicitly requested, and we don't want to mandate it for performance reasons.
>> 
>> Instead, we can just add an `int endPos` field to these five AST nodes. This field can be populated as part of the normal parsing of these node types, which already supports the (optional) tracking of end positions.
>
> Archie Cobbs has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Refactoring/cleanup for handling of ending positions.

I'll leave this to @lahodaj . In my opinion the removal of the `endpos` field in `JCSwitch` adds more code than it removes -- because of that `TreeInfo.endPos` needs a new `EndPosTable` parameter, which means `Flow`/`Lower`/`TransPatterns` needs additional logic to set the end pos table. It's not a complex rewriting, but given that we kind of know we're going to put our hands in here again, I wonder if there could be some merit in being more minimal/pragmatic.

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

PR Review: https://git.openjdk.org/jdk/pull/23669#pullrequestreview-2752637943


More information about the compiler-dev mailing list