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

IntelliJ IDEA User Guide. Basics of refactoring.

Published in the Random EN group
Refactoring Basics
IntelliJ IDEA предлагает полный набор функций автоматизированного рефакторинга codeа, который приводит к существенному росту производительности при правильном использовании. Эта статья научит вас, How это сделать.
  1. Choice First of all, you don't even have to select the desired code element before refactoring. IntelliJ IDEA is smart enough to figure out which expression you're about to refactor and just ask for confirmation if multiple options are possible. IntelliJ IDEA User Guide.  Basics of refactoring.  - 1
    • Undo Another important thing, IntelliJ IDEA allows you to undo everything, including refactorings, no matter how big those changes are. Just press Ctrl + Z ( Cmd + Z for Mac ), and here is the code as it was before you accidentally messed up a few thousand lines of your program.
    • The IntelliJ IDEA mnemonic recommends using the keyboard instead of the mouse. This has been proven to be faster and will eventually lead to more productive code work. Something that will help you easily work with dialogs and pop-ups using the keyboard is mnemonics - keyboard shortcuts that are automatically assigned to each of the dialog elements. After opening the dialog box, press and hold Alt to have IntelliJ IDEA highlight all available mnemonics. You can then use them by pressing the allocated key while holding down the Alt key to access the required elements. IntelliJ IDEA User Guide.  Basics of refactoring.  - 2
    • String Fragments It's a good time saver to be able to extract part of a string expression using the Extract... refactoring command. Simply select a snippet and refactor to replace all instances of that snippet with the suggested constant or variable. IntelliJ IDEA User Guide.  Basics of refactoring.  - 3
    • Changing the Type of a Variable Note that you can choose the type of a variable when using the Extract command of the refactoring. Press Shift + Tab while editing a variable name, and IntelliJ IDEA will prompt you to select the type of the variable (for example, you can use an interface instead of the class that implements it, or vice versa). IntelliJ IDEA User Guide.  Basics of refactoring.  - 4
    • Invert Boolean One of the simplest but very useful refactoring is Invert Boolean , which inverts expressions with all their semantics and data transformations for any Boolean variable, parameter, field, or method. IntelliJ IDEA User Guide.  Basics of refactoring.  - 5
    • Changing the Type The Type Migration refactoring, as its name suggests, allows you to automatically change the type for any class member, along with all elements that depend on it, such as the types of methods, local variables, parameters, and so on. IntelliJ IDEA User Guide.  Basics of refactoring.  - 6
    • Basic keyboard shortcuts for refactoring Rename: Shift, + F6 Copy a class or file: F5 Move a class or file: F6 Select a constant: Alt + Ctrl + C ( Alt + Cmd + C for Mac ) Select a variable: Alt + Ctrl + V ( Alt + Cmd + V for Mac ) Method highlight: Alt + Ctrl + M ( Alt + Cmd + M for Mac ) Field highlight: Alt + Ctrl + F ( Alt + Cmd + F for Mac ) Parameter highlight: Alt + Ctrl + P ( Alt + Cmd + P for Mac ) Inlining a class or method: Alt + Ctrl + N( Alt + Cmd + N for Mac ) Change signature: Ctrl + F6 ( Cmd + F6 for Mac )
    • Other Useful Refactorings Hoisting Class Members Up / Down Highlighting a Parent Class Highlighting an Interface Converting an Anonymous Class to an Inner Class
    • Redo It If you can't remember the keyboard shortcut for a particular refactoring, 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.  Basics of refactoring.  - 7
      That's all for the basics of refactoring. See the following guides for in-depth study of specific topics. Original article
      Comments
      TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
      GO TO FULL VERSION