Skip to content

Latest commit

 

History

History
100 lines (82 loc) · 3.08 KB

ij-osx-extract-variable.md

File metadata and controls

100 lines (82 loc) · 3.08 KB

Top => IntelliJ IDEA on Mac OS X

JetBrains IntelliJ IDEA on Mac OS X

Kata: Extract Field

The extract variable refactoring assigns an expression to a variable, typically to improve readability.

Key sequences to practice

  • ⌃⇥ (Ctrl + Tab) - navigate from the project view pane to an editor pane
  • ⌘↖︎ (Command + Home) or fn⌘← (Fn + Command + Left Arrow) or fn↑ (Fn + Up Arrow) - navigate to the top of the file (in editor)
  • ⌥→ (Option + Right Arrow) - move forward by token while selecting
  • ⌥⇧→ (Option + Shift + Right Arrow) - move forward by token
  • ⌘L (Command + L) - go to line number
  • ⌘F (Command + F) - find in file
  • ⌘G (Command + G) - repeat the last find operation
  • ⎋ (Escape) - dismiss "find" dialog
  • ⌘⌥V (Command + Option + V) - open the "extract variable" dialog
  • ⏎ (Return/Enter) - complete action

Keystrokes without explanations

⌃⇥
⌘↖︎ (or fn⌘←)
⌘L
11
⏎
hold ⌥
→
→
→
→
release ⌥
⌘V
↓
↓
isInternetExplorer
⏎
⌥⏎
⏎
↓
↓
↓
hold ⌥
→
→
→
release ⌥
⌘V
↓
↓
isChrome
⏎
⌥⏎
⏎
⌘X
↑
↑
↑
↑
⌘V

Walkthrough of steps with explanations

  1. Open the Java source file, BrowserMadness.java.
  2. If focus is not already in the editor pane for LongConditional.java, press ⌃⇥ (Ctrl + Tab) and select the editor pane for LongConditional.java.
  3. Press ⌘↖︎ (Command + Home) or fn⌘← (Fn + Command + Left Arrow) or fn↑ (Fn + Up Arrow) to navigate to the top of the file (depends on the keyboard).
  4. Press ⌘L (Command + L) to open the "go to line number" dialog.
  5. Enter line number 9.
  6. Press ⏎ (Return/Enter) to move the caret to the specified line number.
  7. Hold ⌥ (Option) and press → (Right Arrow) four times to advance to the token, browser.
  8. Press ⌘V to open the "extract variable" dialog.
  9. Press ↓ (Down Arrow) twice to select the expression that includes the contains method call.
  10. Overtype the default variable name, msie, with isInternetExplorer.
  11. Press ⏎ (Return/Enter) to complete the refactoring.
  12. Press ⌥⏎ (Option + Return/Enter) to open the intentions drop-down.
  13. Press ⏎ (Return/Enter) to accept the suggestion to "extract if".
  14. Press ↓ (Down Arrow) to move to the next line that contains an expression to be extracted.
  15. Hold ⌥ (Option) and press → (Right Arrow) three times to position the caret at the token, browser.
  16. Press ⌘V (Command + V) to open the "extract variable" dialog.
  17. Press ↓ (Down Arrow) twice to select the expression that includes the contains method call.
  18. Overtype the default variable name, msie, with isChrome.
  19. Press ⏎ (Return/Enter) to complete the refactoring.
  20. Press ⌘X to cut the line containing the extracted variable.
  21. Press ↑ (Up Arrow) to position the caret at the start of the line just below the first extracted variable declaration.
  22. Press ⌘V to paste the cut line at that position in the file.

To reverse the changes:

  1. Press ⌘Z (Command + Z) repeatedly until the changes have been reversed. Should be 30 times.