Bug 341375

Summary: [inline] Inline local from reference should allow inlining single occurrence
Product: [Eclipse Project] JDT Reporter: Woody Zenfell III <woodyzenfell+test>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: ASSIGNED --- QA Contact:
Severity: enhancement    
Priority: P3 CC: markus.kell.r, pbenedict
Version: 3.7Keywords: helpwanted
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

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.