Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fold try/catch, switch, for, while and if statements in IntelliJ Idea?

IntelliJ Idea fold if and other statements in JavaScript, but not in Java. How can I get this feature? Maybe you know some plugin or settings?

like image 552
Javasick Avatar asked Dec 30 '15 13:12

Javasick


3 Answers

I don't think that it's possible from Code > Folding or using the icons from the left bar (collapse/expand), but you can do it in a harder way: manually.

E.g.:

  • select the try block
  • Code > Folding > Fold Selection / Remove Section ( Ctrl + Period, where Period is the .)
  • you'll see ... instead of that block
  • now that block also has the icons for collapse/expand on the left bar
like image 155
ROMANIA_engineer Avatar answered Nov 01 '22 11:11

ROMANIA_engineer


In Android Studio, in order to fold a try/catch structure -

  1. In the editor window, select the left brace after try
  2. Type on keyboard CTRL + Shift + .

Now the complete try { .. } block will be folded.

like image 34
user13107 Avatar answered Nov 01 '22 11:11

user13107


If I want to reduce a try / catch section, it doesn't work for me on Intellij CI 2016, under Ubuntu 16.04 OS.

Even with shortcut or using menus.

Using menus Code > Folding > Fold Selection / Remove Section ( Ctrl + Period, where Period is the .), it'll close the entire function where the try/catch block is.

It doesn't work either if I use shortcut Ctrl+ Shift + .

Seems to be a conflict with other shortcut existing on the OS I'm running onto.

like image 36
mariotaz Avatar answered Nov 01 '22 10:11

mariotaz