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 242251 - [6.9.1-7.4] Refactor/Find Usages in case statements +
Summary: [6.9.1-7.4] Refactor/Find Usages in case statements +
Status: RESOLVED FIXED
Alias: None
Product: ruby
Classification: Unclassified
Component: Refactoring (show other bugs)
Version: 7.4
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: issues@ruby
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-24 01:05 UTC by AltairPL
Modified: 2014-04-24 20:22 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description AltairPL 2014-02-24 01:05:01 UTC
First of all - be easy on me - it's my first issue report, but I think I did everything as I should.

Trying to Refactor/Find Usages of (i.e.) variable name used inside case statement causes that occurrence to be found multiple times, e.g searching for 'value' in code:

case count
when 1 then @value = 1  # will be found 1 time
when 2 then @value = 2  # will be found 2 times
when 3 then @value = 3  # will be found 3 times
when 4 then @value = 4  # will be found 4 times
end

It's most annoying when renaming, as one occurrence will be multiplied few times (most of the time Refactor preview won't be displayed when it's happening), i.e. when renaming 'value' to 'value2' line:
when 4 then @value = 4
will be changed to:
when 4 then @value2@value2@value2@value2 = 4  # in NB 6.9.1
when 4 then @@value2@value2@value2@value2 = 4 # in NB 7.4

I've just noticed when testing this that in 7.4 extra @ is added in front of every renamed occurrence (doesn't matter if it's in case statement or not), so it makes things even worse - should I make another issue for this? or rename this one?

Thanks in advance!
Comment 1 enebo 2014-02-24 14:20:48 UTC
Ah no this is reproduction is great and it probably won't be super difficult to fix.   At least it looks like some problem where we must be appending the new name for every occurrence found.
Comment 2 AltairPL 2014-02-25 21:57:12 UTC
found two very similar issues - probably the same as 'case' one, hence no new issue:

looking for $game_switches:

@common_events[id] = ($game_switches[common_event.switch_id] ? Interpreter.new : nil) if common_event.trigger == 2 # found twice - same for normal if statements and if modifier - don't know if always or only in certain conditions

$game_switches[switch_id] = !$game_switches[switch_id] # left side found once, right side found twice
Comment 3 enebo 2014-04-24 20:22:53 UTC
Fixed in last round of fixed for NB 8 support.  This actually had two issues.  The first was any variables with a sigil were ignoring the sigil (@foo was ignoring @) but during replace was replacing the regiion with the sigil.

The second issue was the Ruby AST tree will have multiple copies of the same node in various cases like when statements (which is odd in its own right but it is what it is).  The refactoring code would perform this replacement one per each time it found the occurrence.  Each when would end up duplicating part of the case/when structure so each when would find the same variable n-when times.  This was addresses by sorting the occurrences and removing duplicates.  I strongly suspect older NB APIs did this for us and then removed that ability.