RFR: 8372948: Store end positions directly in JCTree [v6]

Liam Miller-Cushon cushon at openjdk.org
Mon Jan 26 19:34:03 UTC 2026


On Mon, 26 Jan 2026 19:14:59 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>>> As part of this change it would be perhaps helpful to at least simplify the method so that "unreachable cases" are removed?
>> 
>> I double checked that `test/langtools/tools/javac/tree/TreePosTest.java` is exercising all of the cases in the switch here except for `TOPLEVEL` and `ERRONEOUS`, which I think my be gaps in test coverage rather than truly dead code. Do you see more unreachable cases here that I'm missing?
>> 
>>> (longer term, (as discussed offline with @lahodaj ) I think it would be nice to have end positions set up correctly by parser for all trees, since now it doesn't cost extra to do so)
>> 
>> That sounds like a good direction to me!
>> 
>> I was also wondering how feasible it would be to make the `pos`/`endpos` fields field final, instead of having the parser set them after the instances are constructed, but I haven't looked closely at how much refactoring that would take.
>
> `TreePosTest` exercises all code shapes that are present within all javac tests (I think). In practice, I think that should account for basically all the cases in the switch -- given that the compiler will have at least some tests for each of the trees involved (I hope!!)

Ok, thanks! So if I'm understanding, the cases in the switch are currently necessary, and longer term cases can be removed as the parser is updated to store end positions directly on the additional AST node kinds. Does that sound right, or are there additional changes here that should be made now?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/28610#discussion_r2728947302


More information about the compiler-dev mailing list