Bug 341375 - [inline] Inline local from reference should allow inlining single occurrence
Summary: [inline] Inline local from reference should allow inlining single occurrence
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 enhancement with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2011-03-30 10:58 EDT by Woody Zenfell III CLA
Modified: 2012-01-12 13:50 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Woody Zenfell III CLA 2011-03-30 10:58:46 EDT
Build Identifier: 20110218-0911

The "Inline" refactoring, when initiated at a method call site, asks me whether I want to inline just that call or all calls.  This choice is useful.

The "Inline" refactoring, when initiated at a reference to a local, assumes I want to inline the local to all its references.  This is often not what I want: I often want to inline just that one occurrence.  (Also, it feels inconsistent with the method inlining behavior.)


Reproducible: Always

Steps to Reproduce:
Consider a function like this:

void foo() {
	int bar = 2;

	int baz = bar + 1;
	int bat = bar % 5;
}

If I put my cursor on the reference to "bar" in the initialization of "baz" and invoke the Inline refactoring, it asks "Inline 2 occurrences of local variable 'bar'?".  There is no way for me to inline only this one occurrence.

That is, I would hope to end up with:

void foo() {
	int bar = 2;

	int baz = 2 + 1;
	int bat = bar % 5;
}
Comment 1 Woody Zenfell III CLA 2011-03-30 11:03:02 EDT
Sorry, for added clarity I should have included the 'final' keyword on at least bar's declaration.
Comment 2 Markus Keller CLA 2011-03-30 11:45:44 EDT
Agree that this could be helpful. Inline Local Variable should work the same way as Inline Constant (same UI and same default options, depending on whether a reference or a declaration is selected).
Comment 3 Paul Benedict CLA 2012-01-12 13:50:06 EST
Can this ticket can be expanded to inlining single instances of a constant?

I extracted a string constant in my source file, and then realized this was a mistake. The identical string was being used for 2 different purposes; I needed to go back and inline where the context was different. The strings being equal were just a design coincidence.