Community
Participate
Working Groups
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.
*** This bug has been marked as a duplicate of bug 44803 ***