JDK-8031725 : No way to detect synthetic com.sun.source.tree.Tree's
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7u17
  • Priority: P4
  • Status: Resolved
  • Resolution: Won't Fix
  • Submitted: 2014-01-14
  • Updated: 2021-12-16
  • Resolved: 2021-12-14
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
Javac can create several synthetic com.sun.source.tree.Tree's. Examples are the default constructor and the implicit 'super()' call in constructors, and there might be others. In addition, you can't recognize these trees as synthetic by checking their start offset. The default constructor has a '0' start offset, and the implicit 'super()' call has a start offset equal to the method body start offset.

Request to be able to recognize synthetic constructs. Minimally these constructs should return -1 as their start offset, but preferably there should be a flag.


Comments
It isn't an unreasonable request to have some marker for synthetic and mandated trees generated by javac; see JDK-8250919.
16-12-2021

Just to keep track, I see that NewClassTree expressions have ClassTrees that have a synthetic interface with -1 for the start and end offset.
14-01-2014

Note: there is a proposal to make the trees adhere to the source code more precisely (JDK-8024098), which would remove the need for some (or all) of the synthetic trees, which would alleviate (or remove) the need for the detection.
14-01-2014

There is also a synthetic NewClassTree under enum constants with a start offset equals to the start offset of the enum constant and an end offset of -1.
14-01-2014

Another synthetic tree is the type reference of an enum constant. The start offset of that type reference is the same as the start offset of the enum constant, and the end offset is -1.
14-01-2014