Refactor Code with AI Assistant

How AI Assistant can help you refactor code.

The Problem

Did you know that JetBrains AI Assistant can refactor code for you? You know, just in case you want to change the semantics?

The Solution

You can invoke Context Actions ⌥⏎ (macOS) / Alt+Enter (Windows/Linux) and then select AI Actions > Suggest Refactoring. JetBrains AI Assistant will then offer some suggestions, and code snippets, on how you could refactor your code.

refactor-menu.png

And if you don’t like the suggestion. You can keep or discard aspects of it and iterate until you get something you’re happy with. Perhaps we don’t want to use Java Streams. JetBrains AI Assistant will iterate on the previous suggestion, and give you some new ideas for refactoring your code!

without-streams.png

If you like the suggestion, you can press See Diff and Apply and then Accept All.

see-diff-apply.png

It works with any code, like this code. Once again, invoke Context Actions ⌥⏎ (macOS) / Alt+Enter (Windows/Linux) and then select AI Actions > Refactoring:

c-sharp-code.png

You can also just ask JetBrains AI Assistant to help you with some refactoring:

ask-ai-assistant.png

JetBrains AI Assistant refactoring, because sometimes we want to change things!


Related Resources

Introducing Mellum: JetBrains' New LLM Built for Developers
Introducing Mellum: JetBrains' New LLM Built for Developers
JetBrains launches Mellum, a proprietary large language model (LLM) specifically designed to assist software developers.
Prompt AI Directly in the Editor
Prompt AI Directly in the Editor
With PyCharm, you now have the support of AI Assistant at your fingertips. You can interact with it right where you do most of your work – in the editor.
Streamline Your Workflow in IntelliJ IDEA's Database Tools With AI Assistant
Streamline Your Workflow in IntelliJ IDEA's Database Tools With AI Assistant
Use Assistant’s capabilities within Database Tools for more efficient data querying and handling.