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 - API to associate transformed Trees with originals
Summary: API to associate transformed Trees with originals
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 8.0
Hardware: PC Linux
: P1 normal (vote)
Assignee: Svata Dedic
URL:
Keywords: API, API_REVIEW_FAST
Depends on:
Blocks: 239487
  Show dependency tree
 
Reported: 2014-07-01 15:43 UTC by Svata Dedic
Modified: 2014-07-17 02:18 UTC (History)
2 users (show)

See Also:
Issue Type: TASK
Exception Reporter:


Attachments
Proposed changes (53.81 KB, patch)
2014-07-01 15:44 UTC, Svata Dedic
Details | Diff
Example hint code (3.66 KB, patch)
2014-07-01 15:45 UTC, Svata Dedic
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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