Transform code

You can prompt Gemini from the code editor for code suggestions to modify, optimize, or add code to your app as follows:

  1. To get the prompt input field, do one of the following from the code editor:
    • Right-click in the code editor and select Gemini > Generate code from the context menu.
    • Highlight code that you want Gemini to modify, right-click in the code editor, and select Gemini > Transform code from the context menu.
    • Press CTRL+\ (Command+\ on macOS).
  2. Prompt Gemini by describing how you want to modify or add to your code and press Enter. After Gemini processes your request, you should see a code diff. With the code diff, you can review and accept only the suggestions you want.
  3. Review the code diff and do one of the following:

    • Further modify the suggested code by clicking Refine and entering a new prompt.
    • Click Accept Changes to add the suggested changes to your code.

Things to try:

  • "Simplify this code"
  • "Make this code idiomatic"
  • "Generate a new function that does <description>"
  • "Add documentation for this code"

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026-03-06 UTC.