This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
For hints I need an API which a hint code could use to hint the code generator that a Tree ("n") is a replacement, or an equivalent of, an old Tree ("o"). The code generator could then retain relevant comments or whitespaces or even move the lexical sugar to the replacement node. The proposed patch provides such API and implements a default behaviour that WorkingCopy.rewrite() establishes such association between the old and new Tree. In addition, comments form Trees that are going to be removed form the source code are collected around the nearest parent Tree node which survives the transformation. This way, if the calling code does nothing, just rewrite()s some Trees, the code generator automatically attaches all the comments from the replaced subtree to the substituted Tree node - Trees which are copied to the result, although at different positions, should retain their surrounding comments. A code which creates a completely new code can hint the code generator to move comments to the new content, to a place more or less relevant to the original code. See the attached sample if-to-switch transformation hint.
Created attachment 147840 [details] Proposed changes Diff of proposed changes
Created attachment 147841 [details] Example hint code Changes to the if-to-switch hint that use the new API
Implemented in jet-main#4103f0b6f88e
Integrated into 'main-silver', will be available in build *201407170001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-silver/rev/4103f0b6f88e User: Svata Dedic <sdedic@netbeans.org> Log: #245348: added API to make relationships between old and transformed nodes