RFR: 8372948: Store end positions directly in JCTree

Jonathan Gibbons jjg3 at pobox.com
Wed Dec 3 20:02:46 UTC 2025



On Wed, Dec 3, 2025, at 11:56 AM, Jonathan Gibbons wrote:
> 
> 
> On Wed, Dec 3, 2025, at 11:13 AM, Maurizio Cimadamore wrote:
>> Perhaps with some keywords like `break`, `continue`, ... we might be able to infer the end pos (given it's just start pos + number of chars in the keyword). But not sure how much we are willing to bend the code for special cases like these?
> 
> Doesn't the endPos records the position of the semicolon, not the end of the keyword?
> 
> -- Jon

A useful heuristic is to check the `visit...` methods in `JCPretty`.   If there is a call to `print(String)` or `print(char)` before the `} catch (IOException` then the node should have an endPos.  In other words, an endPos is required for all nodes that end in a specific lexical token.

For example, compare this from `visitLambda`


    printExpr(tree.body);
} catch (IOException e) {

and this from `visitParens`


    print(')');
} catch (IOException e) {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20251203/d9402e9d/attachment.htm>


More information about the compiler-dev mailing list