IntelliJ - View a *single* method in a class full of many methods

Viewed 337

Is there a way to just see one method of a class in the IntelliJ IDEA editor and hide everything else, and/or toggle between this and the regular view.

Please note, I'm not looking to fold/collapse other methods, which is certainly a way to minimize getting lost in a large file. I am looking for a way to only view a specific method I'm working on within a class.

e.g. If there is a legacy code where an existing class has 10 long methods (each ~50 lines long), and I'm working on one of them and don't wish to be lost in the 500 lines of code and need to focus on a single method thereby narrowing my view to 50 lines of code.

I do remember a few versions back that this was possible, but am not able to find that setting now.

Further clarifying my question. Consider the method selected in the image below all other methods collapsed

I am interested in a view that'll show just the method like below (with all the java capabilities like code highlighting, refactoring etc., enabled of course): just one method shown

1 Answers

In IntelliJ IDEA 2019.3.3 (Community Edition) there's a fold option 'Fold Selection' that hides even the signature.

  1. Select / highlight the code above the method you want to focus on
  2. Right click > Folding > Fold Selection. Shortcut = cmd + .

It might be in earlier versions but I haven't checked.

Fold selection menu option

Related