JavaRush /Java Blog /Random EN /IntelliJ IDEA User Guide. Refactoring Basics.
theGrass
Level 24
Саратов

IntelliJ IDEA User Guide. Refactoring Basics.

Published in the Random EN group
Refactoring Basics
IntelliJ IDEA предлагает полный набор функций автоматизированного рефакторинга codeа, который приводит к существенному росту производительности при правильном использовании. Эта статья научит вас, How это сделать.
  1. Selection First of all, you don't even have to select the desired code element before refactoring. IntelliJ IDEA is smart enough to understand which expression you are about to refactor and simply asks for confirmation if multiple options are possible. IntelliJ IDEA User Guide.  Refactoring Basics.  - 1
    • Undo Another important thing is that IntelliJ IDEA allows you to undo everything, including refactorings, no matter how big the changes are. Just press Ctrl + Z ( Cmd + Z for Mac ), and here is the code as it was before you accidentally messed up several thousand lines of your program.
    • The IntelliJ IDEA mnemonic recommends using a keyboard instead of a mouse. This has been proven to be faster and will ultimately lead to more productive code work. What will help you easily work with dialog and pop-up windows using the keyboard is mnemonics - keyboard shortcuts that are automatically assigned to each of the dialog elements. Once the dialog box opens, press and hold Alt to have IntelliJ IDEA highlight all available mnemonics. You can then use them by clicking on the highlighted key while holding down the Alt key to access the required elements. IntelliJ IDEA User Guide.  Refactoring Basics.  - 2
    • String Fragments A great time saver is the ability to extract part of a string expression using the Extract... refactoring command. Simply select a snippet and apply refactoring to replace all uses of that snippet with the suggested constant or variable. IntelliJ IDEA User Guide.  Refactoring Basics.  - 3
    • Changing the type of a variable Note that you can select the type of a variable when using the Extract refactoring command. Press Shift + Tab when editing a variable name, and IntelliJ IDEA will prompt you to choose the variable type (for example, you can use an interface instead of the class that implements it, or vice versa). IntelliJ IDEA User Guide.  Refactoring Basics.  - 4
    • Invert Boolean One of the simplest, but very useful refactorings is Invert Boolean , which inverts expressions with all their semantics and data conversion for any Boolean variable, parameter, field or method. IntelliJ IDEA User Guide.  Refactoring Basics.  - 5
    • Type Migration The Type Migration refactoring technique, as its name suggests, allows you to automatically change the type of any member of a class, along with all its dependent elements, such as the types of methods, local variables, parameters, and so on. IntelliJ IDEA User Guide.  Refactoring Basics.  - 6
    • Basic keyboard shortcuts for refactoring Rename: Shift, + F6 Copy a class or file: F5 Move a class or file: F6 Highlight a constant: Alt + Ctrl + C ( Alt + Cmd + C for Mac ) Highlight a variable: Alt + Ctrl + V ( Alt + Cmd + V for Mac ) Method selection: Alt + Ctrl + M ( Alt + Cmd + M for Mac ) Field selection: Alt + Ctrl + F ( Alt + Cmd + F for Mac ) Parameter selection: Alt + Ctrl + P ( Alt + Cmd + P for Mac ) Inlining a class or method: Alt + Ctrl + N ( Alt + Cmd + N for Mac ) Changing signature: Ctrl + F6 ( Cmd + F6 for Mac )
    • Other useful ways to refactor Move class members up/down Split a parent class Split an interface Convert an anonymous class to an inner class
    • Refactor It If you can't remember the keyboard shortcut for a specific refactor, or you're just not sure what to do next, just use "Refactor This Action" by pressing Ctrl + Shift, + Alt + T ( Cmd + Shift, + Alt + T ) . You will see a list of refactorings available in the current context. IntelliJ IDEA User Guide.  Refactoring Basics.  - 7
      That's it for the basics of refactoring. See the following guides for in-depth exploration of specific topics. Original article
      Comments
      TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
      GO TO FULL VERSION