Bug 194139 - [introduce parameter] not working in some circumstance
Summary: [introduce parameter] not working in some circumstance
Status: RESOLVED DUPLICATE of bug 44803
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC Linux-GTK
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-06-24 12:08 EDT by Claudio Nieder CLA
Modified: 2007-06-25 04:34 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Claudio Nieder CLA 2007-06-24 12:08:38 EDT
This is the starting point:

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;

public class Test
{
 private static final ImageIcon icon=
  new ImageIcon();
 private static final ActionListener action=new ActionListener() {
  public void actionPerformed(ActionEvent eArg)
  {
   //
  }
 };
 
 private static void test()
 {
  JButton b=new JButton(icon);
  b.addActionListener(action);
 }
}

If I put within the method test the cursor on "action" and open the context menu I can select Refactor->Introduce Parameter. A dialog open up which offers me to transform test() into test(Action Listener action). GOOD.

If I put within the method test the cursor on "icon" and open the context menu I can also select Refactor->Introduce Parameter. But instead of the dialog I get the message saying "Cannot extract this name - try selecting the whole instance creation expression. BAD

I would expect the same behaviour in the second case as in the first case.

As a work around I can do this:

Point cursor to "icon" and Refactor->Extract local variable, which transforms test into

 private static void test()
 {
  ImageIcon icon2=icon;
  JButton b=new JButton(icon2);
  b.addActionListener(action);
 }

next point the cursor to icon and Refactor->Introduce Parameter and finally point the cursor to "icon2" and Refactor->Inline.
Comment 1 Martin Aeschlimann CLA 2007-06-25 04:34:40 EDT

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