Bug 419421 - [extract local] Refactoring "Extract local variable" ignores variable scope
Summary: [extract local] Refactoring "Extract local variable" ignores variable scope
Status: CLOSED DUPLICATE of bug 27740
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.4   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-15 03:37 EDT by Uwe Peuker CLA
Modified: 2013-10-15 04:40 EDT (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 Uwe Peuker CLA 2013-10-15 03:37:13 EDT
Demonstrated here (only demonstration, the real code had been more complex):

void testFunction(final boolean check) {

   String data = null;
   if (check) {
      data = "Checked";
      System.err.println(data == null ? "NULL" : data);
   } else {
      data = "Unchecked";
      System.err.println(data == null ? "NULL" : data);
   }
}

Steps:
1. Select "data == null ? "NULL" : data"
2. Choose "Refactor"->"Extract local variable"
3. Will be result in:

void testFunction(final boolean check) {

   String data = null;

   String x = data == null ? "NULL" : data;
   if (check) {
      data = "Checked";
      System.err.println(x);
   } else {
      data = "Unchecked";
      System.err.println(x);
   }
}

The assignment of data will be dismissed in the result printed on "err" stream.
Comment 1 Srikanth Sankaran CLA 2013-10-15 04:14:45 EDT
Move to UI for comment.
Comment 2 Martin Mathew CLA 2013-10-15 04:40:34 EDT

*** This bug has been marked as a duplicate of bug 27740 ***