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.

Bug 245348

Summary: API to associate transformed Trees with originals
Product: java Reporter: Svata Dedic <sdedic>
Component: SourceAssignee: Svata Dedic <sdedic>
Status: RESOLVED FIXED    
Severity: normal CC: Jachym_Vojtek, tzezula
Priority: P1 Keywords: API, API_REVIEW_FAST
Version: 8.0   
Hardware: PC   
OS: Linux   
Issue Type: TASK Exception Reporter:
Bug Depends on:    
Bug Blocks: 239487    
Attachments: Proposed changes
Example hint code

Description Svata Dedic 2014-07-01 15:43:16 UTC
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.
Comment 1 Svata Dedic 2014-07-01 15:44:53 UTC
Created attachment 147840 [details]
Proposed changes

Diff of proposed changes
Comment 2 Svata Dedic 2014-07-01 15:45:25 UTC
Created attachment 147841 [details]
Example hint code

Changes to the if-to-switch hint that use the new API
Comment 3 Svata Dedic 2014-07-10 13:44:10 UTC
Implemented in jet-main#4103f0b6f88e
Comment 4 Quality Engineering 2014-07-17 02:18:26 UTC
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