IntelliJ IDEA предлагает полный набор функций автоматизированного рефакторинга codeа, который приводит к существенному росту производительности при правильном использовании. Эта статья научит вас, How это сделать.
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.
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.
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.
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).
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.
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.
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.
That's all for the basics of refactoring. See the following guides for in-depth study of specific topics. Original article
GO TO FULL VERSION