Example
| Before | After |
|---|---|
public class A { private void drawEdge(Graphics g, float edgeWidth, int x1, int x2, int y1, int y2) { final Graphics2D g2d = (Graphics2D) g; g2d.setStroke(new BasicStroke(edgeWidth)); g.drawLine(x1, y1, x2, y2); } } |
public class A { private void drawEdge(Edge edge, Graphics g) { final Graphics2D g2d = (Graphics2D) g; g2d.setStroke(new BasicStroke(edge.getEdgeWidth())); g.drawLine(edge.getX1(), edge.getY1(), edge.getX2(), edge.getY2()); } } public class Edge { private final float edgeWidth; private final int x1; ... public Edge(float edgeWidth, int x1, int x2, int y1, int y2) { this.edgeWidth = edgeWidth; this.x1 = x1; ... } public float getEdgeWidth() { return edgeWidth; } public int getX1() { return x1; } ... } |
- Select the desired method. To do that, either open the class in question for editing, and position the caret at the method, click such method in the Structure view, or select it in the UML class diagram.
- Choose on the main menu or on the context menu of the selection.
- In the Extract Parameter Object dialog box:
- In the Parameter Class section, specify whether you want to create a new class, or use an existing one to wrap the parameters.
- In the Parameters to extract list, check the parameters you want include in the new class.
- Click Preview to make IntelliJ IDEA search for usages of the selected fields or methods,
and display the refactoring preview results in the Find tool window.
In the preview, you can include usages into refactoring or skip them. Click Do Refactor to apply
refactoring to the selected usages.
If you do not want to view usages, click Refactor. In this case, the usages will be changed immediately.
Note
The Refactoring preview window may appear anyway, if the files to be affected are read-only.

