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 250989 - Assign result tries to refactor builder method name
Summary: Assign result tries to refactor builder method name
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 8.1
Hardware: PC Linux
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-07 10:21 UTC by everflux
Modified: 2015-08-11 01:14 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
wrong refactor invocation (282.42 KB, video/webm)
2015-03-07 10:21 UTC, everflux
Details

Note You need to log in before you can comment on or make changes to this bug.
Description everflux 2015-03-07 10:21:11 UTC
Created attachment 152461 [details]
wrong refactor invocation

Product Version: NetBeans IDE Dev (Build 201503060001)
Java: 1.8.0_40; Java HotSpot(TM) 64-Bit Server VM 25.40-b25
Runtime: Java(TM) SE Runtime Environment 1.8.0_40-b25
System: Linux version 3.16.0-31-generic running on amd64; UTF-8; en_US (nb)

Given (rest assured library)

new RequestSpecBuilder().setContentType("application/json").build();
new ResponseSpecBuilder().expectContentType("application/json").build(); <CURSOR>

When invocing alt-enter, 'assign return value to new variable' the 'build()' method name in the line above is tried to be refactored.

See attached video for details.
Comment 1 everflux 2015-03-07 10:24:57 UTC
This does not happen when using the hint in the upper line.
When the upper line has already a return variable and trying on the lower line the error happens as well.
Comment 2 Svata Dedic 2015-08-06 13:24:13 UTC
The culprit is the auto-import feature during code generation; imports are processed after the rewritten trees are processed and their positions stored. But imports textually precede the rewritten text, so positions should be shifted (they are not). Similar situations may occur when replacing strings in comments.
Reordering the processing will not help: diffs of rewritten trees are computed against original source, NOT source after import mods.

positions read from tree tags were not correct in such situations - and in the case of assign return value hint led to (attempt of) selection of an incorrect identifier (build() method name instead of build variable)

cc:ing refactoring owner - implied defects may be reported against refactoring module.

will be fixed as jet-main#9465ab93e9cc
Comment 3 Quality Engineering 2015-08-11 01:14:36 UTC
Integrated into 'main-silver', will be available in build *201508110002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/9465ab93e9cc
User: Svata Dedic <sdedic@netbeans.org>
Log: #250989: tagged tree offsets adjusted to respect autoimports and textual changes