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

Maurizio Cimadamore mcimadamore at openjdk.org
Mon Jan 26 19:33:57 UTC 2026


On Mon, 26 Jan 2026 16:38:54 GMT, Liam Miller-Cushon <cushon at openjdk.org> wrote:

>> (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)
>
>> 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!!)

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

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


More information about the compiler-dev mailing list