Refactoring Code with IntelliJ IDEA
Learn how to rename, extract, move, and change signatures safely in IntelliJ IDEA, review previews and conflicts, and recover from common refactoring problems.
Use IntelliJ IDEA’s refactorings to change code structure while updating related references. Select a symbol or code fragment, invoke the operation that matches the change, review the preview and any conflicts, then inspect the result and run your project’s checks. The documented Windows/Linux defaults include Shift+F6 for Rename, Ctrl+Alt+M for Extract Method, and Ctrl+F6 for Change Signature; keymaps vary, so use Refactor This (Ctrl+Alt+Shift+T) if a shortcut differs.
JetBrains describes refactoring as updating source code without changing application behavior. Refactoring support helps update code and references, but it does not prove the application still behaves as intended. Review changes and run the checks appropriate to your project.
1. Choose the refactoring that matches the change
| Goal | Use | Typical effect |
|---|---|---|
| Change an identifier and its code references | Rename | Renames a symbol, file, directory, package, or module and updates references. |
| Name a cohesive code fragment | Extract Method | Creates a method and replaces the selected fragment with a call. |
| Relocate a member | Move | Changes where a member belongs; moving a static method to another class is a documented workflow. |
| Change parameters or exceptions | Change Signature | Updates a callable contract and can update related calls. |
| Remove an unused declaration | Safe Delete | Checks for source-code references before deletion. |
| Replace a use with its definition | Inline | Inlines a declaration or call where supported. |
Other common actions include Extract Constant, Extract Field, Extract Parameter, and Introduce Variable. Their availability and details depend on the language and selected code context.
2. Open the refactoring action
- Open the file and place the caret on the symbol, or select the expression or statement to refactor. For a file or folder operation, select the item in the Project tool window.
- Press
Ctrl+Alt+Shift+Ton the documented default Windows/Linux keymap to open Refactor This. - Choose the action that describes the intended structural change. A dedicated shortcut may be faster once you know it.
- Complete the dialog or inline prompts. If IntelliJ IDEA presents a preview or conflicts, inspect them before confirming.
- Review the resulting code and run the project’s relevant tests, build, or other checks.
Documented default Windows/Linux shortcuts include Safe Delete (Alt+Delete), Copy/Move (F5/F6), Extract Method (Ctrl+Alt+M), Extract Constant (Ctrl+Alt+C), Extract Field (Ctrl+Alt+F), Extract Parameter (Ctrl+Alt+P), Introduce Variable (Ctrl+Alt+V), Rename (Shift+F6), Inline (Ctrl+Alt+N), and Change Signature (Ctrl+F6). These are defaults, not universal bindings. Your operating system, keymap, or custom shortcut settings may change them.
3. Rename a method and update its usages
- Place the caret on the method name.
- Invoke Rename with
Shift+F6in the documented default keymap, or find Rename in Refactor This. - Enter the new name and inspect the proposed changes. For a public method or a symbol used across files, use the preview when available.
- Review the usages shown in the Find tool window, then confirm the changes you intend to make.
Rename is code-aware and updates code references to the renamed symbol. A text search and replace is not equivalent: it can miss references resolved by the IDE or change unrelated text. Review any proposed non-code occurrences carefully, especially when renaming files, directories, packages, or modules.
4. Extract a method from a code fragment
- Select the statements or expression that form a cohesive unit.
- Invoke Extract Method (
Ctrl+Alt+Mby default on Windows/Linux). - Choose a method name and review the parameters and returned value IntelliJ IDEA infers.
- Confirm, then inspect the new method and the call that replaced the selection.
Extraction depends on how values flow into and out of the selected fragment. IntelliJ IDEA uses a single detected output variable as the return value. The documented limitations include generic-type references and multiple outputs in automatic mode. If the IDE cannot express the selected fragment cleanly, adjust the selection, refactor a smaller piece, or make the necessary changes manually and review them.
5. Change a method signature and update calls
- Place the caret on the method and invoke Change Signature (
Ctrl+F6by default on Windows/Linux). - In the dialog, make the required contract changes: rename the method; add, remove, reorder, or rename parameters; or change exceptions.
- Where applicable, choose to propagate parameters or exceptions through the call hierarchy.
- Review the affected declarations and calls, and resolve any reported conflicts before applying.
- Inspect callers that require values or behavior the IDE cannot infer, then run project checks.
Change Signature can update related call sites, but it cannot decide the correct new argument value for every caller. Method-contract conversions can fail and need manual adjustment. Treat a successful refactoring as a structural edit, then verify the new contract makes sense at each call site.
6. Move a member deliberately
When a method belongs in another class, use Move rather than copying and deleting it by hand. For a static method, the documented workflow lets you choose a destination class and preview the result. Check the destination, changed references, and any conflicts before proceeding. Moving a member changes ownership and may expose design or dependency issues that a mechanical reference update cannot resolve.
7. Delete safely, undo, and review scope
Use Safe Delete to check whether source-code references remain before removing a declaration. A clean result from that check is useful information, not a replacement for reviewing the deletion’s intent and checking dynamic or external uses that may not appear as source references.
If a refactoring produces an unwanted result, JetBrains documents Ctrl+Z as the undo action. Undo promptly, inspect the restored code, and retry with a narrower selection or a more suitable refactoring. For broad changes, review previews and conflict reports before applying; after applying, use version control diff review to understand the complete edit.
8. Troubleshooting
| Symptom | Likely cause | What to do |
|---|---|---|
| The shortcut does nothing or starts another action | Your OS, selected keymap, or custom bindings differ from the documented default. | Open Refactor This with the shortcut shown by your keymap, or locate the action from the IDE menus/action search. Check the configured keymap. |
| The desired refactoring is unavailable | The caret or selection is not on a supported symbol or fragment, or the action is not supported in that language/context. | Place the caret on the declaration, select a valid expression or statement, and check the language-specific action list. |
| Rename preview includes unexpected results | The symbol has a broad usage scope, or similarly named non-code occurrences were included. | Inspect the Find tool window results and deselect unrelated occurrences if offered. Confirm the intended files and references before applying. |
| Extract Method proposes awkward parameters or cannot extract | The selection has complex data flow, multiple outputs, or a documented limitation such as generic-type references in automatic mode. | Reduce the selection to a cohesive fragment, simplify outputs, or extract smaller pieces. Review inferred inputs and output manually. |
| Change Signature reports conflicts or leaves work to do | Callers need values or contract changes the IDE cannot infer, or a method-contract conversion cannot be completed automatically. | Inspect each conflict and call site, supply correct argument values, and make remaining adjustments manually before running checks. |
| Move cannot complete cleanly | The destination or resulting dependencies conflict with the current structure. | Review the destination and preview, resolve conflicts, or move a smaller unit and update dependent design manually. |
| The code changed but behavior is wrong | Reference updates preserve structure mechanically, while intended runtime behavior may depend on details outside the refactoring. | Undo if needed, inspect the diff and changed call sites, correct the logic, and run the project’s tests and build. |
9. Performance, reliability, and cost
Refactoring scope affects how much code IntelliJ IDEA must inspect and update. Renaming or changing a widely used public method can touch many files; previewing and reviewing the diff helps you understand that scope. For a large change, work in manageable steps and keep a recoverable version-control state. Shortcut choice does not change the correctness of a refactoring.
IntelliJ IDEA’s refactoring actions are local development tools. No performance benchmark or completion-time guarantee is asserted here. Review available conflicts, inspect the result, and run project-specific checks because the IDE cannot establish that all runtime, generated, reflective, or external uses are correct. The research material supplies no price comparison relevant to these code refactorings.
Or skip the browser setup
For screenshots of your documentation, app pages, or a page that demonstrates the refactored interface, ScreenshotNeo provides a website screenshot API and MCP server for developers. A single GET request can return PNG, JPEG, WebP, or PDF. See the ScreenshotNeo API documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before the shot. Bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Learn more at ScreenshotNeo, then sign up free.
FAQ
Does IntelliJ IDEA refactoring work only for Java?
No. Available refactorings depend on the language and code context. The cited general workflows include language-specific support; check the relevant action list for the file you are editing.
Should I run tests after a rename?
Yes, if the rename is part of a change you need to validate. The IDE updates recognized references, but checks catch issues beyond that mechanical edit.
Can I undo a refactoring?
JetBrains documents Ctrl+Z for undo. You can also use version control to inspect or restore changes.


