Priority
Normal
Type
Feature 
State
Open 
Assignee
Dmitry Jemerov 
Subsystem
Refactoring 
Affected versions
Fix for
Build
6656
Severity
0
  • Submitted by   Dave Yost
    3 years ago (22 Jan 2007 05:07)
  • Updated by   root
    3 weeks ago (17 Jan 2010 19:40)
  • Jira: IDEA-36434
    (history, comments)

IDEA-36434

New refactoring: Introduce class...

0
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
Comments (3)
 
History (1)
 
Links
 
Dave Yost
  Dave Yost
22 Jan 2007 05:40
(3 years ago)
#permalink
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
  Dave Yost
12 May 2007 11:18
(2 years ago)
#permalink
I've made a web page that talks about this.
http://yost.com/computers/java/java-spaghetti/
Dave Yost
  Dave Yost
05 Oct 2008 21:55
(16 months ago)
#permalink
Anything happening with this?