4

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

vivekmore
  • 403
  • 5
  • 19
  • 2
    I believe this is what you're looking for. – Haleem Jan 01 '19 at 22:18
  • No, I know how to collapse other methods. 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, 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 with 20 lines of code. – vivekmore Jan 02 '19 at 03:44
  • @basil-bourque - please unmark this as duplicate since it isn't really a duplicate of the question what you've mentioned – vivekmore Jan 02 '19 at 13:30
  • @vivekmore Edit your Question to explain more clearly what your want. I do not understand how collapsing all other methods but one is not the same thing as focusing on just one method of many. Seems like two ways of saying the same thing. – Basil Bourque Jan 02 '19 at 15:30
  • Collapsing would still show the outline/signature of the methods. I'm not interested in that. I'm looking for a way to see just the method content in the editor (no imports, no class definiton, no other methods, nothing but the method) I know I could do that I just cannot find the setting name to enable such a view. Again - I'm not interested in collapsing the remainder code, but entirely hide it and ability to see *only* one method that I am working on. – vivekmore Jan 02 '19 at 15:35
  • Collapsing means showing only this first line of each method, the method declaration line. If you find this distracting then edit your Question to make this distinction, and refer to the other Question explicitly as part of your explanation. If that is not the distinction you mean, then edit your Question to explain as well, as I have no idea of your problem then. – Basil Bourque Jan 02 '19 at 15:37
  • Yes you're right, the collapsed methods (one liners) are indeed distracting. I've further elaborated this in the question. I believe it is not a duplicate anymore. – vivekmore Jan 02 '19 at 16:00
  • @basil-bourque - please unmark this as duplicate since it isn't really a duplicate of the question what you've mentioned – vivekmore Jan 03 '19 at 13:54
  • @BasilBourque - Could you please explain why this is still a marked a duplicate? – vivekmore Jan 06 '19 at 13:37
  • @vivekmore Because the iOS app for Stack Overflow lacks a "Reopen" feature. Had to wait until I had web access. – Basil Bourque Jan 06 '19 at 21:01

1 Answers1

0

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

ana
  • 1