History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: IDEADEV-13837
Type: New Feature New Feature
Status: Open Open
Priority: Normal Normal
Assignee: Dmitry Jemerov
Reporter: Dave Yost
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
IDEA: Development

New refactoring: Introduce class...

Created: 22 Jan 07 05:07   Updated: 05 Oct 08 22:09
Component/s: Refactoring
Fix Version/s: None

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown

Build: 6,656
Severity: High


 Description  « Hide
With code like this
      layeredPane = new JLayeredPane();
      layeredPane.setPreferredSize(new Dimension(300, 310));
      layeredPane.setBorder(BorderFactory.createTitledBorder(
          "Move the Mouse to Move Duke"));
      layeredPane.addMouseMotionListener(this);
      ....
    }
  }

you should be able to point at layeredPane and ask IDEA to introduce a new class to encapsulate code relating to it.

      layeredPane = new OurLayeredPane(this);
      ....
    }
  }
  
  class OurLayeredPane extends JLayeredPane {
    OurLayeredPane(MouseMotionListener listener) {
      setPreferredSize(new Dimension(300, 310));
      setBorder(BorderFactory.createTitledBorder("Move the Mouse to Move Duke"));
      addMouseMotionListener(listener);
    }
  }

IDEA should do its best to drag along as much code as possible into the new class,
soliciting confirmation on code you might not want to move.

The above extract is from the Java Tutorial LayeredPaneDemo.
This tarball contains the original, my refactoring,
and IDEA project and module files.
http://Yost.com/computers/java/LayeredPaneDemo/LayeredPaneDemoRefactored.tgz



 All   Comments   Work Log   Change History      Sort Order:
Dave Yost - 22 Jan 07 05:40
In this same tutorial file, there is this code:
  private JLabel createColoredLabel(String text, Color color, Point origin) {
    JLabel label = new JLabel(text);
    label.setVerticalAlignment(JLabel.TOP);
    label.setHorizontalAlignment(JLabel.CENTER);
    label.setOpaque(true);
    label.setBackground(color);
    label.setForeground(Color.black);
    label.setBorder(BorderFactory.createLineBorder(Color.black));
    label.setBounds(origin.x, origin.y, 140, 140);
    return label;
  }

If I could point IDEA at this label variable an introduce a new ColoredLabel class, then the next thing I would do would be to inline this method. It would be extra cool if IDEA would incorporate both steps in one.

Just to have this ability to introduce a class would be great, but knowing you guys, you'll also take on all the really hard work of managing interconnections between the new class and the code that uses it, introducing fields, constructor arguments, accessors, etc., to make it really awesome.

Also, maximally reducing the specificity of the type of the variable that refers to an instance of the introduced class would also be nice.

If you can make IDEA able to do most of the work I did in this LayeredPaneDemo file, you will have made an important addition to IDEA's refactoring abilities.

Please remember to give us flexibility to make the introduced class either an inner class, a class in the same file, or a standalone class.


Dave Yost - 12 May 07 11:18
I've made a web page that talks about this.
http://yost.com/computers/java/java-spaghetti/

Dave Yost - 05 Oct 08 21:55
Anything happening with this?