简体   繁体   中英

How to remove surrounding code block in IntelliJ IDEA?

In IntelliJ IDEA, is there shortcut to remove surrounding code block (control structure) around selection in a context aware manner? In this example, I would like to remove the outer if block.

Transform this

if (foo) { // Unnecessary if block

  a();

  if (bar) {
    b();
  } else {
    c();
  }
} else {
  d();
}

to this

a();

if (bar) {
  b();
} else {
  c();
}

Use the Code | Unwrap/Remove Code | Unwrap/Remove action ( Cmd + Shift + Delete on Mac or Ctrl + Shift + Delete on Windows). It will popup a list where you can select which surrounding structure you want to remove.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM